Exemplo n.º 1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="UniformRealSampler"/> class.
 /// </summary>
 /// <param name="generator">
 /// The underlying bit generator to use.
 /// </param>
 /// <param name="min">
 /// The lower bound of the values that will be generated.
 /// </param>
 /// <param name="max">
 /// The upper bound of the values that will be generated.
 /// </param>
 /// <exception cref="ArgumentNullException">
 /// If <paramref name="generator"/> is null.
 /// </exception>
 /// <exception cref="ArgumentException">
 /// If <paramref name="min"/> is infinite or nan.
 /// If <paramref name="max"/> is infinite or nan.
 /// If <paramref name="min"/> is greater than or equal to <paramref name="max"/>.
 /// </exception>
 public UniformRealSampler(IRandomNumberEngine generator, double min, double max)
 {
     UniformRealDistribution.ValidateParameters(min, max);
     this.generator = generator ?? throw new ArgumentNullException(nameof(generator));
     this.Min       = min;
     this.Max       = max;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="MultivariateNormalSampler"/> class.
 /// </summary>
 /// <param name="engine">
 /// The simulation engine to be used for sampling.
 /// </param>
 /// <param name="mean">
 /// The mean values of the variables to be generated simultaneously.
 /// </param>
 /// <param name="choleskyFactor">
 /// The Cholesky factorization of a matrix defining the desired joint distribution.
 /// </param>
 private MultivariateNormalSampler(IRandomNumberEngine engine, double[] mean, double[] choleskyFactor)
 {
     this.Length                = mean.Length;
     this.mean                  = mean;
     this.choleskyFactor        = choleskyFactor;
     this.standardNormalSampler = new StandardNormalSampler(engine);
     this.buffer                = new double[this.mean.Length];
 }
Exemplo n.º 3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="LogNormalSampler"/> class.
        /// </summary>
        /// <param name="generator">
        /// The underlying bit generator to use.
        /// </param>
        /// <param name="mu">
        /// The mean of the related normal distribution.
        /// </param>
        /// <param name="sigma">
        /// The standard deviation of the related normal distribution.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// If <paramref name="generator"/> is null.
        /// </exception>
        /// <exception cref="ArgumentException">
        /// If <paramref name="mu"/> is infinite or nan.
        /// if <paramref name="sigma"/> is infinite or nan.
        /// if <paramref name="sigma"/> is less than or equal to zero.
        /// </exception>
        public LogNormalSampler(IRandomNumberEngine generator, double mu, double sigma)
        {
            if (generator is null)
            {
                throw new ArgumentNullException(nameof(generator));
            }

            NormalDistribution.ValidateParameters(mu, sigma);
            this.standardNormalSampler = new StandardNormalSampler(generator);
            this.Mu    = mu;
            this.Sigma = sigma;
        }
 /// <summary>
 /// Builds a new instance of a gaussian copula sampler.
 /// </summary>
 /// <param name="engine">
 /// The random number engine to use as a ransom source.
 /// </param>
 /// <returns>
 /// A new instance of a gaussian copula sampler.
 /// </returns>
 public GaussianCopulaSampler Build(IRandomNumberEngine engine)
 {
     return(new (engine, this.choleskyFactor, this.order));
 }
Exemplo n.º 5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="InverseTransformSampler{T}"/> class.
 /// </summary>
 /// <param name="engine">
 /// The random number engine.
 /// </param>
 /// <param name="distribution">
 /// The reference distribution.
 /// </param>
 public InverseTransformSampler(IRandomNumberEngine engine, IDistribution <T> distribution)
 {
     this.engine       = engine ?? throw new ArgumentNullException(nameof(engine));
     this.Distribution = distribution ?? throw new ArgumentNullException(nameof(distribution));
 }
Exemplo n.º 6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="StandardNormalSampler"/> class.
 /// </summary>
 /// <param name="engine">
 /// The pseudo random engine used to generate random numbers.
 /// </param>
 /// <exception cref="ArgumentNullException">
 /// If <paramref name="engine"/> is null.
 /// </exception>
 public StandardNormalSampler(IRandomNumberEngine engine)
 {
     this.engine = engine ?? throw new ArgumentNullException(nameof(engine));
 }
 static IEnumerable <ulong> GetValues(IRandomNumberEngine engine)
 => Enumerable.Repeat(engine, 100).Select(e => e.NextULong());
Exemplo n.º 8
0
 private static void TestInvalidThrows <TException>(IRandomNumberEngine engine, double mu, double sigma)
     where TException : Exception
 {
     Assert.Throws <TException>(
         () => _ = new LogNormalSampler(engine, mu, sigma));
 }
Exemplo n.º 9
0
 public static void Is(IRandomNumberEngine randomNumberEngine) =>
 Randomizer.randomNumberEngine = randomNumberEngine;
 /// <summary>
 /// Builds a new instance of a multivariate normal sampler.
 /// </summary>
 /// <param name="engine">
 /// The random number engine to use as a ransom source.
 /// </param>
 /// <returns>
 /// A new instance of a multivariate normal sampler.
 /// </returns>
 public MultivariateNormalSampler Build(IRandomNumberEngine engine)
 {
     return(new (engine, this.mean, this.choleskyFactor));
 }