MATLAB Answers

0

Fitting random process distribution using lsqcurvefit and another set of random numbers, inital value does not change

Asked by Yevhen Shynkarenko on 14 Nov 2019 at 8:32
I am trying to fit experimental data of the PL blinking of the individual quantum dots. They are known to switch their state with some probabilty that is changing depending on their previous state. To me it is easier to describe this process by generating the large dataset of random numbers and to look how does the histogram of such distribution fits the real data.
I narrowed the question to fitting distribution of random numbers by another set of random numbers. However, this approach always generates answer
"Optimization completed because the size of the gradient is less than the default value of the optimality tolerance."
"Options relative first-order optimality = 0.00e+00 OptimalityTolerance = 1e-06 (default)"
I tried to track the call to the blink function and I saw that it is always called with initial values only.
Please see the code attached:
%Number of generated numbers
Iter=1000000;
%Data generation
D=randn(Iter,1).*0.5+1;
%calculating histogram of the data
xi=-5:0.05:5;
yi=hist(D,xi);
%normalizing the histogram on maximum
yi=yi./max(yi);
% initial guess
Par0=[0.6, 0.8];
%fixed seed
rng(100);
%Randn is used for repetative function call with the same result
Randn=randn(Iter,1);
%first function is simple analytical expression of gaussian
F1=@(par,x) exp(-((x-par(2))./par(1)).^2./2);
%second function is a wrapper of another function implemented at the end of
%the program
F2=@(par,x) blink(par,x,Randn);
%fitting using the analytical gaussian function
fitPar1 = lsqcurvefit(F1,Par0,xi,yi)
%fitting using more complicated function
fitPar2 = lsqcurvefit(F2,Par0,xi,yi)
%compare results
plot(xi,yi,xi,F1(fitPar1,xi),xi,F2(fitPar2,xi));
function r=blink(p,x,Rand)
%using same array of random numbers to avoid difference from function call to call
dat=Rand;
%use parameters to make linear modification to the array:
dat=dat.*p(1)+p(2);
%calculating the distribution of the result
r=hist(dat,x);
%normalization
r=r./max(r);
end

  0 Comments

Sign in to comment.

Products


Release

R2017b

0 Answers