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