Skip to content

Commit

Permalink
Add a couple of error preventions for edge cases.
Browse files Browse the repository at this point in the history
  • Loading branch information
Leif Johnson committed Jun 25, 2015
1 parent 771199d commit 21303d0
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions theanets/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,15 +144,16 @@ def add_layer(self, layer, is_output=False):

# for the first layer, create an 'input' layer.
if len(self.layers) == 0:
assert isinstance(layer, int), 'first layer must be an int'
self.layers.append(layers.build('input', size=layer, name='in'))
return

# here we set up some defaults for constructing a new layer.
def_out_act = getattr(self, 'DEFAULT_OUTPUT_ACTIVATION', 'linear')
act = getattr(self, 'DEFAULT_OUTPUT_ACTIVATION', 'linear')
form = 'feedforward'
kwargs = dict(
name='out' if is_output else 'hid{}'.format(len(self.layers)),
activation=def_out_act if is_output else 'logistic',
activation=act if is_output else 'logistic',
inputs={self.layers[-1].output_name(): self.layers[-1].size},
size=layer,
)
Expand Down Expand Up @@ -180,6 +181,7 @@ def add_layer(self, layer, is_output=False):
# if layer is a dictionary, try to extract a form for the layer, and
# override our default keyword arguments with the rest.
if isinstance(layer, dict):
layer = dict(layer)
if 'form' in layer:
form = layer.pop('form').lower()
kwargs.update(layer)
Expand Down

0 comments on commit 21303d0

Please sign in to comment.