我在协调高斯混合的一些基本理论结果和命令的输出方面遇到了问题
gmdistribution, random
在Matlab。
考虑两个具有权重的独立三元正态分布的混合
1/2,1/2
。
第一次发行
A
其特征是均值和方差协方差矩阵等于
muA=[-1.4 3.2 -1.9]; %mean vector
rhoA=-0.5; %correlation among components in A
sigmaA=[1 rhoA rhoA; rhoA 1 rhoA; rhoA rhoA 1]; %variance-covariance matrix of A
第二次发行
B
其特征是均值和方差协方差矩阵等于
muB=muB=[1.2 -1.6 1.5]; %mean vector
rhoB=0.3; %correlation among components in B
sigmaB=[1 rhoB rhoB; rhoB 1 rhoB; rhoB rhoB 1]; %variance-covariance matrix of B
让
epsilon
是作为混合物分布的三元随机向量。我的计算表明
ε
应该是
Mtheory=1/2*(muA+muB);
方差协方差矩阵应该是
Vtheory=1/4*[2 rhoA+rhoB rhoA+rhoB; rhoA+rhoB 2 rhoA+rhoB; rhoA+rhoB rhoA+rhoB 2];
现在我们来看看
Mtheory
和
Vtheory
与我们从混合物中提取许多随机数得到的经验矩一致。
clear
rng default
n=10^6; %number of draws
w = ones(1,2)/2; %weights
rhoA=-0.5; %correlation among components of A
rhoB=0.3; %correlation among components of B
muA=[-1.4 3.2 -1.9]; %mean vector of A
muB=[1.2 -1.6 1.5]; %mean vector of B
mu = [muA;muB];
%Variance-covariance matrix for mixing
sigmaA=[1 rhoA rhoA; rhoA 1 rhoA; rhoA rhoA 1]; %variance-covariance matrix of A
sigmaB=[1 rhoB rhoB; rhoB 1 rhoB; rhoB rhoB 1]; %variance-covariance matrix of B
sigma = cat(3,sigmaA,sigmaB);
obj = gmdistribution(mu, sigma,w);
%Draws
epsilon = random(obj, n);
M=mean(epsilon);
V=cov(epsilon);
Mtheory=1/2*(muA+muB);
Vtheory=1/4*[2 rhoA+rhoB rhoA+rhoB; rhoA+rhoB 2 rhoA+rhoB; rhoA+rhoB rhoA+rhoB 2];
问题:
M
和
M理论
几乎一致。
V
和
虚拟理论
完全不同。我做错什么了?我应该做一些非常愚蠢的事情,但我不知道在哪里。