📄 mog_dd.m
字号:
%MOG_DD Mixture of Gaussians data description%% W = mog_dd(A,fracrej,n)%% Training of a mixture of gaussians, with n gaussians.%% Algorithm was inspired from NetLab, Bishop but changed very much.% beforehand a number of gaussians is chosen, using EM the size and% the place of the gaussians is optimized.%% W = mog_dd(A,fracrej,n,ctype)%% By setting ctype, the covariance structure of the covariance can be% set. There are three possibilities:% ctype = 'sphr' : diagonal cov. matrix with equal values% ctype = 'diag' : diagonal cov. matrix% ctype = 'full' : full cov. matrix%%% required functions: mogEM and mogP% Copyright: D. Tax, R.P.W. Duin, davidt@ph.tn.tudelft.nl% Faculty of Applied Physics, Delft University of Technology% P.O. Box 5046, 2600 GA Delft, The Netherlandsfunction W = mog_dd(a,fracrej,n,ctype,reg,numiters)if (nargin<6) numiters = 25;endif (nargin<5) reg = 0.1;endif (nargin<4) ctype = 'sphr';endif (nargin<3) n = 5;endif (nargin<2) fracrej = 0.05;endif (nargin<1)|isempty(a) W = mapping(mfilename,{fracrej,n,ctype,reg}); returnendif isa(fracrej,'double') %training if ~isa(a,'dataset') %train on training set error('MOG_DD: I need a dataset to train.'); end a = target_class(a); % only use the target class [nlab,lablist,m,k,c,prob,featlist] = dataset(a); % train it [means, covs, priors] = mogEM(+a, n, ctype, reg, numiters); % obtain the threshold: d = sum(mogP(+a,means,covs,priors),2); thr = threshold(d,fracrej); %and save all useful data: W.m = means; W.c = covs; W.p = priors; W.threshold = thr;% W = {means,covs,priors,thr}; W = mapping(mfilename,W,str2mat('target','outlier'),k,c);else %testing [W,classlist,type,k,c] = mapping(fracrej); % unpack [nlab,lablist,m,k,c,p] = dataset(a); %compute:% out = sum(mogP(+a,W{1},W{2},W{3}),2);% newout = [out, ones(m,1)*W{4}]; out = sum(mogP(+a,W.m,W.c,W.p),2); newout = [out, ones(m,1)*W.threshold]; W = dataset(newout,getlab(a),classlist,p,lablist);endreturn
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -