Structure#

Submodules#

conex.nn.structure.container module#

Implementation of Base Container.

class conex.nn.structure.container.Container(net: Network, sub_structures: List[NetworkObject], input_ports: Dict[str, Tuple[dict, List[Port]]] | None = None, output_ports: Dict[str, Tuple[dict, List[Port]]] | None = None, behavior: Dict[int, Behavior] | None = None, tag: str | None = None, device: device | int | str | None = None)[source]#

Bases: NetworkObject

The container Structute.

Note: All the children should override required_helper, save_helper and build_helper.

Parameters:
  • net (Network) – The network of the layer.

  • sub_structures (list of NetworkObjects) – The list of NetworkObject to be part of the container.

  • input_ports (dictionary) – a dictionary of lables into the list of ports.

  • output_ports (dictionary) – a dictionary of lables into the list of ports.

  • behavior (dictionary) – A dictionary of keys and behaviors attached to the container.

  • tag (str) – tag of the container divided by “,”.

  • device (device) – device of the structure. defaults to the netowrk device.

add_sub_structures(structure_list: List[NetworkObject])[source]#
required_helper() List[NetworkObject][source]#

A function to find required structures.

This function should return a list of structures required in time of creating the instance.

save_helper(all_structures: List[NetworkObject]) dict[source]#

A function to help saving the structures. into a dictionary.

If tag and behavior parameters are not provided, they be handled by higher saving paradigm. Network should be excluded.

Parameters:

all_structures (list) – a list containing the output of required_helper which are structures required to make same instance.

static ports_helper(ports: Dict[str, List[Port]], helper_struc: list | dict) dict[source]#

Transforms the port dictionary to use objects or indexes.

Parameters:
  • ports (dictionary) – The dictionary of desired ports to transform.

  • helper_struc (list or dictionary) – dictionary of saved structures or a list of structures.

static build_helper(parameter_dic: dict, built_structures: Dict[int, NetworkObject]) dict[source]#

Function to edit the parameter dictionary into acceptable argument of the class constructor.

Note: behavior can also be edited in this function as thay later will be constructed.

training: bool#

conex.nn.structure.cortical_column module#

class conex.nn.structure.cortical_column.CorticalColumn(net: Network, layers: Dict[str, CorticalLayer] | None = None, layer_connections: List[Tuple[str, str, CorticalLayerConnection]] | None = None, input_ports: Dict[str, Tuple[dict, List[Port]]] | None = None, output_ports: Dict[str, Tuple[dict, List[Port]]] | None = None, behavior: Dict[int, Behavior] | None = None, tag: str | None = None, device: device | int | str | None = None)[source]#

Bases: Container

The Implementation of CorticalColumn.

Parameters:
  • net (Network) – The network of the Cortical Column.

  • layers (dictionary) – a dictionary with key as layers’ name and value as corticallayers which will be cortical column’s layers.

  • layer_connections (list) – a list of tuple with values as (source layer name, destination layer name, corticallayerconnection). to connect inner layers.

  • input_ports (dictionary) – a dictionary of lables into the list of ports.

  • output_ports (dictionary) – a dictionary of lables into the list of ports.

  • behavior (dictionary) – a dictionary of keys and behaviors attached to the container.

  • tag (str) – tag of the container divided by “,”.

  • device (device) – device of the structure. defaults to the netowrk device.

create_layer_connections()[source]#
required_helper() List[NetworkObject][source]#

A function to find required structures.

This function should return a list of structures required in time of creating the instance.

save_helper(all_structures: List[NetworkObject]) dict[source]#

A function to help saving the structures. into a dictionary.

If tag and behavior parameters are not provided, they be handled by higher saving paradigm. Network should be excluded.

Parameters:

all_structures (list) – a list containing the output of required_helper which are structures required to make same instance.

static build_helper(parameter_dic: dict, built_structures: Dict[int, NetworkObject]) dict[source]#

Function to edit the parameter dictionary into acceptable argument of the class constructor.

Note: behavior can also be edited in this function as thay later will be constructed.

training: bool#

conex.nn.structure.cortical_layer_connection module#

class conex.nn.structure.cortical_layer_connection.CorticalLayerConnection(net: Network, src: NetworkObject | None = None, dst: NetworkObject | None = None, connections: List[Tuple[str, str, Dict[int, Behavior], str]] | None = None, behavior: Dict[int, Behavior] | None = None, tag: str | None = None, device: device | int | str | None = None)[source]#

Bases: Container

Connection scheme between two layers.

Parameters:
  • src (NetworkObject) – The source network object such as a layer with neurongroups as attribute.

  • dst (NetworkObject) – The destination network object such as a layer with neurongroups as attribute.

  • connections – (list): The list of connection created between two objects. Each connection is defined with quaduple of source neurongroup’s attribute name, destinations’ attribute name, behavior dictionary, and synapse tag.

  • behavior (dict) – The behavior for the CorticalLayerConnection itself.

  • tag (str) – tag of the CorticalLayerConnection divided by “,”.

  • device (device) – device of the structure. Defaults to the netowrk device.

connect_src(src: NetworkObject)[source]#
connect_dst(dst: NetworkObject)[source]#
create_synapses()[source]#
required_helper() List[NetworkObject][source]#

A function to find required structures.

This function should return a list of structures required in time of creating the instance.

save_helper(all_structures: List[NetworkObject]) dict[source]#

A function to help saving the structures. into a dictionary.

If tag and behavior parameters are not provided, they be handled by higher saving paradigm. Network should be excluded.

Parameters:

all_structures (list) – a list containing the output of required_helper which are structures required to make same instance.

static build_helper(parameter_dic: dict, built_structures: Dict[int, NetworkObject]) dict[source]#

Function to edit the parameter dictionary into acceptable argument of the class constructor.

Note: behavior can also be edited in this function as thay later will be constructed.

training: bool#

conex.nn.structure.io_layer module#

class conex.nn.structure.io_layer.InputLayer(net: ~pymonntorch.NetworkCore.Network.Network, input_dataloader: ~torch.utils.data.dataloader.DataLoader, have_sensory: bool = True, have_location: bool = False, have_label: bool = True, sensory_size: int | ~pymonntorch.NetworkBehavior.Structure.Structure.NeuronDimension | None = None, location_size: int | ~pymonntorch.NetworkBehavior.Structure.Structure.NeuronDimension | None = None, sensory_axon: ~pymonntorch.NetworkCore.Behavior.Behavior = <class 'conex.behaviors.neurons.axon.NeuronAxon'>, sensory_axon_params: dict | None = None, location_axon: ~pymonntorch.NetworkCore.Behavior.Behavior = <class 'conex.behaviors.neurons.axon.NeuronAxon'>, location_axon_params: dict | None = None, silent_interval: int = 0, instance_duration: int = 0, sensory_data_dim: int = 2, location_data_dim: int = 2, tag: str | None = None, behavior: ~typing.Dict[int, ~pymonntorch.NetworkCore.Behavior.Behavior] | None = None, sensory_tag: str | None = None, location_tag: str | None = None, output_ports: ~typing.Dict[str, ~typing.Tuple[~typing.Tuple | None, ~typing.List[~typing.Tuple[str, ~typing.Dict[int, ~pymonntorch.NetworkCore.Behavior.Behavior]]]]] | None = None, sensory_user_defined: ~typing.Dict[int, ~pymonntorch.NetworkCore.Behavior.Behavior] | None = None, location_user_defined: ~typing.Dict[int, ~pymonntorch.NetworkCore.Behavior.Behavior] | None = None)[source]#

Bases: NetworkObject

A sample input layer.

Parameters:
  • input_dataloader (torch dataloader) – The dataloader of input layer.

  • have_sensory (bool) – Whether dataloader return sensory data or not.

  • have_location (bool) – Whether dataloader location data or not.

  • have_label (bool) – Whether dataloader label or not.

  • sensory_size (int or behavior) – The size of each sensory neurongroup.

  • location_size (int or behavior) – The size of each location neurongroup.

  • sensory_axon (behavior) – The behavior class for axon paradigm of sensory neurongroup.

  • sensory_axon_params (dict) – Parameters for axon class of sensory neurongroup.

  • location_axon (behavior) – The behavior class for axon paradigm of location neurongroup.

  • location_axon_params (dict) – Parameters for axon class of location neurongroup.

  • silent_interval (int) – Empty interval between two samples.

  • instance_duration (int) – Each sample duraiton

  • sensory_data_dim (int) – The number of dimension of sensory data.

  • location_data_dim (int) – The number of dimension of location data.

  • behavior (dict) – The behavior for the InputLayer itself.

  • tag (str) – tag of the InputLayer divided by “,”.

  • sensory_tag (str) – tag of the sensory population divided by “,”.

  • location_tag (ste) – tag of the location population divided by “,”.

  • sensory_user_defined (dict) – Additional behavior for sensory neurongroup.

  • location_user_defined (dict) – Additional behavior for location neurongroup.

training: bool#
class conex.nn.structure.io_layer.OutputLayer(net: ~pymonntorch.NetworkCore.Network.Network, representation_size: int | ~pymonntorch.NetworkBehavior.Structure.Structure.NeuronDimension | None = None, motor_size: int | ~pymonntorch.NetworkBehavior.Structure.Structure.NeuronDimension | None = None, representation_dendrite_structure: ~typing.Callable = <class 'conex.behaviors.neurons.dendrite.SimpleDendriteStructure'>, representation_dendrite_structure_params: dict | None = None, motor_dendrite_structure: ~typing.Callable = <class 'conex.behaviors.neurons.dendrite.SimpleDendriteStructure'>, motor_dendrite_structure_params: dict | None = None, tag: str | None = None, behavior: ~typing.Dict[int, ~pymonntorch.NetworkCore.Behavior.Behavior] | None = None, representation_tag: str | None = None, motor_tag: str | None = None, input_ports: ~typing.Dict[str, ~typing.Tuple[~typing.Tuple | None, ~typing.List[~typing.Tuple[str, ~typing.Dict[int, ~pymonntorch.NetworkCore.Behavior.Behavior]]]]] | None = None, representation_user_defined: ~typing.Dict[int, ~pymonntorch.NetworkCore.Behavior.Behavior] | None = None, motor_user_defined: ~typing.Dict[int, ~pymonntorch.NetworkCore.Behavior.Behavior] | None = None)[source]#

Bases: NetworkObject

A sample output layer.

Parameters:
  • representation_size (int or behavior) – The size of each representation neurongroup.

  • motor_size (int or behavior) – The size of each motor neurongroup.

  • representation_dendrite_structure (Callable) – Dendrite structure for representation population.

  • representation_dendrite_structure_params (dict) – The parameters for dendrite structure of representation population.

  • motor_dendrite_structure (Callable) – Dendrite structure for motor population.

  • motor_dendrite_structure_params (dict) – The parameters for dendrite structure of representation population.

  • behavior (dict) – The behavior for the InputLayer itself.

  • tag (str) – tag of the InputLayer divided by “,”.

  • representation_tag (str) – tag of the representation population divided by “,”.

  • motor_tag (str) – tag of the motor population divided by “,”.

  • representation_user_defined (dict) – Additional behavior for representation neurongroup.

  • motor_user_defined (dict) – Additional behavior for motor neurongroup.

training: bool#

conex.nn.structure.layer module#

class conex.nn.structure.layer.Layer(net: Network, neurongroups: List[NeuronGroup] | None = None, synapsegroups: List[SynapseGroup] | None = None, input_ports: Dict[str, Tuple[dict, List[Port]]] | None = None, output_ports: Dict[str, Tuple[dict, List[Port]]] | None = None, behavior: Dict[int, Behavior] | None = None, tag: str | None = None, device: device | int | str | None = None)[source]#

Bases: Container

The Layer structure.

Layer structure can have multiple neurongroups, it also contains the synapsegroup between them.

Parameters:
  • net (Network) – The network of the layer.

  • neurongroups (list) – The list of containting neurongroups.

  • synapsegroups (list) – The list of containting synapsegroups.

  • input_ports (dictionary) – a dictionary of lables into the list of ports.

  • output_ports (dictionary) – a dictionary of lables into the list of ports.

  • behavior (dictionary) – a dictionary of keys and behaviors attached to the Layer.

  • tag (str) – tag of the Layer divided by “,”.

  • device (device) – device of the Layer. defaults to the netowrk device.

save_helper(all_structures: List[NetworkObject]) dict[source]#

A function to help saving the structures. into a dictionary.

If tag and behavior parameters are not provided, they be handled by higher saving paradigm. Network should be excluded.

Parameters:

all_structures (list) – a list containing the output of required_helper which are structures required to make same instance.

static build_helper(parameter_dic: dict, built_structures: Dict[int, NetworkObject]) dict[source]#

Function to edit the parameter dictionary into acceptable argument of the class constructor.

Note: behavior can also be edited in this function as thay later will be constructed.

training: bool#
class conex.nn.structure.layer.CorticalLayer(net: Network, excitatory_neurongroup: NeuronGroup | None = None, inhibitory_neurongroup: NeuronGroup | None = None, synapsegroups: List[SynapseGroup] | None = None, input_ports: Dict[str, List[Port]] | None = None, output_ports: Dict[str, List[Port]] | None = None, behavior: Dict[int, Behavior] | None = None, tag: str | None = None, device: device | int | str | None = None)[source]#

Bases: Layer

The Cortical Layer structure.

Cortical Layer structure can have two neurongroups one excitatory and one inhibitory , it also contains the synapsegroup between them.

Parameters:
  • net (Network) – The network of the layer.

  • excitatory_neurongroup (NeuronGroup) – The excitatory neurongroup of layer.

  • inhibitory_neurongroup (NeuronGroup) – The inhibitory neurongroup of layer.

  • synapsegroups (list) – The list of containting synapsegroups.

  • input_ports (dictionary) – a dictionary of lables into the list of ports.

  • output_ports (dictionary) – a dictionary of lables into the list of ports.

  • behavior (dictionary) – a dictionary of keys and behaviors attached to the Layer.

  • tag (str) – tag of the Layer divided by “,”.

  • device (device) – device of the Layer. defaults to the netowrk device.

save_helper(all_structures: List[NetworkObject]) dict[source]#

A function to help saving the structures. into a dictionary.

If tag and behavior parameters are not provided, they be handled by higher saving paradigm. Network should be excluded.

Parameters:

all_structures (list) – a list containing the output of required_helper which are structures required to make same instance.

static build_helper(parameter_dic: dict, built_structures: Dict[int, NetworkObject]) dict[source]#

Function to edit the parameter dictionary into acceptable argument of the class constructor.

Note: behavior can also be edited in this function as thay later will be constructed.

training: bool#

conex.nn.structure.neocortex module#

class conex.nn.structure.neocortex.Neocortex(dt: float | None = 1, behavior: Dict[int, Behavior] | None = None, dtype: dtype = torch.float32, device: device | int | str = 'cpu', synapse_mode: str = 'SxD', index: bool = False, tag: str | None = None)[source]#

Bases: Network

Neocortex.

Neocortex structure is the network equivalent. it also contains the all the structures..

Parameters:
  • dt (float) – The time resolution of the simulation.

  • behavior (dictionary) – a dictionary of keys and behaviors attached to the Layer.

  • dtype (torch dtype) – The precision of floating point compuation.

  • device (device) – device of the Layer. defaults to the netowrk device.

  • synapse_mode (str) – The synapse structure in simulation, possible values: “SxD”, “DxS”.

  • index (bool) – Add the index vector to neuron populations.

  • tag (str) – tag of the Layer divided by “,”.

training: bool#

conex.nn.structure.port module#

class conex.nn.structure.port.Port(object: NetworkObject, label: str | None = None, behavior: Dict[int, Behavior] | None = None)[source]#

Bases: tuple

Container’s Port dataclass

Parameters:
  • object (NetowrkObject) – Inner container Object that port should connect to.

  • label (str or None) – Port port name of the inner object or None to connect to the object itself.

  • behavior (Behavior) – Behaviors that connections will attain while using the port.

object: NetworkObject#

Alias for field number 0

label: str#

Alias for field number 1

behavior: Dict[int, Behavior]#

Alias for field number 2

conex.nn.structure.synapsis module#

class conex.nn.structure.synapsis.Synapsis(net: Network, src: NetworkObject | None = None, dst: NetworkObject | None = None, input_port: str | None = None, output_port: str | None = None, synapsis_behavior: Dict[int, Behavior] | None = None, synaptic_tag: str | None = None, behavior: Dict[int, Behavior] | None = None, tag: str | None = None, device: device | int | str | None = None)[source]#

Bases: Container

Synapsis structure

This structure connects two ports, and connects all the possible synapsegroups between them.

Parameters:
  • net (Network) – The network of the layer.

  • src (NetworkObject) – The source of synpsis object.

  • dst (NetworkObject) – The destination of synpsis object.

  • input_port (str) – The input label of source port.

  • output_port (str) – The output label of destination port.

  • synapsis_behavior (dict) – the behavior of synapses created.

  • synapstic_tag (str) – The tag of the synapses created.

  • behavior (dictionary) – A dictionary of keys and behaviors attached to the container.

  • tag (str) – tag of the container divided by “,”.

  • device (device) – device of the structure. defaults to the netowrk device.

connect_src(src: NetworkObject)[source]#
connect_dst(dst: NetworkObject)[source]#
create_synapses()[source]#
required_helper() List[NetworkObject][source]#

A function to find required structures.

This function should return a list of structures required in time of creating the instance.

save_helper(all_structures: List[NetworkObject]) dict[source]#

A function to help saving the structures. into a dictionary.

If tag and behavior parameters are not provided, they be handled by higher saving paradigm. Network should be excluded.

Parameters:

all_structures (list) – a list containing the output of required_helper which are structures required to make same instance.

static build_helper(parameter_dic: dict, built_structures: Dict[int, NetworkObject]) dict[source]#

Function to edit the parameter dictionary into acceptable argument of the class constructor.

Note: behavior can also be edited in this function as thay later will be constructed.

training: bool#