From: Antony zerrar on
Hi guys,

I have a data set that I want to fit to the Laplace distribution and have some problems in doing so, however fsolve gives the correct answer. I want to replicate it step by step. The code that I use is:

data = [-1 5 2];
x0=[0 1]';
x(:,1)=x0;
index=1;
n=length(data);
l=0.01;
for i=1:15
fm = -1/x(2,index);
fs = -n/x(2,index)+sum(abs(data-x(1,index)))/(x(2,index)^2);
G = [fm ; fs]; % Gradient Vector
H = G*G'; % Hessian Vector
I=eye(2,2);
x(:,index+1) = x(:,index) - inv(H+l*I)*G;
LLF(index+1,1) = -n*log(2)-n*log(x(2,index))-sum(abs(data-x(1,index)))/x(2,index);
index=index+1;
end

Thanks alot!
From: Miroslav Balda on
"Antony zerrar" <zerrar(a)yahoo.com> wrote in message <hvqanp$pr8$1(a)fred.mathworks.com>...
> Hi guys,
>
> I have a data set that I want to fit to the Laplace distribution and have some problems in doing so, however fsolve gives the correct answer. I want to replicate it step by step. The code that I use is:
>
> data = [-1 5 2];
> x0=[0 1]';
> x(:,1)=x0;
> index=1;
> n=length(data);
> l=0.01;
> for i=1:15
> fm = -1/x(2,index);
> fs = -n/x(2,index)+sum(abs(data-x(1,index)))/(x(2,index)^2);
> G = [fm ; fs]; % Gradient Vector
> H = G*G'; % Hessian Vector
> I=eye(2,2);
> x(:,index+1) = x(:,index) - inv(H+l*I)*G;
> LLF(index+1,1) = -n*log(2)-n*log(x(2,index))-sum(abs(data-x(1,index)))/x(2,index);
> index=index+1;
> end
>
> Thanks alot!

Hi Antony,
I'll not comment your code, because I have not study it. It is only a script (not a function) and there is no Levenberg-Marquardt procedure at all. I only can tell you that Laplace distribution is not a smooth function, so there is no gradient at the point mean(x). It may cause some problems when using any gradient method for a fit of parameters of the distribution. Use fminsearch (Nelder-Mead) function instead. If you wish some help, send your experimental data.
Best regards,
Mira