behav_utils#
Analysis library for trial-based behavioural experiments. It loads trials from your files through a YAML config, scores each trial by its task (two-alternative forced choice, go/no-go, reproducing a value, or a task of your own), computes statistics and readouts with resampling-based uncertainty, compares phases and groups, simulates any behavioural model through the same pipeline, and saves experiments in an open format.
It knows nothing about any particular experiment: stimulus units, tasks, distributions, session types and presets all come from the config you give it. Every computation runs on one stimulus axis, [-1, 1], that the loader maps your raw stimulus onto (the category boundary, or for continuous tasks the range’s midpoint, at 0).
A five-minute tour#
No data needed: a synthetic animal stands in for load_experiment('config.yaml').
from behav_utils import (PsychometricModel, TrialArrays, compute_delta_stat, compute_psychometric_curve,
compute_stats, filter_trials, generate_synthetic_animal, plot_psychometric_curve,
select_sessions)
# Ten sessions of a psychometric observer whose slope flattens on laser trials
animal = generate_synthetic_animal(PsychometricModel(sigma=0.25, laser={'sigma': 0.45}), n_sessions=10,
laser_fraction=0.3, rng=0)
sessions = select_sessions(animal, min_trials=0) # which sessions (presets come from the config)
off = filter_trials(sessions, trial_type='non_opto') # which trials: aborts and laser trials out
on = filter_trials(sessions, trial_type='opto')
arrays = TrialArrays.from_sessions(off) # one aligned bundle, scored by the task
compute_stats(arrays, ['accuracy', 'mu', 'sigma', 'win_stay']) # a pd.Series
curve = compute_psychometric_curve(arrays, n_bootstrap=200) # fit and bootstrap band
plot_psychometric_curve(curve) # draw-only, one panel
d = compute_delta_stat({'off': off, 'on': on}, ['sigma', 'accuracy'], reference='off',
n_bootstrap=200, n_permutations=200)
d.contrast('on').table() # Δ, bootstrap CI and permutation p per statistic
The draws are kept small so the tour runs quickly; the defaults (1000 bootstrap draws) suit a real analysis.
Saving needs pyarrow, the store extra:
animal.save('animal_store') # a store: Parquet and JSON
Where to go next#
Install: a pinned release from GitHub, and the optional extras.
Tutorials: notebooks on synthetic data, executed every time this site is built.
Concepts: the pipeline, tasks, the stimulus axis, identities and time, and resampling.
How-to guides: short recipes for common analyses, and for extending the library with a statistic, readout, task, model or reader of your own.
Reference: the API by sub-package, every statistic, the configuration file and the data structures.