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

initial commit to HG from Changeset: 646 (e263d8a21543) added further path and more save "camirversion.m"
author Daniel Wolff
date Fri, 19 Aug 2016 13:07:06 +0200
parents
children
rev   line source
Daniel@0 1 function mixgauss = mixgauss_classifier_train(trainFeatures, trainLabels, nc, varargin)
Daniel@0 2 % function mixgauss = mixgauss_classifier_train(trainFeatures, trainLabels, nclusters, varargin)
Daniel@0 3 % trainFeatures(:,i) for i'th example
Daniel@0 4 % trainLabels should be 0,1
Daniel@0 5 % To evaluate performance on a tets set, use
Daniel@0 6 % mixgauss = mixgauss_classifier_train(trainFeatures, trainLabels, nc, 'testFeatures', tf, 'testLabels', tl)
Daniel@0 7
Daniel@0 8 [testFeatures, testLabels, max_iter, thresh, cov_type, mu, Sigma, priorC, method, ...
Daniel@0 9 cov_prior, verbose, prune_thresh] = process_options(...
Daniel@0 10 varargin, 'testFeatures', [], 'testLabels', [], ...
Daniel@0 11 'max_iter', 10, 'thresh', 0.01, 'cov_type', 'diag', ...
Daniel@0 12 'mu', [], 'Sigma', [], 'priorC', [], 'method', 'kmeans', ...
Daniel@0 13 'cov_prior', [], 'verbose', 0, 'prune_thresh', 0);
Daniel@0 14
Daniel@0 15 Nclasses = 2; % max([trainLabels testLabels]) + 1;
Daniel@0 16
Daniel@0 17 pos = find(trainLabels == 1);
Daniel@0 18 neg = find(trainLabels == 0);
Daniel@0 19
Daniel@0 20 if verbose, fprintf('fitting pos\n'); end
Daniel@0 21 [mixgauss.pos.mu, mixgauss.pos.Sigma, mixgauss.pos.prior] = ...
Daniel@0 22 mixgauss_em(trainFeatures(:, pos), nc, varargin{:});
Daniel@0 23
Daniel@0 24 if verbose, fprintf('fitting neg\n'); end
Daniel@0 25 [mixgauss.neg.mu, mixgauss.neg.Sigma, mixgauss.neg.prior] = ...
Daniel@0 26 mixgauss_em(trainFeatures(:, neg), nc, varargin{:});
Daniel@0 27
Daniel@0 28
Daniel@0 29 if ~isempty(priorC)
Daniel@0 30 mixgauss.priorC = priorC;
Daniel@0 31 else
Daniel@0 32 mixgauss.priorC = normalize([length(pos) length(neg)]);
Daniel@0 33 end