Documentation#
NetworkCore#
TaggableObject#
- class pymonntorch.NetworkCore.TaggableObject.TaggableObject(tag, device='cpu')[source]#
This is the base class for all taggable objects.
This class is used to add tags to objects and to search for objects with a specific tag. It is a torch.nn.Module, so that any object class inheriting from this class can be used as a torch.nn.Module to benefit from its functionality, e.g. state_dict.
- tags#
List of tags.
- Type:
list
- tag_shortcuts#
Cache for faster search.
- Type:
dict
- device#
Device on which the object is located. The default is “cpu”.
- Type:
str
- has_module(tag)[source]#
Check if object has a module with a specific tag.
- Parameters:
tag (str) – Tag to search for.
- Returns:
The object with the tag. If no object is found, None is returned.
- Return type:
Note: The returned object can be any object inheriting from TaggableObject.
- find_objects(key)[source]#
Find objects with a specific tag.
This method should be overridden for deeper search.
- Parameters:
key (str) – Tag to search for.
- Returns:
List of objects with the tag.
- Return type:
list
- clear_cache()[source]#
Clear the tag cache for faster search.
This method is called automatically when a tag is added or removed.
- set_tag_attrs(tag, attr, value)[source]#
Set an attribute of all objects with a specific tag.
- Parameters:
tag (str) – Tag to search for.
attr (str) – Attribute to set.
value (any) – Value to set to the attribute.
Behavior#
- class pymonntorch.NetworkCore.Behavior.Behavior(*args, **kwargs)[source]#
Base class for behaviors. All behaviors all `TaggableObject`s.
- tag#
Tag of the behavior.
- Type:
str
- device#
Device of the behavior. This is overwritten by object’s device upon calling initialize.
- Type:
str
- behavior_enabled#
Whether the behavior is enabled. The default is True.
- Type:
bool
- init_kwargs#
Dictionary of the keyword arguments passed to the constructor.
- Type:
dict
- used_attr_keys#
List of the name of the attributes that have been used in the initialize method.
- Type:
list
- initialize(object)[source]#
Sets the variables of the object. This method is called by the Network class when the object is added to the network.
Note: All sub-classes of Behavior overriding this method should call the super method to ensure everything is placed on the correct device.
- Parameters:
object (TaggableObject) – Object possessing the behavior.
- forward(object)[source]#
Forward pass of the behavior. This method is called by the Network class per simulation iteration.
- Parameters:
object (TaggableObject) – Object possessing the behavior.
- evaluate_diversity_string(ds, object)[source]#
Evaluates the diversity string describing tensors of an object.
- Parameters:
ds (str) – Diversity string describing the tensors of the object.
object (NetworkObject) – The object possessing the behavior.
- Returns:
The resulting tensor.
- Return type:
torch.tensor
- set_parameters_as_variables(object)[source]#
Set the variables defined in the init of behavior as the variables of the object.
- Parameters:
object (NetworkObject) – The object possessing the behavior.
- check_unused_attrs()[source]#
Checks whether all attributes have been used in the initialize method.
- parameter(key, default=None, object=None, do_not_diversify=False, search_other_behaviors=False, tensor=False, required=False)[source]#
Gets the value of an attribute.
- Parameters:
key (str) – Name of the attribute.
default (any) – Default value of the attribute.
object (NetworkObject) – The object possessing the behavior.
do_not_diversify (bool) – Whether to diversify the attribute. The default is False.
search_other_behaviors (bool) – Whether to search for the attribute in other behaviors of the object. The default is False.
tensor (bool) – Whether to make a tensor out of value. Suitable for list and numbers.
required (bool) – Whether the attribute is required. The default is False.
- Returns:
The value of the attribute.
- Return type:
any
NetworkObjects#
- class pymonntorch.NetworkCore.Base.NetworkObject(tag, network, behavior, device='cpu')[source]#
This is the base class for all network objects.
This class is used to treat network objects’ behaviors and is a subclass of TaggableObject.
- behavior#
List or dictionary of behaviors.
- Type:
list or dict
- analysis_modules#
List of analysis modules.
- Type:
list
- add_behaviors(behavior_dict)[source]#
Add multiple behaviors to the network object.
- Parameters:
behavior_dict (dict) – Dictionary of behaviors to be added. The keys must be integers.
- Returns:
The dictionary of behaviors.
- Return type:
dict
- remove_behavior(key_tag_behavior_or_type)[source]#
Remove behavior(s) from the network object.
- Parameters:
key_tag_behavior_or_type (str, Behavior, or type) – Key, tag, behavior object, or type of behavior to be removed.
- set_behaviors(tag, enabled)[source]#
Set behaviors to be enabled or disabled.
- Parameters:
tag (str) – Tag of behaviors to be enabled or disabled.
enabled (bool) – If true, behaviors will be enabled. If false, behaviors will be disabled.
- deactivate_behaviors(tag)[source]#
Disable behaviors.
- Parameters:
tag (str) – Tag of behaviors to be disabled.
- activate_behaviors(tag)[source]#
Enable behaviors.
- Parameters:
tag (str) – Tag of behaviors to be enabled.
- find_objects(key)[source]#
Find behaviors and analysis modules in the network object by key.
- Parameters:
key (str) – Key to be used to access behavior or analysis module.
- Returns:
List of behaviors and analysis modules.
- Return type:
list
- add_analysis_module(module)[source]#
Add an analysis module to the network object.
- Parameters:
module (AnalysisModule) – Analysis module to be added.
- get_all_analysis_module_results(tag, return_modules=False)[source]#
Get results from all analysis modules in the network object.
- Parameters:
tag (str) – Tag of analysis modules to be used.
return_modules (bool) – If true, the analysis modules will be returned. The default is False.
- Returns:
Dictionary of results.
- Return type:
dict
- buffer_roll(mat, new=None, counter=False)[source]#
Shift the elements of a tensor to the right.
- Parameters:
mat (torch.Tensor) – Tensor to be shifted.
new (int or float or bool or torch.Tensor) – New element to be inserted at the beginning of the tensor. The default is None (i.e. the last of the buffer is repositoined at the first).
counter (bool) – If True, rolling is done in opposite direction, and the new element is added at the end.
- Returns:
The shifted tensor.
- Return type:
torch.Tensor
- tensor(mode, dim, scale=None, density=None, dtype=None)[source]#
Get a tensor with desired dimensionality.
The tensor can be initialized in different modes. List of possible values for mode includes: - “random” or “rand” or “rnd” or “uniform”: Uniformly distributed random numbers in range [0, 1). - “normal(mean=a, std=b)”: Normally distributed random numbers with a as mean and b as standard derivation. - “ones”: Tensor filled with ones. - “zeros”: Tensor filled with zeros. - A single number: Tensor filled with that number. - You can also use any function from torch package for this purpose.
- Parameters:
mode (str) – Mode to be used to initialize tensor.
dim (int or tuple of int) – Dimensionality of the tensor.
scale (float) – Scale of the tensor. The default is None (i.e. No scaling is applied).
density (float) – Density of the tensor. The default is None (i.e. dense tensor).
dtype (str or type) – Data type of the tensor. If None, def_dtype will be used.
- Returns:
The initialized tensor.
- Return type:
torch.Tensor
- get_buffer_mat(dim, size, **kwargs)[source]#
Get a buffer of specific size with object’s dimensionality.
- Parameters:
dim (int or tuple of int) – Dimensionality of the buffer.
size (int) – Size of the buffer.
kwargs (dict) – Keyword arguments to be passed to the initialization function.
- Returns:
The buffer.
- Return type:
torch.Tensor
- property iteration#
iteration number or time step.
- Type:
int
Network#
- class pymonntorch.NetworkCore.Network.Network(tag=None, behavior=None, dtype=torch.float32, device='cpu', synapse_mode='SxD', index=True)[source]#
This is the class to construct a neural network.
This is the placeholder of all neural network components to be simulated. All objects will receive an instance of this class.
- NeuronGroups#
List of all NeuronGroups in the network.
- Type:
list
- SynapseGroups#
List of all SynapseGroups in the network.
- Type:
list
- behavior#
List of all network-specific behaviors.
- Type:
list or dict
- def_dtype#
Floating point precision of tensors. Defaults to torch.float32.
- Type:
type
- device#
The device to allocate tensors on. Defaults to ‘cpu’.
- Type:
string
- transposed_synapse_matrix_mode#
If True, in the matrix created by synapse, each row corresponds to a neuron from the source neuron group. Defaults to False.
- Type:
bool
- index_neurons#
If True, the id attribute for neuron groups refers to neuron indices. Defaults to True.
- Type:
bool
- set_behaviors(tag, enabled)[source]#
Set behaviors of specific tag to be enabled or disabled.
- Parameters:
tag (str) – Tag of behaviors to be enabled or disabled.
enabled (bool) – If true, behaviors will be enabled. If false, behaviors will be disabled.
- find_objects(key)[source]#
Find objects in the network with a specific tag.
- Parameters:
key (str) – Tag to search for.
- Returns:
List of objects with the tag.
- Return type:
list
- initialize(info=True, warnings=True, storage_manager=None)[source]#
Initialize the variables of the network and all its components.
- Parameters:
info (bool) – If true, print information about the network.
warnings (bool) – If true, print warnings while checking the tag uniqueness.
storage_manager (StorageManager) – Storage manager to use for the network.
- check_unique_tags(warnings=True)[source]#
Check if all tags in the network are unique. In case of doubles, a new tag will be automatically assigned to second instance.
- Parameters:
warnings (bool) – Whether to log the warnings or not.
- set_synapses_to_neuron_groups()[source]#
Set the synapses of all synapse groups to the corresponding neuron groups.
- simulate_iteration(measure_behavior_execution_time=False)[source]#
Simulate one iteration of the network.
Each iteration includes a forward call of objects’ behaviors in the order of their keys in the dictionary or list index.
- Parameters:
measure_behavior_execution_time (bool) – Whether to measure the actual execution time of the behaviors.
- Returns:
If measure_behavior_execution_time is set to True, a dictionary with the execution times of the behaviors is returned.
- Return type:
None or dict
- simulate_iterations(iterations, batch_size=-1, measure_block_time=True, disable_recording=False, batch_progress_update_func=None)[source]#
Simulates the network for a number of iterations.
- Parameters:
iterations (int) – Number of iterations to simulate.
batch_size (int) – Number of iterations to simulate in one batch. If set to -1, the whole simulation is done in one batch.
measure_block_time (bool) – Whether to measure the time of each batch.
disable_recording (bool) – Whether to disable the recording of the network.
batch_progress_update_func (function) – Function to call after each batch. The function should take the current batch number and network instance as arguments.
NeuronGroup#
- class pymonntorch.NetworkCore.NeuronGroup.NeuronGroup(size, behavior, net, tag=None)[source]#
This is the class to construct a neuronal population.
- size#
The number of neurons in the population.
- Type:
int
- behavior#
The behaviors of the population.
- Type:
list or dict
- tags#
The tags of the population.
- Type:
str
- BaseNeuronGroup#
The base NeuronGroup the population belongs to.
- Type:
- afferent_synapses#
The afferent synapses of the population.
- Type:
dict
- efferent_synapses#
The efferent synapses of the population.
- Type:
dict
- mask#
Whether to define a mask for the population (Used for nested populations).
- Type:
bool
- learning#
Whether to enable learning for the population.
- Type:
bool
- recording#
Whether to enable recording for the population.
- Type:
bool
- id#
The integer id of the population.
- Type:
torch.Tensor
- synapses(mode, tag='All')[source]#
Get synapses connected to the NeuronGroup.
- Parameters:
mode (str or bool) – Whether to return efferent or afferent synapses connected to the NeuronGroup. Values indicating afferent: ` “afferent”, “dendrite”, “pre”, “preSynaptic”, 0, False ` Values indicating efferent: ` “efferent”, “axon”, “post”, “postSynaptic”, 1 , True`
tag (str, optional) – Filters Synapses to have provided tag . Defaults to “All”.
- Returns:
The list containing SynapseGroups
- Return type:
List[SynapseGroup]
- require_synapses(name, afferent=True, efferent=True, warning=True)[source]#
Require the existence of synapses.
- Parameters:
name (str) – The name of the synapse.
afferent (bool) – Whether to require afferent synapses.
efferent (bool) – Whether to require efferent synapses.
warning (bool) – Whether to print a warning if the synapse does not exist.
- vector(mode='zeros()', scale=None, density=None, plot=False, dtype=None)[source]#
Get a tensor with population’s dimensionality.
The tensor can be initialized in different modes. List of possible values for mode includes: - “random” or “rand” or “rnd” or “uniform”: Uniformly distributed random numbers in range [0, 1). - “normal”: Normally distributed random numbers with zero mean and unit variance. - “ones”: Tensor filled with ones. - “zeros”: Tensor filled with zeros. - A single number: Tensor filled with that number. - You can also use any function from torch package for this purpose. Note that you should not use torch. prefix.
- Parameters:
mode (str) – Mode to be used to initialize tensor.
scale (float) – Scale of the tensor. The default is None (i.e. No scaling is applied).
density (float) – Density of the tensor. The default is None (i.e. dense tensor).
plot (bool) – If true, the histogram of the tensor will be plotted. The default is False.
dtype (str or type) – Data type of the tensor. If None, def_dtype will be used.
- Returns:
The initialized tensor.
- Return type:
torch.Tensor
- vector_buffer(buffer_size, **kwargs)[source]#
Get a buffer for the population’s dimensionality.
- Parameters:
buffer_size (int) – The size of the buffer.
**dtype (torch.dtype, optional) – The desired data type of returned tensor.
- Returns:
The buffer.
- Return type:
torch.Tensor
- get_combined_synapse_shape(Synapse_ID)[source]#
Get the population size along with the number of afferent synapses.
- Parameters:
Synapse_ID (str) – The ID of the synapse by which it is registered in list of afferent synapses.
- Returns:
The combined shape.
- Return type:
tuple
- subGroup(mask=None)[source]#
Get a NeuronSubGroup object from the population.
- Parameters:
mask (bool) – The mask condition indicating which neurons to be included in the subgroup.
- Returns:
The subgroup.
- Return type:
NeuronSubGroup
- get_masked_dict(dict_name, key)[source]#
Get value of a key in a specific dictionary attribute of the population.
- Parameters:
dict_name (str) – Name of the dictionary.
key (int or str) – the key to retrieve from the dictionary.
- Returns:
The value.
- Return type:
any
- connected_NG_param_list(param_name, syn_tag='All', afferent_NGs=False, efferent_NGs=False, same_NG=False, search_behaviors=False)[source]#
Get a list of parameters of connected neuron groups.
- Parameters:
param_name (str) – The name of the parameter.
syn_tag (str) – The tag of the synapse. The default is “All”.
afferent_NGs (bool) – Whether to include afferent neuron groups. The default is False.
efferent_NGs (bool) – Whether to include efferent neuron groups. The default is False.
same_NG (bool) – Whether to include the connections within the same neuron group. The default is False.
search_behaviors (bool) – Whether to search the dictionary of behaviors for the parameter. The default is False.
- Returns:
The list of parameters.
- Return type:
list
- partition(block_size=7)[source]#
Get a partitioned population.
- Parameters:
block_size (int) – The size of each block. The default is 7.
- Returns:
The list of partitions.
- Return type:
list of NeuronGroup or NeuronSubGroup
- partition_masks(steps=[1, 1, 1])[source]#
Get a mask tensor for partitioning the population.
- Parameters:
steps (list of int) – The number of steps in each dimension. The default is [1, 1, 1].
- Returns:
The mask tensor.
- Return type:
torch.Tensor
- split_grid_into_sub_group_blocks(steps=[1, 1, 1])[source]#
Split the population into partitioned subgroups.
- Returns:
The list of partitions.
- Return type:
list of NeuronGroup or NeuronSubGroup
- get_subgroup_receptive_field_mask(subgroup, xyz_rf=[1, 1, 1])[source]#
Get the receptive field mask of a neuron subgroup.
- Parameters:
subgroup (NeuronSubGroup or NeuronGroup) – The neuron subgroup.
xyz_rf (list of int) – The receptive field size in each dimension. The default is [1, 1, 1].
- Returns:
The receptive field mask.
- Return type:
torch.Tensor
SynapseGroup#
- class pymonntorch.NetworkCore.SynapseGroup.SynapseGroup(src, dst, net, tag=None, behavior=None)[source]#
This is the class to construct synapses between neuronal populations.
- src#
The pre-synaptic neuron group.
- Type:
- dst#
The post-synaptic neuron group.
- Type:
- tags#
The tags of the synapse group.
- Type:
list
- behavior#
The behaviors of the synapse group.
- Type:
dict or list
- enabled#
Whether the synapse is enabled for learning or not.
- Type:
bool
- group_weighting#
The weighting of the synapse group.
- Type:
float
- set_var(key, value)[source]#
Sets a variable of the synapse group.
- Parameters:
key (str) – The name of the variable.
value (any) – The value of the variable.
- Returns:
The synapse group itself.
- Return type:
- matrix_dim()[source]#
Returns the dimension of the synapse matrix.
For a synapse group between a source population of size n and a destination population of size m, the synapse matrix has the dimension m x n.
- Returns:
The dimension of the synapse matrix.
- Return type:
tuple
- get_random_synapse_mat_fixed(min_number_of_synapses=0)[source]#
Returns a random synapse matrix with a fixed number of synapses per neuron.
- Parameters:
min_number_of_synapses (int) – The minimum number of synapses per neuron.
- Returns:
The random synapse matrix.
- Return type:
torch.Tensor
- matrix(mode='zeros()', scale=None, density=None, only_enabled=True, clone_along_first_axis=False, plot=False, dtype=None)[source]#
Get a tensor with synapse group dimensionality.
The tensor can be initialized in different modes. List of possible values for mode includes: - “random” or “rand” or “rnd” or “uniform”: Uniformly distributed random numbers in range [0, 1). - “normal”: Normally distributed random numbers with zero mean and unit variance. - “ones”: Tensor filled with ones. - “zeros”: Tensor filled with zeros. - A single number: Tensor filled with that number. - You can also use any function from torch package for this purpose. Note that you should not use torch. prefix.
- Parameters:
mode (str) – Mode to be used to initialize tensor.
scale (float) – Scale of the tensor. The default is None (i.e. No scaling is applied).
density (float) – Density of the tensor. The default is None (i.e. dense tensor).
only_enabled (bool) – Whether to only consider enabled synapses or not. The default is True.
clone_along_first_axis (bool) – Whether to clone the tensor along the first axis or not. The default is False.
plot (bool) – If true, the histogram of the tensor will be plotted. The default is False.
dtype (str or type) – Data type of the tensor. If None, def_dtype will be used.
- Returns:
The initialized tensor.
- Return type:
torch.Tensor
- get_synapse_group_size_factor(synapse_group, synapse_type)[source]#
Returns the size factor of a synapse group.
- Parameters:
synapse_group (SynapseGroup) – The synapse group.
synapse_type (str) – The type of the synapse.
- Returns:
The size factor of the synapse group.
- Return type:
float
- get_distance_mat(radius, src_x=None, src_y=None, dst_x=None, dst_y=None)[source]#
Returns a distance matrix between source and destination neurons.
- Parameters:
radius (float) – The radius of the distance to be considered.
src_x (torch.Tensor) – The x coordinates of the source neurons. The default is None (i.e. the x coordinates of the source neurons will be used).
src_y (torch.Tensor) – The y coordinates of the source neurons. The default is None (i.e. the y coordinates of the source neurons will be used).
dst_x (torch.Tensor) – The x coordinates of the destination neurons. The default is None (i.e. the x coordinates of the destination neurons will be used).
dst_y (torch.Tensor) – The y coordinates of the destination neurons. The default is None (i.e. the y coordinates of the destination neurons will be used).
- Returns:
The distance matrix.
- Return type:
torch.Tensor
- get_ring_mat(radius, inner_exp, src_x=None, src_y=None, dst_x=None, dst_y=None)[source]#
Returns a ring-shaped distance matrix between source and destination neurons.
- Parameters:
radius (float) – The radius of the ring.
inner_exp (float) – The exponent of the inner radius.
src_x (torch.Tensor) – The x coordinates of the source neurons. The default is None (i.e. the x coordinates of the source neurons will be used).
src_y (torch.Tensor) – The y coordinates of the source neurons. The default is None (i.e. the y coordinates of the source neurons will be used).
dst_x (torch.Tensor) – The x coordinates of the destination neurons. The default is None (i.e. the x coordinates of the destination neurons will be used).
dst_y (torch.Tensor) – The y coordinates of the destination neurons. The default is None (i.e. the y coordinates of the destination neurons will be used).
- Returns:
The ring matrix.
- Return type:
torch.Tensor
- get_max_receptive_field_size()[source]#
Returns the maximum receptive field size of the synapse group.
- Returns:
The maximum receptive field size of the synapse group.
- Return type:
tuple
NetworkBehavior#
Recorder#
This module includes functions and classes to facilitate recording of network object variables through out the simulation time.
- pymonntorch.NetworkBehavior.Recorder.Recorder.get_Recorder(variable)[source]#
Returns a Recorder instance for the given variable.
- Parameters:
variable (str) – Name of the variable to record.
- Returns:
The Recorder object.
- Return type:
- class pymonntorch.NetworkBehavior.Recorder.Recorder.Recorder(*args, variables=None, gap_width=0, max_length=None, auto_annotate=True, tag=None, **kwargs)[source]#
This is the base class to record variables of a network object.
- Parameters:
variables (list of str) – List of variable names to record. A variable should be of tensor type.
gap_width (int) – The intervals of time to record variables. The default is 0.
tag (str) – A tag name for the Recorder object. The default is None.
max_length (int) – The history buffer size. If None, the variables are recorded for the whole simulation time. The default is None.
auto_annotate (bool) – This parameter specifies whether the variable names include the network object prefix (neurons/synapse/n/s) or not. The default is True.
- initialize(object)[source]#
Sets the variables of the object. This method is called by the Network class when the object is added to the network.
Note: All sub-classes of Behavior overriding this method should call the super method to ensure everything is placed on the correct device.
- Parameters:
object (TaggableObject) – Object possessing the behavior.
- find_objects(key)[source]#
Find objects with a specific tag.
This method should be overridden for deeper search.
- Parameters:
key (str) – Tag to search for.
- Returns:
List of objects with the tag.
- Return type:
list
- forward(parent_obj)[source]#
Forward pass of the behavior. This method is called by the Network class per simulation iteration.
- Parameters:
object (TaggableObject) – Object possessing the behavior.
- class pymonntorch.NetworkBehavior.Recorder.Recorder.EventRecorder(*args, variables=None, gap_width=0, max_length=None, auto_annotate=True, tag=None, **kwargs)[source]#
This class is used to record sparse boolean vectors over time more efficiently. It returns a tensor of (t, i) tuples where t indicates the time step and i is the index of elements with value True. If the variable to record is not boolean itself, it is converted to one by assessing whether values are >0.
- Parameters:
variables (list of str) – List of variable names to record.
gap_width (int) – The intervals of time to record variables. The default is 0.
tag (str) – A tag name for the Recorder object. The default is None.
max_length (int) – The history buffer size. If None, the variables are recorded for the whole simulation time. The default is None.
auto_annotate (bool) – This parameter specifies whether the variable names include the network object prefix (neurons/synapse/n/s) or not. The default is True.
Structure#
This module includes functions and classes to handle structured NeuronGroups.
- pymonntorch.NetworkBehavior.Structure.Structure.vec_to_mat(vec, repeat_count)[source]#
Stack repeat_count numbers of the input vector on first dimension.
- Parameters:
vec (torch.tensor) – The vector to replicate.
repeat_count (int) – Number of replicas.
- Returns:
A matrix of the stacked vec`s for `repeat_count times.
- Return type:
torch.tensor
- pymonntorch.NetworkBehavior.Structure.Structure.vec_to_mat_transposed(vec, repeat_count)[source]#
Stack repeat_count numbers of the input vector on second dimension.
- Parameters:
vec (torch.tensor) – The vector to replicate.
repeat_count (int) – Number of replicas.
- Returns:
A matrix of the stacked vec`s for `repeat_count times.
- Return type:
torch.tensor
- pymonntorch.NetworkBehavior.Structure.Structure.rotation_matrix(axis, theta, dtype=torch.float32)[source]#
Return the rotation matrix associated with counterclockwise rotation about the given axis by theta radians.
- Parameters:
axis (int) – The axis.
theta (float) – The angle of rotation in radians.
dtype (type) – Type of the tensor values. The default is torch.float.
- Returns:
The rotation matrix.
- Return type:
torch.tensor
- pymonntorch.NetworkBehavior.Structure.Structure.get_squared_dim(n_neurons, depth=1)[source]#
Get the squared dimension of a square matrix that can hold n_neurons neurons, with depth layers. The neurons are structured in a square-like manner.
- Parameters:
n_neurons (int) – The desired number of neurons in the NeuronGroup.
depth (int) – The depth of the structured NeuronGroup. The default is 1.
- Returns:
An instance of NeuronDimension behavior with the given depth and calculated height and depth.
- Return type:
- class pymonntorch.NetworkBehavior.Structure.Structure.NeuronDimension(*args, depth=1, height=1, width=1, input_patterns=None, **kwargs)[source]#
The Behavior that defines structure for a NeuronGroup. It overrides the size variable of the NeuronGroup and adds x, y, and z vectors, as well as width, height and depth variables. The Behaviour is special, because its initialize function is executed when the NeuronGroup is created rather than when network.initialize() is called. The neurons are arranged in a 3-dimensional grid with size=width * height * depth. Because is overrides the size variable, it does not have to be added in the behaviour dictionary directly, but also indirectly ( NeuronGroup(size=NeuronDimension(),…) ). In this case it will be added to position 0 in the dictionary.
- Parameters:
width (int) – Width of the NeuronGroup. The default is 1.
height (int) – Height of the NeuronGroup. The default is 1.
depth (int) – Depth of the NeuronGroup. The default is 1.
- set_position(width, height, depth)[source]#
Set the coordinate of neurons by setting vectors x, y, and z.
- Parameters:
width (int) – Width of the neurons.
height (int) – Height of the neurons.
depth (int) – Depth of the neurons.
- get_area_mask(xmin=0, xmax=-1, ymin=0, ymax=-1, zmin=0, zmax=-1)[source]#
Returns a mask tensor with the same shape as the NeuronGroup with the given start and end points.
- Parameters:
xmin (int) – Start point in x axis. The default is 0.
xmax (int) – End point in x axis. The default is -1.
ymin (int) – Start point in y axis. The default is 0.
ymax (int) – End point in y axis. The default is -1.
zmin (int) – Start point in z axis. The default is 0.
zmax (int) – End point in z axis. The default is -1.
- Returns:
The mask tensor.
- Return type:
torch.BoolTensor
- apply_pattern_transformation_function(transform_mat, hup, wup, depth)[source]#
Apply a transformation matrix on the neurons.
- Parameters:
transform_mat (torch.tensor) – The transformation matrix.
hup (int) – The height upperbound.
wup (int) – The width upperbound.
depth (int) – The depth.
- move(x=0, y=0, z=0)[source]#
Move the neurons in the 3D space.
- Parameters:
x (int or float) – The displacement in x axis.
y (int or float) – The displacement in y axis.
z (int or float) – The displacement in z axis.
- Returns:
The modified NeuronDimension.
- Return type:
- scale(x=1, y=1, z=1)[source]#
Scale the neuron grid in the 3D space.
- Parameters:
x (int or float) – The stretch in x axis.
y (int or float) – The stretch in y axis.
z (int or float) – The stretch in z axis.
- Returns:
The modified NeuronDimension.
- Return type:
- noise(x_noise=1, y_noise=1, z_noise=1)[source]#
Apply random noise to neuron coordinates.
- Parameters:
x (int or float) – The noise bounds in x axis.
y (int or float) – The noise bounds in y axis.
z (int or float) – The noise bounds in z axis.
- Returns:
The modified NeuronDimension.
- Return type:
- rotate(axis, angle)[source]#
Rotate the NeuronGroup in space.
- Parameters:
axis (int) – The axis along which the rotation is made.
angle (float) – The angle to rotate in radians.
- Returns:
The modified NeuronDimension.
- Return type:
- stretch_to_equal_size(target_neurons)[source]#
Stretch to NeuronGroup to match a target NeuronGroup dimensions.
- Parameters:
target_neurons (NeuronGroup) – The target NeuronGroup.
- initialize(neurons)[source]#
Sets the variables of the object. This method is called by the Network class when the object is added to the network.
Note: All sub-classes of Behavior overriding this method should call the super method to ensure everything is placed on the correct device.
- Parameters:
object (TaggableObject) – Object possessing the behavior.
Basics#
- class pymonntorch.NetworkBehavior.Basics.BasicHomeostasis.InstantHomeostasis(*args, min_th=None, max_th=None, threshold=None, gap_percent=None, distance_sensitive=True, inc=1.0, dec=1.0, adj_strength=1.0, adjustment_param=None, measurement_param=None, measurement_min=None, measurement_max=None, target_clip_min=None, target_clip_max=None, **kwargs)[source]#
- initialize(object)[source]#
Sets the variables of the object. This method is called by the Network class when the object is added to the network.
Note: All sub-classes of Behavior overriding this method should call the super method to ensure everything is placed on the correct device.
- Parameters:
object (TaggableObject) – Object possessing the behavior.
- forward(object)[source]#
Forward pass of the behavior. This method is called by the Network class per simulation iteration.
- Parameters:
object (TaggableObject) – Object possessing the behavior.
- class pymonntorch.NetworkBehavior.Basics.BasicHomeostasis.TimeIntegratedHomeostasis(*args, min_th=None, max_th=None, threshold=None, gap_percent=None, distance_sensitive=True, inc=1.0, dec=1.0, adj_strength=1.0, adjustment_param=None, measurement_param=None, measurement_min=None, measurement_max=None, target_clip_min=None, target_clip_max=None, integration_length=1, init_avg=None, **kwargs)[source]#
- initialize(object)[source]#
Sets the variables of the object. This method is called by the Network class when the object is added to the network.
Note: All sub-classes of Behavior overriding this method should call the super method to ensure everything is placed on the correct device.
- Parameters:
object (TaggableObject) – Object possessing the behavior.
- class pymonntorch.NetworkBehavior.Basics.Normalization.SynapticNormalization(*args, synapse_type='glutamate', norm_factor=1.0, **kwargs)[source]#
- initialize(neurons)[source]#
Sets the variables of the object. This method is called by the Network class when the object is added to the network.
Note: All sub-classes of Behavior overriding this method should call the super method to ensure everything is placed on the correct device.
- Parameters:
object (TaggableObject) – Object possessing the behavior.
- forward(neurons)[source]#
Forward pass of the behavior. This method is called by the Network class per simulation iteration.
- Parameters:
object (TaggableObject) – Object possessing the behavior.