/// <summary> /// Defines a sample stream for a biniomian distribution /// </summary> /// <param name="random">The random source</param> /// <param name="n">The number of trials</param> /// <param name="p">The probability of success of a given trial</param> public static IEnumerable <int> SampleBinomial(this IPolyrand random, int n, double p) { var sysrand = SysRand.Derive(random); while (true) { yield return(MlStats.SampleFromBinomial(sysrand, n, p)); } }
public static IEnumerable <float> SampleLaplace(this IPolyrand random, float mean, float scale) { var sysrand = SysRand.Derive(random); while (true) { yield return(MlStats.SampleFromLaplacian(sysrand, mean, scale)); } }
/// <summary> /// Defines a sample stream for a poisson distribution which represents the probability of /// a given number of independent events occurring over a period of time at a constant rate /// </summary> /// <param name="random">The random source</param> /// <param name="lambda">The constant rate of occurrence</param> public static IEnumerable <int> SamplePoisson(this IPolyrand random, double lambda) { var sysrand = SysRand.Derive(random); while (true) { yield return(MlStats.SampleFromPoisson(sysrand, lambda)); } }
public static IEnumerable <double> SampleBeta2(this IPolyrand random, double alpha, double beta) { var sysrand = SysRand.Derive(random); while (true) { yield return(MlStats.SampleFromBeta(sysrand, alpha, beta)); } }
/// <summary> /// Defines a sample stream for a biniomian distribution /// </summary> /// <param name="random">The random source</param> /// <param name="n">The number of trials</param> /// <param name="p">The probability of success of a given trial</param> public static IEnumerable <T> SampleBinomial <T>(this IPolyrand random, T n, double p) where T : struct { var sysrand = SysRand.Derive(random); while (true) { yield return(convert <T>(MlStats.SampleFromBinomial(sysrand, convert <T, int>(n), p))); } }
public static IEnumerable <T> SampleLaplace <T>(this IPolyrand random, T mean, T scale) where T : struct { var sysrand = SysRand.Derive(random); while (true) { yield return(convert <T>((MlStats.SampleFromLaplacian(sysrand, convert <T, float>(mean), convert <T, float>(scale))))); } }
/// <summary> /// Defines a sample stream for a poisson distribution which represents the probability of /// a given number of independent events occurring over a period of time at a constant rate /// </summary> /// <param name="random">The random source</param> /// <param name="lambda">The constant rate of occurrence</param> public static IEnumerable <T> SamplePoisson <T>(this IPolyrand random, T lambda) where T : struct { var sysrand = SysRand.Derive(random); var l = convert <T, double>(lambda); while (true) { yield return(convert <T>(MlStats.SampleFromPoisson(sysrand, l))); } }
public static IEnumerable <double[]> SampleDirichlet(IPolyrand random, double[] alphas) { var sysrand = SysRand.Derive(random); while (true) { var dst = new double[alphas.Length]; MlStats.SampleFromDirichlet(sysrand, alphas, dst); yield return(dst); } }
public static System.Random ToSysRand(this IPolyrand rng) => SysRand.Derive(rng);