help-octave
[Top][All Lists]
Advanced

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

Applying leasqr fit to Guassian Data


From: Dan Paterson
Subject: Applying leasqr fit to Guassian Data
Date: Fri, 21 Aug 2015 09:08:31 -0700 (PDT)

Hi,

This is my first time on this forum, and I am uncertain that this is the
right place for my question. I would like to say that my knowledge is
somewhat limited as I am just finishing my undergraduate degree. I'm looking
for some help on modeling that I need relating to a project I am working on
for research and not for a class.  

I am using octave to take data from a dat file, graph the original data,
model using a leasqrs fit (for a simple gaussian function), and then graph
that model on the same graph.  My eventual goal is to be able to take
multiple dat files from a directory and preform the above operation on all
of them.  I do not have a Matlab licence so I used octave and a leasqr and
optimization function that I found from the following link
http://octave.sourceforge.net/optim/index.html (optim package).  In order to
run it you must have the following files from optim:
 _do_user_interaction_
_lm_svd_
_plot_cmds_
cpiv_bard
leasqr
You will also need the actual file you use to run it.  The following is my
script (I know that there are better ways to call the file, but as I had
previously mentioned, my end goal is to have the whole directory):

% Define functions
 leasqrfunc = @(x, p) (1/(p(1)*sqrt(2*pi)))*exp((-(x-p(2)).^2/(2*p(1)^2)));
 leasqrdfdp = @(x, f, p, dp, func)
[(x-p(2))/(p(1)^3*sqrt(2*pi)).*exp((-(x-p(2)).^2/(2*p(1)^2))),
(-exp((-(x-p(2)).^2/(2*p(1)^2)))/(p(1)*sqrt(2*pi))+(((x-p(2)).^2).*exp((-(x-p(2)).^2/(2*p(1)^2)))/(p(1)^4*sqrt(2*pi))))];

 nFiles = dir('*.dat');
 numfiles = length(nFiles);
 mydata = cell(1, numfiles);
 for k = 1:numfiles
  mydata{k} = load(nFiles(k).name);
 end
 nnn=1;
 if nnn == 1;
   a = mydata(:,1);
   a1 = a{:,1};
   t = a1(:,2);
   data= a1(:,6);
   %plot(xa,ya,'b*')
 end

 wt1 = (1 + 0 * t) ./ sqrt (data); 
 F = leasqrfunc;
 dFdp = leasqrdfdp; % exact derivative
 dp = [0.001; 0.001];
 pin = [.5; 118]; 
 stol=0.0001; niter=50;
 minstep = [0.005; 0.005];
 maxstep = [.01; .01];
 options = [minstep, maxstep];

 global verbose;
 verbose = 1;
 [f1, p1, kvg1, iter1, corp1, covp1, covr1, stdresid1, Z1, r21] = ...
    leasqr (t, data, pin, F, stol, niter, wt1, dp, dFdp, options);

The following is the sample file that you can use to draw data from.  You
want the s2 column for the independent variable and detector for your
dependent variable.
TRIAX_exp0052_scan0006.dat
<http://octave.1599824.n4.nabble.com/file/n4672211/TRIAX_exp0052_scan0006.dat>  

My issues are that 
-I am getting multiple errors of the form:
   Change in parameter(s): 1 2 maximal fractional stepwidth enforced
-It does not adjust my two parameters enough to give me a decent fit
-It does not plot my model

I recognize my problem is probably in my tolerance or step size, but after
playing around with it for a long time I still could not fix the above
problems.  

Sorry for the long read and thank you for your time.

-Dan Paterson



--
View this message in context: 
http://octave.1599824.n4.nabble.com/Applying-leasqr-fit-to-Guassian-Data-tp4672211.html
Sent from the Octave - General mailing list archive at Nabble.com.



reply via email to

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