public Dist <S> Select <S>(Func <T, S> selector) { return(Dist <T> .Map <S>(this, selector)); }
public Dist <R> SelectMany <S, R>(Func <T, Dist <S> > selector, Func <T, S, R> resultSelector) { return(Dist <T> .Bind(this, v => Dist <S> .Map(selector(v), u => resultSelector(v, u)))); }
private static Dist <S> Map <S>(Dist <T> distribution, Func <T, S> f) { return(new Dist <S>(distribution.values.Select(v => ProbValue <T> .Map(f, v)))); }
private static Dist <R> Join <S, R>(Dist <T> distribution1, Dist <S> distribution2, Func <T, S, R> f) { return(new Dist <R>(distribution1.SelectMany(v1 => distribution2.Select(v2 => v1.JoinWith(v2, f))))); }
private static Dist <S> Bind <S>(Dist <T> distribution, Func <T, Dist <S> > f) { return(new Dist <S>(distribution.values.SelectMany(v => v.Probability * f(v.Value)))); }
public Dist <R> JoinWith <S, R>(Dist <S> distribution, Func <T, S, R> f) { return(Dist <T> .Join <S, R>(this, distribution, f)); }
public Dist <Tuple <T, S> > Prod <S>(Dist <S> distribution) { return(this.JoinWith(distribution, (v1, v2) => Tuple.Create <T, S>(v1, v2))); }
/// <summary> /// A point distribution. /// </summary> /// <typeparam name="T">The element type.</typeparam> /// <param name="value">The value.</param> /// <returns>A point distribution on the given value.</returns> public static Dist <T> Certainly <T>(T value) { return(Dist <T> .Unit(value)); }
/// <summary> /// Averages the specified distribution. /// </summary> /// <param name="distribution">The distribution.</param> /// <returns>The expected value for the given distribution.</returns> public static decimal Average(this Dist <decimal> distribution) { return(distribution.Average(v => v)); }