混合正規分布からベクトルを生成する機能があります。まず、関数を実行して、からベクトルを生成しましたN(mu, Sigma)
:
function [X] = BSXgen(N,d,mu,sigma)
A = chol(sigma);
X = bsxfun(@plus, mu, A'*randn(d,N));
end
これを使用して 、2 次元空間からベクトルBSXgen(10,2,[0;0],diag([1 1]))
を生成できます。10
次に、混合正規分布からデータを生成します。私がやっていること:
N=5000; %number of vectors
d=2; %dimension of space
K=5; %number of mixtures
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')
私は正しいですか?混合物から本当にデータを生成していますか? よくわからないので、どなたかご意見よろしくお願いします。