Generated from aind-library-template
Project description
aind-behavior-curriculum
A core problem in mice training is accurately keeping track of each mouse's training stage and accurately setting the corresponding rig parameters. As the number of behavior studies, research assistants, and mice increase, manual tracking and parameter input is prone to human error. This library provides a flexible framework for defining mice curriculum enabling mouse training to be automated.
Installation
pip install aind-behavior-curriculum
Documentation
Understanding a Curriculum
A Curriculum
is structured as a graph of training Stages
.
Each Stage
is associated with a Task
, which is a set of rig parameters.
Stages are connected by Stage Transitions
, which are directed edges associated with a trigger condition.
Stages
and Stage Transitions
form the nodes and edges of a Curriculum
graph, respectively.
With this structure alone, a user can define a basic curriculum with the flexibility of defining skip connections and regressions. For nodes with multiple ongoing edges, edges are labelled by priority, set by the user.
An example curriculum consisting of purely stages and stage transitions. This Curriculum consists of a skip connection between Stage 'StageA' and Stage 'Graduated'. Stage Transitions are triggered on a parameter 't2' and the skip transition is ordered before the transition going to Stage StageB. |
$~$
This library also supports Curriculum
hypergraphs.
Conceptually, a user may want to change the rig parameters associated with a stage, but this set of rig parameters would be unnatural to classify as a new training stage altogether.
In this situation, the user may define a graph of Policies
and Policy Transitions
within a Stage
.
A Policy
, changes the task parameters of a Stage
, as described above. A Policy Transition
acts just like a Stage Transition
, and defines transitions between Policies
on a trigger condition. Like Stage Transitions
, Policy Transitions
can connect any two arbitrary Policies
and are ordered by priority set by the user.
An example Curriculum consisting of Stage and Policy graphs. Left: The high level policy graph. Right: Internal policy graphs. |
Policies
are more nuanced than Stages
.
Yellow Policies
in the example indicate 'Start Policies'. To initialize the rig parameters of a Stage
, the user must specify which Policy/Policies
in the Stage
policy graph to start with.
Unlike Stages
, a mouse can occupy multiple active Policies
within a Stage
. As described later, the Trainer
will record the net combination of rig parameters.
$~$
Any hypergraph is supported!
Here are some examples of the possibilities. The high-level stage graph are shown to the left and the inidividual policy graphs are shown to the right.
A 'Tree' Curriculum |
A 'Train Track' Curriculum |
A 'Policy Triangle' Curriculum |
A 'Stage Triangle' Curriculum |
$~$
Understanding the Trainer
The Trainer
is responsible for recording where a mouse is in its associated curriculum hypergraph. The Trainer
contains 4 primary functions:
-
Registration: This is the entry point where the mice enter the system. Here, the user provides the
Trainer
with a mouse and associates the mouse with a curriculum, a start stage, and start policies as a starting place for evaluation. -
Evaluation: For each registered mouse, the
Trainer
looks at the mouse's current position in its hypergraph curriculum. TheTrainer
collects all the current outgoing transitions and checks which evaluate to True. TheTrainer
determines the updated hypergraph position and associatedTask
parameters according to the following simple rules:Trainer
takes the outgoingStage Transition
with the highest priority. If multipleStage Transitions
evaluate to True, then theStage Transition
with the highest priority is chosen. Priority is set by the user.Trainer
takes the outgoingPolicy Transition
with the highest priority. If multiplePolicy Transitions
evaluate to True, then thePolicy Transition
with the highest priority is chosen. Priority is set by the user.Stage Transitions
overridePolicy Transitions
. If aStage Transition
andPolicy Transition
both evaluate to True, theTrainer
jumps directly to the nextStage
.- If no transitions are True, the mouse stays in place.
- For multiple active
Policies
that evaluate to True,Trainer
sets the currentTask
parameters to the net combination of incidentPolicies
.
-
Mouse Override: This allows the user to update a mouse's position manually to any position in its curriculum. Future evaluation occurs from this new position. Due to this feature, it is possible to design a
Curriculum
of 'floating stages' and 'floating policies'. -
Mouse Eject: This allows the user to remove a mouse from its curriculum entirely. The position of the mouse is recorded as 'None' and stays at 'None' on future evaluation unless the mouse is overrides back onto curriculum.
Every Trainer
function keeps a record of mouse history in SubjectHistory
which can be referenced or exported for rig automation and further analysis.
$~$
Building a Curriculum
For examples of how to build a Curriculum
, please reference examples/example_project
and examples/example_project_2
within the project files and their associated diagrams, examples/example_project/diagrams
and examples/example_project_2/diagrams
.
Tips for building your own Curriculum
:
-
Focus on one graph at a time. Define all the
Tasks/Stages/Stage Transitions
associated with the higher level graph, and then move onto defining thePolicies/Policy Transitions
associated with eachStage
. -
Metrics
contains all the variables that trigger conditions associated withStage Transitions
andPolicy Transitions
. Progressively add toMetrics
as needed. -
Keep
Stage Transitions
andPolicy Transitions
simple. A typical transition will only trigger on one metric variable. This makes transitions much easier to name. -
Validate
Stage Transition
andPolicy Transition
priority with theCurriculum.export_digram(...)
utility, which labels edges with its rank. UseCurriculum.set_stage_transition_priority(...)
andStage.set_policy_transition_priority(...)
to reorder priority.
Common mistakes:
-
Every
Stage
needs a set of start policies, seeCurriculum.set_start_policies(...)
. If a stage with no policies is desired, usecurriculum_utils.create_empty_stage(...)
. This is a common pattern for the final stage of aCurriculum
, so the library also offers a prebuilt final stagecurriculum_utils.GRADUATED
. -
The callables in
Policy
andPolicy Transition/Stage Transition
have different input signatures. Please referencePolicy.validate_rule(...)
andPolicyTransition.validate_rule(...)
/StageTransition.validate_rule(...)
$~$
Building a Trainer
The 4 primary functions of the Trainer
described above are decoupled from any database. To use the Trainer
in practice, the user must define Trainer.load_data(...)
and Trainer.write_data(...)
which connect to a user's databases for mice curriculum, mice history, and mice metrics. Please see examples/example_project/trainer.py
for an example.
$~$
Inside Allen Institute of Neural Dynamics
Allen Institute of Neural Dynamics offers an internal repository template that automatically uploads the repository's curriculum to a central bucket available here: https://github.com/AllenNeuralDynamics/aind-behavior-curriculum-template This way, curriculums can be accessed across rig computers and reused/modified similar to Github commits.
As of (5/9/2024), a Metrics database has yet to be defined, therefore a Trainer cannot be defined.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file aind_behavior_curriculum-0.0.28.tar.gz
.
File metadata
- Download URL: aind_behavior_curriculum-0.0.28.tar.gz
- Upload date:
- Size: 245.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 41a78dfd18bc7fb559ac82662bf063b5e1f51c09c5c8efd2cb89fee8117e7fb4 |
|
MD5 | e0d9de9eaa39a1d35e31063e581d7e5f |
|
BLAKE2b-256 | 568c82bdb93ee093ac08d3cc0b40b4f35dd3b6f0c060eb6efc8ba877f9c500e3 |
File details
Details for the file aind_behavior_curriculum-0.0.28-py3-none-any.whl
.
File metadata
- Download URL: aind_behavior_curriculum-0.0.28-py3-none-any.whl
- Upload date:
- Size: 213.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 641a33bf650a678c5010ef41cd9c846527390191a75a11d75387704089bade31 |
|
MD5 | 30273f36578b19d32b75a27b78de9f0d |
|
BLAKE2b-256 | 2db9f5d97939ff80a2d683f1474effb5466bb1e6e14010c8b9feb755029c62aa |