Ejemplo n.º 1
0
 /// <summary>
 /// Joins this instance with another instance, by applying a selection function.
 /// </summary>
 /// <typeparam name="S">The element type.</typeparam>
 /// <typeparam name="R">The result type.</typeparam>
 /// <param name="other">The second.</param>
 /// <param name="selector">The selection map.</param>
 /// <returns>The combined value, with the joint probability.</returns>
 public ProbValue <R> JoinWith <S, R>(ProbValue <S> other, Func <T, S, R> selector)
 {
     return(new ProbValue <R>(selector(this.value, other.value), this.probability * other.probability));
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Applies a specified map to a value with its associated likelyhood.
 /// </summary>
 /// <typeparam name="S">The result type</typeparam>
 /// <param name="f">The map.</param>
 /// <param name="v">The value.</param>
 /// <returns>The mapped value with its associated likelyhood.</returns>
 public static ProbValue <S> Map <S>(Func <T, S> f, ProbValue <T> v)
 {
     return(v.Map(f));
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Joins this instance with another instance, by applying a selection function.
 /// </summary>
 /// <typeparam name="S">The element type.</typeparam>
 /// <typeparam name="R">The result type.</typeparam>
 /// <param name="v1">The first value.</param>
 /// <param name="v2">The second value.</param>
 /// <param name="selector">The selection map.</param>
 /// <returns>The combined value, with the joint probability.</returns>
 public static ProbValue <R> Join <S, R>(ProbValue <T> v1, ProbValue <S> v2, Func <T, S, R> selector)
 {
     return(v1.JoinWith(v2, selector));
 }
Ejemplo n.º 4
0
 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))));
 }