|
|
|
@ -143,7 +143,7 @@ namespace MathNet.Numerics |
|
|
|
/// Least-Squares fitting the points (X,y) = ((x0,x1,..,xk),y) to an arbitrary linear combination y : X -> p0*f0(x0) + p1*f1(x1) + ... + pk*fk(xk),
|
|
|
|
/// returning its best fitting parameters as [p0, p1, p2, ..., pk] array.
|
|
|
|
/// </summary>
|
|
|
|
public static double[] MultiDimensional(double[][] x, double[] y, params Func<double, double>[] functions) |
|
|
|
public static double[] LinearMultiDim(double[][] x, double[] y, params Func<double, double>[] functions) |
|
|
|
{ |
|
|
|
return DenseMatrix |
|
|
|
.OfRows(x.Length, functions.Length, x.Select(xi => functions.Select((f, k) => f(xi[k])))) |
|
|
|
@ -155,9 +155,9 @@ namespace MathNet.Numerics |
|
|
|
/// Least-Squares fitting the points (X,y) = ((x0,x1,..,xk),y) to an arbitrary linear combination y : X -> p0*f0(x0) + p1*f1(x1) + ... + pk*fk(xk),
|
|
|
|
/// returning a function y' for the best fitting combination.
|
|
|
|
/// </summary>
|
|
|
|
public static Func<double[], double> MultiDimensionalFunc(double[][] x, double[] y, params Func<double, double>[] functions) |
|
|
|
public static Func<double[], double> LinearMultiDimFunc(double[][] x, double[] y, params Func<double, double>[] functions) |
|
|
|
{ |
|
|
|
var parameters = MultiDimensional(x, y, functions); |
|
|
|
var parameters = LinearMultiDim(x, y, functions); |
|
|
|
return z => functions.Select((f, i) => parameters[i]*f(z[i])).Sum(); |
|
|
|
} |
|
|
|
|
|
|
|
@ -165,7 +165,7 @@ namespace MathNet.Numerics |
|
|
|
/// Least-Squares fitting the points (X,y) = ((x0,x1,..,xk),y) to an arbitrary linear combination y : X -> p0*f0(x0) + p1*f1(x1) + ... + pk*fk(xk),
|
|
|
|
/// returning its best fitting parameters as [p0, p1, p2, ..., pk] array.
|
|
|
|
/// </summary>
|
|
|
|
public static Vector<double> Vector(Vector<double>[] x, double[] y, Func<Vector<double>, Vector<double>> functions) |
|
|
|
public static Vector<double> LinearVector(Vector<double>[] x, double[] y, Func<Vector<double>, Vector<double>> functions) |
|
|
|
{ |
|
|
|
return DenseMatrix |
|
|
|
.OfRowVectors(x.Select(functions).ToArray()) // PERF: Array.map instead of seq
|
|
|
|
@ -176,9 +176,9 @@ namespace MathNet.Numerics |
|
|
|
/// Least-Squares fitting the points (X,y) = ((x0,x1,..,xk),y) to an arbitrary linear combination y : X -> p0*f0(x0) + p1*f1(x1) + ... + pk*fk(xk),
|
|
|
|
/// returning a function y' for the best fitting combination.
|
|
|
|
/// </summary>
|
|
|
|
public static Func<Vector<double>, double> VectorFunc(Vector<double>[] x, double[] y, Func<Vector<double>, Vector<double>> functions) |
|
|
|
public static Func<Vector<double>, double> LinearVectorFunc(Vector<double>[] x, double[] y, Func<Vector<double>, Vector<double>> functions) |
|
|
|
{ |
|
|
|
var parameters = Vector(x, y, functions); |
|
|
|
var parameters = LinearVector(x, y, functions); |
|
|
|
return z => functions(z).Select((yi, i) => parameters[i]*yi).Sum(); |
|
|
|
} |
|
|
|
} |
|
|
|
|