[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: bfgsmin
From: |
Michael Creel |
Subject: |
Re: bfgsmin |
Date: |
Mon, 16 Mar 2009 05:43:57 -0700 (PDT) |
Bertrand Roessli wrote:
>
> Hello,
>
> I am happy to see that there is some discussion about data fitting.
>
> With the octave-forge package, bfgsmin_example works fine.
> However, if I try to fit an exponential function (from leasqrexample.m),
> bfgsmin is unable to converge (which is easily done with the other
> available functions (simplex, samin,...).
>
> The main problem seems to originate from the numerical derivatives.
> The output reads
>
> octave:1> leasqrexamp
> chisq = 0.86656
> chisq = 0.86656
> chisq = 0.86656
> chisq = 0.86657
> chisq = 0.86657
> chisq = 0.86656
> error: __bfgsmin_gradient: gradient contains NaNs or Inf
> error: feval: function `chi2' not found
> error: octave_base_value::double_value (): wrong type argument `<unknown
> type>'
> warning: __bfgsmin_obj: objective function could not be evaluated -
> setting to DBL_MAX
> error: feval: function `chi2' not found
>
> If somebody has an idea I would appreciate.
>
> This is the code
> ----------------
>
> 1;
> function [obj_value]=chi2(p,x,y)
>
> f=leasqrfunc(x,p);
> v=length(y);
> wt=1./sqrt(y);
> chisq=sum(((y.-real(f)).*wt).^2 )/v
>
> obj_value=chisq;
>
> endfunction
>
>
> t = [1:100];
> p=[10; 0.1];
> data=leasqrfunc(t,p);
>
> %fprintf(1,'\nAdding Random Noise.\n data=data+0.05*rand(1,100);\n');
> data=data+0.05*rand(1,100);
> plot(t,data,"@12");
> fflush(stdout);
> pause;
>
> control = {-1;1}; # maxiters, verbosity, conv. reg., arg_to_min
>
> tic;
> param=[11;1];
> bfgsmin("chi2",{param,t,data},control)
> toc
>
>
> function y = leasqrfunc(x,p)
> % leasqrfunc : this is a function of 'x' and 'p' parameters for
> leasqrexamp.
>
> % Description: leasqr example fit function
>
> % example of function.
> y=p(1)*exp(-p(2)*x);
>
> endfunction
>
>
>
Hmm, I ran your code and it works for me:
chisq = 0.0084524
chisq = 0.0084524
chisq = 0.0084524
chisq = 0.0084524
chisq = 0.0084524
chisq = 0.0084524
chisq = 0.0084524
------------------------------------------------
bfgsmin iteration 15 convergence (f g p): 1 1 1
function value: 0.00845243 stepsize: 0.1375
param gradient (n) change
9.69388 -0.00000 0.00000
0.09558 0.00001 -0.00000
------------------------------------------------
bfgsmin final results: 15 iterations
function value: 0.00845243
STRONG CONVERGENCE
Function conv 1 Param conv 1 Gradient conv 1
param gradient (n) change
9.69388 -0.00000 0.00000
0.09558 0.00001 -0.00000
ans =
9.693878
0.095576
Elapsed time is 0.084275 seconds.
octave:3>
Maybe you have an old version of bfgsmin? Every once in a while I find a bug
and fix it. I believe that it has been in pretty good shape for a while now.
Michael
--
View this message in context:
http://www.nabble.com/Nonlinear-fitting-with-lg%28a%2Bx%29-tp22492005p22537017.html
Sent from the Octave - General mailing list archive at Nabble.com.
- Nonlinear fitting with lg(a+x), reposepuppy, 2009/03/13
- Re: Nonlinear fitting with lg(a+x), Jaroslav Hajek, 2009/03/13
- Re: Nonlinear fitting with lg(a+x), reposepuppy, 2009/03/16
- Re: Nonlinear fitting with lg(a+x), Michael Creel, 2009/03/16
- bfgsmin, Bertrand Roessli, 2009/03/16
- Re: bfgsmin,
Michael Creel <=
- Re: bfgsmin, Bertrand Roessli, 2009/03/16
- Re: bfgsmin, Michael Creel, 2009/03/16
- Re: bfgsmin, Bertrand Roessli, 2009/03/16
- Re: bfgsmin, Michael Creel, 2009/03/16
- Re: bfgsmin, Bertrand Roessli, 2009/03/17
- Re: bfgsmin, Michael Creel, 2009/03/17
- Re: bfgsmin, Michael Creel, 2009/03/17
- Re: Nonlinear fitting with lg(a+x), Jaroslav Hajek, 2009/03/16
Re: Nonlinear fitting with lg(a+x), Michael Creel, 2009/03/13