josephorng
/
A-Multi-Layer-and-Multi-Ensembled-Stock-Trader-Using-Deep-Learning-and-Deep-Reinforcement-Learning
Public
forked from Artificial-Intelligence-Big-Data-Lab/A-Multi-Layer-and-Multi-Ensembled-Stock-Trader-Using-Deep-Learning-and-Deep-Reinforcement-Learning
-
Notifications
You must be signed in to change notification settings - Fork 0
/
plotResults.py
196 lines (169 loc) · 8.05 KB
/
plotResults.py
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
from matplotlib.backends.backend_pdf import PdfPages
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
import sys
from math import floor
from ensemble import ensemble
from matplotlib.gridspec import GridSpec
outputFile=str(sys.argv[2])+".pdf"
numFiles=int(sys.argv[3])
#Number of epochs in the algorithm
numEpochs=35
numPlots=10
pdf=PdfPages(outputFile)
#Configure the size of the picture that will be plotted
#Configure the size of the picture that will be plotted
plt.figure(figsize=((numEpochs/10)*(2),9*5))
#Open the file that was saved on folder csv/walks, containing information about each iteration in that walk
#Lets show a summary of each walk
#For each walk, one column is plotted in a final pdf file
for i in range(1,numFiles+1):
document = pd.read_csv("./Output/csv/"+ sys.argv[1]+"/results-agent-training.csv")
plt.subplot(numPlots,numFiles,0*numFiles + i)
#Draw information in that file. First of all, lets plot accuracy
plt.plot(document.ix[:, 'Iteration'].tolist(),document.ix[:, 'testAccuracy'].tolist(),'r',label='Test')
plt.plot(document.ix[:, 'Iteration'].tolist(),document.ix[:, 'trainAccuracy'].tolist(),'b',label='Train')
plt.plot(document.ix[:, 'Iteration'].tolist(),document.ix[:, 'validationAccuracy'].tolist(),'g',label='Validation')
plt.xticks(range(0,numEpochs,4))
plt.yticks(np.arange(0, 1, step=0.1))
plt.ylim(-0.05,1.05)
plt.axhline(y=0, color='k', linestyle='-')
plt.legend()
plt.grid()
plt.title('Accuracy')
#Lets draw information about coverage, read from the csv file located at csv/walks
plt.subplot(numPlots,numFiles,1*numFiles + i)
plt.plot(document.ix[:, 'Iteration'].tolist(),document.ix[:, 'testCoverage'].tolist(),'r',label='Test')
plt.plot(document.ix[:, 'Iteration'].tolist(),document.ix[:, 'trainCoverage'].tolist(),'b',label='Train')
plt.plot(document.ix[:, 'Iteration'].tolist(),document.ix[:, 'validationCoverage'].tolist(),'g',label='Validation')
plt.xticks(range(0,numEpochs,4))
plt.yticks(np.arange(0, 1, step=0.1))
plt.ylim(-0.05,1.05)
plt.axhline(y=0, color='k', linestyle='-')
plt.legend()
plt.grid()
plt.title('Coverage')
# Information about reward
plt.subplot(numPlots,numFiles,2*numFiles + i )
plt.plot(document.ix[:, 'Iteration'].tolist(),document.ix[:, 'trainReward'].tolist(),'b',label='Train')
plt.plot(document.ix[:, 'Iteration'].tolist(),document.ix[:, 'validationReward'].tolist(),'g',label='Validation')
plt.plot(document.ix[:, 'Iteration'].tolist(),document.ix[:, 'testReward'].tolist(),'r',label='Test')
plt.xticks(range(0,numEpochs,4))
plt.axhline(y=0, color='k', linestyle='-')
plt.legend()
plt.grid()
plt.title('Reward')
#Percentages of long
plt.subplot(numPlots,numFiles,3*numFiles + i )
plt.plot(document.ix[:, 'Iteration'].tolist(),document.ix[:, 'trainLong%'].tolist(),'b',label='Train')
plt.plot(document.ix[:, 'Iteration'].tolist(),document.ix[:, 'validationLong%'].tolist(),'g',label='Validation')
plt.plot(document.ix[:, 'Iteration'].tolist(),document.ix[:, 'testLong%'].tolist(),'r',label='Test')
plt.xticks(range(0,numEpochs,4))
plt.yticks(np.arange(0, 1, step=0.1))
plt.ylim(-0.05,1.05)
plt.axhline(y=0, color='k', linestyle='-')
plt.legend()
plt.grid()
plt.title('Long %')
#Percentages of short
plt.subplot(numPlots,numFiles,4*numFiles + i )
plt.plot(document.ix[:, 'Iteration'].tolist(),document.ix[:, 'trainShort%'].tolist(),'b',label='Train')
plt.plot(document.ix[:, 'Iteration'].tolist(),document.ix[:, 'validationShort%'].tolist(),'g',label='Validation')
plt.plot(document.ix[:, 'Iteration'].tolist(),document.ix[:, 'testShort%'].tolist(),'r',label='Test')
plt.xticks(range(0,numEpochs,4))
plt.yticks(np.arange(0, 1, step=0.1))
plt.ylim(-0.05,1.05)
plt.axhline(y=0, color='k', linestyle='-')
plt.legend()
plt.grid()
plt.title('Short %')
#Coverage
plt.subplot(numPlots,numFiles,5*numFiles + i )
plt.plot(document.ix[:, 'Iteration'].tolist(),list(map(lambda x: 1-x,document.ix[:, 'trainCoverage'].tolist())),'b',label='Train')
plt.plot(document.ix[:, 'Iteration'].tolist(),list(map(lambda x: 1-x,document.ix[:, 'validationCoverage'].tolist())),'g',label='Validation')
plt.plot(document.ix[:, 'Iteration'].tolist(),list(map(lambda x: 1-x,document.ix[:, 'testCoverage'].tolist())),'r',label='Test')
plt.xticks(range(0,numEpochs,4))
plt.yticks(np.arange(0, 1, step=0.1))
plt.ylim(-0.05,1.05)
plt.axhline(y=0, color='k', linestyle='-')
plt.legend()
plt.grid()
plt.title('Hold %')
#Accuracy of longs
plt.subplot(numPlots,numFiles,6*numFiles + i )
plt.plot(document.ix[:, 'Iteration'].tolist(),document.ix[:, 'trainLongAcc'].tolist(),'b',label='Train')
plt.plot(document.ix[:, 'Iteration'].tolist(),document.ix[:, 'validationLongAcc'].tolist(),'g',label='Validation')
plt.plot(document.ix[:, 'Iteration'].tolist(),document.ix[:, 'testLongAcc'].tolist(),'r',label='Test')
plt.xticks(range(0,numEpochs,4))
plt.yticks(np.arange(0, 1, step=0.1))
plt.ylim(-0.05,1.05)
plt.axhline(y=0, color='k', linestyle='-')
plt.legend()
plt.grid()
plt.title('Long Accuracy')
#Accuracy of shorts
plt.subplot(numPlots,numFiles,7*numFiles + i )
plt.plot(document.ix[:, 'Iteration'].tolist(),document.ix[:, 'trainShortAcc'].tolist(),'b',label='Train')
plt.plot(document.ix[:, 'Iteration'].tolist(),document.ix[:, 'validationShortAcc'].tolist(),'g',label='Validation')
plt.plot(document.ix[:, 'Iteration'].tolist(),document.ix[:, 'testShortAcc'].tolist(),'r',label='Test')
plt.xticks(range(0,numEpochs,4))
plt.yticks(np.arange(0, 1, step=0.1))
plt.ylim(-0.05,1.05)
plt.axhline(y=0, color='k', linestyle='-')
plt.legend()
plt.grid()
plt.title('Short Accuracy')
#Precisions of long
plt.subplot(numPlots,numFiles,8*numFiles + i )
plt.plot(document.ix[:, 'Iteration'].tolist(),document.ix[:, 'trainLongPrec'].tolist(),'b',label='Train')
plt.plot(document.ix[:, 'Iteration'].tolist(),document.ix[:, 'validLongPrec'].tolist(),'g',label='Validation')
plt.plot(document.ix[:, 'Iteration'].tolist(),document.ix[:, 'testLongPrec'].tolist(),'r',label='Test')
plt.xticks(range(0,numEpochs,4))
plt.yticks(np.arange(0, 1, step=0.1))
plt.ylim(-0.05,1.05)
plt.axhline(y=0, color='k', linestyle='-')
plt.legend()
plt.grid()
plt.title('Long Precision')
#Precisions of short
plt.subplot(numPlots,numFiles,9*numFiles + i )
plt.plot(document.ix[:, 'Iteration'].tolist(),document.ix[:, 'trainShortPrec'].tolist(),'b',label='Train')
plt.plot(document.ix[:, 'Iteration'].tolist(),document.ix[:, 'validShortPrec'].tolist(),'g',label='Validation')
plt.plot(document.ix[:, 'Iteration'].tolist(),document.ix[:, 'testShortPrec'].tolist(),'r',label='Test')
plt.xticks(range(0,numEpochs,4))
plt.yticks(np.arange(0, 1, step=0.1))
plt.ylim(-0.05,1.05)
plt.axhline(y=0, color='k', linestyle='-')
plt.legend()
plt.grid()
plt.title('Short Precision')
plt.suptitle("Experiment RL metalearner\n"
+"Model: 35 neurons single layer\n"
+"Input: 1000 predictions of CNNs\n"
+"Memory-Window Length: 10000-1\n"
+"Other changes: Does Short, Hold and Long\n"
+"Explorations:" +sys.argv[4] +"."
,size=19
,weight=20
,ha='left'
,x=0.1
,y=0.99)
pdf.savefig()
#Now, lets try the ensemble
i=1
###########-------------------------------------------------------------------|Tabella Full Ensemble|-------------------
x=2
y=1
plt.figure(figsize=(x*3.5,y*3.5))
plt.subplot(y,y,1)
plt.axis('off')
val,col=ensemble("test", sys.argv[1])
t=plt.table(cellText=val, colLabels=col, fontsize=20, loc='center')
t.auto_set_font_size(False)
t.set_fontsize(6)
plt.title("Final Results")
#plt.suptitle("MAJORITY VOTING")
pdf.savefig()
###########--------------------------------------------------------------------------------------------------------------------
pdf.close()