Path: news.mathworks.com!not-for-mail
From: "Kian " <kianian@gmail.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Fitting Mixed Exponential Distribution
Date: Mon, 6 May 2013 16:55:08 +0000 (UTC)
Organization: University of Manitoba
Lines: 34
Message-ID: <km8n9c$lfm$1@newscl01ah.mathworks.com>
References: <km1elm$li9$1@newscl01ah.mathworks.com> <km8caj$dmh$1@newscl01ah.mathworks.com>
Reply-To: "Kian " <kianian@gmail.com>
NNTP-Posting-Host: www-04-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: newscl01ah.mathworks.com 1367859308 22006 172.30.248.35 (6 May 2013 16:55:08 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Mon, 6 May 2013 16:55:08 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 3064487
Xref: news.mathworks.com comp.soft-sys.matlab:794977

"Tom Lane" <tlane@mathworks.com> wrote in message <km8caj$dmh$1@newscl01ah.mathworks.com>...
> > fit = 
> > (1/param(1)*param(2)*exp(-x*1/param(2)))+((1-param(1))*(1/param(3))*exp(-x*param(3)))
> ...
> > [parameters_hat] = lsqnonlin(@myprob,[0 3.033 2.022],[],[],[],x,n, 
> > options);
> 
> You have a 1/param(1) term but you supply 0 as the initial value. Since you 
> say you're trying to fit a mixture of exponentials, I suspect you want 
> something like this instead:
> 
> f = @(param,x) (param(1)    *param(2)*exp(-x*1/param(2)) + ...
>                 (1-param(1))*(1/param(3))*exp(-x*param(3)))
> g = @(param) y - f(param,x);
> options = struct('MaxFunEvals', 2000);
> [parameters_hat] = lsqnonlin(g,[0 3.033 2.022],[],[],options);
> plot(x,y,'bx',x,f(parameters_hat,x),'r-')
> 
> That works for me with the data you provide. However there's nothing to 
> constrain param(1) to stay between 0 and 1, and in fact my solution is 
> outside that range.
> 
> You've set this up as a curve fitting problem but you also seem to be 
> describing it as a density-fitting problem. If the latter is true and you 
> have the Statistics Toolbox, you could try writing the function as a density 
> and using mle to fit it. A similar thing is done for a mixture of two 
> normals here:
> 
> http://www.mathworks.com/help/stats/examples/fitting-custom-univariate-distributions.html
> 
> -- Tom 


Thank you very much Tom. Yes, my problem was actually a density-fitting problem which I was trying to solve it through curve fitting. The link you provided me was exactly what I was looking for. Thank you again.