Definitions & Formulas - DeNardoLab/BehaviorDEPOT GitHub Wiki

This page contains the various definitions and formulas used in the BehaviorDEPOT pipeline.

Keypoint Definitions

  • The following definitions are for body parts that are derived from tracked keypoints.

Tracking.BetwEars = mean(Left Ear + Right Ear)

Tracking.BetwLegs = mean(Left Leg + Right Leg)

Tracking.Head = mean(Nose + Left Ear + Right Ear)

Tracking.Head_Implant = mean(Implant + Left Ear + Right Ear)

Tracking.MidBack

  • If legs are tracked: mean(BetwEars + BetwLegs)
  • Otherwise: mean(BetwEars + Tailbase)
  • If MidBack is tracked directly as a keypoint, then it will remain unchanged

Tracking.BetwShoulders = mean(Left Ear + Right Ear + MidBack)

Tracking.RearBack = mean(Left Leg + Right Leg + Tailbase)

Metric Definitions

  • These definitions describe the metrics calculated from the keypoint tracking info (i.e. DLC).
  • These metrics are calculated in the function 'calculateMetrics' (used in the Analysis Module).

Postural Metrics

Metrics.degBodypartAngle

  • Angles relative to the positive X axis (degrees -180 to +180)
  • Equal to arctangent(Keypoint1(Y)-Keypoint2(Y), Keypoint1(X)-Keypoint2(X))
  • Units: deg

Metrics.Dist.KeypointPair

  • Distance between two body parts
  • Equal to sqrt((Keypoint2(X)-Keypoint1(X))2+((Keypoint2(Y)-Keypoint1(Y)2)
  • Units: cm

Kinematics

Metrics.Diff.Keypoint

  • Distance change by frame, used to calculate linear velocity and acceleration
  • Equal to x(i+1) - x(i) * framerate / resolution
  • Units: cm/s

Metrics.Diff.KeypointAngle

  • Angle change by frame, used to calculate angular velocity
  • Equal to ((angle(i+1)-angle(i) + 180)/360 – 180)
  • Units: deg/frame

Metrics.Velocity.Keypoint

  • Linear velocity of a keypoint
  • Equal to sqrt((dx/dt)2+(dy/dt)2) [Pythagorean Theorem]
  • Units: cm/s

Metrics.Velocity.KeypointAngle

  • Angular velocity of a keypoint-based angle calculation
  • Equal to ((angle(i+1)-angle(i) + 180)/360 – 180)*framerate [transform range from -180->180 to 0->360]
  • Units: deg/s

Metrics.Acceleration.Keypoint

  • Linear acceleration of a keypoint per frame
  • Equal to the velocity differential divided by framerate
  • Units: cm/s2

Distance Metrics

Metrics.DistanceTraveled

  • Cumulative sum of distance per frame times resolution
  • Represents total distance traveled per frame based on central point on body
  • Units: cm

Data Processing Formulas

Hampel Correction

  • A hampel correction is applied to the data to detect outliers.
  • For more info see:
  1. Hampel, F. R. The Influence Curve and its Role in Robust Estimation. J. Am. Stat. Assoc. 69, 383–393 (1974)
  2. MATLAB 'hampel' documentation

Pose-Estimation Smoothing

  • Raw pose-estimation data is smoothed using the 'smooth' function from the MATLAB Curve Fitting Toolbox, which offers the choice of multiple algorithms for smoothing.
  • The default method of smoothing is 'LOWESS', described below.
  • Smoothing methods can be changed from the GUI.
  • See MATLAB 'smooth' documentation for more information on the smoothing algorithm.

LOWESS Smoothing

  • LOWESS = Local regression using weighted linear least squares and a 1st degree polynomial model.
  • The algorithm fits a local regression model to smooth data across the 'span' specified in the smoothing parameters.
  • This method provides high-quality smoothing but can be slow on longer videos.
  • For more information see:
  1. Cleveland, W. S. LOWESS: A Program for Smoothing Scatterplots by Robust Locally Weighted Regression. Am. Stat. 35, 54 (1981)

Other Smoothing Methods

Behavior Label Smoothing

  • A convolution algorithm is applied to raw behavior labels to remove mislabeling due to minor tracking errors.
  • The algorithm applies a vector of length 'windowWidth' to raw behavior labels, scoring each frame based on the number of positive labels when the vector is centered on the frame.
  • The result is a vector that scores each frame based on the density of behavior labels around it.
  • This vector is then thresholded using 'countThreshold' to produce final binary labels, represented as 1 (behavior+) or 0 (behavior-).
  • Typically, a good 'windowWidth' is the approximate number of frames of the smallest behavior bout you wish to capture (e.g. windowWidth = 30 for 1 sec bout @ 30fps)
  • Typically, a good 'countThreshold' is approximately 1/3 of your windowWidth.
  • These values can be tested using the Optimization Module.

Performance Measures

  • These definitions describe the performance calculations made when using the BehaviorDEPOT support modules.
  • Performance calculations are used in the Validation, Optimization, & Inter-Rater Modules.
  • The following abbreviations apply to performance formulas:
  1. TP = true positive frames
  2. TN = true negative frames
  3. FP = false positive frames
  4. FN = false negative frames

Precision

  • Quantifies the positive predictive value of the classifier against the tendency to produce false positive errors.
  • Equal to TP / (TP + FP)

Recall

  • Quantifies the positive predictive value of the classifier against the tendency to produce false negative errors.
  • Equal to TP / (TP + FN)

F1 Score

  • Quantifies overall classifier performance.
  • Equal to (2 * precision * recall) / (precision + recall)

Specificity

  • Quantifies the classifier's ability to accurately label true negatives; helps ensure classifier is only labeling a single behavior.
  • Equal to TN / (TN + FP)
⚠️ **GitHub.com Fallback** ⚠️