www.pudn.com > RPEM_Source_Code.zip > gm_generation.m


%********************************************************************* 
% Function objective: Generate clusters as specified 
% Parameter Explanations: 
% Inputs: 
%    k:     the dimension of observations x's. 
%    onum:  the total number of observations. 
%    range: the cumulative prior proportion of each cluster. 
%    mu:    the means of the clusters. 
%    sigma: the covariance matrix of the clusters. 
% Output: 
%    x:     the observations forming clusters as specified. 
%********************************************************************* 
 
function [x] = gm_generation(k, onum, range, mu, sigma)  
 
randn('seed', 65536); 
rand('seed', 65530); 
 
sn = randn(k,onum); 
 
% number of mixture-of-Gaussian distribution 
mix_no = size(range,2); 
 
 
t = zeros(1,onum); 
x = zeros(k, onum); 
 
for i = 1:onum 
    r = rand;    
    for j = 1:mix_no 
    	if r <= range(j) 
	   t(i) = j; 
	   break; 
	end 
    end 
end 
 
sqrt_sigma = zeros(size(sigma)); 
 
% Calculate the square root of a matrix 
for j = 1:mix_no 
	sqrt_sigma(:,:,j) = sqrtm(sigma(:,:,j)); 
end 
 
% Generate the observations 
for i=1:onum 
	x(:,i)= sqrt_sigma(:,:,t(i))*sn(:,i)+mu(:,t(i)); 
end