Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Whitening fix - compute covariance matrix in float #3505

Merged
merged 7 commits into from
Nov 4, 2024
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 float64.
alejoe91 marked this conversation as resolved.
Show resolved Hide resolved
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"
JoeZiminski marked this conversation as resolved.
Show resolved Hide resolved
)

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)
JoeZiminski marked this conversation as resolved.
Show resolved Hide resolved
random_data = random_data.astype(np.float64)

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

Expand Down
Loading