-
Notifications
You must be signed in to change notification settings - Fork 1
/
play.py
40 lines (30 loc) · 843 Bytes
/
play.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
import numpy as np
import pandas as pd
import daytime
import re
import matplotlib.pyplot as plt
import timeit
import pickle
import scipy
import random
from keras.models import load_model
def play(model_name, env, newdf, feature_weights):
GAMMA = 0.9
count=0
#load the trained model
trained_model = load_model(model_name)
#start with a random initial state
state = random.choice(newdf.state)
featureExpectations = np.zeros(len(feature_weights))
while True:
count += 1
# Choose an action
action = trained_model.predict(np.asarray([np.asarray(state)]))[0]
next_state, reward = env.step(state, action, feature_weights)
if count > 100:
featureExpectations += (GAMMA**(count-100))*next_state
if count % 2000 == 0:
print("Ending the trajectory")
break
state = next_state
return featureExpectations