help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bfgsmin


From: Bertrand Roessli
Subject: bfgsmin
Date: Mon, 16 Mar 2009 13:06:57 +0100

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


On Mon, 2009-03-16 at 04:27 -0700, Michael Creel wrote:
> 
> 
> reposepuppy wrote:
> > 
> > 
> > 
> > Michael Creel wrote:
> >> 
> >> You don't need to linearize anything, just use nonlinear least squares to
> >> minimize the function
> >> 
> >>      sum_over_observations [ r-r0[1-a*lg(1+c/b)] ]^2  with respect to the
> >> unknown constants.
> >> 
> >> If you linearize and then estimate, the resulting estimator is biased and
> >> inconsistent. All you need to do is write Octave code to calculate the
> >> objective function. Then you can use one of the available minimizers to
> >> get the estimates. Octave provides sqp, which can handle this problem.
> >> 
> > 
> > I can't find the function sum_over_observations... Is it a function I have
> > to make up by myself, or some packages submitted somewhere other than
> > octave-forge?
> > And..."All you need to do is write Octave code to calculate the objective
> > function."
> > It might sound silly, but I really don't know (and I don't know where I
> > can find the tutorial) how to calculate it, and how to use the minimizers.
> > I've read the octave.pdf file and the function reference on octave-forge,
> > and I could only found one minimizer called polyfit(x,y,n), which is used
> > to make polynomial fittings...
> > Could you give me a detailed demonstration/code to work it out? The data
> > has been collected in the attachment.
> > http://www.nabble.com/file/p22535164/data%2Bc%2Band%2Br.txt
> > data+c+and+r.txt 
> > 
> 
> For an example of minimization of a function, you could install the package
> "optim", and then run "bfgsmin_example".
> http://octave.svn.sourceforge.net/viewvc/octave/trunk/octave-forge/main/optim/inst/bfgsmin_example.m?revision=HEAD&content-type=text/plain
> 
> For your problem, you  would just need to replace the objective function in
> that example with the one for your problem, Doing that is not hard if you
> know a little about Octave. 
> 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]