def create_model(self, epsilon):
"""Return a compiled model and the state and action input
layers with the given epsilon for numerical stability.
"""
inputs = Input(shape=(self.state_shape,))
action_input = Input(shape=(self.action_shape,))
x1 = Dense(self.neurons_per_layer[0], activation='relu')(inputs)
x1 = Dense(self.neurons_per_layer[1], activation='relu')(x1)
x2 = Dense(self.neurons_per_layer[1], activation='relu')(action_input)
x = add([x1, x2])
for n in self.neurons_per_layer[2:]:
x = Dense(n, activation='relu')(x)
outputs = Dense(self.action_shape)(x)
model = Model(inputs=[inputs, action_input], outputs=outputs)
assert self.optimizer_choice in ['adam', 'rmsprop']
if self.optimizer_choice == 'adam':
opti = Adam(lr=self.alpha, epsilon=epsilon)
else:
opti = RMSprop(lr=self.alpha, epsilon=epsilon)
model.compile(optimizer=opti, loss='mse')
return model, inputs, action_input
评论列表
文章目录