Browse Source

Switch many tuples to value tuples

dependabot/nuget/NUnit3TestAdapter-4.2.0
Christoph Ruegg 5 years ago
parent
commit
53eae56482
  1. 4
      src/FSharp.Tests/FitTests.fs
  2. 2
      src/Numerics.Tests/OptimizationTests/NewtonMinimizerTests.cs
  3. 9
      src/Numerics/Complex32.cs
  4. 9
      src/Numerics/ComplexExtensions.cs
  5. 24
      src/Numerics/FindMinimum.cs
  6. 8
      src/Numerics/FindRoots.cs
  7. 30
      src/Numerics/Fit.cs
  8. 18
      src/Numerics/Integration/GaussRule/GaussKronrodPoint.cs
  9. 6
      src/Numerics/LinearRegression/SimpleRegression.cs
  10. 6
      src/Numerics/Optimization/ObjectiveFunction.cs
  11. 10
      src/Numerics/Optimization/ObjectiveFunctions/GradientHessianObjectiveFunction.cs
  12. 9
      src/Numerics/Optimization/ObjectiveFunctions/GradientObjectiveFunction.cs
  13. 9
      src/Numerics/Optimization/ObjectiveFunctions/HessianObjectiveFunction.cs
  14. 5
      src/Numerics/Optimization/ObjectiveFunctions/NonlinearObjectiveFunction.cs
  15. 6
      src/Numerics/Optimization/TrustRegion/Subproblems/Util.cs
  16. 12
      src/Numerics/Polynomial.cs
  17. 16
      src/Numerics/Precision.cs
  18. 15
      src/Numerics/RootFinding/Cubic.cs
  19. 4
      src/Numerics/RootFinding/RobustNewtonRaphson.cs
  20. 6
      src/Numerics/RootFinding/ZeroCrossingBracketing.cs
  21. 8
      src/Numerics/Statistics/ArrayStatistics.Int32.cs
  22. 8
      src/Numerics/Statistics/ArrayStatistics.Single.cs
  23. 8
      src/Numerics/Statistics/ArrayStatistics.cs
  24. 16
      src/Numerics/Statistics/Statistics.cs
  25. 14
      src/Numerics/Statistics/StreamingStatistics.cs

4
src/FSharp.Tests/FitTests.fs

@ -18,7 +18,7 @@ module FitTests =
let y = x |> Array.map f
// LeastSquares.FitToLine(x,y)
let a, b = Fit.line x y
let struct (a, b) = Fit.line x y
a |> should (equalWithin 1.0e-12) 4.0
b |> should (equalWithin 1.0e-12) -1.5
@ -35,7 +35,7 @@ module FitTests =
let y = [| 4.986; 2.347; 2.061; -2.995; -2.352; -5.782 |]
// LeastSquares.FitToLinearCombination(x, y, (fun z -> 1.0), (fun z -> Math.Sin(z)), (fun z -> Math.Cos(z)))
let [a;b;c] = (x,y) ||> Fit.linear [(fun _ -> 1.0); (Math.Sin); (Math.Cos)]
let [a;b;c] = (x,y) ||> Fit.linear [(fun _ -> 1.0); Math.Sin; Math.Cos]
a |> should (equalWithin 1.0e-4) -0.287476
b |> should (equalWithin 1.0e-4) 4.02159
c |> should (equalWithin 1.0e-4) -1.46962

2
src/Numerics.Tests/OptimizationTests/NewtonMinimizerTests.cs

