problems in passing parameters to fminsearchbnd.
2 ビュー (過去 30 日間)
I have to fit some data and I'm using fminsearchbnd. Unfortunately the solver doesn't convergence and I have discovered that at the first iteration the design variable of myfunFitting function are different than the one supplied through the starting point. How may it be possible? Below you can find my code.
x1=[76.2; 766.0; 842.5; 842.5; 1044.0; 1044.0; 1070.3; 987.0; ...
回答 (1 件)
John D'Errico 2015 年 3 月 27 日
So now we know why it is that your optimization is not working well. Here is your objective function.
So you are trying to fit a model of the form
z = A/(B*y*x^B)
Where A and B are unknowns, and x and y are the independent variables.
Claim 1: Models with a single term that are the product of multiple variables like this almost ALWAYS need to be logged. The estimation is always easier, in fact, often trivial.
Claim 2: Whenever you have problems with huge orders of magnitudes involved, you should ALWAYS consider if you should be working with logs instead.
Lets see how that works here.
log(z) = log(A) - (log(B) + log(y) + B*log(x))
Rewrite this to look like...
log(z) + log(y) = log(A) - log(B) - B*log(x)
Now, think about it. Do you know the value of A? Do you know the value of B? Of course not. You are estimating them. So trivially, we can use the transformation
C = log(A) - log(B)
Putting it in a classic form...
log(z) - log(y) = C + B*(-log(x))
Use polyfit to determine B and C.
Here, we have x1 as x as I wrote it, y2 as y, and Target as z.
BC = polyfit(-log(x1),log(Target) + log(y2),1);
B = BC(1);
A = exp(BC(2) + log(B));
Sadly, I can't actually test this out on your data, because while you gave 24 elements in the vectors x1 and Target, there are only 15 in y2. The best that I can do is this:
BC = polyfit(-log(x1(1:15)),log(Target(1:15)) + log(y2),1)
B = BC(1);
A = exp(BC(2) + log(B))
That your data seems not to fit this model terribly well? Hey, it is your data and your choice of model.
Regardless, you should see that never did I need anything sophisticated to solve your problem. In fact, no serious optimization was ever needed. If you truly wanted to do an optimization, the above scheme would in the very least allow good starting values to be employed, but IF I actually wanted to do this as an optimization, the hugely wide bounds you have used would make that optimization totally unworkable even with the incredibly good starting values you will get from polyfit.
And finally, I would point out that had you defined exp as a variable in your workspace, the last line as I wrote it would now fail. Again, this is why that is a bad thing.