-
Notifications
You must be signed in to change notification settings - Fork 0
/
RBF-With mean error
71 lines (56 loc) · 2.19 KB
/
RBF-With mean error
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
clc
clear all
close all
format long
out = csvread('learning_data_new.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
[row_u,col_u]=size(u); %getting size of dtatset
[row_xo,col_xo]=size(xo);
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=[];
% how many elements we want to look back on
num_of_elements=4;
for i=1:col_u-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)=u(1,i+num_of_elements);% getting the values of u1 and u2 at the "next" timestep
simulate(2,1)=u(2,i+num_of_elements);
sim_ans(1,column_num1) = sim(net,simulate);% storing the simulated value
sim_ans(2,column_num1)=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
% plotting orignal data and simulated data
Mean_error= mean(error,'all')*100
figure
plot( time,xo(1,:),'g',sim_ans(2,:),sim_ans(1,:),'b')
legend("Actual data","simulation")
title('Actual data and simulation')
xlabel('Time')
figure
plot(sim_ans(2,:), error);
title('error graph')
xlabel('Time')