brainiak.eventseg package

Event segmentation of continuous data + event transfer between datasets.


brainiak.eventseg.event module

Event segmentation using a Hidden Markov Model

Given an ROI timeseries, this class uses an annealed fitting procedure to segment the timeseries into events with stable activity patterns. After learning the signature activity pattern of each event, the model can then be applied to other datasets to identify a corresponding sequence of events.

Full details are available in the bioRxiv preprint: Christopher Baldassano, Janice Chen, Asieh Zadbood, Jonathan W Pillow, Uri Hasson, Kenneth A Norman Discovering event structure in continuous narrative perception and memory

class brainiak.eventseg.event.EventSegment(n_events=2, step_var=<function EventSegment._default_var_schedule>, n_iter=500)

Bases: sklearn.base.BaseEstimator

Class for event segmentation of continuous fMRI data

  • n_events (int) – Number of segments to learn
  • step_var (Callable[[int], float] : default 4 * (0.98 ** (step - 1))) – The Gaussian variance to use during fitting, as a function of the number of steps. Should decrease slowly over time.
  • n_iter (int : default 500) – Maximum number of steps to run during fitting
p_start, p_end

length n_events+1 ndarray – initial and final prior distributions over events


n_events+1 by n_events+1 ndarray – HMM transition matrix


ndarray with length = number of training datasets – Log-likelihood for training datasets over the course of training


list of (time by event) ndarrays – Learned (soft) segmentation for training datasets


float – Gaussian variance at the end of learning


voxel by event ndarray – Learned mean patterns for each event

find_events(testing_data, var=None, scramble=False)

Applies learned event segmentation to new testing dataset

After fitting an event segmentation using fit(), this function finds the same sequence of event patterns in a new testing dataset.

  • testing_data (timepoint by voxel ndarray) – fMRI data to segment based on previously-learned event patterns
  • var (float or 1D ndarray of length equal to the number of events) – default: uses variance that maximized training log-likelihood Variance of the event Gaussians. If scalar, all events are assumed to have the same variance.
  • scramble (bool : default False) – If true, the order of the learned events are shuffled before fitting, to give a null distribution

  • segments (time by event ndarray) – The resulting soft segmentation. segments[t,e] = probability that timepoint t is in event e
  • test_ll (float) – Log-likelihood of model fit

fit(X, y=None)

Learn a segmentation on training data

Fits event patterns and a segmentation to training data. After running this function, the learned event patterns can be used to segment other datasets using find_events

  • X (time by voxel ndarray, or a list of such ndarrays) – fMRI data to be segmented. If a list is given, then all datasets are segmented simultaneously with the same event patterns
  • y (not used (added to comply with BaseEstimator definition)) –


Return type:

the EventSegment object


Applies learned event segmentation to new testing dataset

Alternative function for segmenting a new dataset after using fit() to learn a sequence of events, to comply with the sklearn Classifier interface

Parameters:X (timepoint by voxel ndarray) – fMRI data to segment based on previously-learned event patterns
Return type:Event label for each timepoint