annotate toolboxes/FullBNT-1.0.7/KPMstats/mixgauss_classifier_train.m @ 0:e9a9cd732c1e tip

first hg version after svn
author wolffd
date Tue, 10 Feb 2015 15:05:51 +0000
parents
children
rev   line source
wolffd@0 1 function mixgauss = mixgauss_classifier_train(trainFeatures, trainLabels, nc, varargin)
wolffd@0 2 % function mixgauss = mixgauss_classifier_train(trainFeatures, trainLabels, nclusters, varargin)
wolffd@0 3 % trainFeatures(:,i) for i'th example
wolffd@0 4 % trainLabels should be 0,1
wolffd@0 5 % To evaluate performance on a tets set, use
wolffd@0 6 % mixgauss = mixgauss_classifier_train(trainFeatures, trainLabels, nc, 'testFeatures', tf, 'testLabels', tl)
wolffd@0 7
wolffd@0 8 [testFeatures, testLabels, max_iter, thresh, cov_type, mu, Sigma, priorC, method, ...
wolffd@0 9 cov_prior, verbose, prune_thresh] = process_options(...
wolffd@0 10 varargin, 'testFeatures', [], 'testLabels', [], ...
wolffd@0 11 'max_iter', 10, 'thresh', 0.01, 'cov_type', 'diag', ...
wolffd@0 12 'mu', [], 'Sigma', [], 'priorC', [], 'method', 'kmeans', ...
wolffd@0 13 'cov_prior', [], 'verbose', 0, 'prune_thresh', 0);
wolffd@0 14
wolffd@0 15 Nclasses = 2; % max([trainLabels testLabels]) + 1;
wolffd@0 16
wolffd@0 17 pos = find(trainLabels == 1);
wolffd@0 18 neg = find(trainLabels == 0);
wolffd@0 19
wolffd@0 20 if verbose, fprintf('fitting pos\n'); end
wolffd@0 21 [mixgauss.pos.mu, mixgauss.pos.Sigma, mixgauss.pos.prior] = ...
wolffd@0 22 mixgauss_em(trainFeatures(:, pos), nc, varargin{:});
wolffd@0 23
wolffd@0 24 if verbose, fprintf('fitting neg\n'); end
wolffd@0 25 [mixgauss.neg.mu, mixgauss.neg.Sigma, mixgauss.neg.prior] = ...
wolffd@0 26 mixgauss_em(trainFeatures(:, neg), nc, varargin{:});
wolffd@0 27
wolffd@0 28
wolffd@0 29 if ~isempty(priorC)
wolffd@0 30 mixgauss.priorC = priorC;
wolffd@0 31 else
wolffd@0 32 mixgauss.priorC = normalize([length(pos) length(neg)]);
wolffd@0 33 end