将Matlab中的绘制从高斯混合转换为均匀 [英] Transforming draws in Matlab from Gaussian mixture to uniform
问题描述
请考虑以下内容,以在Matlab中绘制2x1
向量,其概率分布是两个高斯分量的混合.
Consider the following draws for a 2x1
vector in Matlab with a probability distribution that is a mixture of two Gaussian components.
P=10^3; %number draws
v=1;
%First component
mu_a = [0,0.5];
sigma_a = [v,0;0,v];
%Second component
mu_b = [0,8.2];
sigma_b = [v,0;0,v];
%Combine
MU = [mu_a;mu_b];
SIGMA = cat(3,sigma_a,sigma_b);
w = ones(1,2)/2; %equal weight 0.5
obj = gmdistribution(MU,SIGMA,w);
%Draws
RV_temp = random(obj,P);%Px2
% Transform each component of RV_temp into a uniform in [0,1] by estimating the cdf.
RV1=ksdensity(RV_temp(:,1), RV_temp(:,1),'function', 'cdf');
RV2=ksdensity(RV_temp(:,2), RV_temp(:,2),'function', 'cdf');
现在,如果通过执行以下操作检查RV1
和RV2
是否在[0,1]
上均匀分布
Now, if we check whether RV1
and RV2
are uniformly distributed on [0,1]
by doing
ecdf(RV1)
ecdf(RV2)
我们可以看到RV1
均匀地分布在[0,1]
上(经验CDF接近45度线),而RV2
不是.
we can see that RV1
is uniformly distributed on [0,1]
(the empirical cdf is close to the 45 degree line) while RV2
is not.
我不明白为什么.看来mu_a(2)
和mu_b(2)
距离越远,ksdensity
进行的抽奖次数就越差.为什么?
I don't understand why. It seems that the more distant are mu_a(2)
and mu_b(2)
, the worse the job done by ksdensity
with a reasonable number of draws. Why?
推荐答案
当您将N(0.5,v)和N(8.2,v)混合使用时,生成的数据范围将比您期望的要大就像在另一个维度上一样,它们更接近,例如N(0,v)和N(0,v).然后,您要求ksdensity
使用此范围内的P点来近似函数.
When you have a mixture of N(0.5,v) and N(8.2,v) then the range of the generated data is larger than if you had expectation which were closer, like N(0,v) and N(0,v), as you have in the other dimension. Then you ask ksdensity
to approximate a function using P points inside this range.
与标准线性插值一样,点越密集,函数的逼近度越好(在范围内),这是相同的情况.因此,在点为稀疏"(或稀疏,是单词吗?)的N(0.5,v)和N(8.2,v)中,逼近比N(0,v)和N(0 ,v)点更密集的地方.
Like in standard linear interpolation, the denser the points the better approximation of the function (inside the range), this is the same case here. Thus in the N(0.5,v) and N(8.2,v) where the points are "sparse" (or sparser, is that a word?) the approximation is worse than in the N(0,v) and N(0,v) where the points are denser.
作为一个小小的注解,您是否有任何理由不将ksdensity
直接应用于双变量数据?另外,在您说5e2
要点也不错的地方,我也无法复制您的评论.最后的评论通常是1e3
比10^3
更为可取.
As a small side note, are there any reason that you do not apply ksdensity
directly on the bivariate data? Also I cannot reproduce your comment where you say that 5e2
points are also good. Final comment, 1e3
is typically prefered over 10^3
.
这篇关于将Matlab中的绘制从高斯混合转换为均匀的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!