📄 gm.m
字号:
function [abest, mbest, sbest, ll] = gm(data, k, nr, sig)
%
% [alpha, mu, sigma, [ll] ] = gm(data, k, [nres, sig])
%
% INPUT:
% data : n by d data points (n points of dimensionality d).
% k : number of desired clusters.
% nres : number of random restarts <default is 1>
% sig : matrix of 0's and 1's used to cancel unwanted elements
% in sigma matrices (for forced decoupling)
%
% OUTPUT:
% alpha : weights of components (k by 1).
% mu : mean for each component (k by d).
% sigma : covariance matrix for each comp. (d by d by k).
% optional:
% ll(1:nres) : log-likelihood per restart
%
%
% NOTES:
% This is a wrapper function that calls gmm.dll to do the actual job.
% The purpose of this function is to supply defaults and to allow
% for variable number of parameters (by supplying defaults). It is
% only for convenience and doesn't do any fitting/calculations.
%
% by Igor Cadez 01/23/99
%get the number of restarts, default is just 1
if(~exist('nr'))
nr = 1;
end
[n, d] = size(data);
%if sig is not specified, use full cov. matrices.
if(~exist('sig'))
sig = ones(d);
end
%min values for preventing singularities...
minsigma = 1e-3;
sigmin = diag(cov(data)) * minsigma;
%precision and max interations
prec = 1e-4;
maxsteps = 100;
[abest, mbest, sbest, ll] = gmm(data, k, nr, sig,sigmin,maxsteps,prec);
sbest = reshape(sbest,d,d,k);
[i, j] = sort(-abest);
abest = abest(j);
mbest = mbest(j,:);
sbest = sbest(:,:,j);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -