Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Fitting Mixed Exponential Distribution

Subject: Fitting Mixed Exponential Distribution

From: Kian

Date: 3 May, 2013 22:45:10

Message: 1 of 3

Hi there,

I ve got sort of stock on an easy problem !

I m trying to fit a 3-parameter (alpha, beta1 and beta2) Mixed Exponential distribution to my data values, the pdf function of which is:
f(x) = (alpha/beta1*exp(-x/beta1)) + ((1-alpha)/beta2*exp(-x/beta2))

I tried to fit my parameters by sort of optimizing my parameters to fit the probability dist. of my data.

Here is how I proceed:

I wrote my obj. function as follows:
function res = myprob(param,x,y)
fit = (1/param(1)*param(2)*exp(-x*1/param(2)))+((1-param(1))*(1/param(3))*exp(-x*param(3)))
res = fit - y;

where,
param(1:3) = [alpha, beta1, beta2]
and
x and y are derived as below:
[n,x] = hist(data,nbin); % Let's take nbin = 10
and y = n/length(data)

I have tried to optimize my parameters by using lsqnonlin function (below), but seems like I am not doing it right.

options = struct('MaxFunEvals', 2000);
[parameters_hat] = lsqnonlin(@myprob,[0 3.033 2.022],[],[],[],x,n, options);

Got my first guesses by method of moments.

Just in case you need some data values, here is a sample:
x = [0.6190, 1.4551, 2.2913, 3.1274, 3.9635, 4.7997, 5.6358, 6.471, 7.308, 8.144];
y = [0.6336, 0.2366, 0.0687, 0.0153, 0.0305, 0.0076, 0, 0, 0, 0.0076];

I really appreciate any help.

Subject: Fitting Mixed Exponential Distribution

From: Tom Lane

Date: 6 May, 2013 13:48:03

Message: 2 of 3

> 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

Subject: Fitting Mixed Exponential Distribution

From: Kian

Date: 6 May, 2013 16:55:08

Message: 3 of 3

"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.

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us