asataura commited on
Commit
6c2cfa4
·
1 Parent(s): c9e0f93

Updating DDQN

Browse files
Files changed (2) hide show
  1. DDQN.py +7 -8
  2. tester.py +0 -1
DDQN.py CHANGED
@@ -9,10 +9,9 @@ import random
9
 
10
 
11
  class DoubleDeepQNetwork:
12
- def __init__(self, states, actions, history, alpha, gamma, epsilon, epsilon_min, epsilon_decay):
13
- self.nS = states
14
- self.nA = actions
15
- self.history = history
16
  self.memory = deque([], maxlen=2500)
17
  self.alpha = alpha
18
  self.gamma = gamma
@@ -27,7 +26,7 @@ class DoubleDeepQNetwork:
27
 
28
  def build_model(self):
29
  model = keras.Sequential() # linear stack of layers https://keras.io/models/sequential/
30
- model.add(keras.layers.Dense(24, input_dim=self.history * self.nS, activation='relu')) # [Input] -> Layer 1
31
  model.add(keras.layers.Dense(24, activation='relu')) # Layer 2 -> 3
32
  model.add(keras.layers.Dense(self.nA, activation='linear')) # Layer 3 -> [output]
33
 
@@ -69,8 +68,8 @@ class DoubleDeepQNetwork:
69
  x = []
70
  y = []
71
  np_array = np.array(minibatch)
72
- st = np.zeros((0, self.history*self.nS)) # States
73
- nst = np.zeros((0, self.history*self.nS)) # Next States
74
  for i in range(len(np_array)): # Creating the state and next state np arrays
75
  st = np.append(st, np_array[i, 0], axis=0)
76
  nst = np.append(nst, np_array[i, 3], axis=0)
@@ -93,7 +92,7 @@ class DoubleDeepQNetwork:
93
  y.append(target_f)
94
  index += 1
95
  # Reshape for Keras Fit
96
- x_reshape = np.array(x).reshape(batch_size, self.history * self.nS)
97
  y_reshape = np.array(y)
98
  epoch_count = 1
99
  hist = self.model.fit(x_reshape, y_reshape, epochs=epoch_count, verbose=0)
 
9
 
10
 
11
  class DoubleDeepQNetwork:
12
+ def __init__(self, s_size, a_size, alpha, gamma, epsilon, epsilon_min, epsilon_decay):
13
+ self.nS = s_size
14
+ self.nA = a_size
 
15
  self.memory = deque([], maxlen=2500)
16
  self.alpha = alpha
17
  self.gamma = gamma
 
26
 
27
  def build_model(self):
28
  model = keras.Sequential() # linear stack of layers https://keras.io/models/sequential/
29
+ model.add(keras.layers.Dense(24, input_dim=self.nS, activation='relu')) # [Input] -> Layer 1
30
  model.add(keras.layers.Dense(24, activation='relu')) # Layer 2 -> 3
31
  model.add(keras.layers.Dense(self.nA, activation='linear')) # Layer 3 -> [output]
32
 
 
68
  x = []
69
  y = []
70
  np_array = np.array(minibatch)
71
+ st = np.zeros((0, self.nS)) # States
72
+ nst = np.zeros((0, self.nS)) # Next States
73
  for i in range(len(np_array)): # Creating the state and next state np arrays
74
  st = np.append(st, np_array[i, 0], axis=0)
75
  nst = np.append(nst, np_array[i, 3], axis=0)
 
92
  y.append(target_f)
93
  index += 1
94
  # Reshape for Keras Fit
95
+ x_reshape = np.array(x).reshape(batch_size, self.nS)
96
  y_reshape = np.array(y)
97
  epoch_count = 1
98
  hist = self.model.fit(x_reshape, y_reshape, epochs=epoch_count, verbose=0)
tester.py CHANGED
@@ -27,7 +27,6 @@ def test(jammer_type, channel_switching_cost):
27
  epsilon_decay = 0.999
28
  discount_rate = 0.95
29
  lr = 0.001
30
- batch_size = 32
31
 
32
  agentName = f'savedAgents/DDQNAgent_{jammer_type}_csc_{channel_switching_cost}'
33
  DDQN_agent = DoubleDeepQNetwork(s_size, a_size, lr, discount_rate, epsilon, epsilon_min, epsilon_decay)
 
27
  epsilon_decay = 0.999
28
  discount_rate = 0.95
29
  lr = 0.001
 
30
 
31
  agentName = f'savedAgents/DDQNAgent_{jammer_type}_csc_{channel_switching_cost}'
32
  DDQN_agent = DoubleDeepQNetwork(s_size, a_size, lr, discount_rate, epsilon, epsilon_min, epsilon_decay)