Skip to content

Commit

Permalink
Merge pull request #3505 from JoeZiminski/fix_whitening_regression
Browse files Browse the repository at this point in the history
Whitening fix - compute covariance matrix in float
  • Loading branch information
alejoe91 authored Nov 4, 2024
2 parents 151947a + 7b8d0a2 commit d78a0da
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/spikeinterface/preprocessing/whiten.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ class WhitenRecording(BasePreprocessor):
recording : RecordingExtractor
The recording extractor to be whitened.
dtype : None or dtype, default: None
Datatype of the output recording (covariance matrix estimation
and whitening are performed in float32).
If None the the parent dtype is kept.
For integer dtype a int_scale must be also given.
mode : "global" | "local", default: "global"
Expand Down Expand Up @@ -74,7 +76,9 @@ def __init__(
dtype_ = fix_dtype(recording, dtype)

if dtype_.kind == "i":
assert int_scale is not None, "For recording with dtype=int you must set dtype=float32 OR set a int_scale"
assert (
int_scale is not None
), "For recording with dtype=int you must set the output dtype to float OR set a int_scale"

if W is not None:
W = np.asarray(W)
Expand Down Expand Up @@ -124,7 +128,7 @@ def __init__(self, parent_recording_segment, W, M, dtype, int_scale):
def get_traces(self, start_frame, end_frame, channel_indices):
traces = self.parent_recording_segment.get_traces(start_frame, end_frame, slice(None))
traces_dtype = traces.dtype
# if uint --> force int
# if uint --> force float
if traces_dtype.kind == "u":
traces = traces.astype("float32")

Expand Down Expand Up @@ -185,6 +189,7 @@ def compute_whitening_matrix(
"""
random_data = get_random_data_chunks(recording, concatenated=True, return_scaled=False, **random_chunk_kwargs)
random_data = random_data.astype(np.float32)

regularize_kwargs = regularize_kwargs if regularize_kwargs is not None else {"method": "GraphicalLassoCV"}

Expand Down

0 comments on commit d78a0da

Please sign in to comment.