Skip to content

feat(analysis): add probability outputs and state transition maps - #4

Merged
btmlnsn merged 13 commits into
btmlnsn:publication/stagingfrom
MyraLyu:pr/probability-outputs-state-transition-map
Sep 24, 2026
Merged

btmlnsn merged 13 commits into
btmlnsn:publication/stagingfrom
MyraLyu:pr/probability-outputs-state-transition-map

Conversation

@MyraLyu

@MyraLyu MyraLyu commented Sep 24, 2026 •

Copy link
Copy Markdown

Summary

Author and primary contributor: Myra Lyu

Integration and visualization refinements: Bobby Tomlinson

This PR adds frame-level behavior-probability outputs and State Transition Maps to LabGym’s analysis workflow. It gives users the complete prediction distribution for each frame and a scientifically interpretable summary of bout-to-bout behavioral transitions.


Changes

Frame-Level Probability Matrix

Problem
Currently, LabGym reported the probability of different behaviors for each video frame; however, it would be difficult for users to interpret and inspect model uncertainty, especially during behavioral transitions or when visually similar behaviors received comparable prediction scores. Users also lacked a visual representation for comparing model outputs across datasets.

Implementation
Added export of a frame-level behavior-probability matrix for each analyzed individual. Each output includes a NumPy .npy matrix, a CSV with frame/time information and one probability column per behavior, and a probability heat map showing behaviors by frame/time.

The heat maps use a fixed linear 0–1 probability scale. Missing or non-finite values are shown in a distinct neutral gray rather than being displayed as low probabilities.

Impact
Users can now inspect the complete probability distribution behind every behavioral prediction, making uncertain frames and behavioral transitions easier to identify. The fixed scale also meaningful visual comparisons across recordings.


State-Transition Map

Problem
LabGym did not provide a compact, interpretable visualization of behavioral transition structure. Users could not easily inspect which behaviors tended to follow a source behavior, compare transition patterns across individuals, or connect a visual map to the underlying counts and probabilities.

Implementation
Added a user-configurable State Transition Map generator that reads LabGym all_events.xlsx outputs and creates a separate result package for each included individual.

The analysis collapses consecutive frames with the same behavior into bouts, counts transitions between successive bouts within uninterrupted sequences, and computes row-normalized transition probabilities: P(destination next | source current).

NA and user-excluded behaviors break the sequence, preventing false transitions across those intervals. Node size represents frame occupancy, while edge width represents transition probability; equal probabilities use equal widths across maps. Edge labels report the transition identifier, probability, and observed count.

Impact
Users can identify dominant behavioral pathways, asymmetric transitions, and differences in behavioral organization across individuals or conditions.The accompanying tables preserve the quantitative evidence behind each visual encoding.


Testing

Prepared-component focused validation passed:

  • 80 tests passed:
    • 9 probability heat-map tests
    • 71 State Transition Map tests

Coverage includes:

  • Frame-level probability export shape and saved .npy/CSV outputs.
  • Detector and non-detector heat-map paths.
  • Fixed linear probability scaling from 0 to 1.
  • Distinct rendering of missing and non-finite probability cells.
  • Bout collapsing, NA/excluded-behavior sequence breaks, transition counts, and row-normalized transition probabilities.
  • Frame-based behavior occupancy.
  • Cross-map consistency of State Transition Map edge widths for equal transition probabilities.

Manual visualization review:

  • The combined probability heat-map and State Transition Map smoke outputs were visually reviewed and accepted after the visualization refinements.

Known limitations

  • Transition probabilities describe the destination behavior after a source bout; they are not whole-recording transition frequencies.
  • A behavior with no outgoing transitions has no defined outgoing probability distribution.

@btmlnsn
btmlnsn merged commit d261ad5 into btmlnsn:publication/staging Sep 24, 2026
3 checks passed
@btmlnsn

btmlnsn commented Sep 24, 2026

Copy link
Copy Markdown
Owner

Nice work!

@btmlnsn

btmlnsn commented Sep 24, 2026

Copy link
Copy Markdown
Owner

Quick integration note: I added 3dc3081 to fix Windows CI. An unused curses.panel import in gui_analyzer.py required _curses, which Windows does not provide, causing test collection to fail. Removing it restored cross-platform imports and CI went green.

@MyraLyu
MyraLyu deleted the pr/probability-outputs-state-transition-map branch November 22, 2026 00:41
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.

2 participants