Ejemplo n.º 1
0
 /// <summary>
 /// Create a new <see cref="NonUniform"/> that obtains its
 /// <see cref="IUniform"/> generator from the given
 /// <see cref="IUniformSource"/>.
 /// </summary>
 /// <remarks>
 /// If <paramref name="source"/> is <see langword="null"/>, this
 /// constructor behaves exactly like the no-arg constructor and
 /// obtains an <see cref="IUniform"/> generator from the set of
 /// default random numbers.
 /// </remarks>
 /// <param name="source">
 /// The <see cref="IUniformSource"/> from which to obtain the
 /// <see cref="IUniform"/> generator.
 /// </param>
 protected NonUniform(IUniformSource source)
 {
     if (source != null)
     {
         _rng = source.GetUniform();
     }
     else
     {
         _rng = UniformStreams.DefaultStreams.GetUniform();
     }
 }
Ejemplo n.º 2
0
        public void BindUniformSource(IUniformSource source)
        {
            foreach (ProgramUniform uniform in _uniforms)
            {
                UniformUsage usage;
                if ((usage = UniformMappings.GetUsage(uniform.Name)) != UniformUsage.GenericUniform)
                {
                    IUniformValue value;
                    if (source.GetUniformValue(usage, out value))
                    {
                        if (uniform.Cache == null)
                        {
                            uniform.Cache = value.Default();
                        }

                        if (!value.Equals(uniform.Cache))
                        {
                            value.Apply(uniform.Slot);
                            uniform.Cache.Set(value);
                        }
                    }
                }
            }
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Create an <see cref="Logistic"/> random number generator that
 /// obtains its underlying <see cref="Uniform"/> generator from the
 /// given <see cref="IUniformSource"/>.
 /// </summary>
 /// <remarks>
 /// The <see cref="Shape"/> for the <see cref="Logistic"/> is set to
 /// <see cref="DefaultShape"/>.
 /// </remarks>
 /// <param name="source">
 /// The <see cref="IUniformSource"/> from which this
 /// <see cref="Exponential"/> can obtain its underlying
 /// <see cref="Uniform"/> generator.
 /// </param>
 public Logistic(IUniformSource source)
     : this(source, DefaultShape)
 {
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Create an <see cref="Logistic"/> random number generator that
 /// obtains its underlying <see cref="Uniform"/> generator from the
 /// given <see cref="IUniformSource"/> and has the given shape
 /// parameter.
 /// </summary>
 /// <param name="source">
 /// The <see cref="IUniformSource"/> from which this
 /// <see cref="Exponential"/> can obtain its underlying
 /// <see cref="Uniform"/> generator.
 /// </param>
 /// <param name="shape">
 /// The shape parameter.  This value is often referred to as
 /// <em>lambda</em>.
 /// </param>
 public Logistic(IUniformSource source, double shape)
     : base(source)
 {
     this.Shape = shape;
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Create an <see cref="Weibull"/> random number generator that
 /// obtains its underlying <see cref="Uniform"/> generator from the
 /// given <see cref="IUniformSource"/> and has the given scale and
 /// shape parameters.
 /// </summary>
 /// <param name="source">
 /// The <see cref="IUniformSource"/> from which this
 /// <see cref="Weibull"/> can obtain its underlying
 /// <see cref="Uniform"/> generator.
 /// </param>
 /// <param name="scale">
 /// The scale parameter.  This value is often referred to as
 /// <em>alpha</em>.</param>
 /// <param name="shape">
 /// The shape parameter.  This value is often referred to as
 /// <em>beta</em>.
 /// </param>
 public Weibull(IUniformSource source, double scale, double shape)
     : base(source)
 {
     this.Scale = scale;
     this.Shape = shape;
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Create an <see cref="Weibull"/> random number generator that
 /// obtains its underlying <see cref="Uniform"/> generator from the
 /// given <see cref="IUniformSource"/>.
 /// </summary>
 /// <remarks>
 /// The <see cref="Scale"/> and <see cref="Shape"/> for the
 /// <see cref="Weibull"/> are set to <see cref="DefaultScale"/> and
 /// <see cref="DefaultShape"/> respectively.
 /// </remarks>
 /// <param name="source">
 /// The <see cref="IUniformSource"/> from which this
 /// <see cref="Weibull"/> can obtain its underlying
 /// <see cref="Uniform"/> generator.
 /// </param>
 public Weibull(IUniformSource source)
     : this(source, DefaultScale, DefaultShape)
 {
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Create an <see cref="Triangular"/> random number generator that
 /// obtains its underlying <see cref="Uniform"/> generator from the
 /// given <see cref="IUniformSource"/> and has the given minimum,
 /// mode, and maximum.
 /// parameter.
 /// </summary>
 /// <exception cref="ArgumentException">
 /// If <paramref name="min"/> is not less than <paramref name="max"/>;
 /// or if <paramref name="mode"/> does not lie between
 /// <paramref name="min"/> and <paramref name="max"/>.
 /// </exception>
 /// <param name="source">
 /// The <see cref="IUniformSource"/> from which this
 /// <see cref="Triangular"/> can obtain its underlying
 /// <see cref="Uniform"/> generator.
 /// </param>
 /// <param name="min">The minimum value.</param>
 /// <param name="mode">The mode.</param>
 /// <param name="max">The maximum value.</param>
 public Triangular(IUniformSource source,
                   double min, double mode, double max)
     : base(source)
 {
     Reset(min, mode, max);
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Create an <see cref="Triangular"/> random number generator that
 /// obtains its underlying <see cref="Uniform"/> generator from the
 /// given <see cref="IUniformSource"/>.
 /// </summary>
 /// <remarks>
 /// The <see cref="Minimum"/>, <see cref="Mode"/>, and
 /// <see cref="Maximum"/> are set to <see cref="DefaultMinimum"/>,
 /// <see cref="DefaultMode"/>, and <see cref="DefaultMaximum"/>
 /// respectively.
 /// </remarks>
 /// <param name="source">
 /// The <see cref="IUniformSource"/> from which this
 /// <see cref="Triangular"/> can obtain its underlying
 /// <see cref="Uniform"/> generator.
 /// </param>
 public Triangular(IUniformSource source)
     : this(source, DefaultMinimum, DefaultMode, DefaultMaximum)
 {
 }
Ejemplo n.º 9
0
 /// <summary>
 /// Create a <see cref="Normal"/> random number generator that
 /// obtains its underlying <see cref="Uniform"/> generator from the
 /// given <see cref="IUniformSource"/> and has the given mean and
 /// standard deviation.
 /// </summary>
 /// <param name="source">
 /// The <see cref="IUniformSource"/> from which this
 /// <see cref="Exponential"/> can obtain its underlying
 /// <see cref="Uniform"/> generator.
 /// </param>
 /// <param name="mean">
 /// The mean.  This value is often referred to as <em>mu</em>.
 /// </param>
 /// <param name="stddev">
 /// The standard deviation.  This value is often referred to as
 /// <em>sigma</em>.
 /// </param>
 public Normal(IUniformSource source, double mean, double stddev)
     : base(source)
 {
     this.Mean = mean;
     this.StandardDeviation = stddev;
 }
Ejemplo n.º 10
0
 /// <summary>
 /// Create a <see cref="Normal"/> random number generator that
 /// obtains its underlying <see cref="Uniform"/> generator from the
 /// given <see cref="IUniformSource"/>.
 /// </summary>
 /// <remarks>
 /// The <see cref="Mean"/> and <see cref="StandardDeviation"/> for the
 /// <see cref="Normal"/> are set to <see cref="DefaultMean"/> and
 /// <see cref="DefaultStandardDeviation"/> respectively.
 /// </remarks>
 /// <param name="source">
 /// The <see cref="IUniformSource"/> from which this
 /// <see cref="Exponential"/> can obtain its underlying
 /// <see cref="Uniform"/> generator.
 /// </param>
 public Normal(IUniformSource source)
     : this(source, DefaultMean, DefaultStandardDeviation)
 {
 }
Ejemplo n.º 11
0
 /// <summary>
 /// Create an <see cref="Exponential"/> random number generator that
 /// obtains its underlying <see cref="Uniform"/> generator from the
 /// given <see cref="IUniformSource"/>.
 /// </summary>
 /// <param name="source">
 /// The <see cref="IUniformSource"/> from which this
 /// <see cref="Exponential"/> can obtain its underlying
 /// <see cref="Uniform"/> generator.
 /// </param>
 public Exponential(IUniformSource source)
     : this(source, DefaultLambda)
 {
 }
Ejemplo n.º 12
0
 /// <summary>
 /// Create an <see cref="Exponential"/> random number generator that
 /// obtains its underlying <see cref="Uniform"/> generator from the
 /// given <see cref="IUniformSource"/> and has the given lamdba value.
 /// </summary>
 /// <param name="source">
 /// The <see cref="IUniformSource"/> from which this
 /// <see cref="Exponential"/> can obtain its underlying
 /// <see cref="Uniform"/> generator.
 /// </param>
 /// <param name="lambda">
 /// The lambda value.  This value is defined as 1/Mean.
 /// </param>
 public Exponential(IUniformSource source, double lambda)
     : base(source)
 {
     this.Lambda = lambda;
 }
Ejemplo n.º 13
0
 /// <summary>
 /// Create an <see cref="Gamma"/> random number generator that
 /// obtains its underlying <see cref="Uniform"/> generator from the
 /// given <see cref="IUniformSource"/>.
 /// </summary>
 /// <remarks>
 /// The <see cref="Scale"/> and <see cref="Shape"/> for the
 /// <see cref="Gamma"/> are set to <see cref="DefaultScale"/> and
 /// <see cref="DefaultShape"/> respectively.
 /// </remarks>
 /// <param name="source">
 /// The <see cref="IUniformSource"/> from which this
 /// <see cref="Gamma"/> can obtain its underlying
 /// <see cref="Uniform"/> generator.
 /// </param>
 public Gamma(IUniformSource source)
     : this(source, DefaultScale, DefaultShape)
 {
 }
Ejemplo n.º 14
0
 /// <summary>
 /// Create an <see cref="Pareto"/> random number generator that
 /// obtains its underlying <see cref="Uniform"/> generator from the
 /// given <see cref="IUniformSource"/>.
 /// </summary>
 /// <remarks>
 /// The <see cref="Shape"/> for the <see cref="Pareto"/> is set to
 /// <see cref="DefaultShape"/>.
 /// </remarks>
 /// <param name="source">
 /// The <see cref="IUniformSource"/> from which this
 /// <see cref="Pareto"/> can obtain its underlying
 /// <see cref="Uniform"/> generator.
 /// </param>
 public Pareto(IUniformSource source)
     : this(source, DefaultShape)
 {
 }
Ejemplo n.º 15
0
 /// <summary>
 /// Create an <see cref="Pareto"/> random number generator that
 /// obtains its underlying <see cref="Uniform"/> generator from the
 /// given <see cref="IUniformSource"/> and has the given shape
 /// parameter.
 /// </summary>
 /// <param name="source">
 /// The <see cref="IUniformSource"/> from which this
 /// <see cref="Pareto"/> can obtain its underlying
 /// <see cref="Uniform"/> generator.
 /// </param>
 /// <param name="shape">
 /// The shape parameter.  This value is often referred to as
 /// <em>alpha</em>.
 /// </param>
 public Pareto(IUniformSource source, double shape)
     : base(source)
 {
     this.Shape = shape;
 }