Definitions & Formulas - DeNardoLab/BehaviorDEPOT GitHub Wiki
This page contains the various definitions and formulas used in the BehaviorDEPOT pipeline.
- The following definitions are for body parts that are derived from tracked keypoints.
- If legs are tracked: mean(BetwEars + BetwLegs)
- Otherwise: mean(BetwEars + Tailbase)
- If MidBack is tracked directly as a keypoint, then it will remain unchanged
- 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).
- Angles relative to the positive X axis (degrees -180 to +180)
- Equal to arctangent(Keypoint1(Y)-Keypoint2(Y), Keypoint1(X)-Keypoint2(X))
- Units: deg
- Distance between two body parts
- Equal to sqrt((Keypoint2(X)-Keypoint1(X))2+((Keypoint2(Y)-Keypoint1(Y)2)
- Units: cm
- Distance change by frame, used to calculate linear velocity and acceleration
- Equal to x(i+1) - x(i) * framerate / resolution
- Units: cm/s
- Angle change by frame, used to calculate angular velocity
- Equal to ((angle(i+1)-angle(i) + 180)/360 – 180)
- Units: deg/frame
- Linear velocity of a keypoint
- Equal to sqrt((dx/dt)2+(dy/dt)2) [Pythagorean Theorem]
- Units: cm/s
- 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
- Linear acceleration of a keypoint per frame
- Equal to the velocity differential divided by framerate
- Units: cm/s2
- Cumulative sum of distance per frame times resolution
- Represents total distance traveled per frame based on central point on body
- Units: cm
- A hampel correction is applied to the data to detect outliers.
- For more info see:
- Hampel, F. R. The Influence Curve and its Role in Robust Estimation. J. Am. Stat. Assoc. 69, 383–393 (1974)
- MATLAB 'hampel' documentation
- 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 = 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:
- Cleveland, W. S. LOWESS: A Program for Smoothing Scatterplots by Robust Locally Weighted Regression. Am. Stat. 35, 54 (1981)
- For more info on alternative methods, see MATLAB 'smooth' method options
- 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.
- 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:
- TP = true positive frames
- TN = true negative frames
- FP = false positive frames
- FN = false negative frames
- Quantifies the positive predictive value of the classifier against the tendency to produce false positive errors.
- Equal to TP / (TP + FP)
- Quantifies the positive predictive value of the classifier against the tendency to produce false negative errors.
- Equal to TP / (TP + FN)
- Quantifies overall classifier performance.
- Equal to (2 * precision * recall) / (precision + recall)
- Quantifies the classifier's ability to accurately label true negatives; helps ensure classifier is only labeling a single behavior.
- Equal to TN / (TN + FP)