MATLAB中的高斯混合模型-经验方差协方差矩阵的计算 [英] Gaussian Mixture Model in MATLAB - Calculation of the Empirical Variance Covariance Matrix
问题描述
在协调有关高斯混合的一些基本理论结果以及Matlab中命令gmdistribution, random
的输出时,我遇到了问题.
I am having issues in reconciling some basic theoretical results on Gaussian mixtures and the output of the commands gmdistribution, random
in Matlab.
考虑权重为1/2,1/2
的两个独立的3变量正态分布的混合.
Consider a mixture of two independent 3-variate normal distributions with weights 1/2,1/2
.
第一分布A
的特征在于均值和方差-协方差矩阵等于
The first distribution A
is characterised by mean and variance-covariance matrix equal to
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
的特征在于均值和方差-协方差矩阵等于
The second distribution B
is characterised by mean and variance-covariance matrix equal to
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
的期望值应为
Let epsilon
be the 3-variate random vector distributed as the mixture. My calculations suggest that the expected value of epsilon
should be
Mtheory=1/2*(muA+muB);
且方差-协方差矩阵应为
and the variance-covariance matrix should be
Vtheory=1/4*[2 rhoA+rhoB rhoA+rhoB; rhoA+rhoB 2 rhoA+rhoB; rhoA+rhoB rhoA+rhoB 2];
现在让我们来看一下Mtheory
和Vtheory
是否与通过从混合物中提取许多随机数而获得的经验矩一致.
Let's now try to see whether Mtheory
and Vtheory
coincide with the empirical moments that we get by drawing many random numbers from the mixture.
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
完全不同.我究竟做错了什么?我应该做一些非常愚蠢的事情,但是我不知道在哪里.
Question: M
and Mtheory
almost coincide. V
and Vtheory
are completely different. What am I doing wrong? I should be doing something very silly but I don't see where.
推荐答案
计算协方差时,请注意数据不在中心.
此外,您的0.25系数是错误的.
这不是变量的缩放比例,而是选择.
计算应使用总差异法律/
When you calculate the Covariance pay attention that your data isn't centered.
Moreover, your 0.25 factor is wrong.
This is not a scaling of the variable but a selection.
The calculation should be done using the Law of Total Variance / Law of Total Covariance.
Where the "The Given Event" is the mixture index.
高斯混合物的协方差计算给出了计算示例.
这篇关于MATLAB中的高斯混合模型-经验方差协方差矩阵的计算的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!