1 %> @brief Least-Distance-to-Class-Mean Classifier
3 %> Implements the Least-Distance-to-Class-Mean Classifier (
"Euclidean Distance classifier" as in [1])
5 %> With option
do weigh the points
using Plamen
's potential function [2].
7 %> @sa uip_clssr_dist.m
10 %> [1] Raudys SJ, Jain AK. Sample Size Effects in Statistical Pattern Recognition: Recommendations for Practitioners.
11 %%> IEEE Transactions on Pattern Analysis and Machine Intelligence. 1991;13(3).
13 %> [2] Angelov PP, Filev DP. An approach to online identification of Takagi-Sugeno fuzzy models. IEEE transactions on
14 %> systems, man, and cybernetics. Part B, Cybernetics : a publication of the IEEE Systems, Man, and Cybernetics Society.
15 %> 2004;34(1):484-98. Available at: http://www.ncbi.nlm.nih.gov/pubmed/15369087.
16 classdef clssr_dist < clssr
18 normtype = 'euclidean
'; % available options are: 'euclidean
', (none else for the moment)
19 flag_pr = 0; % Whether or not to weight the points by the potential function when calculating the per-class mean
20 %> =1. Whether or not to use priors. If set, will calculate the prior class-conditional probabilities based on the amount of
21 %> training data for each class.
25 properties(SetAccess=protected)
30 % Probability of belonging to each class - calculated from training data
36 function o = clssr_dist(o)
37 o.classtitle = 'Least-Distance-to-Class-Mean
';
42 methods(Access=protected)
44 %> Calculates @c classmeans
45 function o = do_train(o, data)
46 o.classlabels = data.classlabels;
48 t = tic; % Starts time counting
50 % pieces = data_split_classes(data);
51 nc = max(data.classes)+1;
52 o.classmeans = zeros(data.nf, nc);
57 o.classmeans(:, i) = mean(data.X(data.classes == i-1, :), 1)';
60 % Plamen
's weighted class means where the weights are the per-class potentials
62 A = 1; % Scaling factor for the potential formula like 1/(1+A*sum(...))
63 % This is just an internal experience
67 Xi = data.X(data.classes == i-1, :);
71 % Recursive calculation of beta and xi for the potential formula
76 beta = beta+sum(x.^2);
81 % Storing these but probably won't use them.
82 o.pr_coeffs(i).beta = beta;
83 o.pr_coeffs(i).xi = xi;
85 % Again, but
this time is to calculate the weighted mean
86 % mean = 1/sum(p_j)*sum(x_j*p_j)
92 p = no/(no*(A*x*x
'+1)+A*beta-2*A*x*xi');
98 o.classmeans(:, i) = sum_xp/sum_p;
103 if ~o.flag_use_priors
104 o.priors = ones(1, data.nc);
106 for k = data.nc:-1:1 % Backwards
for allocation
107 o.priors(k) = sum(data.classes == k-1);
110 o.priors = o.priors/sum(o.priors);
113 o.classlabels_train = data.classlabels;
115 o.time_train = toc(t);
120 %> Calculates @c est.X
using the
"softmax" transform, which is
121 %> X(i, j) = (1/dist_of_point_i_to_class_j^2)/sum(all numerators in j)
123 function est = do_use(o, data)
126 est.classlabels = o.classlabels;
127 est = est.copy_from_data(data);
132 nc = size(o.classmeans, 2);
135 Y = zeros(data.no, nc);
137 X_subtract = repmat(o.classmeans(:, i)', data.no, 1);
139 Y(:, i) = 1./exp(sum(X_.^2, 2)); % distance is Euclidean
141 Y(Y == Inf) = realmax();
143 % Class posterior probabilities are weighted by their respective priors
145 Y = Y.*repmat(o.priors, data.no, 1);
148 Y = Y./repmat(sum(Y, 2), 1, nc); % normalization
153 % est.classes =
renumber_classes(est.classes, o.classlabels_train, o.classlabels);
Dataset representing estimation.
function renumber_classes(in classes_orig, in classlabels_orig, in classlabels_ref)
Analysis Session (AS) base class.