Biclique¶
- class Biclique(connections: Iterable[tuple[str, Connection] | tuple[str, Connection, OneToOne[Tensor]]], neurons: Iterable[tuple[str, Neuron] | tuple[str, Neuron, OneToOne[Tensor]]], combine: Callable[[dict[str, Tensor]], Tensor] | Literal['sum', 'mean', 'prod', 'min', 'max'] = 'sum')[source]¶
Bases:
LayerLayer structured as a complete bipartite graph.
Each input is processed by its corresponding connection, with an optional transformation applied, before being combined with the results of all other connections. These are then, for each group of neurons, optionally transformed and then passed in.
Each element of
connectionsandcmust be a tuple with at least two elements and at most three. The first of these is a string, which must be a Python identifier and unique to across theconnectionsandneurons. The second is the module itself (ConnectionorNeuronrespectively).The optional third is a function which is a callable that takes and returns a
Tensor. If present, this will be applied to the output tensor of the correspondingConnectionor input tensor of the correspondingNeuron.Either a function to combine the tensors from the modules in
connectionsto be passed intoinputsor a string literal may be provided. These may be “sum”, “mean”, “prod”, “min”, or “max”. All useeinopsto reduce. When providing a function, it must take a tuple of tensors (equal to the number of inputs) and produce a single tensor output.- Parameters:
connections (Iterable[tuple[str, Connection] | tuple[str, Connection, OneToOne[torch.Tensor]]]) – modules which receive inputs given to the layer.
neurons (Iterable[tuple[str, Neuron] | tuple[str, Neuron, OneToOne[torch.Tensor]]]) – modules which produce output from the layer.
combine (Callable[[dict[str, torch.Tensor]], torch.Tensor] | Literal["sum", "mean", "prod", "min", "max"], optional) – function to combine tensors from inputs into a single tensor for outputs. Defaults to
"sum".
Note
When
combineis not a string, keyword arguments passed into__call__, other than those captured inforward()will be passed in.- add_cell(*args, **kwargs) None[source]¶
Creates and adds a cell if it doesn’t exist.
If a cell already exists with the given connection and neuron, this will return the existing cell rather than create a new one.
- Parameters:
- Raises:
AttributeError –
connectiondoes not specify a connection.AttributeError –
neurondoes not specify a neuron.
- Returns:
cell specified by the connection and neuron.
- Return type:
- add_connection(*args, **kwargs) None[source]¶
Adds a new connection.
- Parameters:
name (str) – name of the connection to add.
connection (Connection) – connection to add.
- Raises:
RuntimeError –
namealready specifies a connection- Returns:
added connection.
- Return type:
- add_neuron(*args, **kwargs) None[source]¶
Adds a new neuron.
- Parameters:
- Raises:
RuntimeError –
namealready specifies a neuron- Returns:
added neuron.
- Return type:
- del_cell(*args, **kwargs) None[source]¶
Deletes a created cell if it exists.
Even if a cell hasn’t been created with the given pair, if the pair is valid, this will not raise an error.
- Parameters:
- Raises:
AttributeError –
connectiondoes not specify a connection.AttributeError –
neurondoes not specify a neuron.
- del_connection(*args, **kwargs) None[source]¶
Deletes an existing connection.
- Parameters:
name (str) – name of the connection to delete.
- Raises:
AttributeError –
namedoes not specify a connection.
- del_neuron(*args, **kwargs) None[source]¶
Deletes an existing neuron.
- Parameters:
name (str) – name of the neuron to delete.
- Raises:
ValueError –
namedoes not specify a neuron.
- wiring(inputs: dict[str, Tensor], **kwargs) dict[str, Tensor][source]¶
Connection logic between connection outputs and neuron inputs.
This implements the forward logic of the biclique topology where the tensors from the inputs are transformed, combined, and transformed again before being passed to the outputs. Transforms which were unspecified are assumed to be identity.
- Parameters:
inputs (dict[str, torch.Tensor]) – dictionary of connection names to tensors.
- Returns:
dictionary of output names to tensors.
- Return type: