Skip to content

Commit

Permalink
Added google-style arg comments for docs; docstrigs tests; one exampl…
Browse files Browse the repository at this point in the history
…e; renamed ppf to pf
  • Loading branch information
dsblank committed Aug 7, 2017
1 parent 833f0f5 commit 2c09b63
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
name: run tests
command: |
. venv/bin/activate
nosetests --with-coverage --nologcapture
nosetests --with-coverage --nologcapture --with-doc conx
codecov
- store_artifacts:
Expand Down
39 changes: 29 additions & 10 deletions conx/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ def set_dataset_direct(self, inputs, targets, verbose=True):
def slice_dataset(self, start=None, stop=None, verbose=True):
"""
Cut out some input/targets.
net.slice_dataset(100) - reduce to first 100 inputs/targets
net.slice_dataset(100, 200) - reduce to second 100 inputs/targets
"""
Expand Down Expand Up @@ -572,19 +572,19 @@ def test(self, inputs=None, targets=None, batch_size=32, tolerance=0.1):
print("Testing on %s dataset..." % dataset_name)
outputs = self.model.predict(inputs, batch_size=batch_size)
if self.num_input_layers == 1:
ins = [self.ppf(x) for x in inputs.tolist()]
ins = [self.pf(x) for x in inputs.tolist()]
else:
ins = [("[" + ", ".join([self.ppf(vector) for vector in row]) + "]") for row in np.array(list(zip(*inputs))).tolist()]
ins = [("[" + ", ".join([self.pf(vector) for vector in row]) + "]") for row in np.array(list(zip(*inputs))).tolist()]
## targets:
if self.num_target_layers == 1:
targs = [self.ppf(x) for x in targets.tolist()]
targs = [self.pf(x) for x in targets.tolist()]
else:
targs = [("[" + ", ".join([self.ppf(vector) for vector in row]) + "]") for row in np.array(list(zip(*targets))).tolist()]
targs = [("[" + ", ".join([self.pf(vector) for vector in row]) + "]") for row in np.array(list(zip(*targets))).tolist()]
## outputs:
if self.num_target_layers == 1:
outs = [self.ppf(x) for x in outputs.tolist()]
outs = [self.pf(x) for x in outputs.tolist()]
else:
outs = [("[" + ", ".join([self.ppf(vector) for vector in row]) + "]") for row in np.array(list(zip(*outputs))).tolist()]
outs = [("[" + ", ".join([self.pf(vector) for vector in row]) + "]") for row in np.array(list(zip(*outputs))).tolist()]
## correct?
if self.num_target_layers == 1:
correct = [all(x) for x in map(lambda v: v <= tolerance,
Expand Down Expand Up @@ -1616,11 +1616,30 @@ def pp(self, *args, **opts):
else:
label = ""
vector = args[0]
print(label + self.ppf(vector[:20], **opts))
print(label + self.pf(vector[:20], **opts))

def ppf(self, vector, **opts):
def pf(self, vector, **opts):
"""
Pretty-format a vector.
Pretty-format a vector. Returns string.
Args:
vector (list): The first parameter.
pp_max_length (int): Number of decimal places to show for each
value in vector.
Returns:
str: Returns the vector formatted as a short string.
Examples:
These examples demonstrate the net.pf formatting function:
>>> import conx
>>> net = Network("Test")
>>> net.pf([1])
'[1.0]'
>>> net.pf(range(10), pp_max_length=5)
'[0.0, 1.0, 2.0, 3.0, 4.0...]'
"""
config = copy.copy(self.config)
config.update(opts)
Expand Down
1 change: 1 addition & 0 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ pypandoc
sphinx_rtd_theme
nbsphinx
jupyter_sphinx
sphinxcontrib-napoleon
1 change: 1 addition & 0 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
'sphinx.ext.githubpages',
'nbsphinx',
'jupyter_sphinx.embed_widgets',
'sphinxcontrib.napoleon',
]

# Add any paths that contain templates here, relative to this directory.
Expand Down

0 comments on commit 2c09b63

Please sign in to comment.