Skip to main content
19-Tanzanite
July 1, 2016
Question

Minerr/nonlinear optimizing

  • July 1, 2016
  • 2 replies
  • 14664 views

In reference to this document: Minerr/nonlinear optimizing

Your equation for Function is wrong. For a least squares fit the error function should be the square root of the sum of the squares (or just the sum of the squares). You have the sum of the square root of the squares, which is equivalent to the sum of the absolute values. See my Function2 for the correct error function.

Having said that, the best way to fit a function to experimental data is to create a function that generates the vector of residuals: see my Function3. Feed that directly to minerr, and use the Levenberg-Marquardt option.

Minimizing Function gives an error (i.e. Function2) of 1721, 311, or 133, depending on the algorithm used

Minimizing Function2 gives an error (i.e. Function2) of 1628, 109, or 100, depending on the algorithm used

Minimizing Function3 using the LM algorithm gives an error (i.e. Function2) of 261

I'm not sure why the last option does not give an error as low as a couple of the other options, except to say it has to do with where the minimization ends. Using a vector of residuals with the LM algorithm, maybe it takes a slightly different path and gets trapped somewhere in a local minimum. Changing the guesses may help. Nevertheless, despite the fact that the error is slightly higher in this example, in general this is the best approach.

2 replies

RichardJ19-TanzaniteAuthor
19-Tanzanite
July 1, 2016

I played around a little, and it's super sensitive to the guess values. I'm not sure anything we have found is the true minimum, and I'm not sure any gradient method is the way to find the true minimum. Maybe simulated annelaing: Minimizing a Function using Simulated Annealing. I'm traveling in Europe at the moment though, so I'm not sure when I will find time to try that.

1-Visitor
July 7, 2016

I would like to joint the discussion about Minerr Levenberg-Marquardt, since  I found me to some convergence issue, for some additional points:

1) It is possible to use relative deviations( |X-Xxep|/Xexp instead of residual ( |X-Xexp| (  in order to taking in account the variable absolute value) (?)

2)  It is possible to consider two ( or more)  weighted objective functions to be minimized in the same solve block or it is best to consider the sum of them ( a single boolean equation) (?)

3)  In order to check wheter Minerr has found a true minimum, it is possible to use the ERR function  alternatively to recalculate the objective function?

RichardJ19-TanzaniteAuthor
19-Tanzanite
July 7, 2016

1) It is possible to use relative deviations( |X-Xxep|/Xexp instead of residual ( |X-Xexp| (  in order to taking in account the variable absolute value) (?)

Yes, it is just a weighted fit. For a true least squares fit the errors should all be of equal standard deviation. If the errors are independent of the magnitude of the data that means they should be unweighted. If the errors are proportional to the magnitude of the data then they should be weighted by 1/magnitude, which is what you propose.

2)  It is possible to consider two ( or more)  weighted objective functions to be minimized in the same solve block or it is best to consider the sum of them ( a single boolean equation) (?)

Yes, just stack the (weighted) residuals, or put them in two columns of a matrix.

3)  In order to check wheter Minerr has found a true minimum, it is possible to use the ERR function  alternatively to recalculate the objective function?

I'm not sure what you mean. The ERR function is a built-in variable, not a function, that gives you the error in the fit. When minerr stops iterating it has found either a flat area in the objective function or a minimum. There is no way to know which (other than by trying different guesses), and no way to know if it is the global minimum.

1-Visitor
July 8, 2016

Thank you,

I am currently applying the Minerr Levenberg-Marquardt for the classical chemical engineering problem of fitting the pure component parameters of a volumetric EOS ( Equation of State ) versus experimental vapour pressure and liquid density. Since the equation is implicit on the density, depending on the initial values, Minerr could converge to a false minimum ( e.g. wrong root: vapor density). Could  the minimization problem be solved alternatively with Simplex algorithm type. Is this available in MathCAD?