Skip to content

Commit

Permalink
Improve docs for nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
jakobj committed Jul 16, 2020
1 parent 6a67d2b commit f2c94b2
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
19 changes: 19 additions & 0 deletions cgp/node_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,58 @@


class ConstantFloat(OperatorNode):
"""A node with a constant output."""

_arity = 0
_def_output = "1.0"
_def_numpy_output = "np.ones(x.shape[0]) * 1.0"
_def_torch_output = "torch.ones(1).expand(x.shape[0]) * 1.0"


class Add(OperatorNode):
"""A node that adds its two inputs."""

_arity = 2
_def_output = "x_0 + x_1"


class Sub(OperatorNode):
"""A node that substracts its second from its first input."""

_arity = 2
_def_output = "x_0 - x_1"


class Mul(OperatorNode):
"""A node that multiplies its two inputs."""

_arity = 2
_def_output = "x_0 * x_1"


class Div(OperatorNode):
"""A node that devides its first by its second input."""

_arity = 2
_def_output = "x_0 / x_1"


class Pow(OperatorNode):
"""A node that raises its first to the power of its second input."""

_arity = 2
_def_output = "x_0 ** x_1"
_def_numpy_output = "np.power(x_0, x_1)"


class Parameter(OperatorNode):
"""A node that provides a parametrized constant output.
The value of the parameter can be adapted via local search and is
passed on from parents to their offspring.
"""

_arity = 0
_initial_values = {"<p>": lambda: 1.0}
_def_output = "<p>"
Expand Down
27 changes: 25 additions & 2 deletions docs/api_reference/nodes.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,30 @@
Functional nodes
================
Nodes
=====

==============
Abstract Nodes
==============

.. automodule:: cgp.node
:members:
:undoc-members:
:show-inheritance:

==================
Input/Output Nodes
==================

.. automodule:: cgp.node_input_output
:members:
:undoc-members:
:show-inheritance:

==============
Operator Nodes
==============

.. automodule:: cgp.node_impl
:members:
:undoc-members:
:show-inheritance:

0 comments on commit f2c94b2

Please sign in to comment.