# 分布拟合——正态/拉普拉斯/对数高斯/瑞利 分布

$J = \mathop \prod \limits_{i = 1}^N f({x_i})$

$L\left( \theta \right) = \ln J\left( \theta \right) = \sum\limits_{i = 1}^N {f({x_i};\theta )}$

A-正态分布

$f(x) = \frac{1}{{\sqrt {2\pi } \sigma }}{e^{ - \frac{{{{(x - \mu )}^2}}}{{2{\sigma ^2}}}}}$

$\hat \mu = \frac{{\sum\limits_{i = 1}^N {{x_i}} }}{N}$

${\hat \sigma ^2} = \frac{{\sum\limits_{i = 1}^N {{{\left( {{x_i} - \mu } \right)}^2}} }}{N} = \frac{{{{\left( {{\bf{x}} - \mu } \right)}^T}\left( {{\bf{x}} - \mu } \right)}}{N}$

B-拉普拉斯分布

$f(x) = \frac{1}{{2b}}{e^{ - \frac{{\left| {x - \mu } \right|}}{b}}}$

$\hat \mu = \frac{{\sum\limits_{i = 1}^N {{x_i}} }}{N}$

$\hat b = \frac{{\sum\limits_{i = 1}^N {\left| {{x_i} - \mu } \right|} }}{N}$

C-对数正态分布

$f(x) = \frac{1}{{x\sqrt {2\pi } \sigma }}{e^{ - \frac{{{{(\ln x - \mu )}^2}}}{{2{\sigma ^2}}}}}$

$\hat \mu = \frac{{\sum\limits_{i = 1}^N {{t_i}} }}{N}$

${\hat \sigma ^2} = \frac{{\sum\limits_{i = 1}^N {{{\left( {{t_i} - \mu } \right)}^2}} }}{N} = \frac{{{{\left( {{\bf{t}} - \mu } \right)}^T}\left( {{\bf{t}} - \mu } \right)}}{N}$

D-瑞利分布

$f(x) = \frac{x}{{{\sigma ^2}}}{e^{ - \frac{{{x^2}}}{{2{\sigma ^2}}}}}$

${\hat \sigma ^2} = \frac{{\sum\limits_{i = 1}^N {x_i^2} }}{{2N}}$

A-正态分布

x       = x(:);                 % should be column vectors !
N       = length(x);
u       = sum(x)/N;
sig2    = (x-u)'*(x-u)/N;


B-拉普拉斯分布

x       = x(:);                 % should be column vectors !
N       = length(x);
u       = sum( x )/N;
b       = sum(abs(x-u))/N;

C-对数正态分布

t     = log(x(:));                 % should be column vectors !
N       = length(x);
m       = sum( t )/N;
sig2      = (t-m)'*(t-m)/N;

D-瑞利分布

x       = real(x(:));                 % should be column vectors !
N       = length(x);
s       = sum(x.^2)/(2*N);


rng('default') % for reproducibility
x = 3*randn(100000,1)-2;
%fitting
x       = x(:);                 % should be column vectors !
N       = length(x);
u       = sum(x)/N;
sig2    = (x-u)'*(x-u)/N;

%Plot

figure;
%Bar
subplot 311
numter = [-15:.2:10];
[histFreq, histXout] = hist(x, numter);
binWidth = histXout(2)-histXout(1);
bar(histXout, histFreq/binWidth/sum(histFreq)); hold on;grid on;
%Fitting plot
subplot 312
y = 1/sqrt(2*pi*sig2)*exp(-(numter-u).^2/2/sig2);
plot(numter,y,'r','linewidth',2);grid on;

%Fitting result
subplot 313
bar(histXout, histFreq/binWidth/sum(histFreq)); hold on;grid on;
plot(numter,y,'r','linewidth',2);


posted @ 2017-03-16 21:19 桂。 阅读(...) 评论(...) 编辑 收藏