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