mousestyles.behavior package

Submodules

mousestyles.behavior.behavior module

Behavior Analysis

mousestyles.behavior.behavior_tree module

class mousestyles.behavior.behavior_tree.BehaviorTree(structure=None, contents=None, units=None)[source]

Object representing a decomposed tree of behavior. Behaves much like a dictionary, with an additional representation of the tree structure of the data.

Parameters:
  • structure (list, optional) – Representation of parent-child relationships between nodes
  • contents (defaultdict, optional) – Initial node values
  • units (defaultdict, optional) – Mapping of node names to units

Examples

>>> tree = BehaviorTree(['Consumption',
                         ['AS Prob', 'Intensity']])
>>> tree['Consumption'] = 5
>>> tree['AS Prob'] = 1
>>> tree['Intensity'] = 2
>>> tree.contents
defaultdict(float, {'AS Prob': 1, 'Consumption': 5, 'Intensity': 2})
>>> tree.structure
['Consumption', ['AS Prob', 'Intensity']]
>>> print(tree)
Consumption: 5
AS Prob: 1 Intensity: 2
copy()[source]

Return a copy of the tree.

static merge(*args)[source]

Merge several trees into one compound tree.

Parameters:*args (variable-length argument list of BehaviorTree objects) – One or more trees to be merged.
Returns:new_tree – Tree with same structure as input trees, where each node is a list containing the node values from the input trees.
Return type:BehaviorTree

Examples

>>> tree = BehaviorTree(contents={'a': 1, 'b': 2})
>>> tree2 = BehaviorTree(contents={'a': -1.5, 'b': 20})
>>> BehaviorTree.merge(tree, tree2).contents
defaultdict(list, {'a': [1, -1.5], 'b': [2, 20]})
summarize(f)[source]

Computes a summary statistic for the nodes in a tree.

Parameters:f (function) – A function to be applied to the contents in each node. Most often, this will take in a list and return a single number.
Returns:
  • A new tree with the same structure, where each node value tree[k]
  • is replaced by f(tree[k]).

mousestyles.behavior.construct_trees module

Construct behavior trees

mousestyles.behavior.construct_trees.compute_tree(feature, strain, mouse, day, epsilon=1)[source]

Compute and return a tree decomposition of a feature for a single mouse-day

Parameters:
  • feature ({'F', 'W', 'L'}) – The feature used. ‘F’ for food, ‘W’ for water, ‘L’ for locomotion.
  • strain (int) – Integer representing the strain of the mouse
  • mouse (int) – Integer representing the specific mouse
  • day (int) – Integer representing the day to produce the metrics for
  • epsilon (float, optional) – tolerance for merging events into bouts
Returns:

behavior – dictionary-like object representing breakdown of consumption into various nodes

Return type:

BehaviorTree

mousestyles.behavior.construct_trees.process_raw_intervals(feature, consumption, intervals, active_time, total_time, epsilon)[source]

Takes total_consumption and the data in intervals and decomposes it into a tree of behavioral summary statistics.

Parameters:
  • feature ({'F', 'W', 'L'}) – The feature used. ‘F’ for food, ‘W’ for water, ‘L’ for locomotion.
  • consumption (float) – total consumption (food, water, or movement) in the time period
  • intervals (Intervals) – Intervals object representing intervals of behavior
  • active_time (float) – amount of time the mouse was active in the day
  • total_time (float) – total amount of recording time in the day
  • epsilon (float) – tolerance for merging events into bouts
Returns:

behavior – dictionary-like object representing breakdown of consumption into various nodes

Return type:

BehaviorTree

Examples

>>> from mousestyles import data, intervals
>>> ints = intervals.Intervals(data.load_intervals('AS'))
>>> results = process_raw_intervals(1000, ints, 1)

mousestyles.behavior.metrics module

Metrics for behavior

mousestyles.behavior.metrics.active_time(strain, mouse, day)[source]

Returns the total amount of active time recorded for a certain mouse-day.

Parameters:
  • strain (int) –
  • mouse (int) –
  • day (int) –
Returns:

Return type:

The total amount of active time in seconds for the specified mouse-day.

mousestyles.behavior.metrics.create_collapsed_intervals(intervals, bout_threshold)[source]

Returns a collapsed interval object (within a given threshold) on a certain mouse-strain-day for a given activity type.

Parameters:
  • intervals (interval object on a certain mouse-strain-day) –
  • a given activity type (for) –
  • bout_threshold (: float) – Float representing the time threshold to use for collapsing separate events into bouts
Returns:

  • An intervals object intervals for the given activity type and
  • mouse-strain-day within a bout threshold

Examples

>>> ints=behavior.create_intervals('F', strain = 0
                                   , mouse = 0, day = 0
                                   , bout_threshold = 0.001)
>>> collapsed_ints=behavior.create_collapsed_intervals(intervals = ints
                                                , bout_threshold = 0.001)
>>> print(collapsed_ints)
mousestyles.behavior.metrics.create_intervals(activity_type, strain, mouse, day)[source]

Returns an interval object on a certain mouse-strain-day for a given activity type.

Parameters:
  • activity_type (str) – String specifying activity type {“AS”, “F”, “IS”, “M_AS”, “M_IS”, “W”}
  • strain (int) – Integer representing the strain of the mouse
  • mouse (int) – Integer representing the specific mouse
  • day (int) – Integer representing the day to produce the metrics for
  • bout_threshold (: float) – Float representing the time threshold to use for collapsing separate events into bouts
Returns:

  • An intervals object intervals for the given activity type and
  • mouse-strain-day within a bout threshold

Examples

>>> ints=behavior.create_intervals(activity_type = 'F', strain = 0
                                   , mouse = 0, day = 0
                                   , bout_threshold = 0.001)
>>> print(sum(ints))
mousestyles.behavior.metrics.total_amount(strain, mouse, day, feature)[source]
Returns the total amount consumed/moved for one of the following features:
food (“F”), water (“W”), and locomotion (“L”).
Parameters:
  • strain (int) –
  • mouse (int) –
  • day (int) –
  • feature ({'F', 'W', 'L'}) – The feature used. ‘F’ for food, ‘W’ for water, ‘L’ for locomotion.
Returns:

Return type:

The total amount consumed/moved for the given feature in the mouse-day.

mousestyles.behavior.metrics.total_time(strain, mouse, day)[source]

Returns the total amount of time recorded for a certain mouse-day.

Parameters:
  • strain (int) –
  • mouse (int) –
  • day (int) –
Returns:

Return type:

The total amount of time in seconds of the specified mouse-day.

Module contents