正态分布的最大似然估计

给定数据集D={x1, x2, ... , xn},假设都服从均值为mean(假设未知),方差为var的高斯分布(假设已知),则参数θ为均值mean.

p(D|θ) = ∏p(xi|θ) =p(x1|θ)p(x2|θ)...p(xn|θ)


最大似然估计(MLE)


MLE过程:

(1)假设真实高斯分布的均值为20,方差为18*18

(2)根据该概率分布抽取100个样本点

(3)计算p(D|θ),并画出曲线,显示出最大值所对应的θ值,即mean值

% Maximum Likelihood Estimation
function MLE_show

clear;close all;

% 参数设置
mean = 20;     %均值 
std = 18;      %标准差
var = std^2;   %方差
num = 100;     %抽样点数

% 真实分布
x = -50:0.1:100;
f = exp(-(x-mean).*(x-mean)/(2*var))/sqrt(2*pi*var);
figure(1),subplot(1,2,1),plot(x,f);hold on;
title(sprintf('Normal Distribution, mean = %d, var = %d', mean, var));

% 从真实分布抽样出num个点
rx = mean + std .* randn(num,1);
ry = zeros(size(rx,1),1);
subplot(1,2,1),plot(rx,ry,'r.','MarkerSize',13);
xlabel('x');
ylabel('p(x)');

% MLE (假设均值未知,方差已知)
ii = 1;
for i = mean-10:0.1:mean+10
    joint_pdf(ii) = ML_value(rx, i, var, num);
    ii = ii + 1;
end
x1 = mean-10:0.1:mean+10;

maxparam = find(joint_pdf==max(joint_pdf))
x2 = x1(maxparam)*ones(1,3);
y2 = linspace(0,max(joint_pdf)*1.2, 3);
figure(1),subplot(1,2,2),plot(x1,joint_pdf);hold on;
plot(x2,y2,'k-');title(sprintf('Maximum Likelihood Estimation, mean = %2.1f', x1(maxparam)));
xlabel('mean');
ylabel('p(D|mean)');

% 计算联合概率(假设方差已知)
function val = ML_value(rx, meanval, var, num)
t = 1;
for i = 1:num
   t = t*exp(-(rx(i)-meanval).*(rx(i)-meanval)/(2*var))/sqrt(2*pi*var);
end
val = t;
运行结果图:


已标记关键词 清除标记
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页