src.canns.models.basic.cann

Classes

BaseCANN

Base class for Continuous Attractor Neural Network (CANN) models.

BaseCANN1D

Base class for 1D Continuous Attractor Neural Network (CANN) models.

BaseCANN2D

Base class for 2D Continuous Attractor Neural Network (CANN) models.

CANN1D

A standard 1D Continuous Attractor Neural Network (CANN) model.

CANN1D_SFA

A 1D CANN model that incorporates Spike-Frequency Adaptation (SFA).

CANN2D

A 2D Continuous Attractor Neural Network (CANN) model.

CANN2D_SFA

A 2D Continuous Attractor Neural Network (CANN) model with a specific

Module Contents

class src.canns.models.basic.cann.BaseCANN(shape, **kwargs)[source]

Bases: src.canns.models.basic._base.BasicModel

Base class for Continuous Attractor Neural Network (CANN) models. This class sets up the fundamental properties of the network, including neuronal properties, feature space, and the connectivity matrix, which are shared by different CANN model variations.

Initializes the base CANN model.

Parameters:
  • shape (int or tuple) – The number of neurons in the network. If an int is provided, it will be converted to a single-element tuple. If a tuple is provided, it defines the shape of the network (e.g., (length, length) for 2D). Internally, shape is always stored as a tuple.

  • **kwargs – Additional keyword arguments passed to the parent BasicModel.

abstractmethod get_stimulus_by_pos(pos)[source]

Generates an external stimulus based on a given position in the feature space. This method should be implemented in subclasses to define how the stimulus is shaped.

Parameters:

pos (float or Array) – The position in the feature space where the stimulus is centered.

Returns:

An array of stimulus values for each neuron.

Return type:

Array

abstractmethod make_conn()[source]

Constructs the connectivity matrix for the CANN model. This method should be implemented in subclasses to define how neurons are connected based on their feature preferences.

Returns:

A connectivity matrix defining the synaptic strengths between neurons.

Return type:

Array

class src.canns.models.basic.cann.BaseCANN1D(num, tau=1.0, k=8.1, a=0.5, A=10, J0=4.0, z_min=-bm.pi, z_max=bm.pi, **kwargs)[source]

Bases: BaseCANN

Base class for 1D Continuous Attractor Neural Network (CANN) models. This class sets up the fundamental properties of the network, including neuronal properties, feature space, and the connectivity matrix, which are shared by different CANN model variations.

Initializes the base 1D CANN model.

Parameters:
  • num (int) – The number of neurons in the network.

  • tau (float) – The synaptic time constant, controlling how quickly the membrane potential changes.

  • k (float) – A parameter controlling the strength of the global inhibition.

  • a (float) – The half-width of the excitatory connection range. It defines the “spread” of local connections.

  • A (float) – The magnitude (amplitude) of the external stimulus.

  • J0 (float) – The maximum connection strength between neurons.

  • z_min (float) – The minimum value of the feature space (e.g., -pi for an angle).

  • z_max (float) – The maximum value of the feature space (e.g., +pi for an angle).

  • **kwargs – Additional keyword arguments passed to the parent BasicModel.

dist(d)[source]

Calculates the shortest distance between two points in a circular feature space with periodic boundary conditions.

Parameters:

d (Array) – The difference between two positions.

Returns:

The shortest distance, wrapped around the periodic boundary.

Return type:

Array

get_stimulus_by_pos(pos)[source]

Generates a Gaussian-shaped external stimulus centered at a given position.

Parameters:

pos (float) – The center position of the stimulus in the feature space.

Returns:

An array of stimulus values for each neuron.

Return type:

Array

make_conn()[source]

Constructs the connectivity matrix based on a Gaussian-like profile. The connection strength between two neurons depends on the distance between their preferred feature values in the circular space.

Returns:

A (num x num) connectivity matrix.

Return type:

Array

A = 10[source]
J0 = 4.0[source]
a = 0.5[source]
conn_mat[source]
dx[source]
k = 8.1[source]
rho[source]
tau = 1.0[source]
x[source]
z_max[source]
z_min[source]
z_range[source]
class src.canns.models.basic.cann.BaseCANN2D(length, tau=1.0, k=8.1, a=0.5, A=10, J0=4.0, z_min=-bm.pi, z_max=bm.pi, **kwargs)[source]

Bases: BaseCANN

Base class for 2D Continuous Attractor Neural Network (CANN) models. This class sets up the fundamental properties of the network, including neuronal properties, feature space, and the connectivity matrix, which are shared by different CANN model variations.

Initializes the base 2D CANN model.

Parameters:
  • length (int) – The number of neurons in one dimension of the network (the network is square).

  • tau (float) – The synaptic time constant, controlling how quickly the membrane potential changes.

  • k (float) – A parameter controlling the strength of the global inhibition.

  • a (float) – The half-width of the excitatory connection range. It defines the “spread” of local connections.

  • A (float) – The magnitude (amplitude) of the external stimulus.

  • J0 (float) – The maximum connection strength between neurons.

  • z_min (float) – The minimum value of the feature space (e.g., -pi for an angle).

  • z_max (float) – The maximum value of the feature space (e.g., +pi for an angle).

  • **kwargs – Additional keyword arguments passed to the parent BasicModel.

dist(d)[source]

Calculates the shortest distance vector between two points in a 2D feature space with periodic boundary conditions (a torus).

Parameters:

d (Array) – The difference vector between two positions, e.g., [dx, dy].

Returns:

The shortest distance vector, with each component wrapped around

the periodic boundary.

Return type:

Array

get_stimulus_by_pos(pos)[source]

Generates a Gaussian-shaped external stimulus centered at a given coordinate on the 2D neural grid.

Parameters:

pos (Array, tuple) – The center coordinate [x, y] of the stimulus in the feature space.

Returns:

A 2D array (grid) of stimulus values for each neuron.

Return type:

Array

make_conn()[source]

Constructs the connectivity matrix for a 2D grid of neurons based on a Gaussian profile. The connection strength between two neurons depends on the Euclidean distance between their preferred feature coordinates in a 2D toroidal space (space with periodic boundaries in both dimensions).

Returns:

A ((num*num) x (num*num)) connectivity matrix.

Return type:

Array

show_conn()[source]

Displays the connectivity matrix as an image. This method visualizes the connection strengths between neurons in the 2D feature space.

A = 10[source]
J0 = 4.0[source]
a = 0.5[source]
conn_mat[source]
dx[source]
k = 8.1[source]
length[source]
rho[source]
tau = 1.0[source]
x[source]
z_max[source]
z_min[source]
z_range[source]
class src.canns.models.basic.cann.CANN1D(*args, **kwargs)[source]

Bases: BaseCANN1D

A standard 1D Continuous Attractor Neural Network (CANN) model. This model implements the core dynamics where a localized “bump” of activity can be sustained and moved by external inputs.

Reference:

Wu, S., Hamaguchi, K., & Amari, S. I. (2008). Dynamics and computation of continuous attractors. Neural computation, 20(4), 994-1025.

Initializes the 1D CANN model.

Parameters:

BaseCANN1D) ((Parameters are inherited from)

update(inp)[source]

The main update function, defining the dynamics of the network for one time step.

Parameters:

inp (Array) – The external input for the current time step.

inp[source]
r[source]
u[source]
class src.canns.models.basic.cann.CANN1D_SFA(num, tau=1.0, tau_v=50.0, k=8.1, a=0.3, A=0.2, J0=1.0, z_min=-bm.pi, z_max=bm.pi, m=0.3, **kwargs)[source]

Bases: BaseCANN1D

A 1D CANN model that incorporates Spike-Frequency Adaptation (SFA). SFA is a slow negative feedback mechanism that causes neurons to fire less over time for a sustained input, which can induce anticipative tracking behavior.

Reference:

Mi, Y., Fung, C. C., Wong, K. Y., & Wu, S. (2014). Spike frequency adaptation implements anticipative tracking in continuous attractor neural networks. Advances in neural information processing systems, 27.

Initializes the 1D CANN model with SFA.

Parameters:
  • tau_v (float) – The time constant for the adaptation variable ‘v’. A larger value means slower adaptation.

  • m (float) – The strength of the adaptation, coupling the membrane potential ‘u’ to the adaptation variable ‘v’.

  • BaseCANN1D) ((Other parameters are inherited from)

update(inp)[source]

The main update function for the SFA model. It includes dynamics for both the membrane potential and the adaptation variable.

Parameters:

inp (Array) – The external input for the current time step.

inp[source]
m = 0.3[source]
r[source]
tau_v = 50.0[source]
u[source]
v[source]
class src.canns.models.basic.cann.CANN2D(*args, **kwargs)[source]

Bases: BaseCANN2D

A 2D Continuous Attractor Neural Network (CANN) model. This model extends the base CANN2D class to include specific dynamics and properties for a 2D neural network.

Reference:

Wu, S., Hamaguchi, K., & Amari, S. I. (2008). Dynamics and computation of continuous attractors. Neural computation, 20(4), 994-1025.

Initializes the 2D CANN model.

Parameters:

BaseCANN2D) ((Parameters are inherited from)

update(inp)[source]

The main update function, defining the dynamics of the network for one time step.

Parameters:

inp (Array) – The external input to the network, which can be a stimulus or other driving force.

inp[source]
r[source]
u[source]
class src.canns.models.basic.cann.CANN2D_SFA(length, tau=1.0, tau_v=50.0, k=8.1, a=0.3, A=0.2, J0=1.0, z_min=-bm.pi, z_max=bm.pi, m=0.3, **kwargs)[source]

Bases: BaseCANN2D

A 2D Continuous Attractor Neural Network (CANN) model with a specific implementation of the Synaptic Firing Activity (SFA) dynamics. This model extends the base CANN2D class to include SFA-specific dynamics.

Initializes the 2D CANN model with SFA dynamics.

update(inp)[source]

The main update function for the SFA model. It includes dynamics for both the membrane potential and the adaptation variable.

Parameters:

inp (Array) – The external input for the current time step.

inp[source]
m = 0.3[source]
r[source]
tau_v = 50.0[source]
u[source]
v[source]