Exemple #1
0
        /// <summary>
        /// Returns the sampler for a specified rng, data type and distribution spec
        /// </summary>
        /// <param name="rng">The random stream</param>
        /// <param name="spec">The distribution specifier</param>
        /// <typeparam name="T">The sample point type</typeparam>
        public static ISampler <T> Sampler <T>(this MklRng rng, IDistributionSpec <T> spec)
            where T : unmanaged
        {
            var sampler = default(ISampler <T>);

            switch (spec.DistKind)
            {
            case DistKind.Uniform:
                sampler = rng.UniformSampler <T>(UniformSpec.From(spec));
                break;

            case DistKind.UniformBits:
                sampler = rng.UniformBitsSampler <T>(UniformBitsSpec.From(spec));
                break;

            case DistKind.Bernoulli:
                sampler = rng.BernoulliSampler <T>(BernoulliSpec.From(spec));
                break;

            case DistKind.Gaussian:
                sampler = rng.GaussianSampler <T>(GaussianSpec.From(spec));
                break;

            default:
                throw unsupported <T>();
            }

            return(sampler);
        }
Exemple #2
0
        /// <summary>
        /// Returns the sampler for a specified rng, data type and distribution spec
        /// </summary>
        /// <param name="rng">The random stream</param>
        /// <param name="spec">The distribution specifier</param>
        /// <typeparam name="T">The sample point type</typeparam>
        public static IRngSampler <T> Sampler <T>(this MklRng rng, IDistributionSpec <T> spec)
            where T : unmanaged
        {
            var sampler = default(IRngSampler <T>);

            switch (spec.DistKind)
            {
            case DistributionKind.Uniform:
                sampler = rng.UniformSampler <T>(Distributions.uniform(spec));
                break;

            case DistributionKind.UniformBits:
                sampler = rng.UniformBitsSampler <T>(Distributions.uniformbits(spec));
                break;

            case DistributionKind.Bernoulli:
                sampler = rng.BernoulliSampler <T>(Distributions.bernoulli(spec));
                break;

            case DistributionKind.Gaussian:
                sampler = rng.GaussianSampler <T>(Distributions.gaussian(spec));
                break;

            default:
                throw Unsupported.define <T>();
            }

            return(sampler);
        }