[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Wed, 21 Dec 2016 10:51:23 +0100
Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.5.1
Thanks - see my comments at the bottom.
Am 21.12.2016 um 02:02 schrieb siko1056:
> Tweetman wrote
>> I have measured data (attached) to which I want to fit the sum of two
>> exp-functions. Here is my code so far:
>> A = dlmread('output.txt');
>> alpha60 = A(:,1);
>> cv60 = A(:,2);
>> function f = exponential(coeff,alpha60,cv60)
>> a = coeff(1);
>> b = coeff(2);
>> c = coeff(3);
>> d = coeff(4);
>> g = coeff(5);
>> h = coeff(6);
>> i = coeff(7);
>> Y_fun60 = a + b.*e.^(-alpha60./c).^d + g.*e.^(-alpha60./h).^i;
>> f = sum ((Y_fun60 - cv60).^2);
>> options = optimset('TolFun',1e1, 'TolX', 1e1);
>> [cc fval] = fminsearch(@(c) exponential(c,alpha60,cv60),[10 625 30 -270
>> -65 60 -13],options)
>> fitted60 = cc(1) + cc(2).*e.^(-alpha60./cc(3)).^cc(4) +
>> plot(alpha60,cv60, alpha60,fitted60)
>> When I plot this, I find that the fit does not match the data nicely and
>> I am asking myself why. Is it the options that I picked? I played around
>> with a few different starting values and options such as MaxIter, but
>> could not see major improvements. Is it the code, the function to be
>> I am running Octave 3.8.1.
>> BTW: I also ran into an example how to use nlinfit so I thought maybe I
>> could use that instead. Octave tells me it is part of statistics
>> package, but I finally found nlinfit in the function reference of optim
>> package. Is that some kind of version mismatch? How can I install an
>> older version of statistics (e. g. from forge), which one would I need?
>> Thanks for your help,
> Hello JP,
> I made some modifications with your code to get a better understanding:
> A = dlmread('output.txt');
> alpha60 = A(:,1);
> cv60 = A(:,2);
> scatter (alpha60, cv60)
> hold on;
> myfun = @(a,b,c,d,g,h,i) a + b.*e.^(-alpha60./c).^d +
> exponential = @(coeff,cv60) ...
> sumsq (myfun(coeff(1), coeff(2), coeff(3), coeff(4), coeff(5), coeff(6),
> coeff(7)) - cv60);
> options = optimset('Display', 'iter');%, 'TolFun', 1e1, 'TolX', 1e1);
> cc0 = [10, 625, 30, -270, -65, 60, -130];
> [cc, fval] = fminsearch(@(c) exponential(c,cv60), cc0, options)
> %[cc, fval, info] = fminunc(@(c) exponential(c,cv60), cc0, options)
> fitted60 = myfun(cc(1), cc(2), cc(3), cc(4), cc(5), cc(6), cc(7));
> plot (alpha60, cv60, alpha60, fitted60)
> Essentially it should behave the same way as yours did. When you add
> "'Display', 'iter'" to optimset, you can see if your solver actually does
> anything. In your original case the solver more or less just returned you
> initial coefficient guess after one step. I got the solver to "work more" by
> removing your restrictions on 'TolFun' and 'TolX' using the default values.
> Like seen above, I also tried fminunc as alternative to the derivate free
> fminsearch. The results are "better" but for both solvers not overwhelming.
> What good or bad means depends strongly on your application and some
> understanding of your model/data/measurement. To me your data seems scaled
> badly (ranging von 10^0 to 10^7).
> HTH, Kai
> View this message in context:
> Sent from the Octave - General mailing list archive at Nabble.com.
> Help-octave mailing list
Thanks for fminunc, this was new to me. The results are as good or bad
as the ones I got from my first iterations. However, this is by far not
good enough. Problem is that I have more data to fit and what looks like
one continuous step in this dataset becomes a step with two linear
slopes in the other data set - hence my complicated function.
And yes, you are right in judging the range or scaling of the data. On
the one hand, this is the range, on the other I tried to range it from 0
to 1 by using something like cv60 = cv60/max(cv60). Still, the fit did
not look any better on the one hand and on the other I was thinking come
on, mankind is looking at millions of years of evolution, this should
work without scaling.
What bothers me is that with Matlab, fitting this function to this
unscaled data works like a charm with few iterations.
I believe I dont understand the break conditions of both solvers. Under
what conditions do they stop working?