Reference

SORN Network

Sorn

The following methods are available via SORN

class sorn.sorn.Sorn[source]

This class wraps initialization of the network and its parameters

eta_inhib = 0.001
eta_ip = 0.01
eta_stdp = 0.004
static initialize_activity_vector(ne: int, ni: int)[source]

Initialize the activity vectors X and Y for excitatory and inhibitory neurons

Parameters:
  • ne (int) – Number of excitatory neurons

  • ni (int) – Number of inhibitory neurons

Returns:

Array of activity vectors of excitatory population y (array): Array of activity vectors of inhibitory population

Return type:

x (array)

static initialize_threshold_matrix(te_min: float, te_max: float, ti_min: float, ti_max: float)[source]

Initialize the threshold for excitatory and inhibitory neurons

Parameters:
  • te_min (float) – Min threshold value for excitatory units

  • te_max (float) – Min threshold value for inhibitory units

  • ti_min (float) – Max threshold value for excitatory units

  • ti_max (float) – Max threshold value for inhibitory units

Returns:

Threshold values for excitatory units ti (array): Threshold values for inhibitory units

Return type:

te (array)

static initialize_weight_matrix(network_type: str, synaptic_connection: str, self_connection: str, lambd_w: int)[source]

Wrapper for initializing the weight matrices for SORN

Parameters:
  • network_type (str) – Spare or Dense

  • synaptic_connection (str) – EE,EI,IE. Note that Spare connection is defined only for EE connections

  • self_connection (str) – True or False: Synaptic delay or time delay

  • lambd_w (int) – Average number of incoming and outgoing connections per neuron

Returns:

Array of connection strengths

Return type:

weight_matrix (array)

lambda_ee = 20
lambda_ei = 40
lambda_ie = 100
mu_ip = 0.1
ne = 200
network_type_ee = 'Sparse'
network_type_ei = 'Sparse'
network_type_ie = 'Dense'
ni = 40
nu = 10
sigma_ip = 0.0
te_max = 1.0
te_min = 0.0
ti_max = 0.5
ti_min = 0.0

Plasticity

The following methods are available via Plasticity

class sorn.sorn.Plasticity[source]

Instance of class Sorn. Inherits the variables and functions defined in class Sorn. It encapsulates all plasticity mechanisms mentioned in the article. Inherits all attributed from parent class Sorn

static initialize_plasticity()[source]

Initialize weight matrices for plasticity phase based on network configuration

Parameters:

kwargs (self.__dict__) – All arguments are inherited from Sorn attributes

Returns:

Weight matrices WEI, WEE, WIE and threshold matrices Te, Ti and Initial state vectors X,Y

Return type:

tuple(array)

ip(te: array, x: array)[source]

Intrinsic Plasiticity mechanism :param te: Threshold vector of excitatory units :type te: array :param x: Excitatory network activity :type x: array

Returns:

Threshold vector of excitatory units

Return type:

te (array)

istdp(wei: array, x: array, y: array, cutoff_weights: list)[source]

Apply iSTDP rule, which regulates synaptic strength between the pre inhibitory(Xj) and post Excitatory(Xi) synaptic neurons :param wei: Synaptic strengths from inhibitory to excitatory :type wei: array :param x: Excitatory network activity :type x: array :param y: Inhibitory network activity :type y: array :param cutoff_weights: Maximum and minimum weight ranges :type cutoff_weights: list

Returns:

Synaptic strengths from inhibitory to excitatory

Return type:

wei (array)

static ss(wee: array)[source]

Synaptic Scaling or Synaptic Normalization :param wee: Weight matrix :type wee: array

Returns:

Scaled Weight matrix

Return type:

wee (array)

stdp(wee: array, x: array, cutoff_weights: list)[source]

Apply STDP rule : Regulates synaptic strength between the pre(Xj) and post(Xi) synaptic neurons :param wee: Weight matrix :type wee: array :param x: Excitatory network activity :type x: array :param cutoff_weights: Maximum and minimum weight ranges :type cutoff_weights: list

Returns:

Weight matrix

Return type:

wee (array)

static structural_plasticity(wee: array)[source]

Add new connection value to the smallest weight between excitatory units randomly :param wee: Weight matrix :type wee: array

Returns:

Weight matrix

Return type:

wee (array)

MatrixCollection

The following methods are available via MatrixCollection

class sorn.sorn.MatrixCollection(phase: str, state: dict | None = None)[source]

Collect all matrices initialized and updated during simulation(plasiticity and training phases)

Parameters:
  • phase (str) – Training or Plasticity phase

  • state (dict) – Network activity, threshold and connection matrices

Returns:

MatrixCollection instance

network_activity_t(excitatory_net: array, inhibitory_net: array, i: int)[source]

Network state at current time step

Parameters:
  • excitatory_net (array) – Excitatory network activity

  • inhibitory_net (array) – Inhibitory network activity

  • i (int) – Time step

Returns:

Updated Excitatory and Inhibitory states

Return type:

tuple(array)

network_activity_t_1(x: array, y: array, i: int)[source]

Network activity at previous time step

Parameters:
  • x (array) – Excitatory network activity

  • y (array) – Inhibitory network activity

  • i (int) – Time step

Returns:

Previous Excitatory and Inhibitory states

Return type:

tuple(array)

threshold_matrix(te: array, ti: array, i: int)[source]

Update threshold matrices

Parameters:
  • te (array) – Excitatory threshold

  • ti (array) – Inhibitory threshold

  • i (int) – Time step

Returns:

Threshold Matrices Te and Ti

Return type:

tuple(array)

weight_matrix(wee: array, wei: array, wie: array, i: int)[source]

Update weight matrices

Parameters:
  • wee (array) – Excitatory-Excitatory weight matrix

  • wei (array) – Inhibitory-Excitatory weight matrix

  • wie (array) – Excitatory-Inhibitory weight matrix

  • i (int) – Time step

Returns:

Weight Matrices Wee, Wei, Wie

Return type:

tuple(array)

NetworkState

The following methods are available via NetworkState

class sorn.sorn.NetworkState(v_t: array)[source]

The evolution of network states

Parameters:

v_t (array) – External input/stimuli

Returns:

NetworkState instance

Return type:

instance(object)

excitatory_network_state(wee: array, wei: array, te: array, x: array, y: array, white_noise_e: array)[source]

Activity of Excitatory neurons in the network

Parameters:
  • wee (array) – Excitatory-Excitatory weight matrix

  • wei (array) – Inhibitory-Excitatory weight matrix

  • te (array) – Excitatory threshold

  • x (array) – Excitatory network activity

  • y (array) – Inhibitory network activity

  • white_noise_e (array) – Gaussian noise

Returns:

Current Excitatory network activity

Return type:

x(array)

incoming_drive(weights: array, activity_vector: array)[source]

Excitatory Post synaptic potential towards neurons in the reservoir in the absence of external input

Parameters:
  • weights (array) – Synaptic strengths

  • activity_vector (list) – Acitivity of inhibitory or Excitatory neurons

Returns:

Excitatory Post synaptic potential towards neurons

Return type:

incoming(array)

inhibitory_network_state(wie: array, ti: array, y: array, white_noise_i: array)[source]

Activity of Excitatory neurons in the network

Parameters:
  • wee (array) – Excitatory-Excitatory weight matrix

  • wie (array) – Excitatory-Inhibitory weight matrix

  • ti (array) – Inhibitory threshold

  • y (array) – Inhibitory network activity

  • white_noise_i (array) – Gaussian noise

Returns:

Current Inhibitory network activity

Return type:

y(array)

recurrent_drive(wee: array, wei: array, te: array, x: array, y: array, white_noise_e: array)[source]

Network state due to recurrent drive received by the each unit at time t+1. Activity of Excitatory neurons without external stimuli

Parameters:
  • wee (array) – Excitatory-Excitatory weight matrix

  • wei (array) – Inhibitory-Excitatory weight matrix

  • te (array) – Excitatory threshold

  • x (array) – Excitatory network activity

  • y (array) – Inhibitory network activity

  • white_noise_e (array) – Gaussian noise

Returns:

Recurrent network state

Return type:

xt(array)

Simulator

The following methods are available via Simulator_

class sorn.sorn.Simulator_[source]

Simulate SORN using external input/noise using the fresh or pretrained matrices

Parameters:
  • inputs (np.array, optional) – External stimuli. Defaults to None.

  • phase (str, optional) – Plasticity phase. Defaults to “plasticity”.

  • matrices (dict, optional) – Network states, connections and threshold matrices. Defaults to None.

  • timesteps (int, optional) – Total number of time steps to simulate the network. Defaults to 1.

  • noise (bool, optional) – If True, noise will be added. Defaults to True.

Returns:

Network states, connections and threshold matrices

X_all(array): Excitatory network activity collected during entire simulation steps

Y_all(array): Inhibitory network activity collected during entire simulation steps

R_all(array): Recurrent network activity collected during entire simulation steps

frac_pos_active_conn(list): Number of positive connection strengths in the network at each time step during simulation

Return type:

last_state(dict)

run(inputs: array | None = None, phase: str = 'plasticity', state: dict | None = None, timesteps: int | None = None, noise: bool = True, freeze: list | None = None, callbacks: list = [], **kwargs)[source]

Simulation/Plasticity phase

Parameters:
  • inputs (np.array, optional) – External stimuli. Defaults to None.

  • phase (str, optional) – Plasticity phase. Defaults to “plasticity”

  • state (dict, optional) – Network states, connections and threshold matrices. Defaults to None.

  • timesteps (int, optional) – Total number of time steps to simulate the network. Defaults to 1.

  • noise (bool, optional) – If True, noise will be added. Defaults to True.

  • freeze (list, optional) – List of synaptic plasticity mechanisms which will be turned off during simulation. Defaults to None.

  • callbacks (list, optional) – Requested values from [“ExcitatoryActivation”, “InhibitoryActivation”, “RecurrentActivation”, “WEE”, “WEI”, “TE”, “EEConnectionCounts”] collected and returned from the simulate sorn object.

Returns:

Network states, connections and threshold matrices

callback_values(dict): Requexted network parameters and activations

Return type:

last_state(dict)

update_callback_state(*args) None[source]

Trainer

The following methods are available via Trainer_

class sorn.sorn.Trainer_[source]

Train the network with the fresh or pretrained network matrices and external stimuli

run(inputs: array | None = None, phase: str = 'training', state: dict | None = None, timesteps: int | None = None, noise: bool = True, freeze: list | None = None, callbacks: list = [], **kwargs)[source]

Train the network with the fresh or pretrained network matrices and external stimuli

Args: inputs(np.array, optional): External stimuli. Defaults to None.

phase(str, optional): Training phase. Defaults to “training”.

state(dict, optional): Network states, connections and threshold matrices. Defaults to None.

timesteps(int, optional): Total number of time steps to simulate the network. Defaults to 1.

noise(bool, optional): If True, noise will be added. Defaults to True.

freeze(list, optional): List of synaptic plasticity mechanisms which will be turned off during simulation. Defaults to None.

max_workers(int, optional): Maximum workers for multhreading the plasticity steps

Returns:

Network states, connections and threshold matrices

X_all(array): Excitatory network activity collected during entire simulation steps

Y_all(array): Inhibitory network activity collected during entire simulation steps

R_all(array): Recurrent network activity collected during entire simulation steps

frac_pos_active_conn(list): Number of positive connection strengths in the network at each time step during simulation

Return type:

last_state(dict)

update_callback_state(*args) None[source]

Utility Functions

Plotting

The following methods are available via Plotter

class sorn.utils.Plotter[source]

Wrapper class to call plotting methods

static correlation(corr: array, savefig: bool)[source]

Plot correlation between neurons

Parameters:
  • corr (array) – Correlation matrix

  • savefig (bool) – If true will save the plot at the current working directory

Returns:

Neuron Correlation plot

Return type:

matplotlib.pyplot

static hamming_distance(hamming_dist: list, savefig: bool)[source]

Hamming distance between true netorks states and perturbed network states

Parameters:
  • hamming_dist (list) – Hamming distance values

  • savefig (bool) – If True, save the fig at current working directory

Returns:

Hamming distance between true and perturbed network states

Return type:

matplotlib.pyplot

static hist_firing_rate_network(spike_train: array, bin_size: int, savefig: bool)[source]

Plot the histogram of firing rate (total number of neurons spike at each time step)

Parameters:
  • spike_train (array) – Array of spike trains

  • bin_size (int) – Histogram bin size

  • savefig (bool) – If True, plot will be saved in the cwd

Returns:

plot object

static hist_incoming_conn(weights: array, bin_size: int, histtype: str, savefig: bool)[source]

Plot the histogram of number of presynaptic connections per neuron

Parameters:
  • weights (array) – Connection weights

  • bin_size (int) – Histogram bin size

  • histtype (str) – Same as histtype matplotlib

  • savefig (bool) – If True plot will be saved as png file in the cwd

Returns:

plot object

Return type:

plot (matplotlib.pyplot)

static hist_outgoing_conn(weights: array, bin_size: int, histtype: str, savefig: bool)[source]

Plot the histogram of number of incoming connections per neuron

Parameters:
  • weights (array) – Connection weights

  • bin_size (int) – Histogram bin size

  • histtype (str) – Same as histtype matplotlib

  • savefig (bool) – If True plot will be saved as png file in the cwd

Returns:

plot object

static isi_exponential_fit(spike_train: array, neuron: int, bin_size: int, savefig: bool)[source]

Plot Exponential fit on the inter-spike intervals during training or simulation phase

Parameters:
  • spike_train (array) – Array of spike trains

  • neuron (int) – Target neuron

  • bin_size (int) – Spike train will be splitted into bins of size bin_size

  • savefig (bool) – If True, plot will be saved in the cwd

Returns:

plot object

static linear_lognormal_fit(weights: array, num_points: int, savefig: bool)[source]

Lognormal curve fit on connection weight distribution

Parameters:
  • weights (array) – Connection weights

  • num_points (int) – Number of points to be plotted in the x axis

  • savefig (bool) – If True, plot will be saved in the cwd

Returns:

plot object

static network_connection_dynamics(connection_counts: array, savefig: bool)[source]

Plot number of positive connection in the excitatory pool

Parameters:
  • connection_counts (array)

  • savefig (bool)

Returns:

plot object

static plot_network(corr: array, corr_thres: float, fig_name: str | None = None)[source]

Network x graphical visualization of the network using the correlation matrix

Parameters:
  • corr (array) – Correlation between neurons

  • corr_thres (array) – Threshold to prune the connection. Smaller the threshold, higher the density of connections

  • fig_name (array, optional) – Name of the figure. Defaults to None.

Returns:

Plot instance

Return type:

matplotlib.pyplot

static raster_plot(spike_train: array, savefig: bool)[source]

Raster plot of spike trains

Parameters:
  • spike_train (array) – Array of spike trains

  • with_firing_rates (bool) – If True, firing rate of the network will be plotted

  • savefig (bool) – If True, plot will be saved in the cwd

Returns:

plot object

static scatter_plot(spike_train: array, savefig: bool)[source]

Scatter plot of spike trains

Parameters:
  • spike_train (list) – Array of spike trains

  • with_firing_rates (bool) – If True, firing rate of the network will be plotted

  • savefig (bool) – If True, plot will be saved in the cwd

Returns:

plot object

static weight_distribution(weights: array, bin_size: int, savefig: bool)[source]

Plot the distribution of synaptic weights

Parameters:
  • weights (array) – Connection weights

  • bin_size (int) – Spike train will be splited into bins of size bin_size

  • savefig (bool) – If True, plot will be saved in the cwd

Returns:

plot object

Statistics and Analysis

The following methods are available via Statistics

class sorn.utils.Statistics[source]

Wrapper class for statistical analysis methods

static autocorr(firing_rates: list, t: int = 2)[source]

Score interpretation - scores near 1 imply a smoothly varying series - scores near 0 imply that there’s no overall linear relationship between a data point and the following one (that is, plot(x[-length(x)],x[-1]) won’t give a scatter plot with any apparent linearity)

  • scores near -1 suggest that the series is jagged in a particular way: if one point is above the mean, the next is likely to be below the mean by about the same amount, and vice versa.

Parameters:
  • firing_rates (list) – Firing rates of the network

  • t (int, optional) – Window size. Defaults to 2.

Returns:

Autocorrelation between neurons given their firing rates

Return type:

array

static avg_corr_coeff(spike_train: array)[source]

Measure Average Pearson correlation coeffecient between neurons

Parameters:

spike_train (array) – Neural activity

Returns:

Average correlation coeffecient

Return type:

array

static fanofactor(spike_train: array, neuron: int, window_size: int)[source]

Investigate whether neuronal spike generation is a poisson process

Parameters:
  • spike_train (np.array) – Spike train of neurons in the reservoir

  • neuron (int) – Target neuron in the pool

  • window_size (int) – Sliding window size for time step ranges to be considered for measuring the fanofactor

Returns:

Fano factor of the neuron spike train

Return type:

float

static firing_rate_network(spike_train: array)[source]

Calculate number of neurons spikes at each time step.Firing rate of the network

Parameters:

spike_train (array) – Array of spike trains

Returns:

firing_rate

Return type:

int

static firing_rate_neuron(spike_train: array, neuron: int, bin_size: int)[source]

Measure spike rate of given neuron during given time window

Parameters:
  • spike_train (array) – Array of spike trains

  • neuron (int) – Target neuron in the reservoir

  • bin_size (int) – Divide the spike trains into bins of size bin_size

Returns:

firing_rate

Return type:

int

static hamming_distance(actual_spike_train: array, perturbed_spike_train: array)[source]

Hamming distance between true netorks states and perturbed network states

Parameters:
  • actual_spike_train (np.array) – True network’s states

  • perturbed_spike_train (np.array) – Perturbated network’s states

Returns:

Hamming distance between true and perturbed network states

Return type:

float

static scale_dependent_smoothness_measure(firing_rates: list)[source]

Smoothem the firing rate depend on its scale. Smaller values corresponds to smoother series

Parameters:

firing_rates (list) – List of number of active neurons per time step

Returns:

Float value signifies the smoothness of the semantic changes in firing rates

Return type:

sd_diff (list)

static scale_independent_smoothness_measure(firing_rates: list)[source]

Smoothem the firing rate independent of its scale. Smaller values corresponds to smoother series

Parameters:

firing_rates (list) – List of number of active neurons per time step

Returns:

Float value signifies the smoothness of the semantic changes in firing rates

Return type:

coeff_var (list)

static spike_source_entropy(spike_train: array, num_neurons: int)[source]

Measure the uncertainty about the origin of spike from the network using entropy

Parameters:
  • spike_train (np.array) – Spike train of neurons

  • num_neurons (int) – Number of neurons in the reservoir

Returns:

Spike source entropy of the network

Return type:

int

static spike_time_intervals(spike_train)[source]

Generate spike time intervals spike_trains

Parameters:

spike_train (array) – Network activity

Returns:

Inter spike intervals for each neuron in the reservoir

Return type:

list

static spike_times(spike_train: array)[source]

Get the time instants at which neuron spikes

Parameters:

spike_train (array) – Spike trains of neurons

Returns:

Spike time of each neurons in the pool

Return type:

(array)