How do I hold some coefficients constant in a vector of initial guesses passed to lsqcurvefit?
Ältere Kommentare anzeigen
I am working on a project for my year in industry as part of my university course. I have been tasked with automating a fairly user intensive process that involves many iterations of different initial guesses being passed to a levenberg marquardt solver (companies own software) to find the best fit. These initial guesses take the form K = [k1,o1;k2,o2,k3,o3;...;k22,o22] where k1:k22 are the actual initial guesses and o1:o22 is logical vector of the same length denoting whether or not the corresponding k value should be optimised or held constant during the optimisation.
I have my program working using lsqcurvefit for the situations where o1:o22 are all true but when I tried to add upper and lower bounds it tells me that the upper and lower bounds cannot be the same, which was how i intended to hold these values constant. Can anyone help me think of another way around this as I have invested a lot of time getting the program up to this point and have now been stuck on this particular problem for a week or so.
any help would be much appreciated, thank you.
Antworten (1)
It's strange that it tells you that ub cannot equal lb, because I know that you can do this for other Optimization Toolbox functions, such as FMINCON and maybe LSQNONLIN, which you could try as alternatives.
However, since you say that this is a computationally intensive process that you are running many times, the most speed-optimal approach is to use o1:o22 to automatically rewrite the curve modelling function as a function of fewer variables. Lower-dimensional functions do crunch (and optimize) faster.
For example, if your curve was instead a simple 3-parameter quadratic
k(i)*x^2+k(2)*x+k(3)
you wouldn't want to include the polynomial terms where o(i)=0 because that would just waste computation. So you would do
function [F_k_xdata,k0]=CreateFitFun(o,k0_full)
%return handle to curve fit function and initial point in reduced space
A=bsxfun(@power,xdata(:),[2 1 0]);
b=A(:,~o)*k0_full(~o);
A=A(:,o); throw away fixed parameters
k0=k0_full(o);
F_k_xdata=@(k,xdata) A*k(:)+b;
end
and then pass this F_k_data handle and initial point k0 to LSQCURVEFIT.
2 Kommentare
Stevie
am 4 Okt. 2012
I didn't intend to assume k(~o)=0. I modified my original proposed code accordingly. As for messiness, I'd have to see your actual function to get a better idea of the difficulty. In any case, when you need speed, that's what you do...
Again, I cannot understand why you are limited from lb=ub, if the documentation doesn't forbid it, but you could try FMINCON if that's an easier path. It shouldn't have this restriction.
As for why Levenberg-Marquardt won't take bounds at all, you would have to solve a constrained quadratic sub-problem at every iteration and there is a likelihood of slow convergence. I can imagine TMW deeming it not worth the coding effort.
Kategorien
Mehr zu Get Started with Curve Fitting Toolbox finden Sie in Hilfe-Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!