I finally decided to actually solve the problem, and I'm sorry to say I
was on the wrong track. ListT won't do it on its own: you actually need
a custom monad that does the random pick in the bind operation.
Attached are a module to solve the problem and a Main module that tests
it. I hope
I'm using ListT now, trying to do this:
type Sample a = ListT (State StdGen) a
randomStreamR :: (RandomGen g, Random a) = (a,a) - g - ([a], g)
randomStreamR bds g =(randomRs bds g1, g2)
where (g1,g2) = split g
sample :: [a] - Sample a
sample [] = ListT (State f)
where f s = case next s of
Chad Scherrer wrote:
There's a problem I've been struggling with for a long time...
I need to build a function
buildSample :: [A] - State StdGen [(A,B,C)]
given lookup functions
f :: A - [B]
g :: A - [C]
The idea is to first draw randomly form the [A], then apply each
lookup function and
hall problem, I think it's likely this is applicable to
monte carlo processes as well.
thomas.
Paul Johnson [EMAIL PROTECTED]
Sent by: [EMAIL PROTECTED]
08/15/2007 02:38 PM
To
Chad Scherrer [EMAIL PROTECTED]
cc
haskell-cafe@haskell.org
Subject
Re: [Haskell-cafe] monte carlo trouble
Thanks for your replies.
I actually starting out returning a single element instead. But a
given lookup might return [], and the only way I could think of to
handle it in (State StdGen a) would be to fail in the monad. But
that's not really the effect I want - I'd rather have it ignore that
PROTECTED], Thomas Hartman/ext/[EMAIL PROTECTED]
cc
haskell-cafe@haskell.org
Subject
Re: [Haskell-cafe] monte carlo trouble
Thanks for your replies.
I actually starting out returning a single element instead. But a
given lookup might return [], and the only way I could think of to
handle
Funny you should say that, I was just experimenting with generating
one at a time using (StateT StdGen Maybe). If I get stuck (again) I'll
check out ListT. Thanks!
Chad
On 8/15/07, Paul Johnson [EMAIL PROTECTED] wrote:
Chad Scherrer wrote:
Thanks for your replies.
I actually starting out
2007/8/15, Chad Scherrer [EMAIL PROTECTED]:
If there's a way to lazily sample with replacement from a list without
even requiring the length of the list to be known in advance, that
could lead to a solution.
I'm not sure what you mean by with replacement but I think it don't
change the
Yeah, I did have troubles with (StateT StdGen Maybe). If it hits a
Nothing, I'd like it to skip that one and try again with the next
state. But instead, Nothing is treated as a failure condition that
makes the whole thing fail. I just found MaybeT on the wiki, which
looks like it could work. I'll
On Thu, 16 Aug 2007 00:05:14 +0200, you wrote:
I'm not sure what you mean by with replacement
With replacement means that you select a value from the source, but
you don't actually remove it. That way, it's still available to be
selected again later.
Steve Schafer
Fenestra Technologies Corp.
10 matches
Mail list logo