MATLAB 中的高斯混合模型 - 经验方差协方差矩阵的计算
Gaussian Mixture Model in MATLAB - Calculation of the Empirical Variance Covariance Matrix
我在协调高斯混合的一些基本理论结果和 Matlab 中命令 gmdistribution, random
的输出时遇到问题。
考虑两个独立的 3 变量正态分布的混合,权重为 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
为作为混合分布的 3 变量随机向量。我的计算表明 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
和Mtheory
几乎重合。 V
和 Vtheory
是完全不同的。我究竟做错了什么?我应该做一些非常愚蠢的事情,但我不知道在哪里。
当您计算协方差时,请注意您的数据没有居中。
而且,你的0.25系数是错误的。
这不是变量的缩放,而是选择。
应使用 Law of Total Variance / Law of Total Covariance.
进行计算
其中 "The Given Event" 是混合指数。
我在协调高斯混合的一些基本理论结果和 Matlab 中命令 gmdistribution, random
的输出时遇到问题。
考虑两个独立的 3 变量正态分布的混合,权重为 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
为作为混合分布的 3 变量随机向量。我的计算表明 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
和Mtheory
几乎重合。 V
和 Vtheory
是完全不同的。我究竟做错了什么?我应该做一些非常愚蠢的事情,但我不知道在哪里。
当您计算协方差时,请注意您的数据没有居中。
而且,你的0.25系数是错误的。
这不是变量的缩放,而是选择。
应使用 Law of Total Variance / Law of Total Covariance.
进行计算
其中 "The Given Event" 是混合指数。