我的答案是与你的
earlier question的答案相同。对于概率密度函数,
the integral over the entire space is 1.除以总和不会给你正确的密度。要获得正确的密度,您必须除以面积。为了说明我的观点,请尝试以下示例。
[f,x]=hist(randn(10000,1),50);%# create histogram from a normal distribution.
g=1/sqrt(2*pi)*exp(-0.5*x.^2);%# pdf of the normal distribution
%#METHOD 1: DIVIDE BY SUM
figure(1)
bar(x,f/sum(f));hold on
plot(x,g,'r');hold off
%#METHOD 2: DIVIDE BY AREA
figure(2)
bar(x,f/trapz(x,f));hold on
plot(x,g,'r');hold off
你可以看到自己哪个方法与正确答案(红色曲线)一致。
另一种方法(比方法2更简单)将直方图归一化除以“sum(f * dx)”,其表示概率密度函数的积分。也就是说
%#METHOD 3: DIVIDE BY AREA USING sum()
figure(3)
dx = diff(x(1:2))
bar(x,f/sum(f*dx));hold on
plot(x,g,'r');hold off