Browse Source

Remove static properties in LevenbergMarquardtMinimizer. See #672

pull/762/head
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>
/// The scale factor for initial mu
/// </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)
: 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="maximumIterations">The max iterations.</param>
/// <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,
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>
/// The stopping threshold for the function value or L2 norm of the residuals.
/// </summary>
public static double FunctionTolerance { get; set; }
public double FunctionTolerance { get; set; }
/// <summary>
/// The stopping threshold for L2 norm of the change of the parameters.
/// </summary>
public static double StepTolerance { get; set; }
public double StepTolerance { get; set; }
/// <summary>
/// The stopping threshold for infinity norm of the gradient.
/// </summary>
public static double GradientTolerance { get; set; }
public double GradientTolerance { get; set; }
/// <summary>
/// The maximum number of iterations.
/// </summary>
public static int MaximumIterations { get; set; }
public int MaximumIterations { get; set; }
/// <summary>
/// The lower bound of the parameters.
/// </summary>
public static Vector<double> LowerBound { get; private set; }
public Vector<double> LowerBound { get; private set; }
/// <summary>
/// The upper bound of the parameters.
/// </summary>
public static Vector<double> UpperBound { get; private set; }
public Vector<double> UpperBound { get; private set; }
/// <summary>
/// The scale factors for the parameters.
/// </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)
{
@ -51,7 +51,7 @@ namespace MathNet.Numerics.Optimization
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)
{
@ -93,14 +93,14 @@ namespace MathNet.Numerics.Optimization
Scales = scales;
}
protected static double EvaluateFunction(IObjectiveModel objective, Vector<double> Pint)
protected double EvaluateFunction(IObjectiveModel objective, Vector<double> Pint)
{
var Pext = ProjectToExternalParameters(Pint);
objective.EvaluateAt(Pext);
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 hessian = objective.Hessian;
@ -161,7 +161,7 @@ namespace MathNet.Numerics.Optimization
// 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.
protected static Vector<double> ProjectToInternalParameters(Vector<double> Pext)
protected Vector<double> ProjectToInternalParameters(Vector<double> Pext)
{
var Pint = Pext.Clone();
@ -209,7 +209,7 @@ namespace MathNet.Numerics.Optimization
return Pint;
}
protected static Vector<double> ProjectToExternalParameters(Vector<double> Pint)
protected Vector<double> ProjectToExternalParameters(Vector<double> Pint)
{
var Pext = Pint.Clone();
@ -257,7 +257,7 @@ namespace MathNet.Numerics.Optimization
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);

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

@ -10,12 +10,12 @@ namespace MathNet.Numerics.Optimization.TrustRegion
/// <summary>
/// The trust region subproblem.
/// </summary>
public static ITrustRegionSubproblem Subproblem;
public ITrustRegionSubproblem Subproblem;
/// <summary>
/// The stopping threshold for the trust region radius.
/// </summary>
public static double RadiusTolerance { get; set; }
public double RadiusTolerance { get; set; }
public TrustRegionMinimizerBase(ITrustRegionSubproblem subproblem,
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="maximumIterations">The max iterations.</param>
/// <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,
double gradientTolerance = 1E-8, double stepTolerance = 1E-8, double functionTolerance = 1E-8, double radiusTolerance = 1E-18, int maximumIterations = -1)
{

Loading…
Cancel
Save