Skip to content

Postprocessing

jabs.behavior.postprocessing package.

PostprocessingPipeline

Pipeline for applying a series of post-processing stages.

Parameters:

Name Type Description Default
config list[dict[str, str | dict | None]]

Configuration listing the pipeline stages to execute and their parameters.

required

stages property

Return the active (enabled) pipeline stages in execution order.

run(classes, probabilities)

Run the post-processing pipeline on the predicted classes.

Parameters:

Name Type Description Default
classes ndarray

The predicted classes.

required
probabilities ndarray

The predicted probabilities.

required

Returns:

Type Description
ndarray

np.ndarray: Classes after applying all filters in the pipeline.

pipeline

PostprocessingPipeline

Pipeline for applying a series of post-processing stages.

Parameters:

Name Type Description Default
config list[dict[str, str | dict | None]]

Configuration listing the pipeline stages to execute and their parameters.

required

stages property

Return the active (enabled) pipeline stages in execution order.

run(classes, probabilities)

Run the post-processing pipeline on the predicted classes.

Parameters:

Name Type Description Default
classes ndarray

The predicted classes.

required
probabilities ndarray

The predicted probabilities.

required

Returns:

Type Description
ndarray

np.ndarray: Classes after applying all filters in the pipeline.

stages

Postprocessing stages.

BoutDurationFilterStage

Bases: PostprocessingStage

Filter that removes predictions shorter than a specified duration.

Parameters:

Name Type Description Default
min_duration int

Minimum duration (in frames) for a prediction to be kept.

required

config property

Get the filter configuration.

apply(classes, probabilities)

Apply the duration filter to the predictions.

A too-short bout is normally removed by absorbing its frames into the neighboring bouts, which for a lone short BEHAVIOR bout means the surrounding NOT_BEHAVIOR state takes them over. When the whole vector is one too-short BEHAVIOR bout there is no neighbor to absorb it, so the frames are set to NOT_BEHAVIOR directly: leaving them as BEHAVIOR would keep a bout this filter rejected, and would make the result depend on whether other frames happened to be present.

Parameters:

Name Type Description Default
classes ndarray

The predicted classes.

required
probabilities ndarray

The predicted probabilities. (Not used in this stage.)

required

Returns:

Type Description
ndarray

np.ndarray: classes after applying the filter.

help() classmethod

Get help information about the stage.

Returns:

Name Type Description
FilterHelp StageHelp

Dataclass with a general description and kwarg descriptions.

BoutStitchingStage

Bases: PostprocessingStage

Postprocessing stage that combines predictions that are separated by short gaps.

Parameters:

Name Type Description Default
max_stitch_gap int

Maximum gap duration (in frames) allowed between bouts to be stitched together.

required

config property

Get the filter configuration.

apply(classes, probabilities)

Apply stitching to the predictions.

Only a NOT_BEHAVIOR run that actually separates two BEHAVIOR bouts is stitched across. A short NOT_BEHAVIOR run at the very start or end of the vector, or one bordering frames with no prediction, has a BEHAVIOR bout on at most one side, so removing it would relabel not-behavior frames instead of joining two bouts.

Parameters:

Name Type Description Default
classes ndarray

The predicted classes.

required
probabilities ndarray

The predicted probabilities. (Not used in this stage.)

required

Returns:

Type Description
ndarray

np.ndarray: Classes after applying the stitching.

help() classmethod

Get help information about the stage.

Returns:

Name Type Description
FilterHelp StageHelp

Dataclass with a general description and kwarg descriptions.

GapInterpolationStage

Bases: PostprocessingStage

Stage that interpolates gaps in predictions.

config property

Get the filter configuration.

apply(classes, probabilities)

Apply gap interpolation to the predictions.

Parameters:

Name Type Description Default
classes ndarray

The predicted classes.

required
probabilities ndarray

The predicted probabilities. (Not used in this stage.)

required

Returns:

Type Description
ndarray

np.ndarray: Classes after interpolation.

help() classmethod

Get help information about the stage.

Returns:

Name Type Description
FilterHelp StageHelp

Dataclass with a general description and kwarg descriptions.

PostprocessingStage

Bases: ABC

Base class for post-processing stages.

config property

Get the filter configuration.

apply(classes, probabilities) abstractmethod

Apply the stage to the predictions.

Parameters:

Name Type Description Default
classes ndarray

The predicted classes.

required
probabilities ndarray

The predicted probabilities.

required

Returns:

Type Description
ndarray

np.ndarray: Classes after applying the stage transformation.

