annotate toolboxes/FullBNT-1.0.7/KPMstats/parzen_fit_select_unif.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 [mu, N, pick] = parzen_fit_select_unif(data, labels, max_proto, varargin)
wolffd@0 2 % PARZEN_FIT_SELECT_UNIF Fit a parzen density estimator by selecting prototypes uniformly from data
wolffd@0 3 % [mu, N, pick] = parzen_fit_select_unif(data, max_proto, labels, ...)
wolffd@0 4 %
wolffd@0 5 % We partition the data into different subsets based on the labels.
wolffd@0 6 % We then choose up to max_proto columns from each subset, chosen uniformly.
wolffd@0 7 %
wolffd@0 8 % INPUTS
wolffd@0 9 % data(:,t)
wolffd@0 10 % labels(t) - should be in {1,2,..,Q}
wolffd@0 11 % max_proto - max number of prototypes per partition
wolffd@0 12 %
wolffd@0 13 % Optional args
wolffd@0 14 % partition_names{m} - for debugging
wolffd@0 15 % boundary - do not choose prototypes which are within 'boundary' of the label transition
wolffd@0 16 %
wolffd@0 17 % OUTPUTS
wolffd@0 18 % mu(:, m, q) for label q, prototype m for 1 <= m <= N(q)
wolffd@0 19 % N(q) = number of prototypes for label q
wolffd@0 20 % pick{q} = identity of the prototypes
wolffd@0 21
wolffd@0 22 nclasses = max(labels);
wolffd@0 23 [boundary, partition_names] = process_options(...
wolffd@0 24 varargin, 'boundary', 0, 'partition_names', []);
wolffd@0 25
wolffd@0 26 [D T] = size(data);
wolffd@0 27 mu = zeros(D, 1, nclasses); % dynamically determine num prototypes (may be less than K)
wolffd@0 28 mean_feat = mean(data,2);
wolffd@0 29 pick = cell(1,nclasses);
wolffd@0 30 for c=1:nclasses
wolffd@0 31 ndx = find(labels==c);
wolffd@0 32 if isempty(ndx)
wolffd@0 33 %fprintf('no training images have label %d (%s)\n', c, partition_names{c})
wolffd@0 34 fprintf('no training images have label %d\n', c);
wolffd@0 35 nviews = 1;
wolffd@0 36 mu(:,1,c) = mean_feat;
wolffd@0 37 else
wolffd@0 38 foo = linspace(boundary+1, length(ndx-boundary), max_proto);
wolffd@0 39 pick{c} = ndx(unique(floor(foo)));
wolffd@0 40 nviews = length(pick{c});
wolffd@0 41 %fprintf('picking %d views for class %d=%s\n', nviews, c, class_names{c});
wolffd@0 42 mu(:,1:nviews,c) = data(:, pick{c});
wolffd@0 43 end
wolffd@0 44 N(c) = nviews;
wolffd@0 45 end