|
|
|
@ -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); |
|
|
|
|
|
|
|
|