scaling_analysis package

Submodules

scaling_analysis.experiment module

class scaling_analysis.experiment.Experiment(path)

Bases: object

Load example data provided e.g. at [1].

The .h5 example data can be loaded directly using expt = Experiment('/path/to/file.h5').

Parameters:
pathstr

Path to the example data .h5 file

References

[1]

Manley, J., Lu, S., Barber, K., Demas, J., Kim, H., Meyer, D., Martínez Traub, F., & Vaziri, A. (2024). Light beads microscopy recordings of up to one million neurons across mouse dorsal cortex during spontaneous behavior [Data set]. In Neuron. Zenodo. https://doi.org/10.5281/zenodo.10403684.

Attributes:
T_allndarray of shape (T, N)

Matrix of extracted neural timeseries

Yndarray

Maximum intensity projection of volume

centersndarray of shape (3, N)

Centers of neurons in x, y, z order

tndarray of shape (T, )

Timestamps

fhzfloat

Volume rate

motionndarray of shape (T, npc)

Matrix of the first npc motion PC timeseries, aligned to the neural data

velocity_eventsndarray of shape (T, )

Number of treadmill velocity events in each time bin

outstr

Path where analysis results are saved, os.path.dirname(path)

scaling_analysis.pca module

Functions for running PCA on various numbers of randomly sampled neurons.

scaling_analysis.pca.main(path, nneur, nsamplings=1)

CLI for scaling_analysis.pca.

For example, run 1 sampling of PCA on 512 neurons:

python -m scaling_analysis.pca /path/to/file.h5 512 1

Parameters:
pathstr

Path to dataset loaded by Experiment

nneurint

Number of neurons to randomly sample

nsamplingsint, default=1

Number of random samplings to perform

scaling_analysis.pca.run_pca_nneur(neurons, nneur, nsamplings=10, npc=4096, out=None, t_train_frac=1, interleave=400)

Samples a given number of neurons and performs PCA.

Parameters:
neuronsarray_like of shape (T, N)

Neuronal timeseries

nneurint

Number of neurons to sample

nsamplingsint, default=10

Number of samplings and rounds of PCA to perform

npcint, default=4096

Number of PCs to compute

outstr, optional

Path to optionally save results

t_train_frac: float, default=1

Fraction of timepoints to use

interleaveint, default=400

Number of timepoints which are chunked together before randomly assigned chunks to train or test. If interleave=0, each timepoint is independently assigned to train or test (not recommended due to autocorrelations). interleave has no effect when t_train_frac=1

Returns:
var_neurndarray of shape (npc, nsamplings)

Variance explained by each PC

scaling_analysis.plotting module

scaling_analysis.plotting.calc_var_expl(cov_neurs, var_neurs, cov_res_behs, model='linear', cumulative=False, cumulative_pcs=None)
scaling_analysis.plotting.log_log(ax)
scaling_analysis.plotting.no_ticks(ax)
scaling_analysis.plotting.plot_MIPs(Y, planes_to_show=[5, 10, 20], dorsal_depth=50, axial_spacing=16)
scaling_analysis.plotting.plot_neurons_behavior(neurons, motion, treadmill_velocity, t, clim=[-0.3, 1.5], zspacing=10)
scaling_analysis.plotting.set_my_rcParams()

scaling_analysis.predict module

Functions for running SVCA and predicting neural SVCs from instantaneous behavior PCs.

scaling_analysis.predict.main(path, nneur, nsamplings=10, lag=0, nsvc_predict=128, FOV=None, shuffle=False, t_downsample=None, t_subsample=None)

CLI for scaling_analysis.predict.

Parameters:
neuronsarray_like of shape (T, N)

Neuronal timeseries

nneurint

Number of neurons to sample

nsamplingsint, default=10

Number of samplings and rounds of SVCA/prediction to perform

lagint, default=0

Desired lag between neurons and motion (positive indicates behavior precedes neurons)

nsvc_predictint, default=128

Number of SVCs to predict from motion

FOVstr “expand” | float, optional

If None, neurons are sampled randomly. If “expand”, neurons are sampled in order of their distance from the center of the volume. If float, neurons are sampled from a randomly placed lateral FOV of given size

shufflebool, default=False

Whether to shuffle motion (recommended if not using the session permutation method)

t_downsampleint, optional

If provided, downsamples the volume rate by sampling every t_downsample frames

t_subsamplefloat, optional

If provided, subsamples the duration of the recording by only analyzing the first t_subsample fraction of the recording

scaling_analysis.predict.predict_from_behavior(neurons, nneur, centers, motion, ranks, nsamplings=10, lag=0, lams=[0.001, 0.005, 0.01, 0.05, 0.1, 0.15, 0.3], nsvc=4096, nsvc_predict=128, npc_behavior=256, out=None, checkerboard=500, FOV=None, prePCA=True, name_suffix='', MLPregressor=True, **kwargs)

Samples a given number of neurons, performs SVCA, and predicts neural SVCs from a set of motion variables.

Parameters:
neuronsarray_like of shape (T, N)

Neuronal timeseries

nneurint

Number of neurons to sample

centersarray_like of shape (d, N)

Position of neurons. First two dimensions are used for checkerboarding, i.e. d ≥ 2

motionarray_like of shape (T, M)

Set of motion (or other) variables used to predict neurons

ranksarray_like

List of ranks to use in reduced rank regression

nsamplingsint, default=10

Number of samplings and rounds of SVCA/prediction to perform

lagint, default=0

Desired lag between neurons and motion (positive indicates behavior precedes neurons)

lamsarray_like, default=[1e-3,5e-3,0.01,0.05,0.1,0.15,0.3]

List of regularization parameters to use in reduced rank regression

nsvcint, default=4096

Mumber of SVCs to compute (if not None, uses randomized SVD approximation). i.e., n_randomized in PopulationCoding.dimred.SVCA

nsvc_predictint, default=128

Number of SVCs to predict from motion

npc_behaviorint, default=256

Number of behavior PCs to use for predicting neural SVCs

outstr, optional

Path to optionally save results

checkerboardfloat, optional

Size of lateral “checkerboarding” pattern used to split neurons into two sets

FOVstr “expand” | float, optional

If None, neurons are sampled randomly. If “expand”, neurons are sampled in order of their distance from the center of the volume. If float, neurons are sampled from a randomly placed lateral FOV of given size

prePCAbool, default=False

Whether to peform PCA on each subset independently before computing SVCs (see PopulationCoding.dimred.SVCA). Particularly useful when N >> T, so this is ignored and PCA is not performed if N ≤ T * 10

name_suffixstr, optional

Suffix to append to end of file name

MLPregressorbool, default=True

Whether or not to additionally predict SVCs from motion using a multilayer perception with hidden layer of size nranks

kwargspassed to scaling_analysis.svca.run_SVCA_partition
Returns:
cov_neurndarray of shape (nsvc, nsamplings)

Reliable covariance of each SVC on held-out testing timepoints, across samplings

var_neurndarray of shape (nsvc, nsamplings)

Reliable variance of each SVC on held-out testing timepoints, across samplings

cov_res_behndarray of shape (nsvc, nsamplings)

Residual SVC covariance after subtracting predictions from motion, across samplings

cov_res_beh_mlpndarray of shape (nsvc, nsamplings)

Residual SVC covariance after subtracting predictions from motion (with MLP), across samplings. If MLPregressor=false, all NaNs

actual_nneursndarray of shape (nsamplings,)

Actual number of neurons used, across samplings, reported as min(len(ntrain), len(ntest))

undarray

SVC vectors for the first neural subset, ntrain, from a single example sampling

vndarray

SVC vectors for the second neural subset, ntest, from a single example sampling

ntrainndarray

Indices of neurons in the first neural subset, from a single example sampling

ntestndarray

Indices of neurons in the second neural subset, from a single example sampling

itrainndarray

Indices of training timepoints, from a single example sampling

itestndarray

Indices of testing timepoints, from a single example sampling

pcaNone | dict

If prePCA, return a dictionary containing the projections and principal components for both neural sets with the keys train_projs, test_projs, train_vecs, test_vecs from a single example sampling

scaling_analysis.predict_history module

Functions for running SVCA and predicting neural SVCs from multi-timepoint behavior PCs (i.e. with some “history”).

Note predict_from_behavior_history is highly similar from scaling_analysis.predict.predict_from_behavior, and they could likely be refactored.

scaling_analysis.predict_history.main(path, nneur, nsamplings=10, lag=0, nsvc_predict=128, FOV=None, shuffle=False)

CLI for scaling_analysis.predict_from_history.

Parameters:
neuronsarray_like of shape (T, N)

Neuronal timeseries

nneurint

Number of neurons to sample

nsamplingsint, default=10

Number of samplings and rounds of SVCA/prediction to perform

lagint, default=0

Desired lag between neurons and motion (positive indicates behavior precedes neurons)

nsvc_predictint, default=128

Number of SVCs to predict from motion

FOVstr “expand” | float, optional

If None, neurons are sampled randomly. If “expand”, neurons are sampled in order of their distance from the center of the volume. If float, neurons are sampled from a randomly placed lateral FOV of given size

shufflebool, default=False

Whether to shuffle motion (recommended if not using the session permutation method)

scaling_analysis.predict_history.predict_from_behavior_history(neurons, nneur, centers, motion, ranks, pres, posts, navg, nsamplings=10, lag=0, lams=[0.01, 0.1, 1], nsvc=2048, nsvc_predict=128, npc_behavior=256, out=None, checkerboard=250, FOV=None, prePCA=True, name_suffix='', MLPregressor=True, **kwargs)

Samples a given number of neurons, performs SVCA, and predicts neural SVCs from a set of multi-timepoint motion variables, i.e. with some “history”.

Parameters:
neuronsarray_like of shape (T, N)

Neuronal timeseries

nneurint

Number of neurons to sample

centersarray_like of shape (d, N)

Position of neurons. First two dimensions are used for checkerboarding, i.e. d ≥ 2

motionarray_like of shape (T, M)

Set of motion (or other) variables used to predict neurons

ranksarray_like

List of ranks to use in reduced rank regression

presarray_like

List of numbers of motion frames BEFORE neural activity to include. Each pair of pres and posts will be tried to identify an optimal window of multi-timepoint behavior

postsarray_like

Lists of numbers of motion frames AFTER neural activity to include

navgint, optional

If specified, the multi-timepoint window is binned into bins of length navg. This can be utilized to decrease the dimensionality of the multi-timepoint behavioral data, and is recommended whenever the frame rate is fast enough that adjacent behavioral frames are highly correlated

nsamplingsint, default=10

Number of samplings and rounds of SVCA/prediction to perform

lagint, default=0

Desired lag between neurons and motion (positive indicates behavior precedes neurons)

lamsarray_like, default=[1e-3,5e-3,0.01,0.05,0.1,0.15,0.3]

List of regularization parameters to use in reduced rank regression

nsvcint, default=4096

Mumber of SVCs to compute (if not None, uses randomized SVD approximation). i.e., n_randomized in PopulationCoding.dimred.SVCA

nsvc_predictint, default=128

Number of SVCs to predict from motion

npc_behaviorint, default=256

Number of behavior PCs to use for predicting neural SVCs

outstr, optional

Path to optionally save results

checkerboardfloat, optional

Size of lateral “checkerboarding” pattern used to split neurons into two sets

FOVstr “expand” | float, optional

If None, neurons are sampled randomly. If “expand”, neurons are sampled in order of their distance from the center of the volume. If float, neurons are sampled from a randomly placed lateral FOV of given size

prePCAbool, default=False

Whether to peform PCA on each subset independently before computing SVCs (see PopulationCoding.dimred.SVCA). Particularly useful when N >> T, so this is ignored and PCA is not performed if N ≤ T * 10

name_suffixstr, optional

Suffix to append to end of file name

MLPregressorbool, default=True

Whether or not to additionally predict SVCs from motion using a multilayer perception with hidden layer of size nranks. Note that this only fits an MLP model for the instantaneous case and the best multi-timepoint window.

kwargspassed to scaling_analysis.svca.run_SVCA_partition
Returns:
cov_neurndarray of shape (nsvc, len(pres), len(posts), len(ranks), len(lams), nsamplings)

Reliable covariance of each SVC on held-out testing timepoints, across samplings. Note that these cov_neur, etc. must be reported for each multi-timepoint window. This is because the number of timepoints changes (and thus the total variance/covariance)

var_neurndarray of shape (nsvc, len(pres), len(posts), len(ranks), len(lams), nsamplings)

Reliable variance of each SVC on held-out testing timepoints, across samplings

cov_res_behndarray of shape (nsvc_predict, len(pres), len(posts), len(ranks), len(lams), nsamplings)

Residual SVC covariance after subtracting predictions from motion, across samplings

cov_neur_mlpndarray of shape (nsvc_predict, 2, len(ranks), nsamplings)

Reliable covariance of each SVC on held-out testing timepoints, across samplings, for the multi-layer perceptron models. The second dimension reflects the two MLP models fit: the instantaneous case and the optimal multi-timepoint window

var_neur_mlpndarray of shape (nsvc_predict, 2, len(ranks), nsamplings)

Reliable variance of each SVC on held-out testing timepoints, across samplings

cov_res_beh_mlp(nsvc_predict, 2, len(ranks), nsamplings)

Residual SVC covariance after subtracting predictions from motion (with MLP), across samplings. If MLPregressor=false, all NaNs

actual_nneursndarray of shape (nsamplings,)

Actual number of neurons used, across samplings, reported as min(len(ntrain), len(ntest))

scaling_analysis.session_permutation module

Session permutation method for computing reliable variance noise floors

scaling_analysis.session_permutation.main(path1, path2, out, nneur, nsamplings=10)

CLI for scaling_analysis.session_permuation.

For example, run SVCA with session permutation for 10 samplings of 512 neurons:

python -m scaling_analysis.session_permuation file1.h5 file2.h5 /out/ 512 10

Parameters:
path1str

Path to first dataset loaded by Experiment

path2str

Path to second dataset loaded by Experiment

outstr

Path to save session permutation results

nneurint

Number of neurons to randomly sample

nsamplingsint, default=10

Number of random samplings to perform

scaling_analysis.session_permutation.svca_across_sessions(neurons1, neurons2, nneur, nsamplings=10, nsvc=4096, out=None, interleave=400, **kwargs)

Runs SVCA with each neural set sampled from different data matrix (e.g. different sessions), i.e. performing something like the so-called session permutation method [1].

By sampling neurons from completely different recordings, the neural autocorrelations are NOT obfuscated, but the neural subsets are known a priori to not be synchronized.

Parameters:
neurons1array_like of shape (T1, N1)
neurons2array_like of shape (T2, N2)
nneurint

Number of neurons to sample

nsamplingsint, default=10

Number of samplings and rounds of SVCA to perform

nsvcint, default=4096

Number of SVCs to compute (if not None, uses randomized SVD approximation). i.e., n_randomized in PopulationCoding.dimred.SVCA

outstr, optional

Path to optionally save results

interleaveint, default=400

Number of timepoints which are chunked together before randomly assigned chunks to train or test. If interleave=0, each timepoint is independently assigned to train or test (not recommended due to autocorrelations)

Returns:
sneurndarray of shape (nsvc, nsamplings)

Reliable covariance of each cross-session SVC on held-out testing timepoints

varneurndarray of shape (nsvc, nsamplings)

Reliable variance of each cross-session SVC on held-out testing timepoints

References

[1]

Harris, K. D. (2020). Nonsense correlations in neuroscience. bioRxiv, 2020-11. https://doi.org/10.1101/2020.11.29.402719.

scaling_analysis.spatial module

Analysis of the spatial properties of SVCs.

scaling_analysis.spatial.gini_index(X)

Computes the Gini index of the column vectors of X.

scaling_analysis.spatial.hoyer_sparsity(X)

Computes the Hoyer sparsity of the column vectors of X.

scaling_analysis.spatial.local_homogeneity(values, centers, dist_threshes=array([20, 40, 60, 80, 100, 120, 140, 160, 180, 200, 220, 240, 260, 280, 300, 320, 340, 360, 380, 400, 420, 440, 460, 480, 500]), ntodo=None)

Computes the local homogeneity of SVCs, which defines the average % of neighbors (within some radius) of a participating neuron that are also participating in the same SVC.

Parameters:
valuesarray_like of length N

Binary vector indicating which neurons are participating in that SVC

centersarray_like of shape (d, N)

Position of neurons

dist_threshesarray_like, default=np.arange(20, 501, 20)

Radii at which to evaluate local homogeneity

ntodoint, optional

Number of participating neurons whose local homogeneity should be evaluated. If not provided, ntodo = min(ntodo, np.sum(values))

Returns:
local_homogeneityndarary of shape (ntodo, len(dist_threshes))
scaling_analysis.spatial.reorder_svcs(svc, neuron_idx)

Reorder SVCs according to neuron_idx such that it aligns with the ordering in the original data. This is necessary because run_SVCA_partition randomly samples neurons, so ntrain and ntest can be random permutations of the neuron indices which are distinct across samplings.

Parameters:
svcarray_like of shape (nsamplings, nneur, nsvc)

SVCs across many samplings to be reordered

neuron_idxarray_like of shape (nsamplings, #nneur)

Indices of neurons in each sampling with respect to original data matrix. Created by concatenating ntrain and ntest

Returns:
svc_orderedndarray of shape (nsamplings, nneur, nsvc)

Reordered SVCs, where svc_ordered[:,i,:] contains all the coefficients for the same neuron, i.e. the i-th neuron in the original data matrix

scaling_analysis.svca module

Functions for running SVCA on various samplings of neurons from large-scale neural recordings.

scaling_analysis.svca.checkerboard_centers(centers, checkerboard)

Returns indices of variables split into two sets according to a checkerboard pattern based on the positions located in centers.

Parameters:
centersarray_like of shape (d, N)

Position of neurons. First two dimensions are used for checkerboarding, i.e. d ≥ 2

checkerboardfloat

Size of square in checkerboard

Returns:
idx1ndarray

Indices of first set

idx2: ndarray

Indices of second set

scaling_analysis.svca.expanding_FOV(centers, n)

Return the indices of the n positions in centers closest to the middle of FOV

scaling_analysis.svca.main(path, nneur, nsamplings=10, checkerboard=250, FOV=None, n_randomized=4096, shuffle=False, save_indiv=True, tbin=1)

CLI for scaling_analysis.svca.

In particular, this script saves the SVC coefficients associated with each individual sampling, something that scaling_analysis.predict.predict_from_behavior does not do.

For example, save SVCs for 10 samplings of 512 neurons:

python -m scaling_analysis.svca /path/to/file.h5 512 10

Parameters:
pathstr

Path to dataset loaded by Experiment

nneurint

Number of neurons to randomly sample checkerboard : float, optional Size of lateral “checkerboarding” pattern used to split neurons into two sets

nsamplingsint, default=1

Number of random samplings to perform

checkerboardfloat, optional

Size of lateral “checkerboarding” pattern used to split neurons into two sets

FOVstr “expand” | float, optional

If None, neurons are sampled randomly. If “expand”, neurons are sampled in order of their distance from the center of the volume. If float, neurons are sampled from a randomly placed lateral FOV of given size

n_randomizedint, default=4096

Number of SVCs to compute (if not None, uses randomized SVD approximation)

shufflebool, default=False

Whether to shuffle by swapping the train and test timepoints for one neural subset (recommended if not using the session permutation method)

save_indivbool, default=True

Whether or not to save the SVC coefficients for each individual round of sampling

tbinint, default=1

Number of frames which are binned together

scaling_analysis.svca.random_lateral_FOV(centers, FOV)

Select neurons within a randomly placed field of view with a lateral size FOV.

Parameters:
centersarray_like of shape (d, N)

Position of neurons. First two dimensions are used for FOV placement, i.e. d ≥ 2

FOVfloat

Lateral size of FOV, in units of centers

Returns:
idxndarray

Indices of neurons within a randomly placed lateral region of size FOV

scaling_analysis.svca.run_SVCA_partition(X, n, checkerboard=None, centers=None, FOV=None, n_randomized=4096, t_train_frac=0.5, shuffle=False, prePCA=True, interleave=400, **kwargs)

Samples a given number of neurons and performs SVCA.

Parameters:
Xarray_like of shape (T, N)

Neuronal timeseries

nint

Number of neurons to sample

checkerboardfloat, optional

Size of lateral “checkerboarding” pattern used to split neurons into two sets

centersarray_like of shape (d, N), optional

Position of neurons. First two dimensions are used for checkerboarding, i.e. d ≥ 2

FOVstr “expand” | float, optional

If None, neurons are sampled randomly. If “expand”, neurons are sampled in order of their distance from the center of the volume. If float, neurons are sampled from a randomly placed lateral FOV of given size

n_randomizedint, default=4096

Number of SVCs to compute (if not None, uses randomized SVD approximation)

t_train_fracfloat, default=0.5

Fraction of timepoints to use as training data

shufflebool, default=False

Whether to shuffle by swapping the train and test timepoints for one neural subset (recommended if not using the session permutation method)

prePCAbool, optional, default=False

Whether to peform PCA on each subset independently before computing SVCs (see articularly useful when N >> T, so this is ignored and PCA is not performed if N ≤ T * 10

interleaveint, default=400

Number of timepoints which are chunked together before randomly assigned chunks to train or test. If interleave=0, each timepoint is independently assigned to train or test (not recommended due to autocorrelations)

kwargsPassed onto PopulationCoding.dimred.SVCA
Returns:
sneurndarray

Reliable covariance of each SVC on held-out testing timepoints

varneurndarray

Reliable variance of each SVC on held-out testing timepoints

undarray

SVC vectors for the first neural subset, ntrain

vndarray

SVC vectors for the second neural subset, ntest

ntrainndarray

Indices of neurons in the first neural subset

ntestndarray

Indices of neurons in the second neural subset

itrainndarray

Indices of training timepoints

itestndarray

Indices of testing timepoints

pcaNone | dict

If prePCA, return a dictionary containing the projections and principal components for both neural sets with the keys train_projs, test_projs, train_vecs, test_vecs

See also

PopulationCoding.dimred.SVCA

A basic implementation of SVCA which is utilized here.

scaling_analysis.temporal module

Analysis of the temporal characteristics of SVCs.

scaling_analysis.temporal.autocorr(x)

Computes the autocorrelation of x.

scaling_analysis.temporal.compute_timescales(svcs, t)

Computes the autocorrelation timescale associated with each column of svcs.

Parameters:
svcsarray_like of shape (T, N)
tarray_like of length T

Timestamps associated with svcs

Returns:
acorrsndarray of shape (T, N)

Autocorrelation of each column of svcs

timescalesndarray of shape (N,)

Autocorrelation timescale estimated for each column of svcs

timescales_perrndarray of shape (N,)

Error associated with estimate of timescales

scaling_analysis.temporal.find_svca_temporal(neurons, t, nneur, nsamplings=10, nsvc=4096, out=None, **kwargs)

First computes SVCA on neurons with nneur sampled neurons. Then finds the autocorrelation timescale of each SVC.

Parameters:
neuronsarray_like of shape (N, T)

Neuronal activity matrix; assumed N ≥ nneur

tarray_like of length T

Timestamps

nneurint

Number of neurons to sample

nsamplingsint, default=10

Number of samplings and rounds of SVCA/prediction to perform

nsvcint, default=4096

Number of SVCs to compute (if not None, uses randomized SVD approximation) i.e., n_randomized in PopulationCoding.dimred.SVCA

outstr, optional

Path to optionally save results

kwargspassed to run_SVCA_partition
Returns:
cov_neurndarray of shape (nsvc, nsamplings)

Reliable covariance of each SVC on held-out testing timepoints

var_neurndarray of shape (nsvc, nsamplings)

Reliable variance of each SVC on held-out testing timepoints

timescalesndarray of shape (nsvc, nsamplings)

Autocorrelation timescales of each SVC

timescales_perrndarray of shape (nsvc, nsamplings)

Error associated with estimate of timescales

scaling_analysis.temporal.fit_exponential_decay(x, t)

Fits an exponential decay to the signal x(t).

Parameters:
xarray_like of length N

Signal

tarray_like of length N

Timestamps

Returns:
taufloat

Estimated decay timescale

errorfloat

Error associated with estimate

scaling_analysis.temporal.main(path, nneur, nsamplings=10, shuffled=False)

CLI for scaling_analysis.temporal.

For example, run 10 samplings of SVCA on 512 neurons and compute their autocorrelation timescales:

python -m scaling_analysis.temporal /path/to/file.h5 512 10 0

Parameters:
pathstr

Path to dataset loaded by Experiment

nneurint

Number of neurons to randomly sample

nsamplingsint, default=1

Number of random samplings to perform

shuffledbool, default=False

Whether or not to shuffle the timeseries by randomly permuting two second chunks

scaling_analysis.utils module

Some misc. utilities.

scaling_analysis.utils.correct_lag(lag, neurons, motion)

Shifts timeseries to account for an optimal lag between neurons and motion. Positive lag indicates that motion preceds neurons.

scaling_analysis.utils.get_nneur(n_neurons, n_sample)

Raise a warning if n_sample is greater than the next power of two largest than n_neurons. Otherwise return min(n_sample, n_neurons). This is helpful when we are sampling neurons in powers of two, but also want to sample the maximum neuron number.

Parameters:
n_neuronsint

Number of neurons in dataset

n_sampleint

Number of desired neurons to sample, assumed to be a power of 2

scaling_analysis.visual module

Compute visual-evoked and spontaneous neuronal dimensions.

scaling_analysis.visual.compare_spont_vis_dims(neurons, nneur, centers, stims, stim_times, out, nframes_stim=6, nsamplings=10, nsvc=4096, min_dt_stim=100, **kwargs)

Performs SVCA during spontaneous behavior and visual stimulation, and compares the similarity of the resulting SVCs.

Assumes the following experimental protocol (Figure 4D, Manley et al. 2024 [1]):

  1. Spontaneous epoch

  2. Repeated visual epochs, each consisting of the same pattern of stimuli

  3. Spontaneous epoch

Parameters:
neuronsarray_like of shape (N, T)
nneurint

Number of neurons to sample

centersarray_like of shape (d, N)

Position of neurons. First two dimensions are used for checkerboarding, i.e. d ≥ 2

stimsarray_like of length nstim

Labels identifying each stimulus. Each stimulus is assumed to be repeated the same number of times and in the same order during each repetition

stim_timeslist of length nstim

list containing the frame indices associated with each stimulus presentation

outstr

Path to save results

nframes_stimint, default=6

Length of visual stimulation period, in frames

nsamplingsint, default=10

Number of samplings and rounds of SVCA to perform

nsvcint, default=4096

Number of SVCs to compute (if not None, uses randomized SVD approximation) i.e., n_randomized in PopulationCoding.dimred.SVCA

min_dt_stimint, default=100

Number of timepoints before the start of the first visual stimulus and after the end of the last visual stimulus to ignore when selecting spontaneous epochs

kwargspassed to run_SVCA_partition

References

[1]

Manley, J., Lu, S., Barber, K., Demas, J., Kim, H., Meyer, D., Martínez Traub, F., & Vaziri, A. (2024). Simultaneous, cortex-wide dynamics of up to 1 million neurons reveal unbounded scaling of dimensionality with neuron number. Neuron. https://doi.org/10.1016/j.neuron.2024.02.011.

scaling_analysis.visual.main(path, nneur=None, nsamplings=10)

CLI for scaling_analysis.visual.

For example, run 10 samplings of spontaneous/visual SVCA comparisons on 512 neurons:

python -m scaling_analysis.visual /path/to/file.h5 512 10

Parameters:
pathstr

Path to dataset loaded by Experiment

nneurint, default is maximum

Number of neurons to randomly sample

nsamplingsint, default=1

Number of random samplings to perform

Module contents