replay_trajectory_classification.decoder.ClusterlessDecoder#
- class ClusterlessDecoder(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, clusterless_algorithm: str = 'multiunit_likelihood', clusterless_algorithm_params: dict = {'mark_std': 24.0, 'position_std': 6.0})[source]#
Bases:
_DecoderBaseClassifies neural population representation of position from multiunit spikes and waveforms.
- Parameters:
environment (Environment, optional) – The spatial environment to fit
transition_type (EmpiricalMovement | RandomWalk | RandomWalkDirection1 | RandomWalkDirection2 | Uniform) – The continuous state transition matrix
initial_conditions_type (UniformInitialConditions, optional) – The initial conditions class instance
infer_track_interior (bool, optional) – Whether to infer the spatial geometry of track from position
clusterless_algorithm (str) – The type of clusterless algorithm. See _ClUSTERLESS_ALGORITHMS for keys
clusterless_algorithm_params (dict) – Parameters for the clusterless algorithms.
Methods
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, multiunits[, is_training])Fit the spatial grid, initial conditions, place field model, and transition matrices.
fit_environment(position)Discretize the spatial environment into bins.
Set the initial probability of position.
fit_multiunits(position, multiunits[, ...])Get metadata routing of this object.
get_params([deep])Get parameters for this estimator.
load_model([filename])Load the classifier from a file.
predict(multiunits[, time, ...])Predict the probability of spatial position and category from the multiunit spikes and waveforms.
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, ...])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 matrices.
Discretize the spatial environment into bins.
Set the initial probability of position.
fit_state_transitionGet metadata routing of this object.
Get parameters for this estimator.
Load the classifier from a file.
Predict the probability of spatial position and category from the multiunit spikes and waveforms.
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, multiunits: ndarray, is_training: ndarray | None = None)[source]#
Fit the spatial grid, initial conditions, place field model, and transition matrices.
- Parameters:
position (np.ndarray, shape (n_time, n_position_dims)) – Position of the animal.
multiunits (np.ndarray, shape (n_time, n_marks, n_electrodes)) – Array where spikes are indicated by non-Nan values that correspond to the waveform features for each electrode.
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_multiunits(position: ndarray, multiunits: ndarray, is_training: ndarray | None = None)[source]#
- Parameters:
position (np.ndarray, shape (n_time, n_position_dims))
multiunits (np.ndarray, shape (n_time, n_marks, n_electrodes))
is_training (None or array_like, shape (n_time,))
- 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
- predict(multiunits: ndarray, time: ndarray | None = None, is_compute_acausal: bool = True, use_gpu: bool = False) Dataset[source]#
Predict the probability of spatial position and category from the multiunit spikes and waveforms.
- Parameters:
multiunits (np.ndarray, shape (n_time, n_marks, n_electrodes)) – Array where spikes are indicated by non-Nan values that correspond to the waveform features for each electrode.
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$', multiunits: bool | None | str = '$UNCHANGED$', position: bool | None | str = '$UNCHANGED$') ClusterlessDecoder#
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.multiunits (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
multiunitsparameter infit.position (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
positionparameter 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$', multiunits: bool | None | str = '$UNCHANGED$', time: bool | None | str = '$UNCHANGED$', use_gpu: bool | None | str = '$UNCHANGED$') ClusterlessDecoder#
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.multiunits (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
multiunitsparameter 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: