Skip to content

Commit

Permalink
update for DQNk
Browse files Browse the repository at this point in the history
  • Loading branch information
JackXTY committed Apr 13, 2021
1 parent 11826b8 commit a349a60
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions DQN.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,7 @@ def update_greedy(self):

def load_model(self):
self.saver.restore(self.sess, self.path)
# self.memory = np.load(self.path+".npy")
# print(self.memory)
self.memory = np.load(self.path+".npy")

def save_model(self, if_plot=False, postfix=''):
try:
Expand All @@ -255,7 +254,7 @@ def save_model(self, if_plot=False, postfix=''):
class AgentsDQNk(Agent):
def __init__(self, id, N, features=6):
self.id = id
self.path = "./model/DQN/" + str(N) + "/" + str(id)
self.path = "./model/DQN-K/" + str(N) + "/" + str(id)
self.state = []
self.next_state = []
self.has_model = os.path.exists(self.path)
Expand Down Expand Up @@ -288,11 +287,11 @@ def __init__(self, id, N, features=6):
self.model = self.create_model()
self.target_model = self.create_model()

if not(os.path.exists(self.path+".meta")):
print("no training history")
self.sess.run(global_variables_initializer())
else:
print("trained continously")
# if not(os.path.exists(self.path+".meta")):
# print("no training history")
# self.sess.run(global_variables_initializer())
# else:
# print("trained continously")

self.cost_history = []
self.q = []
Expand Down Expand Up @@ -320,14 +319,15 @@ def save_model(self, if_plot=False, postfix=''):
try:
self.model.save(self.path+postfix)
print(self.path + ' saved successfully')
np.save(self.path+".npy", self.memory)
np.save(self.path+postfix+".npy", self.memory)
if if_plot:
self.plot_cost()
except:
print('ERROR: can not save the model')

def load_model(self):
self.model = tf.keras.models.load_model(self.path)
self.memory = np.load(self.path+".npy")

def make_decision(self, no_random=False):
observation = np.array(self.state).reshape([1, self.features])
Expand Down

0 comments on commit a349a60

Please sign in to comment.