-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathGame.py
More file actions
67 lines (49 loc) · 1.42 KB
/
Game.py
File metadata and controls
67 lines (49 loc) · 1.42 KB
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
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from sklearn.preprocessing import MinMaxScaler
import keras
import tensorflow as tf
from utils import *
from MarketAgent import *
import warnings
import sys
import getopt
from tqdm import tqdm
warnings.filterwarnings("ignore")
data = load_data()
data = add_columns(data)
training, testing, scaler = preprocess_data(data)
train_data = training.to_numpy()
test_data = testing.to_numpy()
#! Hyperparameters
epsilon = 0.3
gamma = None
timestpes = len(train_data)
states = train_data.shape[1]
test = False
alpha = None
episodes = None
argv = sys.argv[1:]
try:
opts, args = getopt.getopt(argv, "g:a:e:")
except:
print("Error in reading command Line Arguments")
for opt, arg in opts:
if opt in ['-g', '--gamma']:
gamma = float(arg)
elif opt in ['-a', '--alpha']:
alpha = float(arg)
elif opt in ['-e', '--episodes']:
episodes = int(arg)
agent = MarketAgent(epsilon, gamma, timestpes, states, test)
if __name__ == "__main__":
for i in range(episodes):
print(f"Episode {i+1}/{episodes} \n")
agent.play_episode(epsilon, gamma, alpha, train_data)
#! Prediction
prediction = agent.model.predict(test_data)
predicted_trend = prediction[:, 0]
predicted_trend = np.tanh(predicted_trend)
testing['Trend'] = predicted_trend
testing.to_csv(f"Test_Prediction_{alpha}_{gamma}_new.csv")