예제 #1
0
        /// <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));
            }
        }
예제 #2
0
        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));
            }
        }
예제 #3
0
        /// <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));
            }
        }
예제 #4
0
        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));
            }
        }
예제 #5
0
        /// <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)));
            }
        }
예제 #6
0
        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)))));
            }
        }
예제 #7
0
        /// <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)));
            }
        }
예제 #8
0
        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);
            }
        }
예제 #9
0
 public static System.Random ToSysRand(this IPolyrand rng)
 => SysRand.Derive(rng);