This project has moved and is read-only. For the latest updates, please go here.

Sample generator - is it lazy?

Oct 29, 2012 at 10:05 PM

Hi all, 


I want to create a sample generator which I could later as a function for Monte Carlo, for example 

let dist = new Distributions.Normal()

let f = dist.Sample() ( fun i -> f ) [1 .. 1000]

Using such function I get 1000 exactly the same numbers. I also tried dist.Samples() |> Seq.take 1

but result is the same. My example can be easly solved by dist.Samples() |> Seq.take 1000 but in my situation it is not the case. 

My question is whether distribution sampler is lazy and is there a way to sample different numbers as a function ? 



Oct 30, 2012 at 10:25 AM


I think the problem is that

let f = dist.Sample()

binds f to the return value of Sample not the Sample method.

This seems to work:

let f() = dist.Sample()

let m = ( fun i -> f() ) [1 .. 1000]

As for being lazy, the values are not pre-computed so in a sense it is - that is the value are not computed until the method is called.