replay_trajectory_classification.decoder.SortedSpikesDecoder#
- class SortedSpikesDecoder(environment: Environment = Environment(environment_name='', place_bin_size=2.0, track_graph=None, edge_order=None, edge_spacing=None, is_track_interior=None, position_range=None, infer_track_interior=True, fill_holes=False, dilate=False, bin_count_threshold=0), transition_type: EmpiricalMovement | RandomWalk | RandomWalkDirection1 | RandomWalkDirection2 | Uniform = RandomWalk(environment_name='', movement_var=6.0, movement_mean=0.0, use_diffusion=False), initial_conditions_type: UniformInitialConditions = UniformInitialConditions(), infer_track_interior: bool = True, sorted_spikes_algorithm: str = 'spiking_likelihood_kde', sorted_spikes_algorithm_params: dict = {'block_size': None, 'position_std': 6.0, 'use_diffusion': False})[source]#
Bases:
_DecoderBaseMethods
convert_results_to_xarray(results, time, ...)Converts the results dict into a collection of labeled arrays.
copy()Makes a copy of the classifier
fit(position, spikes[, is_training])Fit the spatial grid, initial conditions, place field model, and transition matrix.
fit_environment(position)Discretize the spatial environment into bins.
Set the initial probability of position.
fit_place_fields(position, spikes[, is_training])Fits the place intensity function.
Get metadata routing of this object.
get_params([deep])Get parameters for this estimator.
load_model([filename])Load the classifier from a file.
plot_place_fields([sampling_frequency, col_wrap])Plots the fitted place fields for each neuron.
predict(spikes[, time, is_compute_acausal, ...])Predict the probability of spatial position from the spikes.
project_1D_position_to_2D(results[, ...])Project the 1D most probable position into the 2D track graph space.
save_model([filename])Save the classifier to a pickled file.
set_fit_request(*[, is_training, position, ...])Request metadata passed to the
fitmethod.set_params(**params)Set the parameters of this estimator.
set_predict_request(*[, is_compute_acausal, ...])Request metadata passed to the
predictmethod.fit_state_transition
Methods
Converts the results dict into a collection of labeled arrays.
Makes a copy of the classifier
Fit the spatial grid, initial conditions, place field model, and transition matrix.
Discretize the spatial environment into bins.
Set the initial probability of position.
Fits the place intensity function.
fit_state_transitionGet metadata routing of this object.
Get parameters for this estimator.
Load the classifier from a file.
Plots the fitted place fields for each neuron.
Predict the probability of spatial position from the spikes.
Project the 1D most probable position into the 2D track graph space.
Save the classifier to a pickled file.
Request metadata passed to the
fitmethod.Set the parameters of this estimator.
Request metadata passed to the
predictmethod.- convert_results_to_xarray(results: dict, time: ndarray, data_log_likelihood: float) Dataset#
Converts the results dict into a collection of labeled arrays.
- copy()#
Makes a copy of the classifier
- fit(position: ndarray, spikes: ndarray, is_training: ndarray | None = None)[source]#
Fit the spatial grid, initial conditions, place field model, and transition matrix.
- Parameters:
position (np.ndarray, shape (n_time, n_position_dims)) – Position of the animal.
spikes (np.ndarray, shape (n_time, n_neurons)) – Binary indicator of whether there was a spike in a given time bin for a given neuron.
is_training (None or np.ndarray, shape (n_time), optional) – Boolean array to indicate which data should be included in fitting of place fields, by default None
- Return type:
self
- fit_environment(position: ndarray) None#
Discretize the spatial environment into bins. Determine valid track positions.
- Parameters:
position (np.ndarray, shape (n_time, n_position_dims)) – Position of the animal in the environment.
- fit_initial_conditions()#
Set the initial probability of position.
- fit_place_fields(position: ndarray, spikes: ndarray, is_training: ndarray | None = None)[source]#
Fits the place intensity function.
- Parameters:
position (np.ndarray, shape (n_time, n_position_dims)) – Position of the animal.
spikes (np.ndarray, (n_time, n_neurons)) – Binary indicator of whether there was a spike in a given time bin for a given neuron.
is_training (np.ndarray, shape (n_time,), optional) – Boolean array to indicate which data should be included in fitting of place fields, by default None
- get_metadata_routing()#
Get metadata routing of this object.
Please check User Guide on how the routing mechanism works.
- Returns:
routing – A
MetadataRequestencapsulating routing information.- Return type:
MetadataRequest
- get_params(deep=True)#
Get parameters for this estimator.
- static load_model(filename='model.pkl')#
Load the classifier from a file.
- Parameters:
filename (str, optional)
- Return type:
classifier instance
- plot_place_fields(sampling_frequency: int = 1, col_wrap: int = 5) FacetGrid[source]#
Plots the fitted place fields for each neuron.
- predict(spikes: ndarray, time: ndarray | None = None, is_compute_acausal: bool = True, use_gpu: bool = False) Dataset[source]#
Predict the probability of spatial position from the spikes.
- Parameters:
spikes (np.ndarray, shape (n_time, n_neurons)) – Binary indicator of whether there was a spike in a given time bin for a given neuron.
time (np.ndarray or None, shape (n_time,), optional) – Label the time axis with these values.
is_compute_acausal (bool, optional) – If True, compute the acausal posterior.
use_gpu (bool, optional) – Use GPU for the state space part of the model, not the likelihood.
- Returns:
results
- Return type:
- project_1D_position_to_2D(results: Dataset, posterior_type='acausal_posterior') ndarray#
Project the 1D most probable position into the 2D track graph space.
Only works for single environment.
- Parameters:
results (xr.Dataset)
posterior_type (causal_posterior | acausal_posterior | likelihood)
- Returns:
map_position2D
- Return type:
np.ndarray
- save_model(filename='model.pkl')#
Save the classifier to a pickled file.
- Parameters:
filename (str, optional)
- set_fit_request(*, is_training: bool | None | str = '$UNCHANGED$', position: bool | None | str = '$UNCHANGED$', spikes: bool | None | str = '$UNCHANGED$') SortedSpikesDecoder#
Request metadata passed to the
fitmethod.Note that this method is only relevant if
enable_metadata_routing=True(seesklearn.set_config()). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed tofitif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it tofit.None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.Added in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
Pipeline. Otherwise it has no effect.- Parameters:
is_training (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
is_trainingparameter infit.position (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
positionparameter infit.spikes (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
spikesparameter infit.
- Returns:
self – The updated object.
- Return type:
- set_params(**params)#
Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects (such as
Pipeline). The latter have parameters of the form<component>__<parameter>so that it’s possible to update each component of a nested object.- Parameters:
**params (dict) – Estimator parameters.
- Returns:
self – Estimator instance.
- Return type:
estimator instance
- set_predict_request(*, is_compute_acausal: bool | None | str = '$UNCHANGED$', spikes: bool | None | str = '$UNCHANGED$', time: bool | None | str = '$UNCHANGED$', use_gpu: bool | None | str = '$UNCHANGED$') SortedSpikesDecoder#
Request metadata passed to the
predictmethod.Note that this method is only relevant if
enable_metadata_routing=True(seesklearn.set_config()). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed topredictif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it topredict.None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.Added in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
Pipeline. Otherwise it has no effect.- Parameters:
is_compute_acausal (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
is_compute_acausalparameter inpredict.spikes (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
spikesparameter inpredict.time (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
timeparameter inpredict.use_gpu (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
use_gpuparameter inpredict.
- Returns:
self – The updated object.
- Return type: