How Matlab compute marginals

조회 수: 2 (최근 30일)
Fabio Garofalo
Fabio Garofalo 2016년 6월 21일
댓글: Fabio Garofalo 2016년 6월 21일
Hi, I'm computing the marginals for a given distribution (a Gaussian with a given covariance) by using the following code
clear all;
close all;
format shorte;
n=100000;
s=[[2,1];[1,3]];
x=chol(s)*randn(2,n);
figure
h=scatterhist(x(1,:),x(2,:));hold(h(1,2),'on');
xi=linspace(-10,10,1001);
plot(h(1,2),xi,1/sqrt(2*pi*s(1,1))*exp(-xi.^2/(2*s(1,1))));
figure
histogram(x(1,:),100,'normalization','pdf','facecolor','w');hold on;
plot(xi,1/sqrt(2*pi*s(1,1))*exp(-xi.^2/(2*s(1,1))));
however it seems that the actual x-marginal does not coincide with the theoretical one, that for the case I'm considering is a probabilistic Gaussian with zero mean and sqrt(s(1,1)) standard deviation.
Am I wrong or there is something else?
Thanks in advance, F
  댓글 수: 1
Fabio Garofalo
Fabio Garofalo 2016년 6월 21일
I guess I've found the error. It must be
x=chol(s)'*randn(2,n);
now the things seem to be satisfactory. I've checked with
cov(x(1,:),x(2,:))
and it is ok.

댓글을 달려면 로그인하십시오.

답변 (0개)

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by