[Haskell-cafe] statistics package and randomness

2009-10-12 Thread Michael Mossey
I'm trying to learn how to use randomness in Haskell and it seems very 
non-straightforward and complex. I could do a lot of things using 'split' 
from System.Random, but apparently it's broken. There is the statistics 
package here:


http://hackage.haskell.org/package/statistics

Is this a better solution?

It uses the ST monad in the RandomVariate module. Can someone point me to a 
tutorial explaining ST, and/or a tutorial in the RandomVariate module?


Pseudorandomness seems like one case where it would just be a hell of a lot 
simpler to have a global generator--never split the state. Is the ST monad 
some way to accomplish this?


Thanks,
Mike


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] statistics package and randomness

2009-10-12 Thread mf-hcafe-15c311f0c


i'll try a very non-technical explanation that has worked for me so
far.  (is it correct?  does it make sense?)

IO and ST are quite similar.  the difference is that whereas IO gives
you a concept of time in the world surrounding your code, ST lets you
create a little bubble inside your code in which you can maintain
state, while the bubble as a whole acts all pure and lazy.  for
example, if you want to implement an algorithm that writes to and
reads from a matrix, you use ST: you want to control the order in
which you read from and write to it, but not the order in which access
events to that data structure mixes with user interaction events.

-matthias



On Mon, Oct 12, 2009 at 12:25:43AM -0700, Michael Mossey wrote:
 To: Haskell Cafe Haskell-Cafe@haskell.org
 Cc: 
 From: Michael Mossey m...@alumni.caltech.edu
 Date: Mon, 12 Oct 2009 00:25:43 -0700
 Subject: [Haskell-cafe] statistics package and randomness
 
 I'm trying to learn how to use randomness in Haskell and it seems very  
 non-straightforward and complex. I could do a lot of things using 'split' 
 from System.Random, but apparently it's broken. There is the statistics  
 package here:

 http://hackage.haskell.org/package/statistics

 Is this a better solution?

 It uses the ST monad in the RandomVariate module. Can someone point me to 
 a tutorial explaining ST, and/or a tutorial in the RandomVariate module?

 Pseudorandomness seems like one case where it would just be a hell of a 
 lot simpler to have a global generator--never split the state. Is the ST 
 monad some way to accomplish this?

 Thanks,
 Mike


 ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe


 ** ACCEPT: CRM114 PASS osb unique microgroom Matcher ** CLASSIFY 
 succeeds; success probability: 1.  pR: 5.5394
 Best match to file #0 (nonspam.css) prob: 1.  pR: 5.5394  Total 
 features in input file: 2960
 #0 (nonspam.css): features: 758386, hits: 2888631, prob: 1.00e+00, pR:   
 5.54 #1 (spam.css): features: 1683715, hits: 3150692, prob: 2.89e-06, pR: 
  -5.54 

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] statistics package and randomness

2009-10-12 Thread Bryan O'Sullivan
On Mon, Oct 12, 2009 at 12:25 AM, Michael Mossey m...@alumni.caltech.eduwrote:

 I'm trying to learn how to use randomness in Haskell and it seems very
 non-straightforward and complex. I could do a lot of things using 'split'
 from System.Random, but apparently it's broken. There is the statistics
 package here:

 http://hackage.haskell.org/package/statistics

 Is this a better solution?


Yes, as it's much faster, more robust, and (depending on your perspective)
easier to use, provided you understand the ST monad.


 It uses the ST monad in the RandomVariate module. Can someone point me to a
 tutorial explaining ST, and/or a tutorial in the RandomVariate module?


For a tutorial on grokking ST, I'd suggest chapter 26 of Real World Haskell,
but I'm biased, since I wrote it:

http://book.realworldhaskell.org/read/advanced-library-design-building-a-bloom-filter.html

Note that this already assumes that you understand monads pretty well.

Pseudorandomness seems like one case where it would just be a hell of a lot
 simpler to have a global generator--never split the state. Is the ST monad
 some way to accomplish this?


Having
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] statistics package and randomness

2009-10-12 Thread Bryan O'Sullivan
On Mon, Oct 12, 2009 at 11:01 AM, Bryan O'Sullivan b...@serpentine.comwrote:


 Pseudorandomness seems like one case where it would just be a hell of a lot
 simpler to have a global generator--never split the state. Is the ST monad
 some way to accomplish this?


 Having [...]


Feh, gmail fail.

Having a global generator is not actually a good thing, since it has to live
*somewhere*. If you keep its existence implicit, it becomes slow, since you
have to lock it against concurrent use by multiple threads. If you make it
explicit, you have to plumb the thing all over the place by hand, which is
also nasty. The advantage of putting the PRNG in the ST monad is that you
can seed a new PRNG close to the point where you'll need it, and not need to
pass around so much state.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe