Re: genuine help needed to speed up minimax algorithm!

2012-08-18 Thread Michael Gardner
If you haven't already, start by eliminating reflection warnings[1].

As for pmap, it's unfortunately useless. You could roll your own using e.g. 
Java's thread pools, or you could wait for the new reducers library[2]. 
Reducers should offer not only useful parallelism, but also better performance 
across-the-board compared to clojure's sequence functions (since they don't pay 
the performance price of laziness).

[1] http://clojuredocs.org/clojure_core/clojure.core/*warn-on-reflection*
[2] 
http://clojure.com/blog/2012/05/08/reducers-a-library-and-model-for-collection-processing.html

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: genuine help needed to speed up minimax algorithm!

2012-08-18 Thread Jim - FooBar();

On 18/08/12 13:13, Michael Gardner wrote:

If you haven't already, start by eliminating reflection warnings[1].

As for pmap, it's unfortunately useless. You could roll your own using e.g. 
Java's thread pools, or you could wait for the new reducers library[2]. 
Reducers should offer not only useful parallelism, but also better performance 
across-the-board compared to clojure's sequence functions (since they don't pay 
the performance price of laziness).

[1] http://clojuredocs.org/clojure_core/clojure.core/*warn-on-reflection*
[2] 
http://clojure.com/blog/2012/05/08/reducers-a-library-and-model-for-collection-processing.html



The only reflection warnings I get are from core.logic and seesaw but 
these are used/required in other namespaces...I get not warnings from my 
own code apart from a couple of cases where I'm calling Math/abs but 
that is easy to fix.


As far as pmap goes, I originally thought of starting a new future for 
each starting branch but that is what pmap does essentially, so it 
looked very handy at first... I don't see how reducers can help here 
because I'm not reducing anything really. actually comparing the scores 
of the leaf nodes  is not so expensive as it sounds (at least I can't 
imagine why it would be). The trick would be to start branching in 
parallel wouldn't it? So, let's assume you've got a brand new board. 
White moves first and he has 20 potential moves to explore (8x2-pawns + 
2x2 knights). There is a lot of work to be done in each branch so 
assigning a future to each, sounds reasonable. However if that was 
actually happening I should be seeing  all 4 cores working non-stop!


I just wish pmap  worked!

Jim



--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


doubt about clojure.test output

2012-08-18 Thread Vincent
Dear ,

I am using clojure.test  for test

in one 'deftest , i had used 3   'is   function to assert
and in another 'deftest , i had used 5  'is function to assert

It ran all test with sucess , but output is 

Ran 4 tests containing 12 assertions 

How come 12 ? 

thanks in advance
Vincent

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: genuine help needed to speed up minimax algorithm!

2012-08-18 Thread Michael Gardner
On Aug 18, 2012, at 7:27 AM, Jim - FooBar(); wrote:

> As far as pmap goes, I originally thought of starting a new future for each 
> starting branch but that is what pmap does essentially, so it looked very 
> handy at first...

Yes, pmap is essentially a trap in that it looks like the perfect tool for some 
light parallelism, but it works so poorly in the vast majority of cases that 
it's basically useless. There have been a few discussions on this list about it 
in the past.

> I don't see how reducers can help here because I'm not reducing anything 
> really.

You should read the link I posted about reducers. It's good stuff.

> I just wish pmap  worked!

So do I. Until the reducers library is ready, you could try something like this 
(no guarantees that this is an optimal implementation!):

