Predictive Analysis

Analysis functions for predictive coding simulations

analysis_pred_utils.bin_pos(field, period=None, res=0.098125)

Bin position array deriver from spikes.

Parameters:
  • field (array-like) – Array of spike positions.

  • period (float, optional) – The period over which to bin the positions. Defaults to 2 * np.pi.

  • res (float, optional) – The resolution of the bins. Defaults to 0.098125.

Returns:

Binned positions

Return type:

numpy.ndarray

analysis_pred_utils.butter_lowpass(cutoff, fs, order=5)

Designs a lowpass Butterworth filter.

Parameters:
  • cutoff (float) – The cutoff frequency of the filter.

  • fs (float) – The sampling frequency of the signal.

  • order (int, optional) – The order of the filter. Default is 5.

Returns:

designed filter.

Return type:

ndarray

analysis_pred_utils.butter_lowpass_filter(data, cutoff, fs, order=5)

Apply a Butterworth lowpass filter to the given data.

Parameters:
  • data (array-like) – The input signal data to be filtered.

  • cutoff (float) – The cutoff frequency of the filter.

  • fs (float) – The sampling frequency of the input signal.

  • order (int, optional) – The order of the filter. Default is 5.

Returns:

The filtered signal.

Return type:

array-like

analysis_pred_utils.calc_bias_stell_intrnrn(stell_decoded, intrnrn_decoded, params, bounds)

Calculate the positional bias between stellate and and interneuron.

Here Interneuron is assumed to be the true position of the animal.

Parameters:
  • stell_decoded (np.ndarray) – Decoded signal from stellate cells.

  • intrnrn_decoded (np.ndarray) – Decoded signal from interneurons.

  • params (dict) – Dictionary containing simulation parameters.

  • bounds (tuple) – Tuple containing the bounds (start, end) for the left and right simulations.

Returns:

The calculated bias between the stellate and interneuron decoded signals.

Return type:

float

analysis_pred_utils.calc_field_size(stell_spks_l, true_pos, params, bounds)

Calculate the average field size w.r.t to positions.

Parameters:
  • stell_spks_l (list of lists) – List of spike times for stellate cells.

  • true_pos (array-like) – Array of true positions.

  • params (dict) – Dictionary containing simulation parameters.

  • bounds (tuple) – Tuple containing the bounds for the analysis.

Returns:

The average field size.

Return type:

float

analysis_pred_utils.calc_inhib_g_at_first_and_last_spike(stell_spks, stell_syn_inhib_g)

Get value of inhibitory synaptic conductance at first and last spike of all fields

This function is used for plots in Figure 5.

Parameters:
  • x (array-like) – Data Array

  • h (dict) – Kernel

Returns:

Convolved array.

Return type:

numpy.ndarray

analysis_pred_utils.calc_predictive_code(stell_spikes_l, intrnrn_spks_l, params, sim_num)

Calculate the predictive code from spikes

This first decodes the position of stellates and interneurons and uses calc_bias_stell_intrnrn() to calculate the predictive code.

Parameters:
  • stell_decoded (np.ndarray) – Decoded signal from stellate cells.

  • intrnrn_decoded (np.ndarray) – Decoded signal from interneurons.

  • params (dict) – Dictionary containing simulation parameters.

  • bounds (tuple) – Tuple containing the bounds (start, end) for the left and right simulations.

Returns:

The calculated bias between the stellate and interneuron decoded signals.

Return type:

float

analysis_pred_utils.calc_speed_of_network(stell_spks_l, params, win_size=100)

Calculate the speed of the network based through decoded position.

This function calculates the speed of the network by decoding the position of the network and calculating the slope of the unwrapped position. It assumes the input DC to the network was in the form of predictive coding simulations Same functionality as in analysis_utils.calc_speed_of_network().

Parameters:
  • stell_spks_l (list) – List of spike times for stellate cells.

  • params (dict) – Dictionary containing simulation parameters

  • win_size (int, optional) – Window size for calculating instantaneous rates. Defaults to 100.

Returns:

The slope representing the speed of the network.

Return type:

float

analysis_pred_utils.calculate_field_positions(separate_fields_x, true_pos)

Calculate the positions at each spike based on true (interneuron) positions.

Parameters:
  • separate_fields_x (list of lists) – A list where each element is a list of field indices.

  • true_pos (numpy.ndarray) – A numpy array containing the true positions.

Returns:

A list where each element is a list of true positions corresponding to the field indices.

Return type:

list of lists

analysis_pred_utils.circular_convolve(x, h)

Convolution for circular data.

Parameters:
  • x (array-like) – Data Array

  • h (dict) – Kernel

Returns:

Convolved array.

Return type:

numpy.ndarray

analysis_pred_utils.circular_difference(angle1, angle2, period=None)

Unsigned arc length

Parameters:
  • angle1 (float) – The first angle in radians.

  • angle2 (float) – The second angle in radians.

  • period (float, optional) – The period of the circular scale. Defaults to 2*pi.

Returns:

The smallest difference between the two angles.

Return type:

float

analysis_pred_utils.convole_field_pos(field_pos_x, params, win_size=6)

Convolves the input field positions derived from spikes to generate a firing field.

Parameters:
  • field_pos_x (list) – List of field positions to be convolved.

  • params (dict) – Dictionary containing simulation parameters

  • win_size (int, optional) – Size of the Gaussian window. Default is 6.

Returns:

Array of convolved field positions, truncated to the minimum length.

Return type:

np.ndarray

analysis_pred_utils.decode_pos_by_intrnrn(intrnrn_spks_l, params)

Decode position from interneuron spikes.

Parameters:
  • intrnrn_spks_l (list of lists) – List of interneuron spikes.

  • params (dict) – Dictionary containing simulation parameters

Returns:

Decoded positions.

Return type:

numpy.ndarray

analysis_pred_utils.find_rates_of_fields(separate_fields_x)

Calculate the instantaneous rates of each field.

Parameters:

separate_fields_x (list) – A list of fields.

Returns:

A list of lists, where each inner list contains the rates calculated for the corresponding field.

Return type:

list

analysis_pred_utils.instant_rate_low_pass(stell_spikes_l, sim_dur)

Apply a low-pass filter to the instantaneous firing rates.

This function bins the spike times and then applies a Butterworth low-pass filter at the cutoff frequency.

Parameters:
  • stell_spikes_l (list) – List of spike times for stellate cells.

  • sim_dur (float) – Duration of the simulation in milliseconds.

Returns:

The filtered instantaneous firing rate.

Return type:

numpy.ndarray

analysis_pred_utils.remove_uneven_fields(cell_spks_x, bounds)

Removes spikes outside the field based on a threshold

Parameters:
  • cell_spks_x (array-like) – Array of cell spike positions.

  • bounds (tuple) – A tuple containing the lower and upper bounds of the direction change in the network.

Returns:

spikes times after removing escape spikes

Return type:

list

analysis_pred_utils.separate_fields(spks)

Separates spike times into different fields based on a calculated threshold.

Parameters:

spks (list of float) – A list of spike times.

Returns:

A list where each element is a list of spike times that are categorized as the same field.

Return type:

list of list of float

analysis_pred_utils.signed_arc_length(theta1, theta2, period=6.283185307179586)

Calculate the signed arc length between two angles.

Parameters:
  • theta1 (float) – The first angle in radians.

  • theta2 (float) – The second angle in radians.

  • period (float, optional) – The period of the circle, default is 2*pi.

Returns:

The signed arc length between theta1 and theta2. Positive if the clockwise distance is shorter, negative if the counterclockwise distance is shorter.

Return type:

float