help() abstractmethod classmethod

Get help information about the stage.

Returns:

Name Type Description
StageHelp StageHelp

Dataclass with a general description and kwarg descriptions.

Example

return StageHelp( description="Removes short bouts below a minimum duration.", kwargs={ "min_duration": KwargHelp( description="Minimum duration (in frames) for a bout to be kept.", type="int" ), } )

stage_registry()

Get the stage registry.

Returns:

Type Description
dict[str, type[PostprocessingStage]]

Dictionary mapping stage names to stage classes.

duration_stage

BoutDurationFilterStage

Bases: PostprocessingStage

Filter that removes predictions shorter than a specified duration.

Parameters:

Name Type Description Default
min_duration int

Minimum duration (in frames) for a prediction to be kept.

required
config property

Get the filter configuration.

apply(classes, probabilities)

Apply the duration filter to the predictions.

A too-short bout is normally removed by absorbing its frames into the neighboring bouts, which for a lone short BEHAVIOR bout means the surrounding NOT_BEHAVIOR state takes them over. When the whole vector is one too-short BEHAVIOR bout there is no neighbor to absorb it, so the frames are set to NOT_BEHAVIOR directly: leaving them as BEHAVIOR would keep a bout this filter rejected, and would make the result depend on whether other frames happened to be present.

Parameters:

Name Type Description Default
classes ndarray

The predicted classes.

required
probabilities ndarray

The predicted probabilities. (Not used in this stage.)

required

Returns:

Type Description
ndarray

np.ndarray: classes after applying the filter.

help() classmethod

Get help information about the stage.

Returns:

Name Type Description
FilterHelp StageHelp

Dataclass with a general description and kwarg descriptions.

interpolation_stage

GapInterpolationStage

Bases: PostprocessingStage

Stage that interpolates gaps in predictions.

config property

Get the filter configuration.

apply(classes, probabilities)

Apply gap interpolation to the predictions.

Parameters:

Name Type Description Default
classes ndarray

The predicted classes.

required
probabilities ndarray

The predicted probabilities. (Not used in this stage.)

required

Returns:

Type Description
ndarray

np.ndarray: Classes after interpolation.

help() classmethod

Get help information about the stage.

Returns:

Name Type Description
FilterHelp StageHelp

Dataclass with a general description and kwarg descriptions.

postprocessing_stage

KwargHelp dataclass

Dataclass for kwarg help information.

Attributes:

Name Type Description
description str

Human-readable description of the parameter.

type str

Type name string (e.g. "int").

default Any

Suggested default value, or None if no default is defined. Used by config generators to populate template files.

PostprocessingStage

Bases: ABC

Base class for post-processing stages.

config property

Get the filter configuration.

apply(classes, probabilities) abstractmethod

Apply the stage to the predictions.

Parameters:

Name Type Description Default
classes ndarray

The predicted classes.

required
probabilities ndarray

The predicted probabilities.

required

Returns:

Type Description
ndarray

np.ndarray: Classes after applying the stage transformation.

help() abstractmethod classmethod

Get help information about the stage.

Returns:

Name Type Description
StageHelp StageHelp

Dataclass with a general description and kwarg descriptions.

Example

return StageHelp( description="Removes short bouts below a minimum duration.", kwargs={ "min_duration": KwargHelp( description="Minimum duration (in frames) for a bout to be kept.", type="int" ), } )

StageHelp dataclass

Dataclass for stage help information.

stitching_stage

BoutStitchingStage

Bases: PostprocessingStage

Postprocessing stage that combines predictions that are separated by short gaps.

Parameters:

Name Type Description Default
max_stitch_gap int

Maximum gap duration (in frames) allowed between bouts to be stitched together.

required
config property

Get the filter configuration.

apply(classes, probabilities)

Apply stitching to the predictions.

Only a NOT_BEHAVIOR run that actually separates two BEHAVIOR bouts is stitched across. A short NOT_BEHAVIOR run at the very start or end of the vector, or one bordering frames with no prediction, has a BEHAVIOR bout on at most one side, so removing it would relabel not-behavior frames instead of joining two bouts.

Parameters:

Name Type Description Default
classes ndarray

The predicted classes.

required
probabilities ndarray

The predicted probabilities. (Not used in this stage.)

required

Returns:

Type Description
ndarray

np.ndarray: Classes after applying the stitching.

help() classmethod

Get help information about the stage.

Returns:

Name Type Description
FilterHelp StageHelp

Dataclass with a general description and kwarg descriptions.