我将具有从混合正态分布生成向量的功能。首先,我已经完成了从N(mu, Sigma)
:
function [X] = BSXgen(N,d,mu,sigma)
A = chol(sigma);
X = bsxfun(@plus, mu, A'*randn(d,N));
end
我可以BSXgen(10,2,[0;0],diag([1 1]))
使用它来从二维空间生成10
个向量。
接下来,我将从混合物正态分布生成数据。我在做什么:
N=5000; %number of vectors
d=2; %dimension of space
K=5; %number of mictures
p=0.2*ones(1,K); %probability of every mixture - in this case p1=...=p5=0.2
mu = [ [2;2] [4;1] [2;8] [4;6] [8;2]] %matrix with mu parameters for every mixture
SIGMA = diag([0.5 0.5]); %in this case - for every mixture we will have the same SIGMA matrix
U = unifrnd(0,1,1,N); %Random variable from U(0,1)
%Generating vectors from mixture
X = [];
for i=1:K
m = size(U(U<sum(p([1:i])) & U>= sum(p([1:i-1]))));
X = [X BSXgen(m(2),d,mu(:,i),SIGMA)];
end
%Plotting vectors
X=X';
scatter(X(:,1),X(:,2),3,'fill')
我是对的吗?我是否真的从混合物中生成数据?我不确定所以我真的很感激任何意见。