Skip to content

Commit a031e42

Browse files
committed
dropout network
1 parent f6bf1ac commit a031e42

File tree

1 file changed

+43
-4
lines changed

1 file changed

+43
-4
lines changed

deep_q_rl/q_network.py

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,20 +94,20 @@ def __init__(self, input_width, input_height, num_actions,
9494

9595
q_vals = lasagne.layers.get_output(self.l_out,
9696
{
97-
self.l_in: (states / input_scale),
97+
# self.l_in: (states / input_scale),
9898
self.l_ram_in: (ram_states / 256.0)
9999
})
100100

101101
if self.freeze_interval > 0:
102102
next_q_vals = lasagne.layers.get_output(self.next_l_out,
103103
{
104-
self.l_in: (next_states / input_scale),
104+
# self.l_in: (next_states / input_scale),
105105
self.l_ram_in: (next_ram_states / 256.0)
106106
})
107107
else:
108108
next_q_vals = lasagne.layers.get_output(self.l_out,
109109
{
110-
self.l_in: (next_states / input_scale),
110+
# self.l_in: (next_states / input_scale),
111111
self.l_ram_in: (next_ram_states / 256.0),
112112
})
113113
next_q_vals = theano.gradient.disconnected_grad(next_q_vals)
@@ -141,7 +141,7 @@ def __init__(self, input_width, input_height, num_actions,
141141
else:
142142
raise ValueError("Bad accumulator: {}".format(batch_accumulator))
143143

144-
params = lasagne.layers.helper.get_all_params(self.l_out)
144+
params = lasagne.layers.helper.get_all_params(self.l_out)
145145
givens = {
146146
states: self.states_shared,
147147
next_states: self.next_states_shared,
@@ -200,6 +200,9 @@ def build_network(self, network_type, input_width, input_height,
200200
elif network_type == "just_ram":
201201
return self.build_ram_network(input_width, input_height, output_dim,
202202
num_frames, batch_size)
203+
elif network_type == "ram_dropout":
204+
return self.build_ram_dropout_network(input_width, input_height,
205+
output_dim, num_frames, batch_size)
203206
else:
204207
raise ValueError("Unrecognized network: {}".format(network_type))
205208

@@ -478,6 +481,42 @@ def build_ram_network(self, input_width, input_height, output_dim,
478481

479482
return l_out
480483

484+
def build_ram_dropout_network(self, input_width, input_height, output_dim,
485+
num_frames, batch_size):
486+
"""
487+
Build a network using only the information from the ram.
488+
"""
489+
self.l_ram_in = lasagne.layers.InputLayer(
490+
shape=(batch_size, self.RAM_SIZE)
491+
)
492+
493+
494+
l_hidden1 = lasagne.layers.DenseLayer(
495+
lasagne.layers.dropout(self.l_ram_in),
496+
num_units=self.RAM_SIZE,
497+
nonlinearity=lasagne.nonlinearities.rectify,
498+
W=lasagne.init.HeUniform(),
499+
b=lasagne.init.Constant(.1)
500+
)
501+
502+
l_hidden2 = lasagne.layers.DenseLayer(
503+
lasagne.layers.dropout(l_hidden1),
504+
num_units=self.RAM_SIZE,
505+
nonlinearity=lasagne.nonlinearities.rectify,
506+
W=lasagne.init.HeUniform(),
507+
b=lasagne.init.Constant(.1)
508+
)
509+
510+
l_out = lasagne.layers.DenseLayer(
511+
lasagne.layers.dropout(l_hidden2),
512+
num_units=output_dim,
513+
nonlinearity=None,
514+
W=lasagne.init.HeUniform(),
515+
b=lasagne.init.Constant(.1)
516+
)
517+
518+
return l_out
519+
481520

482521
def build_nips_network(self, input_width, input_height, output_dim,
483522
num_frames, batch_size):

0 commit comments

Comments
 (0)