ml_gaussian.m

来自「这是一个改进后的小波聚类的MATLAB源代码」· M 代码 · 共 20 行

M
20
字号
function index = ML_gaussian(x,mu,sigma)
% function index = ML_gaussian(x,mu,sigma)
% x is a vector drawn from some multivariate gaussian
% mu(i,:) is the mean of the ith Gaussian
% sigma(:,:,i) is the covariance of the ith Gaussian
% 
% Returns the index of the Gaussian with the highest value of p(x).

N = size(mu,1);  % number of Gaussians

if( N == 0 )
    index = 0;
else
    for i=1:N,
        % leave out factor of 1/(2*pi)^(N/2) since it doesn't affect argmax
        p(i) = 1/sqrt(det(sigma(:,:,i)))*exp(-0.5*(x-mu(i,:))*inv(sigma(:,:,i))*(x-mu(i,:))');
    end
    [m index] = max(p);
end

⌨️ 快捷键说明

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