Add minimum trial threshold to bias intervention - #160
Open
micahwoodard wants to merge 2 commits into
Open
Conversation
…rly interventions (issue #174)
There was a problem hiding this comment.
Pull request overview
This PR introduces an optional “minimum trial threshold” gate for anti-bias interventions so that corrections don’t trigger until enough trials have elapsed, then propagates the new field through schemas/generated code and updates tests accordingly.
Changes:
- Add
trial_thresholdtoBiasInterventionParametersand enforce it inare_antibias_conditions_met(...). - Pass session trial count into bias-intervention checks from the block-based trial generator.
- Regenerate schemas / generated bindings and extend unit tests for the new threshold behavior.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
src/aind_behavior_dynamic_foraging/task_logic/interventions/bias_intervention.py |
Adds trial_threshold parameter and gates intervention triggering based on n_trials. |
src/aind_behavior_dynamic_foraging/task_logic/trial_generators/block_based_trial_generator.py |
Passes len(outcome_history) into are_antibias_conditions_met(...) to supply n_trials. |
tests/test_interventions/test_bias_intervention.py |
Updates call sites to pass n_trials and adds explicit tests for trial_threshold. |
tests/trial_generators/test_block_based_trial_generator.py |
Extends test helper to pass trial_threshold into parameters; updates some tests to override it. |
src/Extensions/AindBehaviorDynamicForaging.Generated.cs |
Regenerated C# model includes TrialThreshold property and printing. |
schema/aind_behavior_dynamic_foraging.json |
Regenerated JSON schema includes trial_threshold. |
schema/uncoupled.json |
Regenerated example/config includes trial_threshold. |
schema/uncoupled_baiting.json |
Regenerated example/config includes trial_threshold. |
schema/coupled_baiting.json |
Regenerated example/config includes trial_threshold. |
Suppressed comments (1)
src/aind_behavior_dynamic_foraging/task_logic/interventions/bias_intervention.py:81
- Docstring references a non-existent parameter name (parameters.min_trials_for_bias_intervention). The actual field added is parameters.trial_threshold, so this documentation is misleading and will confuse future maintenance.
Intervention is only considered once ``n_trials`` has reached
``parameters.min_trials_for_bias_intervention`` and
``trials_in_bias_intervention`` exceeds ``parameters.intervention_interval``.
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+32
to
+34
| trial_threshold: Optional[int] = Field( | ||
| default=None, | ||
| ge=0, |
Comment on lines
+1433
to
+1439
| /// <summary> | ||
| /// Minimum number of trials that must elapse before anti-bias intervention can trigger. Bias is unreliable with few trials, so interventions are suppressed until this threshold is reached. If None, no minimum trial threshold is enforced. | ||
| /// </summary> | ||
| [Newtonsoft.Json.JsonPropertyAttribute("trial_threshold")] | ||
| [System.ComponentModel.DescriptionAttribute("Minimum number of trials that must elapse before anti-bias intervention can trigg" + | ||
| "er. Bias is unreliable with few trials, so interventions are suppressed until th" + | ||
| "is threshold is reached. If None, no minimum trial threshold is enforced.")] |
| intervention_interval: int = 10, | ||
| total_offset: float = 0.0, | ||
| threshold: BiasThreshold = BiasThreshold(upper=0.7, lower=0.3), | ||
| trial_threshold: int = 100, |
alexpiet
approved these changes
Aug 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add minimum trial threshold to bias interventions, regenerates all of the schemas, and updates and adds tests. Default is 100. Relevant file changes at src\aind_behavior_dynamic_foraging\task_logic\interventions\bias_intervention.py. Fixes #174