src.canns.models.basic.hierarchical_model¶
Classes¶
A model of a band cell module for path integration. |
|
A model of recurrently connected units with Gaussian connectivity. |
|
A model of a grid cell module using a 2D continuous attractor network. |
|
A full hierarchical network composed of multiple grid modules. |
|
A hierarchical model combining band cells and grid cells for path integration. |
|
A model of non-recurrently connected units. |
Module Contents¶
- class src.canns.models.basic.hierarchical_model.BandCell(angle, spacing, size=180, z_min=-bm.pi, z_max=bm.pi, noise=2.0, w_L2S=0.2, w_S2L=1.0, gain=0.2, gauss_tau=1.0, gauss_J0=1.1, gauss_k=0.0005, gauss_a=2 / 9 * bm.pi, nonrec_tau=0.1, **kwargs)[source]¶
Bases:
src.canns.models.basic._base.BasicModelA model of a band cell module for path integration.
This model represents a set of neurons whose receptive fields form parallel bands across a 2D space. It is composed of a central GaussRecUnits attractor network (the band cells proper) that represents a 1D phase, and two NonRecUnits populations (left and right) that help shift the activity in the attractor network based on velocity input. This mechanism allows the module to integrate the component of velocity along its preferred direction.
- proj_k[source]¶
The projection vector for converting 2D position/velocity to 1D phase.
- Type:
bm.math.ndarray
Initializes the BandCell model.
- Parameters:
angle (float) – The orientation angle of the bands.
spacing (float) – The spacing between the bands.
size (int, optional) – The number of neurons in each group. Defaults to 180.
z_min (float, optional) – The minimum value of the feature space (phase). Defaults to -pi.
z_max (float, optional) – The maximum value of the feature space (phase). Defaults to pi.
noise (float, optional) – The noise level for the neuron groups. Defaults to 2.0.
w_L2S (float, optional) – Weight from band cells to shifter units. Defaults to 0.2.
w_S2L (float, optional) – Weight from shifter units to band cells. Defaults to 1.0.
gain (float, optional) – A gain factor for the velocity signal. Defaults to 0.2.
gauss_tau (float, optional) – Time constant for GaussRecUnits. Defaults to 1.0.
gauss_J0 (float, optional) – Connection strength scaling factor for GaussRecUnits. Defaults to 1.1.
gauss_k (float, optional) – Global inhibition strength for GaussRecUnits. Defaults to 5e-4.
gauss_a (float, optional) – Gaussian connection width for GaussRecUnits. Defaults to 2/9*pi.
nonrec_tau (float, optional) – Time constant for NonRecUnits. Defaults to 0.1.
**kwargs – Additional keyword arguments for the base class.
- Postophase(pos)[source]¶
Projects a 2D position to a 1D phase.
This function converts a 2D coordinate in the environment into a 1D phase value based on the band cell’s preferred angle and spacing.
- Parameters:
pos (Array) – The 2D position vector.
- Returns:
The corresponding 1D phase.
- Return type:
- dist(d)[source]¶
Calculates the periodic distance in the feature space.
- Parameters:
d (Array) – The array of distances.
- Returns:
The wrapped distances.
- Return type:
Array
- get_stimulus_by_pos(pos)[source]¶
Generates a stimulus input based on a 2D position.
This creates a Gaussian bump of input centered on the phase corresponding to the given position, which can be used to anchor the network’s activity.
- Parameters:
pos (Array) – The 2D position vector.
- Returns:
The stimulus input vector for the band cells.
- Return type:
Array
- make_conn(shift)[source]¶
Creates a shifted Gaussian connection profile.
This is used to create the connections from the left/right shifter units to the band cells, which implements the bump-shifting mechanism.
- Parameters:
shift (float) – The amount to shift the connection profile by.
- Returns:
The shifted connection matrix.
- Return type:
Array
- move_heading(shift)[source]¶
Manually shifts the activity bump in the band cells.
This is a utility function for testing purposes.
- Parameters:
shift (int) – The number of neurons to roll the activity by.
- synapses()[source]¶
Defines the synaptic connections between the neuron groups.
This method sets up the shifted connections from the left/right shifter populations to the central band cell attractor network, as well as the one-to-one connections from the band cells to the shifters.
- update(velocity, loc, loc_input_stre)[source]¶
Updates the BandCell module for one time step.
It integrates the component of velocity along the module’s preferred direction to update the phase representation. The activity bump is shifted by modulating the inputs from the left/right shifter populations. It can also incorporate a direct location-based input.
- Parameters:
velocity (Array) – The 2D velocity vector.
loc (Array) – The current 2D location.
loc_input_stre (float) – The strength of the location-based input.
- class src.canns.models.basic.hierarchical_model.GaussRecUnits(size, tau=1.0, J0=1.1, k=0.0005, a=2 / 9 * bm.pi, z_min=-bm.pi, z_max=bm.pi, noise=2.0)[source]¶
Bases:
src.canns.models.basic._base.BasicModelA model of recurrently connected units with Gaussian connectivity.
This class implements a 1D continuous attractor neural network (CANN). The network maintains a stable “bump” of activity that can represent a continuous variable, such as heading direction. The connectivity between neurons is Gaussian, and the network dynamics include divisive normalization.
Initializes the GaussRecUnits model.
- Parameters:
size (int) – The number of neurons in the network.
tau (float, optional) – The time constant of the neurons. Defaults to 1.0.
J0 (float, optional) – A scaling factor for the critical connection strength. Defaults to 1.1.
k (float, optional) – The strength of the global inhibition. Defaults to 5e-4.
a (float, optional) – The width of the Gaussian connection profile. Defaults to 2/9*pi.
z_min (float, optional) – The minimum value of the feature space. Defaults to -pi.
z_max (float, optional) – The maximum value of the feature space. Defaults to pi.
noise (float, optional) – The level of noise in the system. Defaults to 2.0.
- Jc()[source]¶
Calculates the critical connection strength.
This is the minimum connection strength required to sustain a stable activity bump in the attractor network.
- decode(r, axis=0)[source]¶
Decodes the center of the activity bump.
This method uses a population vector average to compute the center of the neural activity bump from the firing rates.
- dist(d)[source]¶
Calculates the periodic distance in the feature space.
This function wraps distances to ensure they fall within the periodic boundaries of the feature space, i.e., [-z_range/2, z_range/2].
- Parameters:
d (bm.math.ndarray) – The array of distances.
- class src.canns.models.basic.hierarchical_model.GridCell(num, angle, spacing, tau=0.1, tau_v=10.0, k=0.005, a=bm.pi / 9, A=1.0, J0=1.0, mbar=1.0)[source]¶
Bases:
src.canns.models.basic._base.BasicModelA model of a grid cell module using a 2D continuous attractor network.
This class implements a 2D continuous attractor network on a toroidal manifold to model the firing patterns of grid cells. The network dynamics include synaptic depression or adaptation, which helps stabilize the activity bumps. The connectivity is defined on a hexagonal grid structure.
Initializes the GridCell model.
- Parameters:
num (int) – The number of neurons along one dimension of the square grid.
angle (float) – The orientation angle of the grid pattern.
spacing (float) – The spacing of the grid pattern.
tau (float, optional) – The synaptic time constant. Defaults to 0.1.
tau_v (float, optional) – The adaptation time constant. Defaults to 10.0.
k (float, optional) – The strength of global inhibition. Defaults to 5e-3.
a (float, optional) – The width of the connection profile. Defaults to pi/9.
A (float, optional) – The magnitude of external input. Defaults to 1.0.
J0 (float, optional) – The maximum connection strength. Defaults to 1.0.
mbar (float, optional) – The base strength of adaptation. Defaults to 1.0.
- circle_period(d)[source]¶
Wraps values into the periodic range [-pi, pi].
- Parameters:
d (Array) – The input values.
- Returns:
The wrapped values.
- Return type:
Array
- dist(d)[source]¶
Calculates the distance on the hexagonal grid.
It first maps the periodic difference vector d into a Cartesian coordinate system that reflects the hexagonal lattice structure and then computes the Euclidean distance.
- Parameters:
d (Array) – An array of difference vectors in the phase space.
- Returns:
The corresponding distances on the hexagonal lattice.
- Return type:
Array
- get_center()[source]¶
Decodes and updates the 2D center of the activity bump.
It uses a population vector average for both the x and y dimensions of the phase space.
- class src.canns.models.basic.hierarchical_model.HierarchicalNetwork(num_module, num_place, spacing_min=2.0, spacing_max=5.0, module_angle=0.0, band_size=180, band_noise=0.0, band_w_L2S=0.2, band_w_S2L=1.0, band_gain=0.2, grid_num=20, grid_tau=0.1, grid_tau_v=10.0, grid_k=0.005, grid_a=bm.pi / 9, grid_A=1.0, grid_J0=1.0, grid_mbar=1.0, gauss_tau=1.0, gauss_J0=1.1, gauss_k=0.0005, gauss_a=2 / 9 * bm.pi, nonrec_tau=0.1)[source]¶
Bases:
src.canns.models.basic._base.BasicModelGroupA full hierarchical network composed of multiple grid modules.
This class creates and manages a collection of HierarchicalPathIntegrationModel modules, each with a different grid spacing. By combining the outputs of these modules, the network can represent position unambiguously over a large area. The final output is a population of place cells whose activities are used to decode the animal’s estimated position.
References
Anonymous Author(s) “Unfolding the Black Box of Recurrent Neural Networks for Path Integration” (under review).
Initializes the HierarchicalNetwork.
- Parameters:
num_module (int) – The number of grid modules to create.
num_place (int) – The number of place cells along one dimension of a square grid.
spacing_min (float, optional) – Minimum spacing for grid modules. Defaults to 2.0.
spacing_max (float, optional) – Maximum spacing for grid modules. Defaults to 5.0.
module_angle (float, optional) – Base orientation angle for all modules. Defaults to 0.0.
band_size (int, optional) – Number of neurons in each BandCell group. Defaults to 180.
band_noise (float, optional) – Noise level for BandCells. Defaults to 0.0.
band_w_L2S (float, optional) – Weight from band cells to shifter units. Defaults to 0.2.
band_w_S2L (float, optional) – Weight from shifter units to band cells. Defaults to 1.0.
band_gain (float, optional) – Gain factor for velocity signal in BandCells. Defaults to 0.2.
grid_num (int, optional) – Number of neurons per dimension for GridCell. Defaults to 20.
grid_tau (float, optional) – Synaptic time constant for GridCell. Defaults to 0.1.
grid_tau_v (float, optional) – Adaptation time constant for GridCell. Defaults to 10.0.
grid_k (float, optional) – Global inhibition strength for GridCell. Defaults to 5e-3.
grid_a (float, optional) – Connection width for GridCell. Defaults to pi/9.
grid_A (float, optional) – External input magnitude for GridCell. Defaults to 1.0.
grid_J0 (float, optional) – Maximum connection strength for GridCell. Defaults to 1.0.
grid_mbar (float, optional) – Base adaptation strength for GridCell. Defaults to 1.0.
gauss_tau (float, optional) – Time constant for GaussRecUnits in BandCells. Defaults to 1.0.
gauss_J0 (float, optional) – Connection strength scaling for GaussRecUnits. Defaults to 1.1.
gauss_k (float, optional) – Global inhibition for GaussRecUnits. Defaults to 5e-4.
gauss_a (float, optional) – Connection width for GaussRecUnits. Defaults to 2/9*pi.
nonrec_tau (float, optional) – Time constant for NonRecUnits in BandCells. Defaults to 0.1.
- class src.canns.models.basic.hierarchical_model.HierarchicalPathIntegrationModel(spacing, angle, place_center=None, band_size=180, band_noise=0.0, band_w_L2S=0.2, band_w_S2L=1.0, band_gain=0.2, grid_num=20, grid_tau=0.1, grid_tau_v=10.0, grid_k=0.005, grid_a=bm.pi / 9, grid_A=1.0, grid_J0=1.0, grid_mbar=1.0, gauss_tau=1.0, gauss_J0=1.1, gauss_k=0.0005, gauss_a=2 / 9 * bm.pi, nonrec_tau=0.1)[source]¶
Bases:
src.canns.models.basic._base.BasicModelGroupA hierarchical model combining band cells and grid cells for path integration.
This model forms a single grid module. It consists of three BandCell modules, each with a different preferred orientation (separated by 60 degrees), and one GridCell module. The band cells integrate velocity along their respective directions, and their combined outputs provide the input to the GridCell network, effectively driving the grid cell’s activity bump. The model can also project its grid cell activity to a population of place cells.
- Wg2p¶
The connection weights from grid cells to place cells.
- Type:
bm.math.ndarray
Initializes the HierarchicalPathIntegrationModel.
- Parameters:
spacing (float) – The spacing of the grid pattern for this module.
angle (float) – The base orientation angle for the module.
place_center (bm.math.ndarray, optional) – The center locations of the target place cell population. Defaults to a random distribution.
band_size (int, optional) – Number of neurons in each BandCell group. Defaults to 180.
band_noise (float, optional) – Noise level for BandCells. Defaults to 0.0.
band_w_L2S (float, optional) – Weight from band cells to shifter units. Defaults to 0.2.
band_w_S2L (float, optional) – Weight from shifter units to band cells. Defaults to 1.0.
band_gain (float, optional) – Gain factor for velocity signal in BandCells. Defaults to 0.2.
grid_num (int, optional) – Number of neurons per dimension for GridCell. Defaults to 20.
grid_tau (float, optional) – Synaptic time constant for GridCell. Defaults to 0.1.
grid_tau_v (float, optional) – Adaptation time constant for GridCell. Defaults to 10.0.
grid_k (float, optional) – Global inhibition strength for GridCell. Defaults to 5e-3.
grid_a (float, optional) – Connection width for GridCell. Defaults to pi/9.
grid_A (float, optional) – External input magnitude for GridCell. Defaults to 1.0.
grid_J0 (float, optional) – Maximum connection strength for GridCell. Defaults to 1.0.
grid_mbar (float, optional) – Base adaptation strength for GridCell. Defaults to 1.0.
gauss_tau (float, optional) – Time constant for GaussRecUnits in BandCells. Defaults to 1.0.
gauss_J0 (float, optional) – Connection strength scaling for GaussRecUnits. Defaults to 1.1.
gauss_k (float, optional) – Global inhibition for GaussRecUnits. Defaults to 5e-4.
gauss_a (float, optional) – Connection width for GaussRecUnits. Defaults to 2/9*pi.
nonrec_tau (float, optional) – Time constant for NonRecUnits in BandCells. Defaults to 0.1.
- Postophase(pos)[source]¶
Projects a 2D position to the 2D phase space of the grid module.
- Parameters:
pos (Array) – The 2D position vector.
- Returns:
The corresponding 2D phase vector.
- Return type:
Array
- dist(d)[source]¶
Calculates the distance on the hexagonal grid.
- Parameters:
d (Array) – An array of difference vectors in the phase space.
- Returns:
The corresponding distances on the hexagonal lattice.
- Return type:
Array
- get_input(Phase)[source]¶
Generates a stimulus input for the grid cell based on a 2D phase.
- Parameters:
Phase (Array) – The 2D phase vector.
- Returns:
The stimulus input vector for the grid cells.
- Return type:
Array
- make_Wg2p()[source]¶
Creates the connection weights from grid cells to place cells.
The connection strength is determined by the proximity of a place cell’s center to a grid cell’s firing field, calculated in the phase domain.
- class src.canns.models.basic.hierarchical_model.NonRecUnits(size, tau=0.1, z_min=-bm.pi, z_max=bm.pi, noise=2.0)[source]¶
Bases:
src.canns.models.basic._base.BasicModelA model of non-recurrently connected units.
This class implements a simple leaky integrator model for a population of neurons that do not have recurrent connections among themselves. They respond to external inputs and have a non-linear activation function.
Initializes the NonRecUnits model.
- Parameters:
size (int) – The number of neurons.
tau (float, optional) – The time constant of the neurons. Defaults to 0.1.
z_min (float, optional) – The minimum value of the feature space. Defaults to -pi.
z_max (float, optional) – The maximum value of the feature space. Defaults to pi.
noise (float, optional) – The level of noise in the system. Defaults to 2.0.
- activate(x)[source]¶
Applies an activation function to the input.
- Parameters:
x (Array) – The input to the activation function (e.g., synaptic input u).
- Returns:
The result of the activation function (ReLU).
- Return type:
Array