Skip to content

Add binary decoding and correct axis name for plot, fix plot per layers#59

Merged
CeliaBenquet merged 5 commits into
celia/test-unified-cebrafrom
ananda/binary-decoding-and-plot
Dec 11, 2025
Merged

Add binary decoding and correct axis name for plot, fix plot per layers#59
CeliaBenquet merged 5 commits into
celia/test-unified-cebrafrom
ananda/binary-decoding-and-plot

Conversation

@anandawolz
Copy link
Copy Markdown

@anandawolz anandawolz commented Jul 22, 2025

Updates after @CeliaBenquet comments on this PR #59:

1. decoding() signature: changed to return a DecodeResult namedtuple (overall_score, per_label_error, per_label_score, label_types) instead of a raw 3‑tuple

2. Compute method storage: Updated Decoding.compute() to collect and store full DecodeResult objects for each layer, rather than unpacking into separate lists. Callers now work with a consistent, typed return value.

3. DecodingPlot:

  • In plot(), derive the base title (“Layer‑wise decoding performance” or “Layer‑wise decoding error”) and the y‑axis label from the new DecodeResult.label_types and the plot_error flag—no more deprecated flags or special cases.
  • _transform() was adapted to the change in 1 & 2
    Comment: The custom title specified by the user is still not applied when calling plot_metric. I haven’t investigated this issue yet.

4. Test updates:

  • test_decoding_function now expects a DecodeResult and unpacks its fields.
  • test_decoder_plot adds a tiny _LayerMap stub implementing .tolist() so that the single‑layer vs. multi‑layer plot branches still call plot_decoding vs. plot_layer_decoding correctly.
  • no new tests added, but tests are passing

5. Requirements: Please don't merge it: works in one container, breaks in another.

!! I still have to standardize the DecodeResult when the decoding function for dataset_label == visual or == HPC is called. For now their respective functions: decoding_frames& decoding_pos_dir are still returning tuples.

Original PR comments:

This PR refactors and extends the decoding and plotting utilities to properly handle both regression and classification (binary/multiclass) targets in neural decoding analysis, as well as adds options to the plotting interface for binary outcomes. It also makes sure that the test passes.

Details:

  1. Decoding for specific label type. Decoding() now auto-detects label type (regression/classification) and applies appropriate metrics:
  • Regression: R² and median error
  • Classification: Accuracy and classification error
  • Decoding score is R² (continuous) or accuracy (binary)
  1. Plot.
  • Adapted the y-axis name & title for binary decoding r^2-score --> accuracy
  • Improved plotting: Decoding.plot() now dispatches to the correct helper (plot_decoding vs. plot_layer_decoding) based on the result shape
  1. Readability. Replace manual k-loop and 8/9-split with a single GridSearchCV for better readability, runs a bit slower now

  2. Test suite fixes.

  • Enhanced _cut_array and activation post‑processing to handle both 2D and 3D activation arrays without indexing errors
  • Added get_params/set_params stubs to the DummyKNNDecoder mock so it can be cloned by GridSearchCV

@anandawolz anandawolz requested a review from CeliaBenquet July 22, 2025 10:00
@anandawolz anandawolz self-assigned this Jul 22, 2025
Copy link
Copy Markdown
Member

@CeliaBenquet CeliaBenquet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice! thanks @anandawolz, overall, some formating and comments to clarify + the labels_is_binary tag to remove as discussed, to be replaced with dict in the metrics directly.

Comment thread cebra_lens/activations.py Outdated
Comment thread cebra_lens/activations.py Outdated
Comment thread cebra_lens/quantification/decoder.py Outdated
Comment thread cebra_lens/quantification/decoder.py Outdated
Comment thread cebra_lens/quantification/decoder.py Outdated
Comment thread cebra_lens/quantification/decoder.py Outdated
Comment thread cebra_lens/utils_plot.py Outdated
Comment thread cebra_lens/utils_plot.py Outdated
Comment thread cebra_lens/utils_plot.py Outdated
Comment thread cebra_lens/utils_plot.py Outdated
@CeliaBenquet CeliaBenquet added 🛠️ fix and removed 🐞 bug Something isn't working labels Jul 24, 2025
Comment thread requirements.txt
@CeliaBenquet
Copy link
Copy Markdown
Member

@anandawolz can you resolve the last comments and confirm that the requirements.txt works in all containers now? then I will merge, thank you!

@anandawolz anandawolz changed the base branch from ananda/activation-fixes to celia/test-unified-cebra December 8, 2025 22:36
@anandawolz
Copy link
Copy Markdown
Author

Hi @CeliaBenquet, I’ve rerun the full pipeline on the hippocampus dataset and everything passes.
requirements.txt has been reverted to your original version - my accidental changes are removed and I haven’t modified anything else. From my side, this PR is ready to be merged.

@CeliaBenquet
Copy link
Copy Markdown
Member

@anandawolz can you resolve the review comments as well :)

@anandawolz
Copy link
Copy Markdown
Author

@CeliaBenquet, done resolving the review comments

@CeliaBenquet CeliaBenquet merged commit 9cee035 into celia/test-unified-cebra Dec 11, 2025
@MMathisLab MMathisLab deleted the ananda/binary-decoding-and-plot branch April 14, 2026 09:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants