Skip to main content
fixed a typo
Source Link
Alexey Popkov
  • 62.3k
  • 7
  • 154
  • 375

Here is the solution based on Faysal's code:

steps=0; 
FindMinimum[Null,
 {optimVariables, initialGuess}\[Transpose],
 Method -> {"LevenbergMarquardt", 
   "Residual" :-> Sqrt[2] residualVector[optimVariables], 
   "Jacobian" :-> {Sqrt[2] jacobianMatrix[optimVariables], EvaluationMonitor :> ++steps}, 
   "StepControl" -> {"TrustRegion", "StartingScaledStepSize" -> 1/1000, "MaxScaledStepSize" -> 1/10, "AcceptableStepRatio" -> 1/3}}]

Note that it is recommended to use exact numbers for the parameters of the "TrustRegion" method because these parameters are used inside of the algorithm without any check for consistency with WorkingPrecision. I should also note that the actual residual vector and jacobian must be multiplied by Sqrt[2] for having FindMinimum returning the minimum equal to

residualVector[optimVariables].residualVector[optimVariables]

and not to

residualVector[optimVariables].residualVector[optimVariables]/2

as it is by default.

The jacobian may be calculated automatically by the following code:

jacobianMatrix[_] = D[residualVector[optimVariables], {optimVariables}]

One can restrict the jacobian to be evaluated for numerical values only by defining it as:

jacobianMatrix[_List?(VectorQ[#, NumberQ] &)] = 
    D[residualVector[optimVariables], {optimVariables}]

Here is the solution based on Faysal's code:

steps=0; 
FindMinimum[Null,
 {optimVariables, initialGuess}\[Transpose],
 Method -> {"LevenbergMarquardt", 
   "Residual" :> Sqrt[2] residualVector[optimVariables], 
   "Jacobian" :> {Sqrt[2] jacobianMatrix[optimVariables], EvaluationMonitor :> ++steps}, 
   "StepControl" -> {"TrustRegion", "StartingScaledStepSize" -> 1/1000, "MaxScaledStepSize" -> 1/10, "AcceptableStepRatio" -> 1/3}}]

Note that it is recommended to use exact numbers for the parameters of the "TrustRegion" method because these parameters are used inside of the algorithm without any check for consistency with WorkingPrecision. I should also note that the actual residual vector and jacobian must be multiplied by Sqrt[2] for having FindMinimum returning the minimum equal to

residualVector[optimVariables].residualVector[optimVariables]

and not to

residualVector[optimVariables].residualVector[optimVariables]/2

as it is by default.

The jacobian may be calculated automatically by the following code:

jacobianMatrix[_] = D[residualVector[optimVariables], {optimVariables}]

One can restrict the jacobian to be evaluated for numerical values only by defining it as:

jacobianMatrix[_List?(VectorQ[#, NumberQ] &)] = 
    D[residualVector[optimVariables], {optimVariables}]

Here is the solution based on Faysal's code:

steps=0; 
FindMinimum[Null,
 {optimVariables, initialGuess}\[Transpose],
 Method -> {"LevenbergMarquardt", 
   "Residual" -> Sqrt[2] residualVector[optimVariables], 
   "Jacobian" -> {Sqrt[2] jacobianMatrix[optimVariables], EvaluationMonitor :> ++steps}, 
   "StepControl" -> {"TrustRegion", "StartingScaledStepSize" -> 1/1000, "MaxScaledStepSize" -> 1/10, "AcceptableStepRatio" -> 1/3}}]

Note that it is recommended to use exact numbers for the parameters of the "TrustRegion" method because these parameters are used inside of the algorithm without any check for consistency with WorkingPrecision. I should also note that the actual residual vector and jacobian must be multiplied by Sqrt[2] for having FindMinimum returning the minimum equal to

residualVector[optimVariables].residualVector[optimVariables]

and not to

residualVector[optimVariables].residualVector[optimVariables]/2

as it is by default.

The jacobian may be calculated automatically by the following code:

jacobianMatrix[_] = D[residualVector[optimVariables], {optimVariables}]

One can restrict the jacobian to be evaluated for numerical values only by defining it as:

jacobianMatrix[_List?(VectorQ[#, NumberQ] &)] = 
    D[residualVector[optimVariables], {optimVariables}]
added 1035 characters in body
Source Link
Alexey Popkov
  • 62.3k
  • 7
  • 154
  • 375

Here is the solution based on Faysal's code:

steps=0; 
FindMinimum[Null,
 {OptimVariablesoptimVariables, initialGuess}\[Transpose],
 Method -> {"LevenbergMarquardt", 
   "Residual" :> residualVector[OptimVariables]Sqrt[2] residualVector[optimVariables], 
   "Jacobian" :> jacobianMatrix[OptimVariables]{Sqrt[2] jacobianMatrix[optimVariables], EvaluationMonitor :> ++steps}, 
   "StepControl" -> {"TrustRegion", "StartingScaledStepSize" -> .1/1000, "MaxScaledStepSize" -> 1/10, "AcceptableStepRatio" -> 1/3}}]

Note that it is recommended to use exact numbers for the parameters of the "TrustRegion" method because these parameters are used inside of the algorithm without any check for consistency with WorkingPrecision. I should also note that the actual residual vector and jacobian must be multiplied by Sqrt[2] for having FindMinimum returning the minimum equal to

residualVector[optimVariables].residualVector[optimVariables]

and not to

residualVector[optimVariables].residualVector[optimVariables]/2

as it is by default.

The jacobian may be calculated automatically by the following code:

jacobianMatrix[_] = D[residualVector[optimVariables], {optimVariables}]

One can restrict the jacobian to be evaluated for numerical values only by defining it as:

jacobianMatrix[_List?(VectorQ[#, NumberQ] &)] = 
    D[residualVector[optimVariables], {optimVariables}]

Here is the solution based on Faysal's code:

FindMinimum[Null,
 {OptimVariables, initialGuess}\[Transpose],
 Method -> {"LevenbergMarquardt", 
   "Residual" :> residualVector[OptimVariables], 
   "Jacobian" :> jacobianMatrix[OptimVariables], 
   "StepControl" -> {"TrustRegion", "StartingScaledStepSize" -> .1}}]

Here is the solution based on Faysal's code:

steps=0; 
FindMinimum[Null,
 {optimVariables, initialGuess}\[Transpose],
 Method -> {"LevenbergMarquardt", 
   "Residual" :> Sqrt[2] residualVector[optimVariables], 
   "Jacobian" :> {Sqrt[2] jacobianMatrix[optimVariables], EvaluationMonitor :> ++steps}, 
   "StepControl" -> {"TrustRegion", "StartingScaledStepSize" -> 1/1000, "MaxScaledStepSize" -> 1/10, "AcceptableStepRatio" -> 1/3}}]

Note that it is recommended to use exact numbers for the parameters of the "TrustRegion" method because these parameters are used inside of the algorithm without any check for consistency with WorkingPrecision. I should also note that the actual residual vector and jacobian must be multiplied by Sqrt[2] for having FindMinimum returning the minimum equal to

residualVector[optimVariables].residualVector[optimVariables]

and not to

residualVector[optimVariables].residualVector[optimVariables]/2

as it is by default.

The jacobian may be calculated automatically by the following code:

jacobianMatrix[_] = D[residualVector[optimVariables], {optimVariables}]

One can restrict the jacobian to be evaluated for numerical values only by defining it as:

jacobianMatrix[_List?(VectorQ[#, NumberQ] &)] = 
    D[residualVector[optimVariables], {optimVariables}]
Source Link
Alexey Popkov
  • 62.3k
  • 7
  • 154
  • 375

Here is the solution based on Faysal's code:

FindMinimum[Null,
 {OptimVariables, initialGuess}\[Transpose],
 Method -> {"LevenbergMarquardt", 
   "Residual" :> residualVector[OptimVariables], 
   "Jacobian" :> jacobianMatrix[OptimVariables], 
   "StepControl" -> {"TrustRegion", "StartingScaledStepSize" -> .1}}]