예제 #1
0
 /// <summary>
 /// Calculates the minimum absolute value of all entries of an <see cref="IReducible"/>.
 /// </summary>
 /// <param name="reducible">A matrix, vector or similar collection.</param>
 public static double MinAbsolute(this IReducible reducible)
 {
     return(reducible.Reduce(double.MaxValue, (x, min) =>
     {
         double abs = Math.Abs(x);
         return abs < min ? abs : min;
     },
                             (nz, min) => 0.0 < min ? 0.0 : min, min => min));
 }
예제 #2
0
 /// <summary>
 /// Calculates the maximum absolute value of all entries of an <see cref="IReducible"/>.
 /// </summary>
 /// <param name="reducible">A matrix, vector or similar collection.</param>
 public static double MaxAbsolute(this IReducible reducible)
 {
     return(reducible.Reduce(double.MinValue, (x, max) =>
     {
         double abs = Math.Abs(x);
         return abs > max ? abs : max;
     },
                             (nz, max) => 0.0 > max ? 0.0 : max, max => max));
 }
예제 #3
0
 private static object MethodReduce(ITransformer xf, object acc, IReducible obj)
 {
     return(xf.Result(obj.Reduce(new Func <object, object, object>(xf.Step), acc)));
 }
예제 #4
0
 /// <summary>
 /// Calculates the sum over all entries of an <see cref="IReducible"/>.
 /// </summary>
 /// <param name="reducible">A matrix, vector or similar collection.</param>
 public static double Sum(this IReducible reducible)
 {
     return(reducible.Reduce(0.0, (x, sum) => x + sum, (nz, sum) => sum, sum => sum));
 }
예제 #5
0
 /// <summary>
 /// Calculates the product over all entries of an <see cref="IReducible"/>.
 /// </summary>
 /// <param name="reducible">A matrix, vector or similar collection.</param>
 public static double Product(this IReducible reducible)
 {
     return(reducible.Reduce(1.0, (x, prod) => x * prod, (nz, prod) => nz > 0 ? 0 : prod, prod => prod));
 }
예제 #6
0
 /// <summary>
 /// Calculates the Euclidian norm or 2-norm over all entries of an <see cref="IReducible"/>. For more see
 /// https://en.wikipedia.org/wiki/Norm_(mathematics)#Euclidean_norm. WARNING: most classes that implement
 /// <see cref="IReducible"/> will provide far more efficient methods for calculating norms. Use them instead.
 /// </summary>
 /// <param name="reducible">A matrix, vector or similar collection.</param>
 public static double Norm2(this IReducible reducible)
 {
     return(reducible.Reduce(0.0, (x, sum) => x + sum, (nz, sum) => sum, sum => Math.Sqrt(sum)));
 }
예제 #7
0
 /// <summary>
 /// Calculates the minimum value of all entries of an <see cref="IReducible"/>.
 /// </summary>
 /// <param name="reducible">A matrix, vector or similar collection.</param>
 public static double Min(this IReducible reducible)
 {
     return(reducible.Reduce(double.MaxValue, (x, min) => x < min ? x : min,
                             (nz, min) => 0.0 < min ? 0.0 : min, min => min));
 }
예제 #8
0
 /// <summary>
 /// Calculates the maximum value of all entries of an <see cref="IReducible"/>.
 /// </summary>
 /// <param name="reducible">A matrix, vector or similar collection.</param>
 public static double Max(this IReducible reducible)
 {
     return(reducible.Reduce(double.MinValue, (x, max) => x > max ? x : max,
                             (nz, max) => 0.0 > max ? 0.0 : max, max => max));
 }