-
Notifications
You must be signed in to change notification settings - Fork 0
/
RBF- validation and training set
123 lines (103 loc) · 3.61 KB
/
RBF- validation and training set
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
clc
clear all
close all
format long
out = csvread('Data_1000points_sampled_every5.csv');%importing the data file
u= [out(:,1) out(:,2)]'; % matrix containing u1 and u2
xo = out(:,3)'; %matrix containing x1
time=out(:,4)'; % time stamps
net=0;
[row_u,col_u]=size(u); %getting size of dtatset
[row_xo,col_xo]=size(xo);
training=[];
training=[u(1,1:col_u-100);u(2,1:col_u-100)];
[row_training,col_training]=size(training);
training_time=[time(1,1:col_u-100)];
validation=[];
validation=[u(1,col_u-99:col_u);u(2,col_u-99:col_u)];
[row_validation,col_validation]=size(validation);
validation_time=[time(1,col_u-99:col_u)];
column_num=1;%keeps track of column index
weighted_in =[];%matrix to store 5 u1 and u2 values from orignal dataset
weighted_out=[];%stores corresponding value of x1
simulate=[];% stores the value of u1 and u2 to be used in sim function
column_num1=1;% keeping track of column index
sim_ans=[];% stores the simulated value of x1 generated by sim function
error=[];
error_valid=[];
% how many elements we want to look back on
index=1;
Mean_error=[];
sim_valid_ans=[];
% for a=1:10
num_of_elements=5;
column_num1 = 1;
error=[];
for i=1:col_training-num_of_elements % outer loop
column_num=1;
for j=i:i+num_of_elements-1% inner loop
%in this loop we generate our smaller datasets and feed them into
%the rbe
weighted_in(1,column_num)=u(1,j);
weighted_in(2,column_num)=u(2,j);
weighted_out(1,column_num)=xo(1,j);
column_num=column_num+1;
end
% feeding it into the rbe
net=newrbe(weighted_in,weighted_out);
% now we simulate the value of x1 in the timestep that is "next" and hasnt
% been input into the net yet
simulate(1,1)=training(1,i+num_of_elements);% getting the values of u1 and u2 at the "next" timestep
simulate(2,1)=training(2,i+num_of_elements);
sim_ans(1,column_num1) = sim(net,simulate);% storing the simulated value
sim_ans(2,column_num1)=training_time(1,i);% storing the corresponding timestep
if xo(1,i)==0
error(1,column_num1)=0;
column_num1 = column_num1+1;
else
error(1,column_num1)=abs(sim_ans(1,column_num1)-xo(1,i))/xo(1,i);
column_num1 = column_num1+1;
end
end
%simulating
column_num1=1;
column_num=1;
for x=1:col_validation-num_of_elements
% column_num=1;
% for y=x:x+num_of_elements-1
% p(1,column_num)= validation(1,y)
% p(2,column_num)= validation(2,y)
% column_num=column_num+1;
% end
p=[validation(1,x);validation(2,x)];
sim_valid_ans(1,column_num1)=sim(net,p);
if xo(1,x+col_training)==0
error_valid(1,column_num1)=0;
column_num1 = column_num1+1;
else
error_valid(1,column_num1)=abs(sim_valid_ans(1,column_num1)-xo(1,x+col_training))/xo(1,x+col_training);
column_num1 = column_num1+1;
end
sim_valid_ans(2,column_num1)=validation_time(1,x);% storing the corresponding timestep
end
% plotting orignal data and simulated data
% Mean_error(1,index)= mean(error,'all')*100;
% Mean_error(2,index)= index;
% index=index+1;
% legend('
% end
% figure
% plot( Mean_error(2,:),Mean_error(1,:))
% figure
plot( time,xo(1,:),'g',sim_ans(2,:),sim_ans(1,:),'b')
legend("Actual data(training and validation combined)","simulation for training only")
title('Actual data and simulation training set ')
xlabel('Time')
figure
plot(sim_ans(2,:), error);
title('error graph training')
xlabel('Time')
figure
plot(validation_time,xo(1,col_training+1:col_u),'g',sim_valid_ans(2,:), sim_valid_ans(1,:));
legend('actual data', ' simulated');
title(' actual and simulated for validation set');