Skip to content

Fix NaN corruption in displace_t - #312

Open
EItanm1999 wants to merge 1 commit into
lnccbrown:mainfrom
EItanm1999:fix-displace-t-nan-corruption
Open

Fix NaN corruption in displace_t#312
EItanm1999 wants to merge 1 commit into
lnccbrown:mainfrom
EItanm1999:fix-displace-t-nan-corruption

Conversation

@EItanm1999

@EItanm1999 EItanm1999 commented Jul 30, 2026

Copy link
Copy Markdown

Found a bug where displace_t's rt -> (rt-t) shift could produce a non-positive value with nothing checking for it before log() was called. Resulted in producing NaN and corrupting the KDE fit. Fix computes the shift once, excludes any result <= 0 by relabeling it with the existing filter sentinel, and lets the already-existing downstream filtering pull it out using the same mechanism for omitted trials.

New Model: [Your Model Name]

Description

Type of Contribution

  • Level 1: Boundary/Drift variant
  • Level 2: Python simulator
  • Level 3: Cython simulator

Model Details

  • Parameters:
  • Number of choices:
  • Reference:
  • Use case:

Correctness Validation

  • Tested against theoretical predictions (mean, variance, etc.)
  • Compared with published results (if available)
  • Edge cases tested and handled
  • Statistical properties validated with large samples

Validation details:

Testing

  • Tests written:
  • All tests pass:
  • Test coverage:
  • Performance benchmark (if Cython):

Documentation

  • Model config has comprehensive docstring
  • References to papers/equations included
  • Parameter meanings and ranges documented
  • Example usage provided
  • Tutorial notebook:

Pre-Submission Checklist

  • Code follows existing style and patterns
  • All new tests pass locally
  • Existing tests still pass (pytest tests/)
  • Model is registered and importable
  • No unnecessary files committed (temp files, notebook outputs, etc.)
  • Commit messages are clear and descriptive

Additional Notes


Summary by CodeRabbit

  • Bug Fixes
    • Prevented invalid or non-positive shifted reaction times from producing NaN values.
    • Ensured inadmissible trials are consistently excluded during KDE processing.
    • Added warnings when time displacement is used with models outside the validated set.

Found a bug where displace_t's rt -> (rt-t) shift could produce a
non-positive value with nothing checking for it before log() was
called. Resulted in producing NaN and corrupting the KDE fit. Fix
computes the shift once, excludes any result <= 0 by relabeling it
with the existing filter sentinel, and lets the already-existing
downstream filtering pull it out using the same mechanism for
omitted trials.
@coderabbitai

coderabbitai Bot commented Jul 30, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

LogKDE now warns when displace_t=True is used with an unvalidated model and filters nonpositive shifted reaction times before computing log reaction times.

Changes

Displaced RT handling

Layer / File(s) Summary
Validated model warning
ssms/support_utils/kde_class.py
Adds a validated-model allowlist and emits a UserWarning for unsupported models when displace_t is enabled.
Shifted RT filtering
ssms/support_utils/kde_class.py
Marks nonpositive shifted reaction times as inadmissible and computes log reaction times only for valid entries.

Estimated code review effort: 2 (Simple) | ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: fixing NaN issues in displace_t handling.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@ssms/support_utils/kde_class.py`:
- Around line 85-91: Normalize model_name by removing the supported trailing
“_deadline” suffix before checking membership in _DISPLACE_T_VALIDATED_MODELS,
while retaining the original name in the warning message. Update the validation
logic around the model_name lookup so both base models and deadline variants
such as ddm_st_deadline use the base-model allowlist entry.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 3b5cbf53-93d4-4c3d-a50a-4d92f1c2c082

📥 Commits

Reviewing files that changed from the base of the PR and between 51ede0a and c47b24c.

📒 Files selected for processing (1)
  • ssms/support_utils/kde_class.py

Comment on lines +85 to +91
model_name = simulator_data["metadata"].get("model")
if model_name not in _DISPLACE_T_VALIDATED_MODELS:
warnings.warn(
f"displace_t=True untested for model '{model_name}' (validated: {sorted(_DISPLACE_T_VALIDATED_MODELS)}).",
UserWarning,
stacklevel=2,
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Normalize deadline-suffixed model names before allowlist lookup.

Line 86 treats a validated deadline variant such as ddm_st_deadline as untested because it cannot match the base-model allowlist entry ddm_st, producing a false warning.

Proposed fix
             model_name = simulator_data["metadata"].get("model")
-            if model_name not in _DISPLACE_T_VALIDATED_MODELS:
+            base_model_name = (
+                model_name.removesuffix("_deadline") if model_name else model_name
+            )
+            if base_model_name not in _DISPLACE_T_VALIDATED_MODELS:
                 warnings.warn(

As per coding guidelines, support deadline-model naming through the _deadline suffix, such as ddm_deadline, where applicable.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
model_name = simulator_data["metadata"].get("model")
if model_name not in _DISPLACE_T_VALIDATED_MODELS:
warnings.warn(
f"displace_t=True untested for model '{model_name}' (validated: {sorted(_DISPLACE_T_VALIDATED_MODELS)}).",
UserWarning,
stacklevel=2,
)
model_name = simulator_data["metadata"].get("model")
base_model_name = (
model_name.removesuffix("_deadline") if model_name else model_name
)
if base_model_name not in _DISPLACE_T_VALIDATED_MODELS:
warnings.warn(
f"displace_t=True untested for model '{model_name}' (validated: {sorted(_DISPLACE_T_VALIDATED_MODELS)}).",
UserWarning,
stacklevel=2,
)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@ssms/support_utils/kde_class.py` around lines 85 - 91, Normalize model_name
by removing the supported trailing “_deadline” suffix before checking membership
in _DISPLACE_T_VALIDATED_MODELS, while retaining the original name in the
warning message. Update the validation logic around the model_name lookup so
both base models and deadline variants such as ddm_st_deadline use the
base-model allowlist entry.

Source: Coding guidelines

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant