-
Notifications
You must be signed in to change notification settings - Fork 0
/
WrapperTestOnly.m
65 lines (53 loc) · 2.23 KB
/
WrapperTestOnly.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
% Initializes all HMM parameters
% Code by: Nitin J. Sanket ([email protected])
clc
clear all
close all
%% Load the model
load('HMMModelM90N10Med.mat');
%% Add all paths
addpath(genpath('./'));
%% Generate Testing and Training Paths
TestPath = '../SingleSequence/';
%% Get the names
TestDirs = dir([TestPath,'*.txt']);
%% Load Testing Data
disp(['Filtering using ', HMMModel.FilterName]);
TestData = cell(1,length(TestDirs));
for i = 1:length(TestDirs)
TestData{i} = FilterData(load([TestPath,TestDirs(i).name]), HMMModel.FilterName);
end
disp('Loading Testing data Complete....');
%% Initialize other parameters
% Initialize Variables
M = 90; % Number of clusters/unique possible observation samples
N = 10; % Number of states
NIter = 25; % Number of iterations of EM
NumClasses = 6;% Number of classes
NumSamplesPerClassTest = length(TestDirs)/NumClasses; % Number of samples in every class of testing set, assumes same number of samples in every class
disp('--------------------------------------------------------------------');
disp(['Using ', num2str(M), ' clusters....']);
disp(['Using ', num2str(N), ' states....']);
disp('--------------------------------------------------------------------');
%% Test HMM
NamesOrg = {'beat3','beat4','circle','eight','inf','wave'};
Names = [repmat({'beat3'},1,NumSamplesPerClassTest),repmat({'beat4'},1,NumSamplesPerClassTest),...
repmat({'circle'},1,NumSamplesPerClassTest),repmat({'eight'},1,NumSamplesPerClassTest),...
repmat({'inf'},1,NumSamplesPerClassTest),repmat({'wave'},1,NumSamplesPerClassTest)];
Score = cell(length(TestDirs),1);
GuessedClass = cell(length(TestDirs),1);
Confidence = zeros(length(TestDirs),1);
Accuracy = 0;
for i = 1:length(TestDirs)
[Score{i}, GuessedClass{i}, Confidence(i)] = TestHMM(TestData{i}(:,2:end), HMMModel, Names{i}, NamesOrg, NumClasses, N);
if(strcmp(GuessedClass{i},Names{i}))
Accuracy = Accuracy + 1;
end
bar(Score{i});
title(['Actual ',Names{i}, ' Guessed ', GuessedClass{i}, ' with Confidence ', num2str(Confidence(i))]);
set(gca,'XTickLabel',NamesOrg);
ylabel('Confidence');
saveas(gcf, ['./Outputs/',num2str(i),'.jpg']);
end
Accuracy = (Accuracy./length(TestDirs)).*100;
disp(['Total Accuracy ', num2str(Accuracy)]);