@ -101,7 +101,7 @@ namespace MathNet.Numerics.UnitTests.OptimizationTests
[Test]
public void FindMinimum_Rosenbrock_Hard()
{
var obj = ObjectiveFunction.GradientHessian(point => Tuple.Create(RosenbrockFunction.Value(point), RosenbrockFunction.Gradient(point), RosenbrockFunction.Hessian(point)));
var obj = ObjectiveFunction.GradientHessian(point => (RosenbrockFunction.Value(point), RosenbrockFunction.Gradient(point), RosenbrockFunction.Hessian(point)));
var solver = new NewtonMinimizer(1e-5, 1000);
var result = solver.FindMinimum(obj, new DenseVector(new[] { -1.2, 1.0 }));

9
src/Numerics/Complex32.cs

@ -489,22 +489,21 @@ namespace MathNet.Numerics
/// <summary>
/// Evaluate all square roots of this <c>Complex32</c>.
/// </summary>
public Tuple<Complex32, Complex32> SquareRoots()
public (Complex32, Complex32) SquareRoots()
{
var principal = SquareRoot();
return new Tuple<Complex32, Complex32>(principal, -principal);
return (principal, -principal);
}
/// <summary>
/// Evaluate all cubic roots of this <c>Complex32</c>.
/// </summary>
public Tuple<Complex32, Complex32, Complex32> CubicRoots()
public (Complex32, Complex32, Complex32) CubicRoots()
{
float r = (float)Math.Pow(Magnitude, 1d / 3d);
float theta = Phase / 3;
const float shift = (float)Constants.Pi2 / 3;
return new Tuple<Complex32, Complex32, Complex32>(
FromPolarCoordinates(r, theta),
return (FromPolarCoordinates(r, theta),
FromPolarCoordinates(r, theta + shift),
FromPolarCoordinates(r, theta - shift));
}

9
src/Numerics/ComplexExtensions.cs

@ -295,22 +295,21 @@ namespace MathNet.Numerics
/// <summary>
/// Evaluate all square roots of this <c>Complex</c>.
/// </summary>
public static Tuple<Complex, Complex> SquareRoots(this Complex complex)
public static (Complex, Complex) SquareRoots(this Complex complex)
{
var principal = SquareRoot(complex);
return new Tuple<Complex, Complex>(principal, -principal);
return (principal, -principal);
}
/// <summary>
/// Evaluate all cubic roots of this <c>Complex</c>.
/// </summary>
public static Tuple<Complex, Complex, Complex> CubicRoots(this Complex complex)
public static (Complex, Complex, Complex) CubicRoots(this Complex complex)
{
var r = Math.Pow(complex.Magnitude, 1d/3d);
var theta = complex.Phase/3;
const double shift = Constants.Pi2/3;
return new Tuple<Complex, Complex, Complex>(
Complex.FromPolarCoordinates(r, theta),
return (Complex.FromPolarCoordinates(r, theta),
Complex.FromPolarCoordinates(r, theta + shift),
Complex.FromPolarCoordinates(r, theta - shift));
}

24
src/Numerics/FindMinimum.cs

@ -3,7 +3,7 @@
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
//
// Copyright (c) 2009-2017 Math.NET
// Copyright (c) 2009-2021 Math.NET
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
@ -61,44 +61,44 @@ namespace MathNet.Numerics
/// Find vector x that minimizes the function f(x) using the Nelder-Mead Simplex algorithm.
/// For more options and diagnostics consider to use <see cref="NelderMeadSimplex"/> directly.
/// </summary>
public static Tuple<double, double> OfFunction(Func<double, double, double> function, double initialGuess0, double initialGuess1, double tolerance = 1e-8, int maxIterations = 1000)
public static (double P0, double P1) OfFunction(Func<double, double, double> function, double initialGuess0, double initialGuess1, double tolerance = 1e-8, int maxIterations = 1000)
{
var objective = ObjectiveFunction.Value(v => function(v[0], v[1]));
var result = NelderMeadSimplex.Minimum(objective, CreateVector.Dense(new[] { initialGuess0, initialGuess1 }), tolerance, maxIterations);
return Tuple.Create(result.MinimizingPoint[0], result.MinimizingPoint[1]);
return (result.MinimizingPoint[0], result.MinimizingPoint[1]);
}
/// <summary>
/// Find vector x that minimizes the function f(x) using the Nelder-Mead Simplex algorithm.
/// For more options and diagnostics consider to use <see cref="NelderMeadSimplex"/> directly.
/// </summary>
public static Tuple<double, double, double> OfFunction(Func<double, double, double, double> function, double initialGuess0, double initialGuess1, double initialGuess2, double tolerance = 1e-8, int maxIterations = 1000)
public static (double P0, double P1, double P2) OfFunction(Func<double, double, double, double> function, double initialGuess0, double initialGuess1, double initialGuess2, double tolerance = 1e-8, int maxIterations = 1000)
{
var objective = ObjectiveFunction.Value(v => function(v[0], v[1], v[2]));
var result = NelderMeadSimplex.Minimum(objective, CreateVector.Dense(new[] { initialGuess0, initialGuess1, initialGuess2 }), tolerance, maxIterations);
return Tuple.Create(result.MinimizingPoint[0], result.MinimizingPoint[1], result.MinimizingPoint[2]);
return (result.MinimizingPoint[0], result.MinimizingPoint[1], result.MinimizingPoint[2]);
}
/// <summary>
/// Find vector x that minimizes the function f(x) using the Nelder-Mead Simplex algorithm.
/// For more options and diagnostics consider to use <see cref="NelderMeadSimplex"/> directly.
/// </summary>
public static Tuple<double, double, double, double> OfFunction(Func<double, double, double, double, double> function, double initialGuess0, double initialGuess1, double initialGuess2, double initialGuess3, double tolerance = 1e-8, int maxIterations = 1000)
public static (double P0, double P1, double P2, double P3) OfFunction(Func<double, double, double, double, double> function, double initialGuess0, double initialGuess1, double initialGuess2, double initialGuess3, double tolerance = 1e-8, int maxIterations = 1000)
{
var objective = ObjectiveFunction.Value(v => function(v[0], v[1], v[2], v[3]));
var result = NelderMeadSimplex.Minimum(objective, CreateVector.Dense(new[] { initialGuess0, initialGuess1, initialGuess2, initialGuess3 }), tolerance, maxIterations);
return Tuple.Create(result.MinimizingPoint[0], result.MinimizingPoint[1], result.MinimizingPoint[2], result.MinimizingPoint[3]);
return (result.MinimizingPoint[0], result.MinimizingPoint[1], result.MinimizingPoint[2], result.MinimizingPoint[3]);
}
/// <summary>
/// Find vector x that minimizes the function f(x) using the Nelder-Mead Simplex algorithm.
/// For more options and diagnostics consider to use <see cref="NelderMeadSimplex"/> directly.
/// </summary>
public static Tuple<double, double, double, double, double> OfFunction(Func<double, double, double, double, double, double> function, double initialGuess0, double initialGuess1, double initialGuess2, double initialGuess3, double initialGuess4, double tolerance = 1e-8, int maxIterations = 1000)
public static (double P0, double P1, double P2, double P3, double P4) OfFunction(Func<double, double, double, double, double, double> function, double initialGuess0, double initialGuess1, double initialGuess2, double initialGuess3, double initialGuess4, double tolerance = 1e-8, int maxIterations = 1000)
{
var objective = ObjectiveFunction.Value(v => function(v[0], v[1], v[2], v[3], v[4]));
var result = NelderMeadSimplex.Minimum(objective, CreateVector.Dense(new[] { initialGuess0, initialGuess1, initialGuess2, initialGuess3, initialGuess4 }), tolerance, maxIterations);
return Tuple.Create(result.MinimizingPoint[0], result.MinimizingPoint[1], result.MinimizingPoint[2], result.MinimizingPoint[3], result.MinimizingPoint[4]);
return (result.MinimizingPoint[0], result.MinimizingPoint[1], result.MinimizingPoint[2], result.MinimizingPoint[3], result.MinimizingPoint[4]);
}
/// <summary>
@ -144,7 +144,7 @@ namespace MathNet.Numerics
/// For more options and diagnostics consider to use <see cref="BfgsMinimizer"/> directly.
/// An alternative routine using conjugate gradients (CG) is available in <see cref="ConjugateGradientMinimizer"/>.
/// </summary>
public static Vector<double> OfFunctionGradient(Func<Vector<double>, Tuple<double, Vector<double>>> functionGradient, Vector<double> initialGuess, double gradientTolerance=1e-5, double parameterTolerance=1e-5, double functionProgressTolerance=1e-5, int maxIterations=1000)
public static Vector<double> OfFunctionGradient(Func<Vector<double>, (double, Vector<double>)> functionGradient, Vector<double> initialGuess, double gradientTolerance=1e-5, double parameterTolerance=1e-5, double functionProgressTolerance=1e-5, int maxIterations=1000)
{
var objective = ObjectiveFunction.Gradient(functionGradient);
var algorithm = new BfgsMinimizer(gradientTolerance, parameterTolerance, functionProgressTolerance, maxIterations);
@ -168,7 +168,7 @@ namespace MathNet.Numerics
/// Find vector x that minimizes the function f(x), constrained within bounds, using the Broyden–Fletcher–Goldfarb–Shanno Bounded (BFGS-B) algorithm.
/// For more options and diagnostics consider to use <see cref="BfgsBMinimizer"/> directly.
/// </summary>
public static Vector<double> OfFunctionGradientConstrained(Func<Vector<double>, Tuple<double, Vector<double>>> functionGradient, Vector<double> lowerBound, Vector<double> upperBound, Vector<double> initialGuess, double gradientTolerance=1e-5, double parameterTolerance=1e-5, double functionProgressTolerance=1e-5, int maxIterations=1000)
public static Vector<double> OfFunctionGradientConstrained(Func<Vector<double>, (double, Vector<double>)> functionGradient, Vector<double> lowerBound, Vector<double> upperBound, Vector<double> initialGuess, double gradientTolerance=1e-5, double parameterTolerance=1e-5, double functionProgressTolerance=1e-5, int maxIterations=1000)
{
var objective = ObjectiveFunction.Gradient(functionGradient);
var algorithm = new BfgsBMinimizer(gradientTolerance, parameterTolerance, functionProgressTolerance, maxIterations);
@ -191,7 +191,7 @@ namespace MathNet.Numerics
/// Find vector x that minimizes the function f(x) using the Newton algorithm.
/// For more options and diagnostics consider to use <see cref="NewtonMinimizer"/> directly.
/// </summary>
public static Vector<double> OfFunctionGradientHessian(Func<Vector<double>, Tuple<double, Vector<double>, Matrix<double>>> functionGradientHessian, Vector<double> initialGuess, double gradientTolerance=1e-8, int maxIterations=1000)
public static Vector<double> OfFunctionGradientHessian(Func<Vector<double>, (double, Vector<double>, Matrix<double>)> functionGradientHessian, Vector<double> initialGuess, double gradientTolerance=1e-8, int maxIterations=1000)
{
var objective = ObjectiveFunction.GradientHessian(functionGradientHessian);
var result = NewtonMinimizer.Minimum(objective, initialGuess, gradientTolerance, maxIterations);

8
src/Numerics/FindRoots.cs

@ -84,26 +84,26 @@ namespace MathNet.Numerics
/// Find both complex roots of the quadratic equation c + b*x + a*x^2 = 0.
/// Note the special coefficient order ascending by exponent (consistent with polynomials).
/// </summary>
public static Tuple<Complex, Complex> Quadratic(double c, double b, double a)
public static (Complex, Complex) Quadratic(double c, double b, double a)
{
if (b == 0d)
{
var t = new Complex(-c/a, 0d).SquareRoot();
return new Tuple<Complex, Complex>(t, -t);
return (t, -t);
}
var q = b > 0d
? -0.5*(b + new Complex(b*b - 4*a*c, 0d).SquareRoot())
: -0.5*(b - new Complex(b*b - 4*a*c, 0d).SquareRoot());
return new Tuple<Complex, Complex>(q/a, c/q);
return (q/a, c/q);
}
/// <summary>
/// Find all three complex roots of the cubic equation d + c*x + b*x^2 + a*x^3 = 0.
/// Note the special coefficient order ascending by exponent (consistent with polynomials).
/// </summary>
public static Tuple<Complex, Complex, Complex> Cubic(double d, double c, double b, double a)
public static (Complex, Complex, Complex) Cubic(double d, double c, double b, double a)
{
return RootFinding.Cubic.Roots(d, c, b, a);
}

30
src/Numerics/Fit.cs

@ -45,7 +45,7 @@ namespace MathNet.Numerics
/// returning its best fitting parameters as [a, b] array,
/// where a is the intercept and b the slope.
/// </summary>
public static Tuple<double, double> Line(double[] x, double[] y)
public static (double A, double B) Line(double[] x, double[] y)
{
return SimpleRegression.Fit(x, y);
}
@ -85,12 +85,12 @@ namespace MathNet.Numerics
/// Least-Squares fitting the points (x,y) to an exponential y : x -> a*exp(r*x),
/// returning its best fitting parameters as (a, r) tuple.
/// </summary>
public static Tuple<double, double> Exponential(double[] x, double[] y, DirectRegressionMethod method = DirectRegressionMethod.QR)
public static (double A, double R) Exponential(double[] x, double[] y, DirectRegressionMethod method = DirectRegressionMethod.QR)
{
// Transformation: y_h := ln(y) ~> y_h : x -> ln(a) + r*x;
double[] lny = Generate.Map(y, Math.Log);
double[] p = LinearCombination(x, lny, method, t => 1.0, t => t);
return Tuple.Create(Math.Exp(p[0]), p[1]);
return (Math.Exp(p[0]), p[1]);
}
/// <summary>
@ -109,11 +109,11 @@ namespace MathNet.Numerics
/// Least-Squares fitting the points (x,y) to a logarithm y : x -> a + b*ln(x),
/// returning its best fitting parameters as (a, b) tuple.
/// </summary>
public static Tuple<double, double> Logarithm(double[] x, double[] y, DirectRegressionMethod method = DirectRegressionMethod.QR)
public static (double A, double B) Logarithm(double[] x, double[] y, DirectRegressionMethod method = DirectRegressionMethod.QR)
{
double[] lnx = Generate.Map(x, Math.Log);
double[] p = LinearCombination(lnx, y, method, t => 1.0, t => t);
return Tuple.Create(p[0], p[1]);
return (p[0], p[1]);
}
/// <summary>
@ -132,12 +132,12 @@ namespace MathNet.Numerics
/// Least-Squares fitting the points (x,y) to a power y : x -> a*x^b,
/// returning its best fitting parameters as (a, b) tuple.
/// </summary>
public static Tuple<double, double> Power(double[] x, double[] y, DirectRegressionMethod method = DirectRegressionMethod.QR)
public static (double A, double B) Power(double[] x, double[] y, DirectRegressionMethod method = DirectRegressionMethod.QR)
{
// Transformation: y_h := ln(y) ~> y_h : x -> ln(a) + b*ln(x);
double[] lny = Generate.Map(y, Math.Log);
double[] p = LinearCombination(x, lny, method, t => 1.0, Math.Log);
return Tuple.Create(Math.Exp(p[0]), p[1]);
return (Math.Exp(p[0]), p[1]);
}
/// <summary>
@ -348,7 +348,7 @@ namespace MathNet.Numerics
/// Non-linear least-squares fitting the points (x,y) to an arbitrary function y : x -> f(p0, p1, x),
/// returning its best fitting parameter p0 and p1.
/// </summary>
public static Tuple<double, double> Curve(double[] x, double[] y, Func<double, double, double, double> f, double initialGuess0, double initialGuess1, double tolerance = 1e-8, int maxIterations = 1000)
public static (double P0, double P1) Curve(double[] x, double[] y, Func<double, double, double, double> f, double initialGuess0, double initialGuess1, double tolerance = 1e-8, int maxIterations = 1000)
{
return FindMinimum.OfFunction((p0, p1) => Distance.Euclidean(Generate.Map(x, t => f(p0, p1, t)), y), initialGuess0, initialGuess1, tolerance, maxIterations);
}
@ -357,7 +357,7 @@ namespace MathNet.Numerics
/// Non-linear least-squares fitting the points (x,y) to an arbitrary function y : x -> f(p0, p1, p2, x),
/// returning its best fitting parameter p0, p1 and p2.
/// </summary>
public static Tuple<double, double, double> Curve(double[] x, double[] y, Func<double, double, double, double, double> f, double initialGuess0, double initialGuess1, double initialGuess2, double tolerance = 1e-8, int maxIterations = 1000)
public static (double P0, double P1, double P2) Curve(double[] x, double[] y, Func<double, double, double, double, double> f, double initialGuess0, double initialGuess1, double initialGuess2, double tolerance = 1e-8, int maxIterations = 1000)
{
return FindMinimum.OfFunction((p0, p1, p2) => Distance.Euclidean(Generate.Map(x, t => f(p0, p1, p2, t)), y), initialGuess0, initialGuess1, initialGuess2, tolerance, maxIterations);
}
@ -366,7 +366,7 @@ namespace MathNet.Numerics
/// Non-linear least-squares fitting the points (x,y) to an arbitrary function y : x -> f(p0, p1, p2, p3, x),
/// returning its best fitting parameter p0, p1, p2 and p3.
/// </summary>
public static Tuple<double, double, double, double> Curve(double[] x, double[] y, Func<double, double, double, double, double, double> f, double initialGuess0, double initialGuess1, double initialGuess2, double initialGuess3, double tolerance = 1e-8, int maxIterations = 1000)
public static (double P0, double P1, double P2, double P3) Curve(double[] x, double[] y, Func<double, double, double, double, double, double> f, double initialGuess0, double initialGuess1, double initialGuess2, double initialGuess3, double tolerance = 1e-8, int maxIterations = 1000)
{
return FindMinimum.OfFunction((p0, p1, p2, p3) => Distance.Euclidean(Generate.Map(x, t => f(p0, p1, p2, p3, t)), y), initialGuess0, initialGuess1, initialGuess2, initialGuess3, tolerance, maxIterations);
}
@ -375,7 +375,7 @@ namespace MathNet.Numerics
/// Non-linear least-squares fitting the points (x,y) to an arbitrary function y : x -> f(p0, p1, p2, p3, p4, x),
/// returning its best fitting parameter p0, p1, p2, p3 and p4.
/// </summary>
public static Tuple<double, double, double, double, double> Curve(double[] x, double[] y, Func<double, double, double, double, double, double, double> f, double initialGuess0, double initialGuess1, double initialGuess2, double initialGuess3, double initialGuess4, double tolerance = 1e-8, int maxIterations = 1000)
public static (double P0, double P1, double P2, double P3, double P4) Curve(double[] x, double[] y, Func<double, double, double, double, double, double, double> f, double initialGuess0, double initialGuess1, double initialGuess2, double initialGuess3, double initialGuess4, double tolerance = 1e-8, int maxIterations = 1000)
{
return FindMinimum.OfFunction((p0, p1, p2, p3, p4) => Distance.Euclidean(Generate.Map(x, t => f(p0, p1, p2, p3, p4, t)), y), initialGuess0, initialGuess1, initialGuess2, initialGuess3, initialGuess4, tolerance, maxIterations);
}
@ -397,7 +397,7 @@ namespace MathNet.Numerics
public static Func<double, double> CurveFunc(double[] x, double[] y, Func<double, double, double, double> f, double initialGuess0, double initialGuess1, double tolerance = 1e-8, int maxIterations = 1000)
{
var parameters = Curve(x, y, f, initialGuess0, initialGuess1, tolerance, maxIterations);
return z => f(parameters.Item1, parameters.Item2, z);
return z => f(parameters.P0, parameters.P1, z);
}
/// <summary>
@ -407,7 +407,7 @@ namespace MathNet.Numerics
public static Func<double, double> CurveFunc(double[] x, double[] y, Func<double, double, double, double, double> f, double initialGuess0, double initialGuess1, double initialGuess2, double tolerance = 1e-8, int maxIterations = 1000)
{
var parameters = Curve(x, y, f, initialGuess0, initialGuess1, initialGuess2, tolerance, maxIterations);
return z => f(parameters.Item1, parameters.Item2, parameters.Item3, z);
return z => f(parameters.P0, parameters.P1, parameters.P2, z);
}
/// <summary>
@ -417,7 +417,7 @@ namespace MathNet.Numerics
public static Func<double, double> CurveFunc(double[] x, double[] y, Func<double, double, double, double, double, double> f, double initialGuess0, double initialGuess1, double initialGuess2, double initialGuess3, double tolerance = 1e-8, int maxIterations = 1000)
{
var parameters = Curve(x, y, f, initialGuess0, initialGuess1, initialGuess2, initialGuess3, tolerance, maxIterations);
return z => f(parameters.Item1, parameters.Item2, parameters.Item3, parameters.Item4, z);
return z => f(parameters.P0, parameters.P1, parameters.P2, parameters.P3, z);
}
/// <summary>
@ -427,7 +427,7 @@ namespace MathNet.Numerics
public static Func<double, double> CurveFunc(double[] x, double[] y, Func<double, double, double, double, double, double, double> f, double initialGuess0, double initialGuess1, double initialGuess2, double initialGuess3, double initialGuess4, double tolerance = 1e-8, int maxIterations = 1000)
{
var parameters = Curve(x, y, f, initialGuess0, initialGuess1, initialGuess2, initialGuess3, initialGuess4, tolerance, maxIterations);
return z => f(parameters.Item1, parameters.Item2, parameters.Item3, parameters.Item4, parameters.Item5, z);
return z => f(parameters.P0, parameters.P1, parameters.P2, parameters.P3, parameters.P4, z);
}
}
}

18
src/Numerics/Integration/GaussRule/GaussKronrodPoint.cs

@ -530,7 +530,7 @@ namespace MathNet.Numerics.Integration.GaussRule
/// <summary>
/// Return value and derivative of a Legendre series at given points.
/// </summary>
static Tuple<double, double> LegendreSeries(double[] a, double x)
static (double, double) LegendreSeries(double[] a, double x)
{
// S = a[0]*P[0, x] + ... + a[k]*P[k, x] + ... + a[n]*P[n, x]
// where P[k, x] is the Legendre polynomial of order k
@ -548,9 +548,9 @@ namespace MathNet.Numerics.Integration.GaussRule
// b'[k, x] = (2k + 1)/(k + 1)*b[k + 1, x] + (2k + 1)/(k + 1)*x*b'[k + 1, x] - (k + 1)/(k + 2)*b'[k + 2, x]
if (a.Length == 1)
return new Tuple<double, double>(a[0], 0);
return (a[0], 0);
if (a.Length == 2)
return new Tuple<double, double>(a[0] + a[1] * x, a[1]);
return (a[0] + a[1] * x, a[1]);
double b0 = 0.0, b1 = 0.0, b2 = 0.0;
double p0 = 0.0, p1 = 0.0, p2 = 0.0;
@ -568,14 +568,13 @@ namespace MathNet.Numerics.Integration.GaussRule
var value = a[0] + b1 * x - 0.5 * b2;
var derivative = b1 + p1 * x - 0.5 * p2;
return new Tuple<double, double>( value, derivative );
return (value, derivative);
}
/// <summary>
/// Return value and derivative of a Legendre polynomial of order at given points.
/// </summary>
static Tuple<double, double> LegendreP(int order, double x)
static (double, double) LegendreP(int order, double x)
{
// The Legendre polynomial, P[n, x], is defined by the recurrence relation:
//
@ -590,9 +589,9 @@ namespace MathNet.Numerics.Integration.GaussRule
// = (2 * n + 1) * (P[n, x] + x * P'[n, x]) - n * P'[n - 1, x]
if (order == 0)
return new Tuple<double, double>(1.0, 0.0);
return (1.0, 0.0);
if (order == 1)
return new Tuple<double, double>(x, 1.0);
return (x, 1.0);
double b0 = 0.0, b1 = 1.0, b2 = 0.0;
double p0 = 0.0, p1 = 0.0, p2 = 0.0;
@ -610,8 +609,7 @@ namespace MathNet.Numerics.Integration.GaussRule
var value = b0;
var derivative = p0;
return new Tuple<double, double>(value, derivative);
return (value, derivative);
}
}
}

6
src/Numerics/LinearRegression/SimpleRegression.cs

@ -41,7 +41,7 @@ namespace MathNet.Numerics.LinearRegression
/// </summary>
/// <param name="x">Predictor (independent)</param>
/// <param name="y">Response (dependent)</param>
public static Tuple<double, double> Fit(double[] x, double[] y)
public static (double A, double B) Fit(double[] x, double[] y)
{
if (x.Length != y.Length)
{
@ -76,7 +76,7 @@ namespace MathNet.Numerics.LinearRegression
}
var b = covariance/variance;
return new Tuple<double, double>(my - b*mx, b);
return (my - b*mx, b);
}
/// <summary>
@ -85,7 +85,7 @@ namespace MathNet.Numerics.LinearRegression
/// where a is the intercept and b the slope.
/// </summary>
/// <param name="samples">Predictor-Response samples as tuples</param>
public static Tuple<double, double> Fit(IEnumerable<Tuple<double, double>> samples)
public static (double A, double B) Fit(IEnumerable<Tuple<double, double>> samples)
{
var xy = samples.UnpackSinglePass();
return Fit(xy.Item1, xy.Item2);

6
src/Numerics/Optimization/ObjectiveFunction.cs

@ -46,7 +46,7 @@ namespace MathNet.Numerics.Optimization
/// <summary>
/// Objective function where the Gradient is available. Greedy evaluation.
/// </summary>
public static IObjectiveFunction Gradient(Func<Vector<double>, Tuple<double, Vector<double>>> function)
public static IObjectiveFunction Gradient(Func<Vector<double>, (double, Vector<double>)> function)
{
return new GradientObjectiveFunction(function);
}
@ -62,7 +62,7 @@ namespace MathNet.Numerics.Optimization
/// <summary>
/// Objective function where the Hessian is available. Greedy evaluation.
/// </summary>
public static IObjectiveFunction Hessian(Func<Vector<double>, Tuple<double, Matrix<double>>> function)
public static IObjectiveFunction Hessian(Func<Vector<double>, (double, Matrix<double>)> function)
{
return new HessianObjectiveFunction(function);
}
@ -78,7 +78,7 @@ namespace MathNet.Numerics.Optimization
/// <summary>
/// Objective function where both Gradient and Hessian are available. Greedy evaluation.
/// </summary>
public static IObjectiveFunction GradientHessian(Func<Vector<double>, Tuple<double, Vector<double>, Matrix<double>>> function)
public static IObjectiveFunction GradientHessian(Func<Vector<double>, (double, Vector<double>, Matrix<double>)> function)
{
return new GradientHessianObjectiveFunction(function);
}

10
src/Numerics/Optimization/ObjectiveFunctions/GradientHessianObjectiveFunction.cs

@ -34,9 +34,9 @@ namespace MathNet.Numerics.Optimization.ObjectiveFunctions
{
internal class GradientHessianObjectiveFunction : IObjectiveFunction
{
readonly Func<Vector<double>, Tuple<double, Vector<double>, Matrix<double>>> _function;
readonly Func<Vector<double>, (double, Vector<double>, Matrix<double>)> _function;
public GradientHessianObjectiveFunction(Func<Vector<double>, Tuple<double, Vector<double>, Matrix<double>>> function)
public GradientHessianObjectiveFunction(Func<Vector<double>, (double, Vector<double>, Matrix<double>)> function)
{
_function = function;
}
@ -65,11 +65,7 @@ namespace MathNet.Numerics.Optimization.ObjectiveFunctions
public void EvaluateAt(Vector<double> point)
{
Point = point;
var result = _function(point);
Value = result.Item1;
Gradient = result.Item2;
Hessian = result.Item3;
(Value, Gradient, Hessian) = _function(point);
}
public Vector<double> Point { get; private set; }

9
src/Numerics/Optimization/ObjectiveFunctions/GradientObjectiveFunction.cs

@ -34,9 +34,9 @@ namespace MathNet.Numerics.Optimization.ObjectiveFunctions
{
internal class GradientObjectiveFunction : IObjectiveFunction
{
readonly Func<Vector<double>, Tuple<double, Vector<double>>> _function;
readonly Func<Vector<double>, (double, Vector<double>)> _function;
public GradientObjectiveFunction(Func<Vector<double>, Tuple<double, Vector<double>>> function)
public GradientObjectiveFunction(Func<Vector<double>, (double, Vector<double>)> function)
{
_function = function;
}
@ -64,10 +64,7 @@ namespace MathNet.Numerics.Optimization.ObjectiveFunctions
public void EvaluateAt(Vector<double> point)
{
Point = point;
var result = _function(point);
Value = result.Item1;
Gradient = result.Item2;
(Value, Gradient) = _function(point);
}
public Vector<double> Point { get; private set; }

9
src/Numerics/Optimization/ObjectiveFunctions/HessianObjectiveFunction.cs

@ -34,9 +34,9 @@ namespace MathNet.Numerics.Optimization.ObjectiveFunctions
{
internal class HessianObjectiveFunction : IObjectiveFunction
{
readonly Func<Vector<double>, Tuple<double, Matrix<double>>> _function;
readonly Func<Vector<double>, (double, Matrix<double>)> _function;
public HessianObjectiveFunction(Func<Vector<double>, Tuple<double, Matrix<double>>> function)
public HessianObjectiveFunction(Func<Vector<double>, (double, Matrix<double>)> function)
{
_function = function;
}
@ -64,10 +64,7 @@ namespace MathNet.Numerics.Optimization.ObjectiveFunctions
public void EvaluateAt(Vector<double> point)
{
Point = point;
var result = _function(point);
Value = result.Item1;
Hessian = result.Item2;
(Value, Hessian) = _function(point);
}
public Vector<double> Point { get; private set; }

5
src/Numerics/Optimization/ObjectiveFunctions/NonlinearObjectiveFunction.cs

@ -265,11 +265,10 @@ namespace MathNet.Numerics.Optimization.ObjectiveFunctions
public IObjectiveFunction ToObjectiveFunction()
{
Tuple<double, Vector<double>, Matrix<double>> Function(Vector<double> point)
(double, Vector<double>, Matrix<double>) Function(Vector<double> point)
{
EvaluateAt(point);
return new Tuple<double, Vector<double>, Matrix<double>>(Value, Gradient, Hessian);
return (Value, Gradient, Hessian);
}
var objective = new GradientHessianObjectiveFunction(Function);

6
src/Numerics/Optimization/TrustRegion/Subproblems/Util.cs

@ -5,7 +5,7 @@ namespace MathNet.Numerics.Optimization.TrustRegion.Subproblems
{
internal static class Util
{
public static Tuple<double, double> FindBeta(double alpha, Vector<double> sd, Vector<double> gn, double delta)
public static (double, double) FindBeta(double alpha, Vector<double> sd, Vector<double> gn, double delta)
{
// Pstep is intersection of the trust region boundary
// Pstep = α*Psd + β*(Pgn - α*Psd)
@ -27,9 +27,7 @@ namespace MathNet.Numerics.Optimization.TrustRegion.Subproblems
var beta2 = -2.0 * c / aux;
// return sorted beta
return (beta1 < beta2)
? new Tuple<double, double>(beta1, beta2)
: new Tuple<double, double>(beta2, beta1);
return beta1 < beta2 ? (beta1, beta2) : (beta2, beta1);
}
}
}

12
src/Numerics/Polynomial.cs

@ -624,7 +624,7 @@ namespace MathNet.Numerics
/// <param name="a">Left polynomial</param>
/// <param name="b">Right polynomial</param>
/// <returns>A tuple holding quotient in first and remainder in second</returns>
public static Tuple<Polynomial, Polynomial> DivideRemainder(Polynomial a, Polynomial b)
public static (Polynomial, Polynomial) DivideRemainder(Polynomial a, Polynomial b)
{
var bDegree = b.Degree;
if (bDegree < 0)
@ -636,20 +636,20 @@ namespace MathNet.Numerics
if (aDegree < 0)
{
// zero divided by non-zero is zero without remainder
return Tuple.Create(a, a);
return (a, a);
}
if (bDegree == 0)
{
// division by scalar
return Tuple.Create(Divide(a, b.Coefficients[0]), Zero);
return (Divide(a, b.Coefficients[0]), Zero);
}
if (aDegree < bDegree)
{
// denominator degree higher than nominator degree
// quotient always be 0 and return c1 as remainder
return Tuple.Create(Zero, a);
return (Zero, a);
}
var c1 = a.Coefficients.ToArray();
@ -691,7 +691,7 @@ namespace MathNet.Numerics
rem[k] = c1[k];
}
return Tuple.Create(new Polynomial(quo), new Polynomial(rem));
return (new Polynomial(quo), new Polynomial(rem));
}
#endregion
@ -756,7 +756,7 @@ namespace MathNet.Numerics
/// </summary>
/// <param name="b">Right polynomial</param>
/// <returns>A tuple holding quotient in first and remainder in second</returns>
public Tuple<Polynomial, Polynomial> DivideRemainder(Polynomial b)
public (Polynomial, Polynomial) DivideRemainder(Polynomial b)
{
return DivideRemainder(this, b);
}

16
src/Numerics/Precision.cs

@ -446,7 +446,7 @@ namespace MathNet.Numerics
/// Thrown if <paramref name="maxNumbersBetween"/> is smaller than zero.
/// </exception>
/// <returns>Tuple of the bottom and top range ends.</returns>
public static Tuple<double, double> RangeOfMatchingFloatingPointNumbers(this double value, long maxNumbersBetween)
public static (double, double) RangeOfMatchingFloatingPointNumbers(this double value, long maxNumbersBetween)
{
// Make sure ulpDifference is non-negative
if (maxNumbersBetween < 1)
@ -458,13 +458,13 @@ namespace MathNet.Numerics
// return the same infinity for the range.
if (double.IsInfinity(value))
{
return new Tuple<double, double>(value, value);
return (value, value);
}
// If the value is a NaN then the range is a NaN too.
if (double.IsNaN(value))
{
return new Tuple<double, double>(double.NaN, double.NaN);
return (double.NaN, double.NaN);
}
// Translate the bit pattern of the double to an integer.
@ -498,7 +498,7 @@ namespace MathNet.Numerics
// However due to the conversion way this means that the actual double value gets more negative :-S
: BitConverter.Int64BitsToDouble(intValue + maxNumbersBetween);
return new Tuple<double, double>(bottomRangeEnd, topRangeEnd);
return (bottomRangeEnd, topRangeEnd);
}
else
{
@ -519,7 +519,7 @@ namespace MathNet.Numerics
// the reversal at the negative end
: BitConverter.Int64BitsToDouble(long.MinValue + (maxNumbersBetween - intValue));
return new Tuple<double, double>(bottomRangeEnd, topRangeEnd);
return (bottomRangeEnd, topRangeEnd);
}
}
@ -565,7 +565,7 @@ namespace MathNet.Numerics
/// Tuple with the number of ULPS between the <c>value</c> and the <c>value - relativeDifference</c> as first,
/// and the number of ULPS between the <c>value</c> and the <c>value + relativeDifference</c> as second value.
/// </returns>
public static Tuple<long, long> RangeOfMatchingNumbers(this double value, double relativeDifference)
public static (long, long) RangeOfMatchingNumbers(this double value, double relativeDifference)
{
// Make sure the relative is non-negative
if (relativeDifference < 0)
@ -591,7 +591,7 @@ namespace MathNet.Numerics
if (value.Equals(0))
{
var v = BitConverter.DoubleToInt64Bits(relativeDifference);
return new Tuple<long, long>(v, v);
return (v, v);
}
// Calculate the ulps for the maximum and minimum values
@ -603,7 +603,7 @@ namespace MathNet.Numerics
long intValue = AsDirectionalInt64(value);
// Determine the ranges
return new Tuple<long, long>(Math.Abs(intValue - min), Math.Abs(max - intValue));
return (Math.Abs(intValue - min), Math.Abs(max - intValue));
}
/// <summary>

15
src/Numerics/RootFinding/Cubic.cs

@ -64,7 +64,7 @@ namespace MathNet.Numerics.RootFinding
/// Find all real-valued roots of the cubic equation a0 + a1*x + a2*x^2 + x^3 = 0.
/// Note the special coefficient order ascending by exponent (consistent with polynomials).
/// </summary>
public static Tuple<double, double, double> RealRoots(double a0, double a1, double a2)
public static (double, double, double) RealRoots(double a0, double a1, double a2)
{
double Q, R;
QR(a2, a1, a0, out Q, out R);
@ -98,14 +98,14 @@ namespace MathNet.Numerics.RootFinding
x3 = 2d*Math.Sqrt(-Q)*Math.Cos((theta - Constants.Pi2)/3d) + shift;
}
return new Tuple<double, double, double>(x1, x2, x3);
return (x1, x2, x3);
}
/// <summary>
/// Find all three complex roots of the cubic equation d + c*x + b*x^2 + a*x^3 = 0.
/// Note the special coefficient order ascending by exponent (consistent with polynomials).
/// </summary>
public static Tuple<Complex, Complex, Complex> Roots(double d, double c, double b, double a)
public static (Complex, Complex, Complex) Roots(double d, double c, double b, double a)
{
double A = b*b - 3*a*c;
double B = 2*b*b*b - 9*a*b*c + 27*a*a*d;
@ -117,22 +117,19 @@ namespace MathNet.Numerics.RootFinding
if (A == 0d)
{
var u = new Complex(s*b, 0d);
return new Tuple<Complex, Complex, Complex>(u, u, u);
return (u, u, u);
}
var v = new Complex((9*a*d - b*c)/(2*A), 0d);
var w = new Complex((4*a*b*c - 9*a*a*d - b*b*b)/(a*A), 0d);
return new Tuple<Complex, Complex, Complex>(v, v, w);
return (v, v, w);
}
var C = (A == 0)
? new Complex(B, 0d).CubicRoots()
: ((B + Complex.Sqrt(B*B - 4*A*A*A))/2).CubicRoots();
return new Tuple<Complex, Complex, Complex>(
s*(b + C.Item1 + A/C.Item1),
s*(b + C.Item2 + A/C.Item2),
s*(b + C.Item3 + A/C.Item3));
return (s*(b + C.Item1 + A/C.Item1), s*(b + C.Item2 + A/C.Item2), s*(b + C.Item3 + A/C.Item3));
}
}
}

4
src/Numerics/RootFinding/RobustNewtonRaphson.cs

@ -171,9 +171,9 @@ namespace MathNet.Numerics.RootFinding
static bool TryScanForCrossingsWithRoots(Func<double, double> f, Func<double, double> df, double lowerBound, double upperBound, double accuracy, int maxIterations, int subdivision, out double root)
{
var zeroCrossings = ZeroCrossingBracketing.FindIntervalsWithin(f, lowerBound, upperBound, subdivision);
foreach (Tuple<double, double> bounds in zeroCrossings)
foreach ((double lower, double upper) in zeroCrossings)
{
if (TryFindRoot(f, df, bounds.Item1, bounds.Item2, accuracy, maxIterations, subdivision, out root))
if (TryFindRoot(f, df, lower, upper, accuracy, maxIterations, subdivision, out root))
{
return true;
}

6
src/Numerics/RootFinding/ZeroCrossingBracketing.cs

@ -34,7 +34,7 @@ namespace MathNet.Numerics.RootFinding
{
public static class ZeroCrossingBracketing
{
public static IEnumerable<Tuple<double, double>> FindIntervalsWithin(Func<double, double> f, double lowerBound, double upperBound, int subdivisions)
public static IEnumerable<(double, double)> FindIntervalsWithin(Func<double, double> f, double lowerBound, double upperBound, int subdivisions)
{
// TODO: Consider binary-style search instead of linear scan
double fmin = f(lowerBound);
@ -42,7 +42,7 @@ namespace MathNet.Numerics.RootFinding
if (Math.Sign(fmin) != Math.Sign(fmax))
{
yield return new Tuple<double, double>(lowerBound, upperBound);
yield return (lowerBound, upperBound);
yield break;
}
@ -63,7 +63,7 @@ namespace MathNet.Numerics.RootFinding
if (Math.Sign(sfmax) != sign)
{
yield return new Tuple<double, double>(smin, smax);
yield return (smin, smax);
sign = Math.Sign(sfmax);
}

8
src/Numerics/Statistics/ArrayStatistics.Int32.cs

@ -175,9 +175,9 @@ namespace MathNet.Numerics.Statistics
/// Returns NaN for mean if data is empty or any entry is NaN and NaN for variance if data has less than two entries or if any entry is NaN.
/// </summary>
/// <param name="samples">Sample array, no sorting is assumed.</param>
public static Tuple<double, double> MeanVariance(int[] samples)
public static (double Mean, double Variance) MeanVariance(int[] samples)
{
return new Tuple<double, double>(Mean(samples), Variance(samples));
return (Mean(samples), Variance(samples));
}
/// <summary>
@ -186,9 +186,9 @@ namespace MathNet.Numerics.Statistics
/// Returns NaN for mean if data is empty or any entry is NaN and NaN for standard deviation if data has less than two entries or if any entry is NaN.
/// </summary>
/// <param name="samples">Sample array, no sorting is assumed.</param>
public static Tuple<double, double> MeanStandardDeviation(int[] samples)
public static (double Mean, double StandardDeviation) MeanStandardDeviation(int[] samples)
{
return new Tuple<double, double>(Mean(samples), StandardDeviation(samples));
return (Mean(samples), StandardDeviation(samples));
}
/// <summary>

8
src/Numerics/Statistics/ArrayStatistics.Single.cs

@ -271,9 +271,9 @@ namespace MathNet.Numerics.Statistics
/// Returns NaN for mean if data is empty or any entry is NaN and NaN for variance if data has less than two entries or if any entry is NaN.
/// </summary>
/// <param name="samples">Sample array, no sorting is assumed.</param>
public static Tuple<double, double> MeanVariance(float[] samples)
public static (double Mean, double Variance) MeanVariance(float[] samples)
{
return new Tuple<double, double>(Mean(samples), Variance(samples));
return (Mean(samples), Variance(samples));
}
/// <summary>
@ -282,9 +282,9 @@ namespace MathNet.Numerics.Statistics
/// Returns NaN for mean if data is empty or any entry is NaN and NaN for standard deviation if data has less than two entries or if any entry is NaN.
/// </summary>
/// <param name="samples">Sample array, no sorting is assumed.</param>
public static Tuple<double, double> MeanStandardDeviation(float[] samples)
public static (double Mean, double StandardDeviation) MeanStandardDeviation(float[] samples)
{
return new Tuple<double, double>(Mean(samples), StandardDeviation(samples));
return (Mean(samples), StandardDeviation(samples));
}
/// <summary>

8
src/Numerics/Statistics/ArrayStatistics.cs

@ -281,9 +281,9 @@ namespace MathNet.Numerics.Statistics
/// Returns NaN for mean if data is empty or any entry is NaN and NaN for variance if data has less than two entries or if any entry is NaN.
/// </summary>
/// <param name="samples">Sample array, no sorting is assumed.</param>
public static Tuple<double, double> MeanVariance(double[] samples)
public static (double Mean, double Variance) MeanVariance(double[] samples)
{
return new Tuple<double, double>(Mean(samples), Variance(samples));
return (Mean(samples), Variance(samples));
}
/// <summary>
@ -292,9 +292,9 @@ namespace MathNet.Numerics.Statistics
/// Returns NaN for mean if data is empty or any entry is NaN and NaN for standard deviation if data has less than two entries or if any entry is NaN.
/// </summary>
/// <param name="samples">Sample array, no sorting is assumed.</param>
public static Tuple<double, double> MeanStandardDeviation(double[] samples)
public static (double Mean, double StandardDeviation) MeanStandardDeviation(double[] samples)
{
return new Tuple<double, double>(Mean(samples), StandardDeviation(samples));
return (Mean(samples), StandardDeviation(samples));
}
/// <summary>

16
src/Numerics/Statistics/Statistics.cs

@ -561,7 +561,7 @@ namespace MathNet.Numerics.Statistics
/// </summary>
/// <param name="samples">The data to calculate the mean of.</param>
/// <returns>The mean of the sample.</returns>
public static Tuple<double, double> MeanVariance(this IEnumerable<double> samples)
public static (double Mean, double Variance) MeanVariance(this IEnumerable<double> samples)
{
return samples is double[] array
? ArrayStatistics.MeanVariance(array)
@ -575,7 +575,7 @@ namespace MathNet.Numerics.Statistics
/// </summary>
/// <param name="samples">The data to calculate the mean of.</param>
/// <returns>The mean of the sample.</returns>
public static Tuple<double, double> MeanVariance(this IEnumerable<float> samples)
public static (double Mean, double Variance) MeanVariance(this IEnumerable<float> samples)
{
return samples is float[] array
? ArrayStatistics.MeanVariance(array)
@ -589,7 +589,7 @@ namespace MathNet.Numerics.Statistics
/// </summary>
/// <param name="samples">The data to calculate the mean of.</param>
/// <returns>The mean of the sample.</returns>
public static Tuple<double, double> MeanStandardDeviation(this IEnumerable<double> samples)
public static (double Mean, double StandardDeviation) MeanStandardDeviation(this IEnumerable<double> samples)
{
return samples is double[] array
? ArrayStatistics.MeanStandardDeviation(array)
@ -603,7 +603,7 @@ namespace MathNet.Numerics.Statistics
/// </summary>
/// <param name="samples">The data to calculate the mean of.</param>
/// <returns>The mean of the sample.</returns>
public static Tuple<double, double> MeanStandardDeviation(this IEnumerable<float> samples)
public static (double Mean, double StandardDeviation) MeanStandardDeviation(this IEnumerable<float> samples)
{
return samples is float[] array
? ArrayStatistics.MeanStandardDeviation(array)
@ -615,10 +615,10 @@ namespace MathNet.Numerics.Statistics
/// Uses a normalizer (Bessel's correction; type 2).
/// </summary>
/// <param name="samples">A subset of samples, sampled from the full population.</param>
public static Tuple<double, double> SkewnessKurtosis(this IEnumerable<double> samples)
public static (double Skewness, double Kurtosis) SkewnessKurtosis(this IEnumerable<double> samples)
{
var stats = new RunningStatistics(samples);
return new Tuple<double, double>(stats.Skewness, stats.Kurtosis);
return (stats.Skewness, stats.Kurtosis);
}
/// <summary>
@ -626,10 +626,10 @@ namespace MathNet.Numerics.Statistics
/// Does not use a normalizer and would thus be biased if applied to a subset (type 1).
/// </summary>
/// <param name="population">The full population data.</param>
public static Tuple<double, double> PopulationSkewnessKurtosis(this IEnumerable<double> population)
public static (double Skewness, double Kurtosis) PopulationSkewnessKurtosis(this IEnumerable<double> population)
{
var stats = new RunningStatistics(population);
return new Tuple<double, double>(stats.PopulationSkewness, stats.PopulationKurtosis);
return (stats.PopulationSkewness, stats.PopulationKurtosis);
}
/// <summary>

14
src/Numerics/Statistics/StreamingStatistics.cs

@ -573,7 +573,7 @@ namespace MathNet.Numerics.Statistics
/// Returns NaN for mean if data is empty or any entry is NaN, and NaN for variance if data has less than two entries or if any entry is NaN.
/// </summary>
/// <param name="samples">Sample stream, no sorting is assumed.</param>
public static Tuple<double, double> MeanVariance(IEnumerable<double> samples)
public static (double Mean, double Variance) MeanVariance(IEnumerable<double> samples)
{
double mean = 0;
double variance = 0;
@ -599,9 +599,7 @@ namespace MathNet.Numerics.Statistics
}
}
return new Tuple<double, double>(
count > 0 ? mean : double.NaN,
count > 1 ? variance/(count - 1) : double.NaN);
return (count > 0 ? mean : double.NaN, count > 1 ? variance/(count - 1) : double.NaN);
}
/// <summary>
@ -610,7 +608,7 @@ namespace MathNet.Numerics.Statistics
/// Returns NaN for mean if data is empty or any entry is NaN, and NaN for variance if data has less than two entries or if any entry is NaN.
/// </summary>
/// <param name="samples">Sample stream, no sorting is assumed.</param>
public static Tuple<double, double> MeanVariance(IEnumerable<float> samples)
public static (double Mean, double Variance) MeanVariance(IEnumerable<float> samples)
{
return MeanVariance(samples.Select(x => (double)x));
}
@ -621,10 +619,10 @@ namespace MathNet.Numerics.Statistics
/// Returns NaN for mean if data is empty or any entry is NaN, and NaN for standard deviation if data has less than two entries or if any entry is NaN.
/// </summary>
/// <param name="samples">Sample stream, no sorting is assumed.</param>
public static Tuple<double, double> MeanStandardDeviation(IEnumerable<double> samples)
public static (double Mean, double StandardDeviation) MeanStandardDeviation(IEnumerable<double> samples)
{
var meanVariance = MeanVariance(samples);
return new Tuple<double, double>(meanVariance.Item1, Math.Sqrt(meanVariance.Item2));
return (meanVariance.Item1, Math.Sqrt(meanVariance.Item2));
}
/// <summary>
@ -633,7 +631,7 @@ namespace MathNet.Numerics.Statistics
/// Returns NaN for mean if data is empty or any entry is NaN, and NaN for standard deviation if data has less than two entries or if any entry is NaN.
/// </summary>
/// <param name="samples">Sample stream, no sorting is assumed.</param>
public static Tuple<double, double> MeanStandardDeviation(IEnumerable<float> samples)
public static (double Mean, double StandardDeviation) MeanStandardDeviation(IEnumerable<float> samples)
{
return MeanStandardDeviation(samples.Select(x => (double)x));
}

Loading…
Cancel
Save