Introduction to Matlab
Download
Report
Transcript Introduction to Matlab
Generating Multivariate Gaussian
Generating Multivariate Gaussian
• We require n normal random numbers X = ( X1, X 2 ,..., X n )T
drawn from a multivariate normal distribution with
μC = (m1, m1,..., mn )T
és 12 s 12 L
ê
2
ês
s
12
2
CC = êê
O
êM
ês
êë 1n
s 1n ù
ú
ú
ú
ú
ú
s n2 ú
ú
û
Generating Multivariate Gaussian
• Generate n independent, zero-mean, unit variance normal random
variables
Y = (Y1, Y2 ,..., Yn )T
• Take
X = SY + μ X
μY = (0,0,...,0)T
where CX = SST
é1 0 L
ê
ê0 1
T
CY = E{YY } = êê
O
êM
êê0
ë
0ù
ú
ú
ú
ú
ú
1ú
ú
û
(Cholesky factorization)
CX = E{(X - μC )(X - μC )T } = E{(SY)(SY)T } = E{SYYT ST } = SE{YYT }ST = SST
Generating Multivariate Gaussian
é0ù
mX = ê ú
ê0ú
ëû
é1 0ù
ú
CX = ê
ê0 1ú
ë
û
r=0
mx=[0 0]';
Cx=[1 0; 0 1];
x1=-3:0.1:3;
x2=-3:0.1:3;
for i=1:length(x1),
for j=1:length(x2),
f(i,j)=(1/(2*pi*det(Cx)^1/2))*exp((
-1/2)*([x1(i) x2(j)]mx')*inv(Cx)*([x1(i);x2(j)]-mx));
end
end
mesh(x1,x2,f)
pause;
contour(x1,x2,f)
pause
Generating Multivariate Gaussian
é0ù
mX = ê ú
ê0ú
ëû
é1 0ù
ú
CX = ê
ê0 1ú
ë
û
N=1000;
[y1,y2]=gennormal(N,0,1);
plot(y1,y2,'.')
Generating Multivariate Gaussian
é0ù
mX = ê ú
ê0ú
ëû
é
ê1
ê
CX = ê
ê1
ê
êë2
mx=[0 0]';
Cx=[1 1/2; 1/2 1];
1ù
ú
2ú
ú
ú
1ú
ú
û
r=
1
2
Generating Multivariate Gaussian
é
ê1
ê
CX = ê
ê1
ê
êë2
1ù
ú
2ú
ú
ú
1ú
ú
û
é1
ê
S = ê1
ê
êë2
0 ù
ú
3ú
ú
2 ú
û
N=1000;
mx=zeros(2,N);
[y1,y2]=gennormal(N,0,1);
y=[y1;y2];
S=[1, 0; 1/2, sqrt(3)/2];
x=S*y+mx;
x1=x(1,:);
x2=x(2,:);
plot(x1,x2,'.')
r=corrcoef(x1',x2')
r =
1.0000
0.5056
0.5056
1.0000
Generating Multivariate Gaussian
é5ù
mX = ê ú
ê5ú
ëû
é 1 0.9ù
ú r = 0.9
CX = ê
ê0.9 1 ú
ë
û
mx=[5 5]';
Cx=[1 9/10; 9/10 1];
Generating Multivariate Gaussian
é 1 0.9ù
ú
CX = ê
ê0.9 1 ú
ë
û
é1
ê
S = ê9
ê
êë10
0 ù
ú
19 ú
ú
10 ú
û
N=1000;
mx=5*ones(2,N);
[y1,y2]=gennormal(N,0,1);
y=[y1;y2];
S=[1, 0; 9/10, sqrt(19)/10];
x=S*y+mx;
x1=x(1,:);
x2=x(2,:);
plot(x1,x2,'.')
r=corrcoef(x1',x2')
r =
1.0000
0.9041
0.9041
1.0000