?? mmgauss.html
字號:
<html><head> <meta HTTP-EQUIV="Content-Type" CONTENT="text/html;charset=ISO-8859-1"> <title>mmgauss.m</title><link rel="stylesheet" type="text/css" href="../../../m-syntax.css"></head><body><code><span class=defun_kw>function</span> <span class=defun_out>model</span>=<span class=defun_name>mmgauss</span>(<span class=defun_in>X,options,init_model</span>)
<br><span class=h1>% MMGAUSS Minimax estimation of Gaussian distribution.
</span><br><span class=help>%
</span><br><span class=help>% <span class=help_field>Synopsis:</span></span><br><span class=help>% model = mmgauss(X)
</span><br><span class=help>% model = mmgauss(X,options)
</span><br><span class=help>% model = mmgauss(X,options,init_model)
</span><br><span class=help>%
</span><br><span class=help>% <span class=help_field>Description:</span></span><br><span class=help>% This function computes the minimax estimation of Gaussian
</span><br><span class=help>% parameters. The minimax estimation (reffer to [SH10]) for
</span><br><span class=help>% Gaussian model is defined as:
</span><br><span class=help>%
</span><br><span class=help>% (Mean,Cov) = argmax min( pdfgauss(X, Mean, Cov) ).
</span><br><span class=help>% Mean,Cov
</span><br><span class=help>%
</span><br><span class=help>% The sample data X should be good representatives of the
</span><br><span class=help>% distribution. In contrast to maximum-likelihood estimation,
</span><br><span class=help>% the data do not have to be i.i.d.
</span><br><span class=help>%
</span><br><span class=help>% An itrative algorithm is used for estimation. It iterates
</span><br><span class=help>% until
</span><br><span class=help>% upper_bound - lower_bound < eps,
</span><br><span class=help>% where eps is prescribed precission and upper_bound, lower_bound
</span><br><span class=help>% are bounds on the optimal solution
</span><br><span class=help>% upper_bound > max min( pdfgauss(X, Mean, Cov) ) > lower_bound
</span><br><span class=help>% Mean,Cov
</span><br><span class=help>%
</span><br><span class=help>% <span class=help_field>Input:</span></span><br><span class=help>% X [dim x num_data] Data sample.
</span><br><span class=help>%
</span><br><span class=help>% options [struct] Control parameters:
</span><br><span class=help>% .eps [1x1] Precision of found estimate (default 0.1).
</span><br><span class=help>% .tmax [1x1] Maximal number of iterations (default inf).
</span><br><span class=help>% .cov_type [int] Type of estimated covariance matrix:
</span><br><span class=help>% cov_type = 'full' full covariance matrix (default)
</span><br><span class=help>% cov_type = 'diag' diagonal covarinace matrix
</span><br><span class=help>% cov_type = 'spherical' spherical covariance matrix
</span><br><span class=help>% .verb [int] If 1 then info is printed (default 0).
</span><br><span class=help>%
</span><br><span class=help>% init_model [struct] Initial model:
</span><br><span class=help>% .Alpha [1xnum_data] Weights of training vectors.
</span><br><span class=help>% .t [1x1] (optional) Counter of iterations.
</span><br><span class=help>%
</span><br><span class=help>% <span class=help_field>Output:</span></span><br><span class=help>% model [struct] Gaussian distribution:
</span><br><span class=help>% .Mean [dim x 1] Estimated mean vector.
</span><br><span class=help>% .Cov [dim x dim] Estimated covariance matrix.
</span><br><span class=help>%
</span><br><span class=help>% .t [1x1] Number of iterations.
</span><br><span class=help>% .exitflag [1x1] 1 ... (upper_bound - lower_bound) < eps
</span><br><span class=help>% 0 ... maximal number of iterations tmax exceeded.
</span><br><span class=help>% .upper_bound [1x1] Upper bound on the optimized criterion.
</span><br><span class=help>% .lower_bound [1x1] Lower bound on the optimized criterion.
</span><br><span class=help>% .Alpha [1 x num_data] Data weights. The minimax estimate
</span><br><span class=help>% is equal to maximum-likelihood estimate of weighted data.
</span><br><span class=help>% .options [struct] Copy of used options.
</span><br><span class=help>%
</span><br><span class=help>% <span class=help_field>Example:</span></span><br><span class=help>% X = [[0;0] [1;0] [0;1]];
</span><br><span class=help>% mm_model = mmgauss(X);
</span><br><span class=help>% figure; ppatterns(X);
</span><br><span class=help>% pgauss(mm_model, struct('p',exp(mm_model.lower_bound')));
</span><br><span class=help>%
</span><br><span class=help>% See also
</span><br><span class=help>% PDFGAUSS, MLCGMM, EMGMM.
</span><br><span class=help>%
</span><br><hr><br><span class=help1>% <span class=help1_field>About:</span> Statistical Pattern Recognition Toolbox
</span><br><span class=help1>% (C) 1999-2003, Written by Vojtech Franc and Vaclav Hlavac
</span><br><span class=help1>% <a href="http://www.cvut.cz">Czech Technical University Prague</a>
</span><br><span class=help1>% <a href="http://www.feld.cvut.cz">Faculty of Electrical Engineering</a>
</span><br><span class=help1>% <a href="http://cmp.felk.cvut.cz">Center for Machine Perception</a>
</span><br><br><span class=help1>% <span class=help1_field>Modifications:</span>
</span><br><span class=help1>% 26-may-2004, VF
</span><br><span class=help1>% 30-apr-2004, VF
</span><br><span class=help1>% 19-sep-2003, VF
</span><br><span class=help1>% 27-feb-2003, VF
</span><br><span class=help1>% 24. 6.00 V. Hlavac, comments polished.
</span><br><br><hr>[dim,num_data]=size(X);
<br>
<br><span class=comment>% processing input arguments
</span><br><span class=comment>% ------------------------------------------
</span><br><span class=keyword>if</span> <span class=stack>nargin</span> < 2, options=[]; <span class=keyword>else</span> options = c2s(options); <span class=keyword>end</span>
<br><span class=keyword>if</span> ~isfield(options,<span class=quotes>'eps'</span>), options.eps =0.1; <span class=keyword>end</span>
<br><span class=keyword>if</span> ~isfield(options,<span class=quotes>'tmax'</span>), options.tmax = inf; <span class=keyword>end</span>
<br><span class=keyword>if</span> ~isfield(options,<span class=quotes>'verb'</span>), options.verb = 0; <span class=keyword>end</span>
<br><span class=keyword>if</span> ~isfield(options,<span class=quotes>'cov_type'</span>), options.cov_type = <span class=quotes>'full'</span>; <span class=keyword>end</span>
<br>
<br><span class=comment>% inicialization
</span><br><span class=comment>%---------------------------------
</span><br><span class=keyword>if</span> <span class=stack>nargin</span> < 3,
<br> model.Alpha = ones(1,num_data);
<br> model.t = 0;
<br> model.fun = <span class=quotes>'pdfgauss'</span>;
<br> model.options = options;
<br><span class=keyword>else</span>
<br> model = init_model;
<br> <span class=keyword>if</span> ~isfield(init_model,<span class=quotes>'t'</span>), model.t = 0; <span class=keyword>end</span>
<br><span class=keyword>end</span>
<br>
<br><span class=comment>% Main loop
</span><br><span class=comment>% ----------------------------------------
</span><br>stop = 0;
<br><span class=keyword>while</span> ~stop & options.tmax > model.t,
<br>
<br> <span class=keyword>if</span> options.verb,
<br> <span class=io>fprintf</span>(<span class=quotes>'iteration %d: '</span>, model.t );
<br> <span class=keyword>end</span>
<br>
<br> <span class=comment>% compute ML estimate for given weights model.Alpha
</span><br> tmp_model = melgmm( X, model.Alpha, options.cov_type);
<br>
<br> model.Mean = tmp_model.Mean;
<br> model.Cov = tmp_model.Cov;
<br>
<br> <span class=comment>% find a sample with the minimal probability
</span><br> logPx = log( pdfgauss(X, model));
<br> [minLogPx,min_inx] = min( logPx );
<br>
<br> <span class=comment>% compute upper bound and lower bound
</span><br> model.upper_bound=sum(model.Alpha.*logPx)/sum(model.Alpha);
<br> model.lower_bound=minLogPx;
<br>
<br> <span class=keyword>if</span> options.verb,
<br> <span class=io>fprintf</span>(<span class=quotes>'upper_bound=%f, lower_bound=%f\n'</span>, model.upper_bound, ...
<br> model.lower_bound );
<br> <span class=keyword>end</span>
<br>
<br> <span class=comment>% check stopping condition
</span><br> <span class=keyword>if</span> model.upper_bound - model.lower_bound < options.eps,
<br> stop = 1;
<br> model.exitflag = 1;
<br> <span class=keyword>else</span>
<br> <span class=comment>% increase occurance of the 'worst' sample by 1
</span><br> model.Alpha(min_inx) = model.Alpha(min_inx) + 1;
<br> model.t = model.t + 1;
<br> model.exitflag = 0;
<br> <span class=keyword>end</span>
<br>
<br><span class=keyword>end</span>
<br>
<br><span class=jump>return</span>;
<br></code>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -