0

I ma using mathdotnet form C# in VS2013.

I need to generate a sequence of samples from

IEnumerable<double> Samples(double a, double b)

at

http://numerics.mathdotnet.com/api/MathNet.Numerics.Distributions/Beta.htm#Samples

I do not know how to control the sample size. For exmaple, I only need to get 5000 smaple points from the distribution.

This is my C# code:

  Beta betadistr = new Beta(alpha, beta);
  list<double> sample = betadistr.samples(alpha, beta); 

What is the size of sample ?

And what is the difference between

 IEnumerable<double> Samples(double a, double b)

and

  IEnumerable<double> Samples(Random rnd, double a, double b)

How to use the rnd to control the sample?

TylerH
  • 20,799
  • 66
  • 75
  • 101
user3601704
  • 753
  • 1
  • 14
  • 46

1 Answers1

0

The distributions offer two ways to generate multiple samples in one go:

  • Sample() returns an infinite sequence. Allows lazy evaluation. Take as many as you need, on demand.
  • Sample(array) fills an array completely. Generally the fastest if the whole array is needed.

so, if you strictly need an IList<double> with 5000 samples, you can do either:

Beta beta = new Beta(alpha, beta);
List<double> samples = beta.Samples().Take(5000).ToList();

or

Beta beta = new Beta(alpha, beta);
double[] samples = new double[5000];
beta.Samples(samples);

If you don't actually need the Beta instance for anything else, you can simplify this by using the static routines, which work the same way:

List<double> samples = Beta.Samples(alpha, beta).Take(5000).ToList();

or

double[] samples = new double[5000];
Beta.Samples(samples, alpha, beta);

For all of theses variations you can also provide your own Random instance, or one of those provided by Math.NET Numerics. In case of the class instance you can pass it to the constructor, in case of the static routines there is an overload accepting it as first argument. See Probability Distributions for more details.

Christoph Rüegg
  • 4,626
  • 1
  • 20
  • 34