Fminsearch function evaluations has been exceeded

Hello,

I attempted to fit an exponential curve to my data in my initial attempt. It seems that I may need to delve deeper into the process of fitting and optimization in general.

On occasion, I encounter the following error. How can I resolve this issue?

fminsearch: Exiting due to exceeding the maximum number of function evaluations - consider increasing the MaxFunEvals option.
Current function value: 705.45696

You can access my test data through the following link: data135.txt (7.4 KB)

Here is the minimal example code I have used:

function q =pt2expfit(p,xd,yd)
    // fitting function 
    y = p(1) * (1 - exp(-xd / p(2))).^p(3);
    // leastsq function
    q = sum((y(:,1)-yd(:,1)).^2);
endfunction

function MainScript()
    // load measurement data
    data = fscanfMat('data135.txt');
    xd = data(:,1);
    yd = data(:,2)-data(1,2); // move y-values to start at 0
    init = [50,1,3];
        
    // fit data, init: start values for fminsearch fit function
    // find paramters for fitting function
     [p,fval,exitflag,output] = fminsearch(pt2expfit,init)
     y_fit = p(1) * (1 - exp(-xd / p(2))).^p(3);
     disp(output)   
    // compare fitting function with real data

     plot(xd,[yd,y_fit])
endfunction

MainScript()

Hello,

After some modifications for Scilab 2024.0 (change ^ to .^ where applicable, otherwise the script was not running), I got the result in 81 iterations and 148 function calls.

--> MainScript()

  algorithm = "Nelder-Mead simplex direct search"
  funcCount = 148
  iterations = 81
  message: [3x1 string]

I tested under Windows and macOS.

S.

Thank you, for this fast reply! Wow, a new Version is available again. I’ll test the fitting function.

However, I don’t understand how you have obtained the reported results. Which version of Scilab were you using ?

I used version 2023. The detailed “output” information provided by fminsearch has been quite helpful. I’m definitely looking forward to finding the time to explore Scilab’s optimization solutions more thoroughly.

I have some colleagues in the lab who lack a deep understanding of mathematics and have no programming experience. They primarily work with LabVIEW and Excel. Recently, we had a discussion about whether these guys should consider transitioning to Scilab or Python for their data analysis needs. Personally, I prefer using Scilab, especially because I rely on the Xcos application.

With Scilab, you have everything in one place and popular toolboxes are maintained. For differentiable optimization I particularly recommend the following toolboxes:

S.

I’m concerned about the transition into the saturated region in the curve we interpolated above. Do you have expertise in whether it’s possible to give this region a bit more emphasis or weighting?

Yes, just add a weight when you compute the residual, e.g.

w = 1+9*(xd>=2 & xd <=3)
q = sum(w.*(y(:,1)-yd(:,1)).^2);

This is great!! It helped a lot!

I am genuinely pleased with the current results, and I hope my inquiry isn’t considered impolite. However, I am encountering the following output message:

fminsearch: Exiting: The maximum number of function evaluations has been exceeded

  • Please consider increasing the MaxFunEvals option.
    Current function value: 414.64762

Unfortunately, I haven’t had the opportunity to delve further into the intricacies of fminsearch. Perhaps you could provide a brief solution without inconveniencing you too much? How can I prevent this output from occurring?

Can you edit your post and drag/drop the scilab file (with .sci or .sce extension) ?