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