public static float ExpectedValue(
            this IWeightedDistribution <float> distribution,
            Func <float, float> function,
            float start = 0f,
            float end   = 1f,
            int buckets = 1000)
        {
            Func <float, float> value  = x => function(x) * distribution.Weight(x);
            Func <float, float> weight = distribution.Weight;

            return(value.Area(start, end, buckets) / weight.Area(start, end, buckets));
        }
Exemplo n.º 2
0
        public static IWeightedDistribution <float> Distribution(
            IWeightedDistribution <float> distribution,
            float shift,
            float stretch = 0f,
            float around  = 0f)
        {
            if (Mathf.Approximately(stretch, 0) &&
                Mathf.Approximately(shift, 0))
            {
                return(distribution);
            }

            shift = shift + around - around * stretch;
            return(new Stretch(distribution, stretch, shift));
        }
Exemplo n.º 3
0
 private Rejection(Func <T, float> weightFunction, IWeightedDistribution <T> helper, float factor)
 {
     this.weightFunction = weightFunction;
     this.helper         = helper;
     this.factor         = factor;
 }
Exemplo n.º 4
0
 public static IWeightedDistribution <T> Distribution(
     Func <T, float> weightFunction,
     IWeightedDistribution <T> helper,
     float factor = 1) => new Rejection <T>(weightFunction, helper, factor);
Exemplo n.º 5
0
 private void Awake() => this.distribution = this.itemsByWeight.ToWeighted();
Exemplo n.º 6
0
 private Stretch(IWeightedDistribution <float> distribution, float stretch, float shift)
 {
     _distribution = distribution;
     _shift        = shift;
     _stretch      = stretch;
 }