/// <summary> /// Generates a random observation from the current distribution. /// </summary> /// /// <returns>A random observations drawn from this distribution.</returns> /// public override double Generate() { // Choose one coefficient at random int c = GeneralDiscreteDistribution.Random(coefficients); // Sample from the chosen coefficient var d = components[c] as ISampleableDistribution <double>; if (d == null) { throw new InvalidOperationException(); } return(d.Generate()); }
/// <summary> /// Generates a random observation from the current distribution. /// </summary> /// /// <returns>A random observations drawn from this distribution.</returns> /// public override double Generate(Random source) { if (sampleable == null) { sampleable = new ISampleableDistribution <double> [components.Length]; for (int i = 0; i < sampleable.Length; i++) { sampleable[i] = this.components[i] as ISampleableDistribution <double>; } } // Choose one coefficient at random int j = GeneralDiscreteDistribution.Random(coefficients, source); // Sample from the chosen coefficient return(sampleable[j].Generate()); }
/// <summary> /// Generates a random vector of observations from the current distribution. /// </summary> /// /// <param name="samples">The number of samples to generate.</param> /// <param name="result">The location where to store the samples.</param> /// /// <returns>A random vector of observations drawn from this distribution.</returns> /// public override double[] Generate(int samples, double[] result) { if (sampleable == null) { sampleable = new ISampleableDistribution <double> [components.Length]; for (int i = 0; i < sampleable.Length; i++) { sampleable[i] = this.components[i] as ISampleableDistribution <double>; } } for (int i = 0; i < samples; i++) { // Choose one coefficient at random int j = GeneralDiscreteDistribution.Random(coefficients); // Sample from the chosen coefficient result[i] = sampleable[j].Generate(); } return(result); }