From 3e63cf170d53f67c7d7ca1f574e3a5335dddadb8 Mon Sep 17 00:00:00 2001 From: David Mayerich Date: Mon, 20 Mar 2017 01:32:59 -0500 Subject: [PATCH] added matlab files to aid in classifier characterization --- matlab/cls_ConfusionMatrix.m | 13 +++++++++++++ matlab/cls_MeanClassFeatures.m | 12 ++++++++++++ matlab/cls_PlotConfusionMatrix.m | 13 +++++++++++++ 3 files changed, 38 insertions(+), 0 deletions(-) create mode 100644 matlab/cls_ConfusionMatrix.m create mode 100644 matlab/cls_MeanClassFeatures.m create mode 100644 matlab/cls_PlotConfusionMatrix.m diff --git a/matlab/cls_ConfusionMatrix.m b/matlab/cls_ConfusionMatrix.m new file mode 100644 index 0000000..f5081fd --- /dev/null +++ b/matlab/cls_ConfusionMatrix.m @@ -0,0 +1,13 @@ +function M = cls_ConfusionMatrix(GT, T) + +%calculate the classes (unique elements in the GT array) +C = unique(GT); +nc = length(C); %calculate the number of classes +M = zeros(nc); %allocate space for the confusion matrix + +%for each class +for ci = 1:nc + for cj = 1:nc + M(ci, cj) = nnz((GT == C(ci)) .* (T == C(cj))); + end +end \ No newline at end of file diff --git a/matlab/cls_MeanClassFeatures.m b/matlab/cls_MeanClassFeatures.m new file mode 100644 index 0000000..2a04fe0 --- /dev/null +++ b/matlab/cls_MeanClassFeatures.m @@ -0,0 +1,12 @@ +function S = cls_MeanClassFeatures(F, T) +%Calculates the mean set of features for each class given the feature matrix F and targets T + +C = unique(T); %get the class IDs +nc = length(C); + +S = zeros(nc, size(F, 2)); %allocate space for the mean feature vectors +for c = 1:nc %for each class + S(c, :) = mean(F(T == C(c), :)); %calculate the mean feature vector for class c +end + +S = S'; \ No newline at end of file diff --git a/matlab/cls_PlotConfusionMatrix.m b/matlab/cls_PlotConfusionMatrix.m new file mode 100644 index 0000000..a2dd163 --- /dev/null +++ b/matlab/cls_PlotConfusionMatrix.m @@ -0,0 +1,13 @@ +function cls_PlotConfusionMatrix(M) + + +%normalize each row by its column +sum_cols = repmat(sum(M, 1), size(M, 1), 1); +Mc = M ./ sum_cols; +subplot(2, 1, 1), +bar(Mc'); + +sum_rows = repmat(sum(M, 2), 1, size(M, 2)); +Mr = M ./ sum_rows; +subplot(2, 1, 2), +bar(Mr); \ No newline at end of file -- libgit2 0.21.4