Which optimization tool should I use for my case?

Dear MATLAB experts,
I'm struggling here to solve a problem with the following characteristics:
I've a file containing a huge column of data, which I order in a histogram, let's call it . Afterwards, I would like to sum the histogram, starting everytime from a different point , that is:
I have an experimentally measured value and I would like to find then which best fits to the experimental value. I have basically calculated:
and then fitted it with a known function to calculate the derivative and estimate the minimum.
In the real problem I have actually three experimental values, so that has actually three terms, and afterwards I would like to include even more parameters apart from . As you can imagine, the script I've written for this is extremely time consuming, and I'm not even sure that this procedure is correct/optimal.
So, it feels like I'm doing the minimization procedure by hand, and surely there are better tools for posing such a problem. Are any of you aware of, which tool could better fit my needs? I've seen already stuff like patternsearch, fminunc, etc, but they all need a definite function which I do not have.
Any help would be very much appreciated.
Thank you all in advance.
Cheers

 Respuesta aceptada

Alan Weiss
Alan Weiss el 5 de Mayo de 2021
I'm not sure that I understand what you are doing, but I think that you could use the fminbnd solver along with some interpolation or floor or ceiling function.
First, compute all of the tail sums. I assume that your psi vector is a row vector.
tails = cumsum(fliplr(psi));
tails = fliplr(psi);
If I am right, tails(1) is now the sum of all of the elements in psi, and tails(end) is psi(nmax).
Now to look for the element of tails that best matches your criterion, do fminbnd on the function
fun = @(x)tails(floor(x));
Well, you put in your criterion, but you see that fun takes a continuous argument and immediately takes the floor of that argument so it is only working on integers.
I think that you can take it from here. Good luck,
Alan Weiss
MATLAB mathematical toolbox documentation

4 comentarios

Dear Alan
Thank you for your answer! Although it was not exactly what I was looking for, it certainly helped me to find the right path.
I finally opted for defining a function that reads the input file, calculates the histogram, sum the channels and calculates the difference respect the experimental value.
Up to this point, everything works very well (and faster that before).
Then, I called this function with the option fminunc to minimize it, using an initial guess , using an anonymous function to pass extra parameters. For some reason, here is where I've problems again, because as a result, fminunc is giving me always the initial guess. I will keep trying, and when I find the definitive solution, I will come back.
Thank you again!
Cheers
Alan Weiss
Alan Weiss el 6 de Mayo de 2021
The reason fminunc is not the right solver here is that it is gradient-based. The gradient of your function is zero almost everywhere, because it is a step function. So fminunc will never move from the initial point.
You have several choices. If your data is 1-D as I think it is, use fminbnd as I initially suggested, because it does not care if the function is locally constant. I still think this is the best choice. Another thing you can try is to use fminunc on an interpolation of your function, as I originally suggested. If your data is 1-D, you can use the interp1 function.
Good luck,
Alan Weiss
MATLAB mathematical toolbox documentation
As a first approximation, I'm using one parameter, so my function is 1-D. But in the end I will have to think of at least four parameters, that's why I thought fminunc could do the trick. I'm now trying the fminsearch option. If you have a better advice for multivariable functions, that will be very much appreciated.
Thanks again for the help!
Regards
Federico
Alan Weiss
Alan Weiss el 6 de Mayo de 2021
I think that you would do best with functions that do not rely on smoothness. In particular, patternsearch from Global Optimization Toolbox would be my first choice for this problem in multiple dimensions. You can easily set a stopping criterion of a mesh size of less than 1, and set an initial mesh size of more than 1.
I do not recomment fminsearch for this problem. It has the same behavioral deficiency as fminunc: it is unlikely to move from an initial point, or could easily get fooled and stuck by the local flatness. Also, it could step out of bounds, and then I am not sure what would happen. I strongly recommend fminbnd as the solver of choice in 1 dimension for testing before you move to higher dimensions.
Alan Weiss
MATLAB mathematical toolbox documentation

Iniciar sesión para comentar.

Más respuestas (0)

Preguntada:

el 5 de Mayo de 2021

Comentada:

el 6 de Mayo de 2021

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by