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