reservoirpy.ops.link#
- class reservoirpy.ops.link(node1, node2, name=None)[source]#
Link two
Node
instances to form aModel
instance. node1 output will be used as input for node2 in the created model. This is similar to a function composition operation:\[model(x) = (node1 \circ node2)(x) = node2(node1(x))\]You can also perform this operation using the
>>
operator:model = node1 >> node2
Or using this function:
model = link(node1, node2)
-node1 and node2 can also be
Model
instances. In this case, the newModel
created will contain all nodes previously contained in all the models, and link all node1 outputs to all node2 inputs. This allows to chain the>>
operator:step1 = node0 >> node1 # this is a model step2 = step1 >> node2 # this is another
-node1 and node2 can finally be lists or tuples of nodes. In this case, all node1 outputs will be linked to a
Concat
node to concatenate them, and theConcat
node will be linked to all node2 inputs. You can still use the>>
operator in this situation, except for many-to-many nodes connections:# many-to-one model = [node1, node2, ..., node] >> node_out # one-to-many model = node_in >> [node1, node2, ..., node] # ! many-to-many requires to use the `link` method explicitly! model = link([node1, node2, ..., node], [node1, node2, ..., node])
- Parameters:
- Returns:
A
Model
instance chaining the nodes.- Return type:
- Raises:
TypeError – Dimension mismatch between connected nodes: node1 output dimension if different from node2 input dimension. Reinitialize the nodes or create new ones.
Notes
Be careful to how you link the different nodes: reservoirpy does not allow to have circular dependencies between them:
model = node1 >> node2 # fine model = node1 >> node2 >> node1 # raises! data would flow in # circles forever...