用协方差矩阵求方差的matlab代码,Matlab中的高斯混合模型-经验方差协方差矩阵的计算...

本文探讨了在使用Matlab的gmdistribution函数实现双元高斯混合模型时,理论计算的均值和方差协方差矩阵与实际随机采样结果的不一致。作者详细展示了问题设置,包括两个独立分布的参数,并质疑了可能的错误来源,旨在帮助读者理解并解决此类混淆。
摘要由CSDN通过智能技术生成

我在协调高斯混合的一些基本理论结果和命令的输出方面遇到了问题

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

虚拟理论

完全不同。我做错什么了?我应该做一些非常愚蠢的事情,但我不知道在哪里。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值