⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gm_generation.m

📁 EM算法
💻 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

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -