Browse Source

Remove static properties in LevenbergMarquardtMinimizer. See #672

dependabot/nuget/NUnit3TestAdapter-4.2.0
Jong Hyun Kim 5 years ago
parent
commit
d04897c263
  1. 4
      src/Numerics/Optimization/LevenbergMarquardtMinimizer.cs
  2. 28
      src/Numerics/Optimization/NonlinearMinimizerBase.cs
  3. 6
      src/Numerics/Optimization/TrustRegion/TrustRegionMinimizerBase.cs

4
src/Numerics/Optimization/LevenbergMarquardtMinimizer.cs

@ -10,7 +10,7 @@ namespace MathNet.Numerics.Optimization
/// <summary> /// <summary>
/// The scale factor for initial mu /// The scale factor for initial mu
/// </summary> /// </summary>
public static double InitialMu { get; set; } public double InitialMu { get; set; } = 1E-3;
public LevenbergMarquardtMinimizer(double initialMu = 1E-3, double gradientTolerance = 1E-15, double stepTolerance = 1E-15, double functionTolerance = 1E-15, int maximumIterations = -1) public LevenbergMarquardtMinimizer(double initialMu = 1E-3, double gradientTolerance = 1E-15, double stepTolerance = 1E-15, double functionTolerance = 1E-15, int maximumIterations = -1)
: base(gradientTolerance, stepTolerance, functionTolerance, maximumIterations) : base(gradientTolerance, stepTolerance, functionTolerance, maximumIterations)
@ -51,7 +51,7 @@ namespace MathNet.Numerics.Optimization
/// <param name="functionTolerance">The stopping threshold for L2 norm of the residuals.</param> /// <param name="functionTolerance">The stopping threshold for L2 norm of the residuals.</param>
/// <param name="maximumIterations">The max iterations.</param> /// <param name="maximumIterations">The max iterations.</param>
/// <returns>The result of the Levenberg-Marquardt minimization</returns> /// <returns>The result of the Levenberg-Marquardt minimization</returns>
public static NonlinearMinimizationResult Minimum(IObjectiveModel objective, Vector<double> initialGuess, public NonlinearMinimizationResult Minimum(IObjectiveModel objective, Vector<double> initialGuess,
Vector<double> lowerBound = null, Vector<double> upperBound = null, Vector<double> scales = null, List<bool> isFixed = null, Vector<double> lowerBound = null, Vector<double> upperBound = null, Vector<double> scales = null, List<bool> isFixed = null,
double initialMu = 1E-3, double gradientTolerance = 1E-15, double stepTolerance = 1E-15, double functionTolerance = 1E-15, int maximumIterations = -1) double initialMu = 1E-3, double gradientTolerance = 1E-15, double stepTolerance = 1E-15, double functionTolerance = 1E-15, int maximumIterations = -1)
{ {

28
src/Numerics/Optimization/NonlinearMinimizerBase.cs

@ -9,39 +9,39 @@ namespace MathNet.Numerics.Optimization
/// <summary> /// <summary>
/// The stopping threshold for the function value or L2 norm of the residuals. /// The stopping threshold for the function value or L2 norm of the residuals.
/// </summary> /// </summary>
public static double FunctionTolerance { get; set; } public double FunctionTolerance { get; set; }
/// <summary> /// <summary>
/// The stopping threshold for L2 norm of the change of the parameters. /// The stopping threshold for L2 norm of the change of the parameters.
/// </summary> /// </summary>
public static double StepTolerance { get; set; } public double StepTolerance { get; set; }
/// <summary> /// <summary>
/// The stopping threshold for infinity norm of the gradient. /// The stopping threshold for infinity norm of the gradient.
/// </summary> /// </summary>
public static double GradientTolerance { get; set; } public double GradientTolerance { get; set; }
/// <summary> /// <summary>
/// The maximum number of iterations. /// The maximum number of iterations.
/// </summary> /// </summary>
public static int MaximumIterations { get; set; } public int MaximumIterations { get; set; }
/// <summary> /// <summary>
/// The lower bound of the parameters. /// The lower bound of the parameters.
/// </summary> /// </summary>
public static Vector<double> LowerBound { get; private set; } public Vector<double> LowerBound { get; private set; }
/// <summary> /// <summary>
/// The upper bound of the parameters. /// The upper bound of the parameters.
/// </summary> /// </summary>
public static Vector<double> UpperBound { get; private set; } public Vector<double> UpperBound { get; private set; }
/// <summary> /// <summary>
/// The scale factors for the parameters. /// The scale factors for the parameters.
/// </summary> /// </summary>
public static Vector<double> Scales { get; private set; } public Vector<double> Scales { get; private set; }
private static bool IsBounded => LowerBound != null || UpperBound != null || Scales != null; private bool IsBounded => LowerBound != null || UpperBound != null || Scales != null;
protected NonlinearMinimizerBase(double gradientTolerance = 1E-18, double stepTolerance = 1E-18, double functionTolerance = 1E-18, int maximumIterations = -1) protected NonlinearMinimizerBase(double gradientTolerance = 1E-18, double stepTolerance = 1E-18, double functionTolerance = 1E-18, int maximumIterations = -1)
{ {
@ -51,7 +51,7 @@ namespace MathNet.Numerics.Optimization
MaximumIterations = maximumIterations; MaximumIterations = maximumIterations;
} }
protected static void ValidateBounds(Vector<double> parameters, Vector<double> lowerBound = null, Vector<double> upperBound = null, Vector<double> scales = null) protected void ValidateBounds(Vector<double> parameters, Vector<double> lowerBound = null, Vector<double> upperBound = null, Vector<double> scales = null)
{ {
if (parameters == null) if (parameters == null)
{ {
@ -93,14 +93,14 @@ namespace MathNet.Numerics.Optimization
Scales = scales; Scales = scales;
} }
protected static double EvaluateFunction(IObjectiveModel objective, Vector<double> Pint) protected double EvaluateFunction(IObjectiveModel objective, Vector<double> Pint)
{ {
var Pext = ProjectToExternalParameters(Pint); var Pext = ProjectToExternalParameters(Pint);
objective.EvaluateAt(Pext); objective.EvaluateAt(Pext);
return objective.Value; return objective.Value;
} }
protected static Tuple<Vector<double>, Matrix<double>> EvaluateJacobian(IObjectiveModel objective, Vector<double> Pint) protected Tuple<Vector<double>, Matrix<double>> EvaluateJacobian(IObjectiveModel objective, Vector<double> Pint)
{ {
var gradient = objective.Gradient; var gradient = objective.Gradient;
var hessian = objective.Hessian; var hessian = objective.Hessian;
@ -161,7 +161,7 @@ namespace MathNet.Numerics.Optimization
// Except when it is initial guess, the parameters argument is always internal parameter. // Except when it is initial guess, the parameters argument is always internal parameter.
// So, first map the parameters argument to the external parameters in order to calculate function values. // So, first map the parameters argument to the external parameters in order to calculate function values.
protected static Vector<double> ProjectToInternalParameters(Vector<double> Pext) protected Vector<double> ProjectToInternalParameters(Vector<double> Pext)
{ {
var Pint = Pext.Clone(); var Pint = Pext.Clone();
@ -209,7 +209,7 @@ namespace MathNet.Numerics.Optimization
return Pint; return Pint;
} }
protected static Vector<double> ProjectToExternalParameters(Vector<double> Pint) protected Vector<double> ProjectToExternalParameters(Vector<double> Pint)
{ {
var Pext = Pint.Clone(); var Pext = Pint.Clone();
@ -257,7 +257,7 @@ namespace MathNet.Numerics.Optimization
return Pext; return Pext;
} }
protected static Vector<double> ScaleFactorsOfJacobian(Vector<double> Pint) protected Vector<double> ScaleFactorsOfJacobian(Vector<double> Pint)
{ {
var scale = Vector<double>.Build.Dense(Pint.Count, 1.0); var scale = Vector<double>.Build.Dense(Pint.Count, 1.0);

6
src/Numerics/Optimization/TrustRegion/TrustRegionMinimizerBase.cs

@ -10,12 +10,12 @@ namespace MathNet.Numerics.Optimization.TrustRegion
/// <summary> /// <summary>
/// The trust region subproblem. /// The trust region subproblem.
/// </summary> /// </summary>
public static ITrustRegionSubproblem Subproblem; public ITrustRegionSubproblem Subproblem;
/// <summary> /// <summary>
/// The stopping threshold for the trust region radius. /// The stopping threshold for the trust region radius.
/// </summary> /// </summary>
public static double RadiusTolerance { get; set; } public double RadiusTolerance { get; set; }
public TrustRegionMinimizerBase(ITrustRegionSubproblem subproblem, public TrustRegionMinimizerBase(ITrustRegionSubproblem subproblem,
double gradientTolerance = 1E-8, double stepTolerance = 1E-8, double functionTolerance = 1E-8, double radiusTolerance = 1E-8, int maximumIterations = -1) double gradientTolerance = 1E-8, double stepTolerance = 1E-8, double functionTolerance = 1E-8, double radiusTolerance = 1E-8, int maximumIterations = -1)
@ -59,7 +59,7 @@ namespace MathNet.Numerics.Optimization.TrustRegion
/// <param name="radiusTolerance">The stopping threshold for trust region radius</param> /// <param name="radiusTolerance">The stopping threshold for trust region radius</param>
/// <param name="maximumIterations">The max iterations.</param> /// <param name="maximumIterations">The max iterations.</param>
/// <returns></returns> /// <returns></returns>
public static NonlinearMinimizationResult Minimum(ITrustRegionSubproblem subproblem, IObjectiveModel objective, Vector<double> initialGuess, public NonlinearMinimizationResult Minimum(ITrustRegionSubproblem subproblem, IObjectiveModel objective, Vector<double> initialGuess,
Vector<double> lowerBound = null, Vector<double> upperBound = null, Vector<double> scales = null, List<bool> isFixed = null, Vector<double> lowerBound = null, Vector<double> upperBound = null, Vector<double> scales = null, List<bool> isFixed = null,
double gradientTolerance = 1E-8, double stepTolerance = 1E-8, double functionTolerance = 1E-8, double radiusTolerance = 1E-18, int maximumIterations = -1) double gradientTolerance = 1E-8, double stepTolerance = 1E-8, double functionTolerance = 1E-8, double radiusTolerance = 1E-18, int maximumIterations = -1)
{ {

Loading…
Cancel
Save