wolffd@0: function [mu, N, pick] = parzen_fit_select_unif(data, labels, max_proto, varargin) wolffd@0: % PARZEN_FIT_SELECT_UNIF Fit a parzen density estimator by selecting prototypes uniformly from data wolffd@0: % [mu, N, pick] = parzen_fit_select_unif(data, max_proto, labels, ...) wolffd@0: % wolffd@0: % We partition the data into different subsets based on the labels. wolffd@0: % We then choose up to max_proto columns from each subset, chosen uniformly. wolffd@0: % wolffd@0: % INPUTS wolffd@0: % data(:,t) wolffd@0: % labels(t) - should be in {1,2,..,Q} wolffd@0: % max_proto - max number of prototypes per partition wolffd@0: % wolffd@0: % Optional args wolffd@0: % partition_names{m} - for debugging wolffd@0: % boundary - do not choose prototypes which are within 'boundary' of the label transition wolffd@0: % wolffd@0: % OUTPUTS wolffd@0: % mu(:, m, q) for label q, prototype m for 1 <= m <= N(q) wolffd@0: % N(q) = number of prototypes for label q wolffd@0: % pick{q} = identity of the prototypes wolffd@0: wolffd@0: nclasses = max(labels); wolffd@0: [boundary, partition_names] = process_options(... wolffd@0: varargin, 'boundary', 0, 'partition_names', []); wolffd@0: wolffd@0: [D T] = size(data); wolffd@0: mu = zeros(D, 1, nclasses); % dynamically determine num prototypes (may be less than K) wolffd@0: mean_feat = mean(data,2); wolffd@0: pick = cell(1,nclasses); wolffd@0: for c=1:nclasses wolffd@0: ndx = find(labels==c); wolffd@0: if isempty(ndx) wolffd@0: %fprintf('no training images have label %d (%s)\n', c, partition_names{c}) wolffd@0: fprintf('no training images have label %d\n', c); wolffd@0: nviews = 1; wolffd@0: mu(:,1,c) = mean_feat; wolffd@0: else wolffd@0: foo = linspace(boundary+1, length(ndx-boundary), max_proto); wolffd@0: pick{c} = ndx(unique(floor(foo))); wolffd@0: nviews = length(pick{c}); wolffd@0: %fprintf('picking %d views for class %d=%s\n', nviews, c, class_names{c}); wolffd@0: mu(:,1:nviews,c) = data(:, pick{c}); wolffd@0: end wolffd@0: N(c) = nviews; wolffd@0: end