(defn with-thread-pool* [num-threads f]
  (let [pool (java.util.concurrent.Executors/newFixedThreadPool num-threads)]
(try (f pool)
  (finally
(when pool (.shutdown pool))

(defmacro with-thread-pool [[name num-threads] & body]
  `(with-thread-pool* ~num-threads (fn [~name] ~@body)))

(defn pmap-pool [f coll]
  (with-thread-pool [pool (.. Runtime getRuntime availableProcessors)]
(doall
  (map #(.get %)
(.invokeAll pool
  (map (partial partial f)
coll))

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Countdown numbers game in clojure.core.logic

2012-08-18 Thread David Powell
I just had a go of solving the Numbers Game from the UK gameshow Countdown
[1] in clojure.core.logic.

https://gist.github.com/3374505

It works, but it is a bit slow.

Anybody got any ideas on better approaches?

[1] http://en.wikipedia.org/wiki/Countdown_(game_show)#Numbers_round

-- 
Dave

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: doubt about clojure.test output

2012-08-18 Thread Chris Ford
Would you be able to post some code demonstrating what you have observed,
perhaps reduced to the minimal case?

Cheers,

Chris

On 18 August 2012 13:49, Vincent  wrote:

> Dear ,
>
> I am using clojure.test  for test
>
> in one 'deftest , i had used 3   'is   function to assert
> and in another 'deftest , i had used 5  'is function to assert
>
> It ran all test with sucess , but output is
>
> Ran 4 tests containing 12 assertions
>
> How come 12 ?
>
> thanks in advance
> Vincent
>
>  --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with
> your first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: deployment

2012-08-18 Thread Joshua Ballanco
On Fri, Aug 17, 2012 at 05:29:50PM -0700, George Oliver wrote:
> hi, 
> 
> I'm a Clojure beginner working on a web project and starting to think about 
> deployment. Currently I host my project in a local VM and have a small VPS 
> for public testing. Looking down the road I'd like a more flexible hosting 
> solution. 
> 
> It seems like the hosting landscape is changing fast so I'd like to know -- 
> how do you deploy your projects 'now'?
> 
> So far I've found stuff like:
> 
> * A continuum of Clojure support from cloud providers, with some free tiers 
> at AWS, Heroku, Openshift, etc.
> * tools like lein-beanstalk for hosting apps on Elastic Beanstalk
> * libraries like appengine-magic for hosting on GAE
> * libraries like pallet for abstracting deployment to multiple cloud 
> providers
> * many more tools depending on how much 'more Java' you're willing to 
> incorporate into your project, for example deploying a WAR in a Tomcat 
> container (not even sure I have the lingo right there! :) )
> * combining these tools and libraries with CI tools such as Jenkins for a 
> complete automatic develop -> build -> deploy solution. 
> 
> From what I've seen, and given that (a) I have a small project (probably 
> not more than 5k users eventually) and (b) I'm not a professional 
> programmer, but (c) I'd like to manage this in a professional way, it seems 
> like a strategy could be:
> 
> 1. use a tool like lein-beanstalk for public deployment and use simple 
> scripts for building
> 2. in the meantime get familiar with pallet for more flexibility in the 
> future
> 3. eventually deploy using pallet
> 4. at this point learn a CI tool to fully automate the process. 
> 
> What do you think?
> 
> 
> thanks, George
> 
> -- 
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en

I can't speak of specific experience, since we're still in the early
development phase, but we have had an outstanding experience with
Torquebox and so have been looking at it's Clojure cousin Immutant
(http://immutant.org/). At the very least, I think it's worth adding to
your list.

- Josh


-- 
Joshua Ballanco

ELC Technologies™
1771 NW Pettygrove Street, Suite 140
Portland, OR, 97209
jballa...@elctech.com

P +1 866.863.7365
F +1 877.658.6313
M +1 646.463.2673
T +90 533.085.5773

http://www.elctech.com

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: genuine help needed to speed up minimax algorithm!

2012-08-18 Thread Jim - FooBar();

On 18/08/12 13:57, Michael Gardner wrote:

  Until the reducers library is ready, you could try something like this (no 
guarantees that this is an optimal implementation!):

(defn with-thread-pool* [num-threads f]
   (let [pool (java.util.concurrent.Executors/newFixedThreadPool num-threads)]
 (try (f pool)
   (finally
 (when pool (.shutdown pool))

(defmacro with-thread-pool [[name num-threads] & body]
   `(with-thread-pool* ~num-threads (fn [~name] ~@body)))

(defn pmap-pool [f coll]
   (with-thread-pool [pool (.. Runtime getRuntime availableProcessors)]
 (doall
   (map #(.get %)
 (.invokeAll pool
   (map (partial partial f)
 coll))



Hi Michael,

Unfortunately I get exactly the same performance with pmap when using 
the above code... and again 2 of my cpus are sitting around waiting!
If use pmap or map-pool on all levels i get almost 100% utilisation of 
cpu but nothing useful happens!!! anyway, I'll have a look at reducers!

thanks for the snippet anyway!

Jim

--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: genuine help needed to speed up minimax algorithm!

2012-08-18 Thread Jim - FooBar();

JESUS CHRIST!
What the hell just happened? I used clojure 1.5 alpha 3 that has the new 
reducers and now i get back the same result in 3 seconds
HOW ON EARTH IS THAT POSSIBLE? I mean i've watched the videos but i 
would never expect so much performance increase!!! what is happening? Is 
my algorithm completely wrong? this is scary stuff...


the bad news is that i always get the same answer regardless of the 
depth...also something suspicious is the fact the no matter the depth 
the r/map returns in constant time! something smells here!



Jim












On 18/08/12 19:24, Jim - FooBar(); wrote:

On 18/08/12 13:57, Michael Gardner wrote:
  Until the reducers library is ready, you could try something like 
this (no guarantees that this is an optimal implementation!):


(defn with-thread-pool* [num-threads f]
   (let [pool (java.util.concurrent.Executors/newFixedThreadPool 
num-threads)]

 (try (f pool)
   (finally
 (when pool (.shutdown pool))

(defmacro with-thread-pool [[name num-threads] & body]
   `(with-thread-pool* ~num-threads (fn [~name] ~@body)))

(defn pmap-pool [f coll]
   (with-thread-pool [pool (.. Runtime getRuntime availableProcessors)]
 (doall
   (map #(.get %)
 (.invokeAll pool
   (map (partial partial f)
 coll))



Hi Michael,

Unfortunately I get exactly the same performance with pmap when using 
the above code... and again 2 of my cpus are sitting around waiting!
If use pmap or map-pool on all levels i get almost 100% utilisation of 
cpu but nothing useful happens!!! anyway, I'll have a look at reducers!

thanks for the snippet anyway!

Jim


--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: doubt about clojure.test output

2012-08-18 Thread Moritz Ulrich
Is one of the asserts in some kind of loop or recursion?

On Sat, Aug 18, 2012 at 2:49 PM, Vincent  wrote:
> Dear ,
>
> I am using clojure.test  for test
>
> in one 'deftest , i had used 3   'is   function to assert
> and in another 'deftest , i had used 5  'is function to assert
>
> It ran all test with sucess , but output is
>
> Ran 4 tests containing 12 assertions
>
> How come 12 ?
>
> thanks in advance
> Vincent
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with your
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: doubt about clojure.test output

2012-08-18 Thread Haim Ashkenazi
Hi Vencent,

On Sat, Aug 18, 2012 at 3:49 PM, Vincent  wrote:

> Dear ,
>
> I am using clojure.test  for test
>
> in one 'deftest , i had used 3   'is   function to assert
> and in another 'deftest , i had used 5  'is function to assert
>
> It ran all test with sucess , but output is
>
> Ran 4 tests containing 12 assertions
>
> How come 12 ?
>
I had a case where I used Noir test helper (has-status) inside 'is'
functions without realizing that has-status in itself uses assertions. The
output showed me twice the assertions i wrote. The solutions was to not
wrap has-status with an 'is' function.

HTH

>
> thanks in advance
> Vincent
>
>
-- 
Haim

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: Countdown numbers game in clojure.core.logic

2012-08-18 Thread David Nolen
On Sat, Aug 18, 2012 at 10:36 AM, David Powell  wrote:
>
> I just had a go of solving the Numbers Game from the UK gameshow Countdown
> [1] in clojure.core.logic.
>
> https://gist.github.com/3374505
>
> It works, but it is a bit slow.
>
> Anybody got any ideas on better approaches?
>
> [1] http://en.wikipedia.org/wiki/Countdown_(game_show)#Numbers_round
>
> --
> Dave

I don't have time to offer a better solution but your approach seems
pretty brute force. You need to encode some knowledge into the game.
First I would eliminate actually searching over * and /. This because
it seems to me that it would be useful to know ahead of time what
other numbers can be produced from the cards - for example values
between the large card and 10. I would also continue to use the larger
card (and numbers derived from it) until we are close to the solution.

Hope this helps,
David

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


help needed to use reducers and monoid

2012-08-18 Thread Jim - FooBar();

Hi all,

so I was playing with the reducers library today and I think I've 
identified the critical spot where my code can be parallelized. after 
all i am building a tree and i am using a map that nests. According to 
all the posts this is ideal situation for reducing...anyway, assuming 
I'm correct in thinking that the following line is culprit,


(->> (:children tree)   ;;a lazy-seq of maps where :children is a 
lazy-seq of maps etc

(apply max-key (evaluator eval-fn))
(:node))  ;;return the best state

I thought about doing this:

(->> (:children tree)
   (vec)  ;;make it a vector so it it parallelisable
   (r/fold #(max-key (evaluator eval-fn) %))
   (:node))

but that wont work cos I'm not supplying a combing fn and the reducing 
one is used instead, which cannot take 0 args. Now, obviously I need to 
use r/monoid to construct a combining fn but i don't understand what to 
pass in as an identity value ("ctor") to be called with no args at the 
bottom. So my question is foldable! (2-fold):


1. How do I construct a combining fn out of 'max-key'  and is there an
   idiom or a pattern for doing so?
2. Since the docs say that r/fold will only work in parallel for
   tree-like structures like maps and vectors, I've passing the
   lazy-seq through 'vec'. Does that make any sense whatsoever or will
   the entire thing be realized before it ever reaches r/fold?


Any insights are very much welcome...I am just starting playing around 
with reducers but it seems like the situation I'm in is the perfect 
candidate for this sort of thing and I want to know more! Also without 
this, my chess minimax searching is hopeless!



Jim

--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en