Skip to content

Commit 592e585

Browse files
committed
Adding the Project Files
Code and Report files, Data Files
1 parent 102e9e6 commit 592e585

File tree

130 files changed

+471679
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

130 files changed

+471679
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
clear all
2+
close all
3+
4+
Data = xlsread('Data.xlsx');
5+
6+
% X1 = normc(Data(:,1));
7+
% X2 = normc(Data(:,2));
8+
9+
X1 = Data(:,1);
10+
X2 = Data(:,2);
11+
12+
% X1 = normc(X1);
13+
% X2 = normc(X2);
14+
15+
%Given Datasets 'X1' and 'X2'
16+
17+
% figure(1)
18+
% plot(X2);
19+
% hold on
20+
% plot(X1,'-r');
21+
% hold off
22+
23+
figure(1)
24+
plot(X1,X2);
25+
26+
%Training with the first 60 samples of the given data
27+
28+
StepSize = 1;
29+
30+
S1 = X1(1:StepSize:60);
31+
S2 = X1(2:StepSize:61);
32+
S3 = X2(1:StepSize:60);
33+
S4 = X2(2:StepSize:61);
34+
35+
S5 = [S1 S2 S3 S4]';
36+
37+
T = X1(3:StepSize:62)';
38+
39+
save S5
40+
save T %Saving our Inputs and Outputs for Training Phase
41+
42+
time1 = clock; %Clocking the begin time so as to calculate the time taken
43+
44+
a1 = minmax(S1');
45+
a2 = minmax(S2');
46+
a3 = minmax(S3');
47+
a4 = minmax(S4');
48+
49+
Min_Max = [a1; a2; a3; a4]; %Min-max of the data for scaling purpose in the network
50+
51+
net = newff(Min_Max,[100 1],{'purelin' 'purelin'},'trainbr'); %Using a feedforward network with 100 hidden layers
52+
53+
net.trainParam.goal = 0.000001;
54+
net.trainParam.epochs = 1000;
55+
net.performFcn = 'mae';
56+
%net.plotFcns = {'plotPerform','plottrainstate','ploterrhist','plotfit','plotregression'};
57+
58+
59+
net = train(net,S5,T);
60+
61+
save 'DataNN'
62+
save net
63+
save X1
64+
save X2
65+
66+
%Testing remaining 30 nodes in the data
67+
68+
StepSize = 1;
69+
70+
S1 = X1(61:StepSize:87);
71+
S2 = X1(62:StepSize:88);
72+
S3 = X2(61:StepSize:87);
73+
S4 = X2(62:StepSize:88);
74+
75+
S6 = [S1 S2 S3 S4]';
76+
77+
R = X1(63:StepSize:89)';
78+
79+
Ra = sim(net,S6);
80+
81+
save S6
82+
83+
time2 = clock;
84+
85+
figure(2)
86+
plot(R);
87+
hold on
88+
plot(Ra,':r');
89+
hold off
90+
91+
%Calculating Total Time Taken in secs
92+
93+
Total_Time_Secs = (time2(5) - time1(5)) * 60 + (time2(5) - time1(6));
94+
95+
%Calculating the Mean Absolute Prediction Error (MAPE)
96+
%R actual output
97+
%Ra predicted output
98+
99+
Er = Ra - R;
100+
figure(3)
101+
plot(Er)
102+
103+
R = R + 1; %Doing this step as MAPE doesnt take '0''s as input which leads to infinite error
104+
Ra = R + 1;
105+
MAPE = errperf(R,Ra,'mape');
106+
MSPE = errperf(R,Ra,'mspe'); %Comparison of the Error Percentages
107+
108+
save R
109+
save Ra
110+
save MAPE
111+
save MSPE
Binary file not shown.
10.1 KB
Binary file not shown.
13.5 KB
Binary file not shown.
13.9 KB
Binary file not shown.
13.9 KB
Binary file not shown.
13.9 KB
Binary file not shown.
13.9 KB
Binary file not shown.
1.78 KB
Binary file not shown.
13.6 KB
Binary file not shown.
1.78 KB
Binary file not shown.
Binary file not shown.
13.5 KB
Binary file not shown.
13.5 KB
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,258 @@
1+
function V=errperf(T,P,M)
2+
3+
%ERRPERF Determine various error related performance metrics.
4+
%
5+
% ERRPERF(T,P,M) uses T and P, which are target and prediction vectors
6+
% respectively, and returns the value for M, which is one of several error
7+
% related performance metrics.
8+
%
9+
% T and P can be row or column vectors of the same size. M can be one of
10+
% the following performance metrics:
11+
%
12+
% mae (mean absolute error)
13+
% mse (mean squared error)
14+
% rmse (root mean squared error)
15+
%
16+
% mare (mean absolute relative error)
17+
% msre (mean squared relative error)
18+
% rmsre (root mean squared relative error)
19+
%
20+
% mape (mean absolute percentage error)
21+
% mspe (mean squared percentage error)
22+
% rmspe (root mean squared percentage error)
23+
%
24+
% EXAMPLE:
25+
%
26+
% rand('state',0)
27+
%
28+
% T = [0:0.2:1]
29+
% P = rand(size(T)).*T
30+
%
31+
% errperf(T,P,'mae') returns 0.1574
32+
%
33+
% To compute the relevant performance metric, the function uses recursion
34+
% to first compute one or more error vectors. The function can therefore
35+
% secondarily be used to compute these error vectors. M can therefore also
36+
% be one of the following:
37+
%
38+
% e (errors)
39+
% ae (absolute errors)
40+
% se (squared errors)
41+
%
42+
% re (relative errors)
43+
% are (absolute relative errors)
44+
% sre (squared relative errors)
45+
%
46+
% pe (percentage errors)
47+
% ape (absolute percentage errors)
48+
% spe (squared percentage errors)
49+
%
50+
% REMARKS:
51+
%
52+
% - The Neural Network Toolbox also has functions to compute mae and mse.
53+
% This function does not make use of the toolbox.
54+
%
55+
% - Percentage error equals relative error times 100.
56+
%
57+
% - The abbreviations used in the code, and the calculation tree are
58+
% documented in a comments section within the file.
59+
%
60+
% VERSION: 20070703
61+
% MATLAB VERSION: 7.4.0.287 (R2007a)
62+
% LICENSE: As-is; public domain
63+
%
64+
% See also MAE, MSE.
65+
66+
%{
67+
VERSION HISTORY:
68+
20070703: - Added MATLAB version check.
69+
20070606: - Added support for metrics MARE, MSRE, and RMSRE.
70+
- Addressed a possible division by zero condition in calculating
71+
relative and percentage errors.
72+
20070528: - Original version.
73+
74+
KEYWORDS:
75+
perf, performance, metric, performance measure, machine learning
76+
%}
77+
78+
%% Comments
79+
80+
%{
81+
82+
Abbreviations:
83+
84+
a: absolute
85+
e: error(s)
86+
M: METRIC
87+
m: mean
88+
P: PREDICTIONS
89+
p: percentage
90+
r: relative (if before e)
91+
r: square root (if before m)
92+
s: squared
93+
T: TARGETS
94+
V: VALUE(S)
95+
96+
Calculation tree:
97+
98+
e
99+
|
100+
|-ae-mae
101+
|
102+
|-se-mse-rmse
103+
|
104+
|-re-pe
105+
| |
106+
| |-ape-mape
107+
| |
108+
| |-spe-mspe-rmspe
109+
|
110+
|-are-mare
111+
|
112+
|-sre-msre-rmsre
113+
114+
%}
115+
116+
%% Check MATLAB version
117+
118+
if datenum(version('-date'))<datenum('29-Jan-2007')
119+
error(['The MATLAB version in use is ',version('-release'),'. ',...
120+
'This function requires at least version 2007a.'])
121+
end
122+
123+
%% Parse and validate input
124+
125+
Inputs=inputParser;
126+
127+
Inputs.addRequired('T',@(x) isnumeric(x) && ndims(x)==2 && ...
128+
(size(x,1)==1 || size(x,2)==1));
129+
Inputs.addRequired('P',@(x) isnumeric(x) && ndims(x)==2 && ...
130+
(size(x,1)==1 || size(x,2)==1));
131+
Inputs.addRequired('M',@(x) ischar(x) && ~isempty(x));
132+
133+
Inputs.parse(T,P,M);
134+
clear Inputs
135+
136+
assert(isequal(size(T),size(P)),'T and P must have the same size.')
137+
138+
%% Transform input
139+
140+
M=lower(M);
141+
142+
%% Compute metric
143+
144+
switch M
145+
146+
% Errors
147+
case 'e'
148+
149+
V=T-P;
150+
151+
% Absolute errors
152+
case 'ae'
153+
154+
Ve=errperf(T,P,'e');
155+
V=abs(Ve);
156+
157+
% Mean absolute error
158+
case 'mae'
159+
160+
Vae=errperf(T,P,'ae');
161+
V=mean(Vae);
162+
163+
% Squared errors
164+
case 'se'
165+
166+
Ve=errperf(T,P,'e');
167+
V=Ve.^2;
168+
169+
% Mean squared error
170+
case 'mse'
171+
172+
Vse=errperf(T,P,'se');
173+
V=mean(Vse);
174+
175+
% Root mean squared error
176+
case 'rmse'
177+
178+
Vmse=errperf(T,P,'mse');
179+
V=sqrt(Vmse);
180+
181+
% Relative errors
182+
case 're'
183+
184+
assert(all(T),'All elements of T must be nonzero.')
185+
Ve=errperf(T,P,'e');
186+
V=Ve./T;
187+
188+
% Absolute relative errors
189+
case 'are'
190+
191+
Vre=errperf(T,P,'re');
192+
V=abs(Vre);
193+
194+
% Mean absolute relative error
195+
case 'mare'
196+
197+
Vare=errperf(T,P,'are');
198+
V=mean(Vare);
199+
200+
% Squared relative errors
201+
case 'sre'
202+
203+
Vre=errperf(T,P,'re');
204+
V=Vre.^2;
205+
206+
% Mean squared relative error
207+
case 'msre'
208+
209+
Vsre=errperf(T,P,'sre');
210+
V=mean(Vsre);
211+
212+
% Root mean squared relative error
213+
case 'rmsre'
214+
215+
Vmsre=errperf(T,P,'msre');
216+
V=sqrt(Vmsre);
217+
218+
% Percentage errors
219+
case 'pe'
220+
221+
Vre=errperf(T,P,'re');
222+
V=Vre*100;
223+
224+
% Absolute percentage errors
225+
case 'ape'
226+
227+
Vpe=errperf(T,P,'pe');
228+
V=abs(Vpe);
229+
230+
% Mean absolute percentage error
231+
case 'mape'
232+
233+
Vape=errperf(T,P,'ape');
234+
V=mean(Vape);
235+
236+
% Squared percentage errors
237+
case 'spe'
238+
239+
Vpe=errperf(T,P,'pe');
240+
V=Vpe.^2;
241+
242+
% Mean squared percentage error
243+
case 'mspe'
244+
245+
Vspe=errperf(T,P,'spe');
246+
V=mean(Vspe);
247+
248+
% Root mean squared percentage error
249+
case 'rmspe'
250+
251+
Vmspe=errperf(T,P,'mspe');
252+
V=sqrt(Vmspe);
253+
254+
otherwise
255+
256+
error('M is invalid.')
257+
258+
end
13.5 KB
Binary file not shown.

Object Tracking Data/Data/Data.xlsx

10.1 KB
Binary file not shown.
12.9 KB
Binary file not shown.

0 commit comments

Comments
 (0)