Date: November 9, 2025 Status: Ready to implement based on user feedback
- Genotypes: 2 (+, -)
- WT (+): 9 animals
- KO (-): 10 animals
- Sex: 9 Male, 10 Female
- Reversal task:
A_Mouse LD 1 choice reversal v3(rolling 7/8 criterion) - Special: Some animals achieve 2 reversals per session
- Genotypes: 4 (+, +/+, +/-, -/-)
-
- (WT): 13 animals
- +/+: 8 animals
- +/-: 7 animals
- -/-: 7 animals
-
- Sex: 18 Male, 17 Female
- Reversal task:
A_Mouse LD 1 Reversal 9 task(single reversal) - Special: Different reversal schedule than W cohort
- stimulus_correct_side: Which side is correct (-1=left, +1=right)
- bias: Constant term (1.0)
- prev_choice: Previous choice (-1=left, +1=right)
- wsls: Win-stay/lose-shift (prev_choice Γ prev_correct)
- session_progression: Progress within session (0 to 1)
-
recent_side_bias: Proportion of RIGHT choices in last 10 trials
recent_side_bias = sum(last_10_choices == 'right') / 10 # Range: 0.0 (all left) to 1.0 (all right)
-
task_stage: Numerical encoding of training progression
task_stage_map = { 'LD Initial Touch': 0, 'LD Must Touch': 1, 'LD Punish Incorrect': 2, 'LD 1 choice v2': 3, 'LD 1 choice reversal v3': 4, # or LD 1 Reversal 9 'Pairwise Must Touch': 5, 'Pairwise Punish Incorrect': 6, 'Pairwise Discrimination v3': 7, 'Pairwise Discrimination v3 - Reversal': 8 } # Normalized to 0-1 range
-
cumulative_trials: Total trials experienced (captures overall training)
cumulative_trials = trial_count_so_far / total_trials_in_dataset
- trials_since_reversal: Trials since last reversal occurred
trials_since_reversal = trial_num - last_reversal_trial_num # Helps capture adaptation dynamics # Normalized to 0-1 based on max trials
- stimulus_identity: Which image is S+ (0 or 1, binary feature)
# Track which specific image is rewarded # Important because PD has 2 different images unlike LD
Based on user preference for Option B:
def classify_state(accuracy, cv_latency, mean_latency, dwell_time):
"""
Classify behavioral state based on metrics.
Returns one of:
- "Deliberative High-Performance"
- "Deliberative Moderate-Performance"
- "Disengaged Lapse"
- "Procedural Fast-Performance" (low CV, fast latency)
"""
# Lapse: near-chance accuracy
if accuracy < 0.55:
return "Disengaged Lapse"
# High deliberation (CV > 0.6)
if cv_latency > 0.6:
if accuracy > 0.65:
return "Deliberative High-Performance"
else:
return "Deliberative Moderate-Performance"
# Low deliberation (procedural/automatic)
else:
return "Procedural Fast-Performance"For each identified state, we'll measure and report:
- Mean accuracy Β± SEM
- Mean latency Β± SEM
- Latency CV (coefficient of variation)
- Mean dwell time (bout duration)
- Occupancy (% of trials)
- GLM weights (stimulus, bias, prev_choice, wsls)
Using rolling 7/8 and 5/6 criteria:
def detect_reversals_w_cohort(trial_correctness, ldr_criterion_data):
"""
Detect reversal points for W cohort.
Uses:
- First reversal: 7/8 correct in 8-trial window
- Second reversal: 5/6 correct in 6-trial blocks (after first)
"""
# Get criterion trial numbers from LDR file
first_reversal_trial = ldr_criterion_data['No trials to criterion - Generic Evaluation (1)']
second_reversal_trial = ldr_criterion_data['No trials to criterion - Generic Evaluation (2)']
# Initialize: position 8 (left) is correct
correct_side = -1 # Left
stimulus_values = []
for trial_num in range(1, 31):
# Check if reversal occurred at this trial
if trial_num == first_reversal_trial:
correct_side = +1 # FLIP to right (position 11)
elif not pd.isna(second_reversal_trial) and trial_num == second_reversal_trial:
correct_side = -1 # FLIP back to left (position 8)
stimulus_values.append(correct_side)
return stimulus_valuesSimpler - usually single reversal:
def detect_reversals_f_cohort(ldr_criterion_data):
"""
Detect reversal points for F cohort.
Usually single reversal from position 8 β 11.
"""
first_reversal_trial = ldr_criterion_data['No trials to criterion - Generic Evaluation (1)']
correct_side = -1 # Start with left (position 8)
stimulus_values = []
for trial_num in range(1, 31):
if trial_num == first_reversal_trial:
correct_side = +1 # FLIP to right (position 11)
stimulus_values.append(correct_side)
return stimulus_valuesTasks to analyze:
A_Mouse LD 1 choice v2(position 8 only, no reversals)A_Mouse LD Punish Incorrect Training v2A_Mouse Pairwise Discrimination v3(no reversal)
Separate analyses for:
- W cohort (19 animals)
- F cohort (36 animals)
Outputs:
- State identification and characterization
- State-specific psychometric curves
- GLM weight interpretations
- Learning curves by genotype and sex
Tasks to analyze:
A_Mouse LD 1 choice reversal v3(W cohort - rolling criterion)A_Mouse LD 1 Reversal 9(F cohort - single reversal)
Additional analyses:
- State transitions around reversal points
- Adaptation speed (trials to criterion after reversal)
- Reversal-specific state occupancy
- Genotype effects on reversal learning
Simple WT vs KO comparison:
genotype_comparison = {
'WT (+)': 9 animals,
'KO (-)': 10 animals
}
# Statistical tests:
- Final accuracy: t-test
- State occupancy: ANOVA
- Reversal speed: t-test (trials to criterion)
- Learning rate: linear mixed modelMulti-level comparison:
genotype_comparison = {
'WT (+)': 13 animals,
'Homozygous WT (+/+)': 8 animals,
'Heterozygous (+/-)': 7 animals,
'Homozygous KO (-/-)': 7 animals
}
# Statistical tests:
- Overall genotype effect: One-way ANOVA
- Post-hoc pairwise: Tukey HSD
- Dose-response: Linear trend test (+/+ β +/- β -/-)Collapse F genotypes to match W:
# For W vs F comparison:
F_collapsed = {
'WT': ['+', '+/+'], # Combine
'KO': ['+/-', '-/-'] # Combine hetero + homo KO
}
# Then compare W_WT vs F_WT and W_KO vs F_KO- GLM-HMM summary (weights, transitions, states)
- State-specific psychometric curves
- State occupancy over sessions
- Learning curves by genotype
- State transition heatmap
- Final accuracy by genotype (bar plot with error bars)
- State occupancy by genotype (stacked bar)
- Learning curves overlaid by genotype
- Latency distributions by genotype
- Learning curves by sex
- State occupancy by sex
- Sex Γ genotype interaction
- State transitions around reversal points
- Trials to criterion by genotype
- Adaptation curves (post-reversal learning)
- W vs F learning curves
- W vs F state characterization
- W vs F reversal performance
Total: ~25-30 figures per cohort = 50-60 figures total
- Add
recent_side_biasfeature - Add
task_stagefeature - Add
cumulative_trialsfeature - Add
trials_since_reversalfor reversal tasks - Add
stimulus_identityfor PD tasks
- Create
detect_reversals_w_cohort()function - Create
detect_reversals_f_cohort()function - Integrate with LDR criterion file
- Validate against
Second_Criterion_Count
- Create
classify_state()function - Add state validation metrics
- Auto-label all states in plots
- W cohort - non-reversal tasks
- F cohort - non-reversal tasks
- Generate all Phase 1 figures
- Statistical comparisons (genotype, sex)
- W cohort - reversal tasks
- F cohort - reversal tasks
- Generate all Phase 2 figures
- Reversal-specific analyses
- W vs F comparison figures
- Combined statistical tests
- Final summary document
-
Code:
- Updated
glmhmm_utils.pywith new features - New
reversal_detection.pymodule - Updated
run_complete_analysis.py
- Updated
-
Figures:
- 25-30 figures per cohort
- Organized by analysis type
- Publication-ready (300 DPI)
-
Documentation:
RESULTS_W_COHORT.mdRESULTS_F_COHORT.mdCROSS_COHORT_COMPARISON.md- Statistical test summary tables (CSV)
-
Summary:
- Key findings by genotype
- State characterizations
- Reversal learning metrics
- Recommendations for follow-up
β
Q1: PD side bias?
A: Yes, adding recent_side_bias feature (proportion right choices in last 10 trials)
β Q2: State labels? A: Option B - Process-focused ("Deliberative High-Performance", etc.)
β Q3: Reversal logic? A: Confirmed correct
β Q4: W vs F differences? A: Both start position 8 correct, but different reversal task schedules
β Q5: What is stimulus? A: Stimulus = which side is CORRECT (-1=left, +1=right)
β
Q6: Training effects?
A: Adding task_stage and cumulative_trials features
β Q7: Genotype comparisons? A: Multi-level for F (4 genotypes), simple for W (2 genotypes), collapsed for cross-cohort
Ready to implement! π