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

📄 gmmevalvanilla.m

📁 一个关于数据聚类和模式识别的程序,在生物化学,化学中因该都可以用到.希望对大家有用,谢谢支持
💻 M
字号:
function [prob, gaussianProb] = gmmEval(data, mu, sigma, w);
% gmmEval: Evaluation of a GMM (Gaussian mixture model)
%	Usage: [prob, gaussianProb] = gmmEval(data, mu, sigma, w);
%		data: dim x dataNum matrix where each column is a data point
%		mu: dim x gaussianNum matrix where each column is a mean vector
%		sigma: dim x 1 vector where each element represents the covariance of a variable
%		w: 1 x gaussianNum vector where each element is a weighting coefficient
%		prob: 1 x dataNum vector of output probabilities
%		gaussianProb(i,j) is the probability of data(:,j) to the i-th Gaussian

%	Roger Jang, 20000602

if nargin==0, selfdemo; return; end

[dim, dataNum] = size(data);
gaussianNum = size(mu, 2);
gaussianProb = zeros(gaussianNum, dataNum);	% gaussianProb(i,j) is the prob. of data j to Gaussian i

for i = 1:gaussianNum,
	gaussianProb(i,:) = gaussian(data, mu(:, i), sigma(i)*eye(dim));
end
prob = w(:)'*gaussianProb;


% ====== Self demo
function selfdemo
mu = [-3 3; 3, -3; 3, 3]';
sigma = [1 3 2];
w = [0.2, 0.3, 0.5];
bound = 8;
pointNum = 31;
x = linspace(-bound, bound, pointNum);
y = linspace(-bound, bound, pointNum);
[xx, yy] = meshgrid(x, y);
data = [xx(:), yy(:)]';
prob = feval(mfilename, data, mu, sigma, w);
zz = reshape(prob, pointNum, pointNum);
mesh(xx, yy, zz);
axis([-inf inf -inf inf -inf inf]);
set(gca, 'box', 'on');

⌨️ 快捷键说明

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