## Abstract

A fundamental challenge for behavioral neuroscientists is to accurately quantify (dis)similarities in animal behavior without excluding inherent variability present between individuals. We explored two new applications of curve and shape alignment techniques to address this issue. As a proof-of-concept we applied these methods to compare normal or alarmed behavior in pairs of medaka (*Oryzias latipes*). The curve alignment method we call Behavioral Distortion Distance (BDD) revealed that alarmed fish display less predictable swimming over time, even if individuals incorporate the same action patterns like immobility, sudden changes in swimming trajectory, or changing their position in the water column. The Conformal Spatiotemporal Distance (CSD) technique on the other hand revealed that, in spite of the unpredictability, alarmed individuals exhibit lower variability in overall swim patterns, possibly accounting for the widely held notion of “stereotypy” in alarm responses. More generally, we propose that these new applications of established computational geometric techniques are useful in combination to represent, compare, and quantify complex behaviors consisting of common action patterns that differ in duration, sequence, or frequency.

### Similar content being viewed by others

## Introduction

Quantitative comparison of the behavior of animals is a key element of neuroscience. As important as this is, even the most comprehensive ethograms fail to capture the inherent variability in the behaviors of individuals, whether they consist of simple or complex sets of actions^{1,2,3,4}. This is further compounded by the error-prone nature of subjective assessment during human observations. A pertinent issue for behavioral studies, therefore, is the development of appropriate methods for the quantitative comparison of behaviors between two animals or a single individual under two or more conditions.

Researchers typically quantify parameters (such as the average speed or average height climbed) based on expert knowledge of the ethology of that species or the kinematics of a behavior. These measures are useful, yet they can be inadequate as descriptors of behavior for a variety of reasons. One notable reason is that they are gross approximations of the behavioral action being measured. Averaging of observational data may not be representative of the kinematics and can be confounded by what has been described elsewhere as “the failure of averaging^{2}”. Furthermore, there can be considerable variability in the execution of even those behaviors that are considered “stereotypical” or instinctive. As elaborated at great length by Schleidt in 1974, individual variability can exist in the form of “incompleteness of the elements” that make up an innate behavior or in the form of changes in the characteristics of those “elements” such as their duration, sequencing, or frequency within a given episode of executing the behavior^{5}. Trait variability between individuals such as locomotor handedness is also influenced by alellic differences^{6}. Consequently, the above mentioned gross approximations are at best imperfect representations of the behavior that neither capture nor do justice to the intra and inter subject variability^{7}. Another reason measures fail to be adequate descriptors of behavior is that even if specific parameters are defined as relevant in a behavioral readout, they may not be available when examining a new species or when studying previously uncategorized behaviors. Quantification of infrequent events (such as episodes of immobility or jumps) is useful, but also somewhat unsatisfactory as a measure since it omits and obscures a large portion of the behavioral data. In an ideal scenario, an entire behavioral episode is represented in as complete a form as possible during quantification.

Studies over the past few years have addressed these (or related) issues by applying tools from computational geometry, computer vision, and machine learning to describe behaviors^{8}. These methods have proved effective in describing animal behavior more comprehensively. For example, in examining the entire behavioral repertoire of the hydra^{9}, for automated annotation of behavior in fruit flies^{10}, for discovering generative rules governing *Drosophila* locomotion^{11}, for identifying the temporal features that explain spontaneous swimming behavior in worms^{12}, for identifying the dynamics of shoaling in fish^{13}, and for detecting sub-second modules in mice behavior^{14}. Such studies are providing new insights like the continuity between behavioral states^{15}, between the generative rules of locomotion of vertebrates and invertebrates^{11}, and objective means for comparison of new data-sets to perform spatiotemporal mapping of posture of non-stereotyped actions^{7}. Here, we report on two new applications of computational geometric methods that can be applied broadly for the representation and quantitative analysis of dissimilarity in the locomotory behavior of pairs of animals moving freely in a two-dimensional space. We applied these methods to compare swimming behavior of pairs of fish.

The first among these methods applies a technique for automated curve alignment developed by Sebastian *et al*.^{16} that can be efficiently calculated with a method called *dynamic time warping*^{17}. Dynamic time warping has been applied widely to time series analysis^{18,19} as well as the study of biological phenomena, such as speech patterns^{20} and cardiac filling phases^{21}. In recent years, others have employed techniques based on dynamic time warping to examine and compare temporal patterns and acoustic features in bottle-nosed dolphins^{22}, whales^{23}, and songbirds^{24}. The same technique has also been adapted to compare locomotion and infer postures in humans^{25,26}. Motivated by a classic result in differential geometry called the Frenet-Serret Formula^{27}, we introduce the notion of a *behavior curve* associated to an animal’s trajectory and derive a measure that we call the Behavioral Distortion Distance (BDD). This can be efficiently calculated via dynamic time warping to provide meaningful quantitative comparisons for entire episodes of locomotion.

The second application we considered examines the spatiotemporal kinetics encoded in heat maps. When comparing heat maps between animals that represent the time spent at each location in an arena, it is not useful to look at a straightforward average since hot spots from different animals will average out and disappear. Instead, one must first align the heat maps so that corresponding hot spots coincide in order to reveal if there are common patterns and similarities. We implemented a well-established algorithm^{28,29,30,31,32} used previously in cortical cartography^{33,34}, for finding conformal (angle preserving) alignments between surfaces – a heat map can be interpreted as a surface in 3-dimensional space where different intensities correspond to different heights in the *z*-direction – that uses discrete geometric objects called *circle packings*. We call the resulting measure between heat maps the Conformal Spatiotemporal Distance (CSD).

As a proof-of-concept, we asked if these methods can quantitatively distinguish normal swimming behavior from a behavior described as “alarmed” in fish^{35}. We compared medaka fish from a preexisting data-set that had been exposed either to an alarm substance or to a control^{36}. Though the species where such a phenomenon has been described have expanded considerably^{37,38,39,40} since its discovery in minnows approximately 80 years ago^{41}, alarm behavior to conspecific injury has been mainly studied in the Ostariophysi species of fish^{42,43}. Even among Ostariophysi, species differ in the expression of alarmed behavior. Many different parameters, in captivity and in the wild, have been described for different fish including a change in inter-individual distance in shoals, freezing, darting, change in the vertical position in a water body, etc.^{44,45,46,47,48}. As such, it is difficult to predict what an alarmed behavior in response to the chemosensory alarm substance will look like in a species where this has not been described before, or when they have multiple defensive behaviors^{49}. We therefore chose as our test case a single published study (at the time we started this project) from one of the authors describing an alarm response in medaka^{36}. We asked if the individuals in the two conditions (alarmed and normal) were distinguishable without us defining what action sequence or locomotory pattern constitutes an alarmed state.

We found that BDD and CSD can differentiate between alarmed and normal states. The BDD between most pairs of alarmed individuals were also high, which suggests that swimming trajectories can become so unpredictable when medaka are alarmed that they may not match a second individual responding to the same stimulus. On the other hand, the CSD between most pairs of alarmed individuals were low, highlighting the existence of a discernible spatiotemporal pattern in spite of low predictability in their swimming trajectory. Overall, our results suggest that BDD and CSD together are useful aides to represent long episodes of swimming behavior. Our results also indicate that these computational geometric methods can be applied more universally for quantitative comparison of locomotion of any kind, in any animal.

## Results

The preexisting data-set we used for this report recorded the swimming motion of 36 medaka over a 10-minute interval^{36}. The observational tanks were featureless small rectangular tanks with dimensions 20 cm × 12 cm × 5 cm (*L* × *H* × *W*). While the tanks restricted movement compared to the animals’ natural habitat, they allowed multiple degrees of freedom in swimming motion and can be accepted as reasonably “free” spaces for motion. In particular, the fish could swim in any manner across the tank approximately six to seven body lengths long, four body lengths deep, and one and a half body lengths wide. Half of the fish were exposed to an alarm substance (*Schreckstoff* or SS) at the same time point (minute 2 in a 10 minute observation), while the other half were exposed to a control substance (tank water or NSS). Mathuru^{36} discovered a statistically significant difference in the average speed of the experimental subjects (SS) compared to the control subjects (NSS) during the post-stimulus (2–10 minute) time interval (Mann-Whitney U = 49.0, p = 0.0003) and a statistically significant difference in intervals of immobility (defined as displacement less than 3 mm in 1 second by the experimenter; Mann-Whitney U = 13.0, p = 0.000002).

Here, we explored the use of two additional measures that rely on notions of “distance” between the swimming patterns of pairs of subjects using the tracked data generated from the automated tracker in the previous study^{36}. The BDD or the Behavioral Distortion Distance, defined in the methods section, measures the differences in local locomotory behavior (independent of location and relative time) whereas the CSD or the Conformal Spatiotemporal Distance, also defined in the methods section, measures the spatiotemporal location pattern of a subject over a specified duration. For all of the results listed in this article, BDD refers to the behavioral distortion distance indexed by speed and curvature, or BDD_{Θ} for Θ = {*s*, *κ*} in the notation of the Methods section.

### Analysis of pairwise differences in behavior

The BDD and CSD between all pairs of the 36 test subjects over five 2-minute time intervals and the entire post-stimulus (minutes 2 to 10) time interval are illustrated in Fig. 1. The pairs of subjects are split into three categories: pairs of control subjects (NSS-NSS), mixed pairs with one control and one experimental subject (NSS-SS), and pairs of experimental subjects (SS-SS). The BDD and CSD for each pair of subjects and specified duration are illustrated in Figs 2 and 3, respectively, and the summary statistics are given in Tables 1 and 2.

Figure 1 reveals that while the pre-stimulus interval BDD are similar between the three categories, the mean BDD between NSS-SS pairs and between SS-SS pairs are both larger than the mean BDD in the pre-stimulus period, as well as the mean BDD between NSS-NSS pairs for each of the post-stimulus time intervals. In a comparable manner, the mean CSD between NSS-SS pairs and between SS-SS pairs are both smaller than the mean CSD in each of the post-stimulus time intervals, while it remains the same between NSS-NSS pairs. Figure 2 provides a colored visual aide to compare BDD between all pairs, while Table 1 summarizes this information. It shows that the mean BDD ranged between 0.061 and 0.069 for NSS-NSS pairs for both the pre- and post-stimulus intervals. However, the ranges increased in the post-stimulus period to between 0.074 and 0.141 for NSS-SS pairs and SS-SS pairs. In a similar manner, Fig. 3 provides a colored visual aide to compare CSD between all pairs and Table 2 and shows that the mean CSD between NSS-NSS pairs over the pre- and post-stimulus time intervals ranged between 0.0133 and 0.0137, while, for NSS-SS pairs and SS-SS pairs, the range decreased from approximately 0.014 to between 0.0095 and 0.0125. Kruskal-Wallis H statistical tests confirmed that the differences over the five 2-minute time intervals for NSS-NSS pairs for both the BDD (Fig. 1A, H-statistic = 6.759, *p* = 0.149) and the CSD (Fig. 1E, H-statistic = 0.897, *p* = 0.925) were statistically insignificant. However, they did reveal statistically significant differences for the BDD between NSS-SS pairs (Fig. 1B, H-statistic = 387.579, *p* = 1.34 × 10^{−82}), between SS-SS pairs (Fig. 1C, H-statistic = 259.470, *p* = 5.92 × 10^{−55}); and the CSD between NSS-SS pairs (Fig. 1F, H-statistic = 76.781, *p* = 8.37 × 10^{−16}), between SS-SS pairs (Fig. 1G, H-statistic = 124.940, *p* = 4.70 × 10^{−26}). This suggests that the BDD and CSD over each of the specified 2-minute time intervals throughout the duration of the assay (10-minute) is unchanging when control substance or tank water is introduced, but statistically significant differences emerge when one or both members of the pair are exposed to *Schreckstoff*.

To evaluate if the exposure to *Shcreckstoff* is the reason for the differences in the BDD and CSD measures above, we performed pairwise comparisons between the pre-stimulus time interval (0–2 minutes) and each of the four 2-minute post-stimulus intervals via Wilcoxon signed-rank T tests. This revealed statistically significant increases in the BDD between NSS-SS pairs (Fig. 1B, all T-statistics <4600, all *p*-values < 10^{−37}) and the BDD between SS-SS pairs (Fig. 1C, all T-statistics <1400, all *p*-values < 10^{−15}). Statistically significant decreases in the CSD between NSS-SS pairs (Fig. 1F, all T-statistics <18000, all *p*-values < 10^{−6}) and between SS-SS pairs (Fig. 1G, all T-statistics <2600, all *p*-values < 10^{−8}) were also detected. Therefore, the BDD increases while the CSD decreases between pairs of medaka after stimulus delivery when at least one individual is exposed to *Schreckstoff*. Next, we also conducted pairwise comparisons of the distributions of BDD and CSD between the three categories of pairs over the entire post-stimulus time interval. In Fig. 1D, the mean BDD between NSS-SS pairs and SS-SS pairs are both larger than the mean BDD between NSS-NSS pairs. To verify that these differences are statistically significant, we conducted Mann-Whitney U tests between the distributions of BDD for NSS-NSS pairs and NSS-SS pairs (Fig. 1D, U-statistic = 10730.0, *p* = 1.49 × 10^{−23}) and NSS-NSS pairs and SS-SS pairs (Fig. 1D, U-statistic = 5282.0, *p* = 1.05 × 10^{−16}). In Fig. 1H, the mean CSD between SS-SS pairs is less than that between NSS-SS pairs, which is less than that between NSS-NSS pairs. Again, to verify that these differences are statistically significant, we conducted Mann-Whitney U tests between the distributions of CSD for NSS-NSS pairs and SS-SS pairs (Fig. 1H, U-statistic = 15126.0, *p* = 9.84 × 10^{−6}) and for NSS-SS pairs and SS-SS pairs (Fig. 1H, U-statistic = 30470.0, *p* = 5.24 × 10^{−5}). The Mann-Whitney U tests did not reveal statistically significant differences between the distributions of BDD for NSS-SS pairs and SS-SS pairs (Fig. 1D, U-statistic = 25437.0, *p* = 0.64), nor did they reveal statistically significant differences between the distributions of CSD for NSS-NSS pairs and NSS-SS pairs (Fig. 1H, U-statistic = 26729.5, *p* = 0.17). Therefore, this suggests that the BDD detected different levels of variation in behavior between pairs of control subjects and pairs with at least one experimental subject. On the other hand, CSD detected different levels of variation in behavior between pairs of experimental subjects and pairs with at least one control subject over the post-stimulus time interval. Moreover, the variations in behavior measured by BDD between pairs of experimental subjects were as large as those between mixed pairs with one control and one experimental subject.

We also compared the distributions of BDD and CSD between the three categories of pairs and the set of all pairs (again over the entire post-stimulus time interval). Mann-Whitney U tests revealed that the mean BDD between NSS-NSS pairs is significantly lower than that of all pairs (U-statistic = 68674.5, *p* = 3.33 × 10^{−16}) and the mean BDD between NSS-SS pairs is significantly higher than that of all pairs (U-statistic = 87351.5, *p* = 2.63 × 10^{−4}). Additionally, Mann-Whitney U tests revealed the mean CSD between SS-SS pairs is significantly lower than that of all pairs (U-statistic = 57300.5, *p* = 2.85 × 10^{−4}). The Mann-Whitney U tests did not reveal statistically significant differences between the distributions of BDD for SS-SS pairs and all pairs, nor did they reveal significant differences between the distributions of CSD for NSS-NSS pairs and all pairs, nor NSS-SS pairs and all pairs. Therefore, the variations in behavior detected by BDD between NSS-NSS pairs and NSS-SS pairs are significant compared to the set of all pairs, not just to SS-SS pairs and each other. Similarly, the variations in behavior detected by CSD between SS-SS pairs are significant compared to the set of all pairs, not just to the other two categories of pairs (NSS-NSS and NSS-SS).

Finally, to further illustrate that the differences reported in the previous paragraphs are unlikely to be the results of random fluctuations, we conducted an additional analysis based on randomized (also known as permutation) tests^{50}. For this, we compared the mean BDD between NSS-SS pairs to a distribution of mean BDD between randomly relabeled pairs. Specifically, we uniformly sampled 100000 of the 9075135300 ways to divide the 36 test subjects into two 18-element subsets and calculated the mean BDD between the subsets in each of those partitions. Then, we compared the mean BDD between the NSS-SS partition to the distribution of mean BDD for randomized partitions. The corresponding distribution statistics, standard scores, and *p*-values are listed in Table 3.

Together, these results and statistical analyses suggest that the variability in dynamics and trajectory increase, while the variability in spatiotemporal preference decreases, when the pair of medaka being compared contains at least one alarmed individual.

### Individual variability and classification

Following our analyses of pairwise comparisons, we asked if BDD and CSD could yield meaningful information about individual behavioral episodes, without direct comparison to other episodes in a larger data-set. One approach for this is to measure the distance between a subject and itself over different (non-overlapping) time intervals. This is not practical for CSD, since that method only captures meaningful information over extended periods of time. We calculated the mean BDD from each subject to itself over 1000 non-overlapping sub-intervals of the post-stimulus time interval, sampled uniformly at random. The resulting values, which we call the Intra-Individual BDD (IIBDD) for each subject, are listed in Supplementary Table 1. A Mann-Whitney U test showed that the mean IIBDD of experimental subjects is significantly higher than that of control subjects (U-statistic = 23.5, *p*-value = 1.25 × 10^{−5}). Therefore, the variation in behavior measured by BDD from an experimental subject to itself is, on average, significantly larger than that from a control subject to itself.

This led us to ask if IIBDD could be used to classify normal and alarmed behaviour by itself. We conducted three logistic regressions on the thirty-six test subjects using average speed, and immobility, the parameters used in the previous report, and IIBDD. The logistic regression for average speed had an intercept of 4.449 and a coefficient of −0.168 (*χ*^{2} = 15.562, *p*-value = 7.98 × 10^{−5}); the logistic regression for immobility had an intercept of −3.005 and a coefficient of 0.302 (*χ*^{2} = 30.659, *p*-value = 3.08 × 10^{−8}); and the logistic regression for IIBDD had an intercept of −20.680 and a coefficient of 244.250 (*χ*^{2} = 25.494, *p*-value = 4.44 × 10^{−7}). The data used for these regressions are in Supplementary Table 1 and the corresponding classifications are given in Table 4. The logistic regressions show that all three parameters can be used to classify normal and alarmed behavior, with duration of immobility and IIBDD exhibiting better goodness of fit than average speed. Therefore, IIBDD allows for classification of a new animal’s behavior as alarmed or normal if the new experiment replicates the conditions of the original experiment.

## Discussion

Complex behaviors with common action patterns or modules, albeit in exaggerated or in compressed forms, can be precluded from identification as different. To address this issue we investigated two new applications of known techniques in computational geometry for curve alignment, which we call the Behavioral Distortion Distance or BDD, and for surface alignment that we call the Conformal Spatiotemporal Distance or CSD. These applications were motivated by the aim of devising generic methods that can be used to detect differences in a locomotory pattern without the need for experimenters to define the action sequence that constitutes a particular behavioral state. We applied them here to reexamine a report of an alarm response in medaka^{36}. As the pattern of change in locomotion when a fish is alarmed is not universal and can vary in a species or context dependent manner^{38,39}, it serves as a good test case for the two applications. We find that both BDD and CSD are suitable for quantitative comparison of such behaviors without the need to rely on domain specific expert knowledge of the underlying ethology. They confirm that indeed medaka behavior changes after exposure to *Schreckstoff* derived from conspecifics. The methods section describes the mathematical framework and definitions applied to develop these applications in detail.

The section analyzing pairwise differences shows that the fish in the two groups have similar locomotory behavior in the first 2-minutes, or in the pre-stimulus period. Therefore, there is no intrinsic behavioral difference between the groups at the onset. A significant change in BDD and CSD between the pre- and post-stimulus time intervals is noticeable only when the pairs had at least one fish exposed to *Schreckstoff*. This can be visualized more clearly in Figs 2 and 3. In such cases, the changes in BDD and CSD were complementary in the sense that the BDD was larger and the CSD was smaller. Notably, we did not observe significant differences in BDD between pairs of experimental fish and mixed pairs with one control fish and one experimental fish. This suggests that the behaviors of pairs of alarmed fish are as different from one another as they are from fish exhibiting normal behavior. In particular, BDD did not identify a stereotypical alarm response. While the CSD between mixed pairs was not significantly different from that of control pairs and experimental pairs, the mean CSD between experimental pairs was significantly lower than control (in fact, all) pairs. This suggests that alarmed fish exhibited a lower level of variability in their action pattern. One possible interpretation for this, following a visual inspection of the heatmaps of these individuals, is that this reduced variability could be due to periods of immobility represented as hot spots in their heatmaps.

Our analysis of the medaka alarm response using BDD and CSD brings together two seemingly contrasting ideas of stereotypic innate behavior and individual variability. Combining our observations, we conclude that the alarm response to *Schreckstoff* in medaka comprises increased variation in the local geometry and kinematics of a trajectory with a common spatiotemporal pattern. This is consistent with the ethogram of periods of erratic swimming interspersed with periods of immobility. Increased variation in the local geometry suggests swimming trajectories become less predictable over time in alarmed fish that likely serves as an advantageous anti-predator strategy. Yet, the ability of CSD to capture a commonality mirrors a description in Schleidt^{5} of “observer’s eye and mind perform a complex task of averaging and assigning weights to many different characteristics”, essentially integrating information over the experimental time period.

Following our analysis of pairwise BDD and CSD, we investigated the ability of Intra-Individual BDD (IIBDD, the average BDD from a subject to itself over many randomly sampled non-overlapping time intervals) to classify normal and alarmed behaviors. We found that IIBDD performed comparably in this task to the duration of immobility via logistic regressions.

For our implementation of BDD, we took into account kinematic factors of medaka swimming such as the instantaneous speed (rate of displacement), as well as intrinsic geometric properties of the trajectory such as curvature (the rate of change of turning while traveling at unit speed; see Fig. 4 and Supplementary Video S1). Our choice of these factors was dependent on the information available in the original data-set, however, additional factors such as posture, if available, can be easily incorporated to calculate the distance between two generic behavioral curves. When comparing two behavioral curves, multiple optimal solutions are possible. In our context, such cases are considered equivalent. For instance, if we compare an episode in which an animal turned exactly once to an episode where a second animal turned exactly twice with the same curvature for each turn and speed, there will be two minima for BDD - aligning the single spike in curvature from the first episode to either of the two spikes in curvature from the second episode. Both these possible alternative alignments will give the same BDD score. We consider the two alternative alignments to be equivalent as they do not reveal any additional information about the behavior of the two animals other than the fact that the two episodes exhibited different behaviors.

A general caveat of using the BDD and CSD for analysis is that they can only be applied to a pair of curves (resp. heat maps) at a time. It therefore accompanies a degree to difficulty in visualizing a characteristic feature, if any, common to all individuals when comparing two conditions. As demonstrated here, it is possible to overcome this limitation to an extent by (1) statistical analysis of all pairs and (2) intra-individual comparisons. Another caveat of these measures is the assumption that the behavior being analyzed can be described by the intrinsic geometric and kinematic properties of locomotion. Indeed, behavioural posture is unaccounted in these analyses. However, here this limitation exists because of the recording technique employed. It can be overcome if postural data is identified in videos with higher resolution recordings that could then be incorporated to compute the BDD and CSD. In medaka, a higher BDD value and a lower CSD value represented an alarmed state. This may not be a characteristic feature of alarmed states in all species. However, if there is any substantial change in the pattern of locomotion compared to normal state in a species, it will likely be revealed in a change in BDD and CSD values in spite of individual differences in the execution of the motor action.

More generally, we have implemented the curve alignment process so that it can be used to compare any two curves that change over a common length of time. Our implementation can generate parametric curves from tracking data normally obtained for analysis of behavior (that is, *x*- and *y*-coordinates, time-stamp, frame rate, etc.) These new applications can therefore be used to compare locomotion dependent behavior of any animal tracked in a two dimensional arena. They will be particularly useful for characterizing the degree of similarity when comparing two or more conditions - such as when different treatments of a drug are applied to different groups, or in studying differences in exploratory pattern in different groups of animals. As demonstrated above, another useful aspect of these measures is that once a data-set is generated, the IIBDD from a smaller subset in a subsequent experiment is also informative provided the conditions of the original experiment are replicated when generating new data. These applications can also be applied to animals moving in 3-dimensional arena. We expect these methods will be more widely used after this demonstration of their utility. Accordingly, our software package is publicly available at the GitHub repository: https://github.com/mechunderlyingbehavior/locomotion.git.

## Methods

### Behavioral data

The data used for testing the applications comes from Mathuru^{36}. Details of the experimental setup, including the method for preparation of the alarm substance (*Schreckstoff*), can be found in the methods section of the original publication. Briefly, fish behavior was recorded on an external Agent v5 HD web camera placed approximately 50 cm in front of the tank. Recorded videos were digitized at 20 frames/second. The frames were converted to 8-bit grayscale thresholded images by subtracting the background on ImageJ (from https://imagej.nih.gov/ij/). The spatial resolution of the videos was 2.4 pixels/mm. Fish position was tracked automatically on MetaMorph 6.3 (from https://www.moleculardevices.com) using the “track objects” algorithm. The original tracking data used in our model is uploaded to public data repository and is provided with this paper. Experiments in the original dataset were performed in accordance to the guidelines recommended by the Institutional Animal Care and Use Committee (IACUC) of the Biological Resource Center at A*STAR. Approved experimental protocols (IACUC 161110) were followed.

### Curve alignment and behavioral distortion distance (BDD)

Our first method compares the behavior of two animals by comparing the intrinsic geometric properties and dynamics of their trajectories. It is an application of the *edit distance* between curves introduced by Sebastian *et al*.^{16}, which can be calculated via a technique known as *dynamic time warping* introduced by Sakoe and Chiba^{20}.

#### Theoretical framework and definitions

We assume that the trajectory of each fish is a continuous, smooth parametric curve given by a vector-valued function \({\bf{r}}:[{t}_{0},{t}_{f}]\to {{\mathbb{R}}}^{3}\) where *t*_{0} and *t*_{f} denote the start and end times of a specified time interval, respectively. To identify the geometric and dynamic features of the trajectories that are most relevant to behavior, we first calculate the rate at which an animal’s motion is changing relative to its current frame of reference. We model an animal’s frame of reference at a point along its trajectory with its *Frenet-Serret frame* at that point: For a non-degenerate, continuously differentiable, parametric curve *C* with the vector-valued function \({\bf{r}}:[{t}_{0},{t}_{f}]\to {{\mathbb{R}}}^{3}\) it is well known in differential geometry^{27} that the unit tangent, normal, binormal vectors, defined by

respectively, at each point of the trajectory form an orthonormal basis of \({{\mathbb{R}}}^{3}\). (Here, *g*′(*t*) denotes the derivative of a function *g* with respect to *t*, ||**v**|| denotes the magnitude of a vector \({\bf{v}}\in {{\mathbb{R}}}^{3}\), and × denotes the cross product.) In other words, we can recoordinatize \({{\mathbb{R}}}^{3}\) according to a fish’s position and orientation at each moment in time. Measuring the rate of change of an animal’s frame of reference at a given point is equivalent to calculating the rate of change of its Frenet-Serret frame, given by the famous Frenet-Serret formula^{51,52}, which states that if \({\bf{r}}:[{t}_{0},{t}_{f}]\to {{\mathbb{R}}}^{3}\) is a non-degenerate, continuously differentiable, parametric curve and *T*(*t*), *N*(*t*), and *B*(*t*) are its unit tangent, normal, and binormal vectors at time *t*, then

where

The upshot of the Frenet-Serret formula in our context is that the rate of change of the Frenet-Serret frame is completely determined by *s*(*t*), *κ*(*t*), and *τ*(*t*), which are the *speed*, *curvature*, and *torsion*, respectively, of **r** at time *t*. While speed will be familiar to many readers as the rate of displacement, the curvature indicates the rate at which the curve is turning while traveling at unit speed, and the torsion indicates the rate which the curve is twisting while traveling at unit speed. Portions of the trajectory, speed, and curvature of the Medaka NSS 01 fish (Supplementary Video 1) over the first fifteen seconds of its experiment are shown in Fig. 4 and in Supplementary Video 2.

Depending on the application, there may be additional factors that are relevant to behavior, such as position, posture, or distance to an object of interest. To accomodate such factors, we introduce the following notion:

###
**Definition 1.**

Let \({\bf{r}}\,:[{t}_{0},{t}_{f}]\to {{\mathbb{R}}}^{3}\) be the trajectory of an animal and let \(\Theta =\{{\theta }_{1},\ldots ,{\theta }_{m}\}\) be a set of *m* behavioral factors, such as *s*, *κ*, and *τ*. The behavior curve of the trajectory indexed by Θ is the parametric curve \({C}_{\Theta }\,:[{t}_{0},{t}_{f}]\to {{\mathbb{R}}}^{m}\) given by \({C}_{\Theta }(t)=({\theta }_{1}(t),\ldots ,{\theta }_{m}(t))\).

Our objective is to find an acceptable notion of distance between the behavior curves of two episodes. Because it is virtually impossible to deliver an external chemical stimulus simultaneously to two freely swimming animals (as the stimulus takes time to disperse through the tank water), it is not meaningful to compare two behavior curves at common moments in time. For instance, a slight time lag due to different reaction times could yield arbitrarily large quantitative differences between two animals that exhibit identical sequences of behaviors with that approach. Instead, we must identify an appropriate correspondence between pairs of points from each behavior curve in order to make a meaningful comparison. To solve this curve alignment problem, we apply the *edit distance* developed by Sebastian *et al*.^{16}, which measures the least amount of energy required to bend, stretch, and/or compress one parametric curve onto another by finding an alignment that minimizes a specified energy. In our context, an *alignment* between two parametric curves \({C}^{1}\,:[{t}_{0},{t}_{f}]\to {{\mathbb{R}}}^{{d}_{1}}\) and \({C}^{2}\,:[{t}_{0}^{\ast },{t}_{f}^{\ast }]\to {{\mathbb{R}}}^{{d}_{2}}\) is a function

satisfying the conditions that \(\phi ({u}_{0})=({t}_{0},{t}_{0}^{\ast })\), \(\phi ({u}_{f})=({t}_{f},{t}_{f}^{\ast })\), and *φ*_{i} is monotone increasing and differentiable for each *i* ∈ {1, 2}, and the *energy* we seek to minimize is given by

We can now define the behavioral distortion distance:

###
**Definition 2.**

Let \({{\bf{r}}}_{1}\,:[{t}_{0},{t}_{f}]\to {{\mathbb{R}}}^{d}\) and \({{\bf{r}}}_{2}\,:[{t}_{0}^{\ast },{t}_{f}^{\ast }]\to {{\mathbb{R}}}^{d}\) be the trajectories of two animals and let \(\Theta =\{{\theta }_{1},\ldots ,{\theta }_{m}\}\) be a set of behavioral factors. The behavioral distortion distance between **r**_{1} and **r**_{2} with respect to Θ is

where *φ*_{min} is an alignment between the behavior curves \({C}_{\Theta }^{1}\) and \({C}_{\Theta }^{2}\) corresponding to **r**_{1} and **r**_{2}, respectively, that minimizes *E*.

An example optimal alignment between the behavior curves with Θ = {*s*} for the first 15 seconds of observation for the Medaka NSS 01 fish and Medaka SS 01 fish is illustrated in Fig. 5. Supplementary Video 3 is an animation example that illustrates this alignment over a 30 second observation interval of the same pair of animals.

#### Implementation

We obtain the trajectories from the “track objects” method in the MetaMorph software as sequences of *x*- and *y*-coordinates in the real plane. While the observational tank is 3-dimensional, the camera only captures the projection of a 2-dimensional, 20 cm × 12 cm, vertical cross-section of an animals movement. As described in Mathuru^{36}, since videos were recorded from the front of the tank, displacement in the orthogonal width could not be recorded, effectively reducing a three dimensional space to a two dimensional observation. Ideally, we would be able to capture 3-dimensional trajectories; however, the BDD has the same derivation for 2-dimensional trajectories. The Frenet-Serret frames of a plane curve are given by the tangent and normal vectors and the Frenet-Serret formula is identical with torsion constantly equal to 0.

We use *dynamic time warping* (DTW) to calculate BDD, the same approach Sebastian *et al*.^{16} use to calculate edit distance. Our implementation of the DTW algorithm is an extension of the standard DTW method in the Machine Learning module, mlpy^{53}, in Python (see Muller^{54} for a description of how DTW works). Specifically, we modified the existing DTW method in mlpy to compare multivariate time series (instead of only univariate time series) by changing the distance function from 1-dimensional Euclidean distance to *m*-dimensional Euclidean distance for a specified *m*. While our method is able to handle input data of an arbitrarily high dimension (any number of behavioral factors), the analyses in this study have only used speed and curvature. The speed and curvature values are generated from the *x*- and *y*-coordinates using the formulas

where the derivatives are computed by applying the gradient function in the NumPy^{55} Python package to the *x* and *y* time series. We smoothed the trajectories using the Savitzky-Golay function in the SciPy^{56} Python package (see Savitzky and Golay^{57} for a description of the Savitzky-Golay smoothing filter). That function takes two integer parameters, namely the order of the polynomials used for smoothing and length (number of frames) of the smoothing window centered at each frame. Since the choice of parameters is application dependent, we searched for the parameters that simultaneously minimized mean square error (deviation from raw trajectory) and jerk (rate of change of acceleration) for every order between 1 and 9 and every window length up to 600 frames (30 seconds). We encountered numerical instability for orders above 7. The products of mean square error and mean jerk with respect to window length are plotted for each order between 1 and 7 in Fig. 6. We used the order 5 Savitzy-Golay smoothing with a window length of 53 frames.

Furthermore, to account for variations in mean values of behavioral factors between animals and differences in magnitudes between behavioral factors themselves, we normalize all of the data using the sigmoid function

where *μ* and *σ* are the mean and the standard deviation of the respective input sequence. We chose the sigmoid function for our particular application because the distribution of the curvatures of the trajectories is positively skewed, as can be seen from Fig. 4. Since the range of the sigmoid function is [0, 1], the value of BDD_{Θ} is bounded above by the square root of the number of factors in Θ.

### Surface alignment and conformal spatiotemporal distance (CSD)

The second application we considered compares the spatiotemporal distributions between two animals. When comparing heat maps of time spent at each location in an arena between animals, it is not useful to look at a straightforward average since hot spots from different animals will average out and disappear. Instead, one must first align the heat maps so corresponding hot spots coincide in order to reveal if there are common patterns and similarities. To do this, we apply the *symmetric distortion energy* between surfaces introduced by Koehl and Hass^{30,58}.

#### Theoretical framework and definitions

To examine the overall spatiotemporal patterns of an animal within an enclosure, we study its spatiotemporal distribution function, that is, the continuous function \(\rho :\Omega \to {\mathbb{R}}\) where Ω is the enclosure of the animal and *ρ*(*z*) is the number of seconds the animal spends at location *z* within Ω over a specified time interval *I*. When Ω is a region in the plane, this function can be visualized/interpreted as a heatmap where small values of *ρ* correspond to “cold” points and large values of *ρ* correspond to “hot” points. Alternatively, the spatiotemporal distribution function can be visualized/interpreted as the surface in \({{\mathbb{R}}}^{3}\) with points {(*x*, *y*, *ρ*(*x*, *y*)|(*x*, *y*) ∈ Ω)}, as illustrated in Fig. 7. We assume that this surface is smooth and Riemannian, that is, it is equipped with a well-defined notion of distance and angles.

We can compare the spatiotemporal distribution functions between two animals by taking an appropriate norm between them, but that will be sensitive to a variety of factors that cannot be controlled, such as the position of an animal when the substance is administered. Mirroring our formulation of BDD, we must build some flexibility into our model by first aligning the corresponding surfaces before calculating a norm between them.

To align a pair of Riemannian surfaces *S*_{1} and *S*_{2}, we look at the space of diffeomorphisms between them. A differentiable map *f*: *S*_{1} → *S*_{2} is a *diffeomorphism* if it is a bijection and its inverse *f *^{−1} is also differentiable. A diffeomorphism gives a point-to-point correspondence between surfaces in a way that does not introduce any tears or folds, but it can distort the shape of a surface in unusual ways, for instance by stretching it. Ideally, we would like to find a diffeomorphism that does not distort *S*_{1} while mapping it onto *S*_{2}; such a mapping is called an *isometry*. Unfortunately, an isometry between *S*_{1} and *S*_{2} may not exist. Any diffeomorphism between surfaces with different areas, for instance, will have to stretch one of the surfaces somewhere. While we cannot hope to find an isometry between *S*_{1} and *S*_{2}, we can always find a map that preserves angles, such a map is called *conformal*. This is the content of a deep result in geometry called the *Uniformization Theorem*^{59}, which states that every simply connected Riemann surface is conformally equivalent to one of three Riemann surfaces: the open unit disk, the complex plane, or the Riemann sphere. While a conformal mapping *f* : *S*_{1} → *S*_{2} may distort distances, it will stretch *S*_{1} uniformly in all directions at each point. This defines a function \({\lambda }_{f}:{S}_{1}\to {\mathbb{R}}\) that maps each point *z* in *S*_{1} to the factor by which vectors at *p* are stretched by *f*. The map *f* is an isometry if and only if *λ*_{f}(*z*) = 1 for all *z* ∈ *S*_{1}. Accordingly, one can measure how far a conformal diffeomorphism is from being an isometry be calculating how far the stretching factor is from 1 at each point. Koehl and Hass^{58} introduced the *symmetric distortion energy* of a conformal diffeomorphism *f* : *S*_{1} → *S*_{2} with dilation functions \({\lambda }_{f}\,:{S}_{1}\to {\mathbb{R}}\) and \({\lambda }_{{f}^{-1}}\,:{S}_{2}\to {\mathbb{R}}\) as

In our context, an optimal alignment between *S*_{1} and *S*_{2} will be a conformal diffeomorphism that minimizes the symmetric distortion energy. We can then measure the difference between two aligned surfaces by calculating the *L*_{2}-norm between their corresponding functions.

###
**Definition 3.**

Let *S*_{1} and *S*_{2} be the surfaces of spatiotemporal distribution functions \({\rho }_{1}\,:\Omega \to {\mathbb{R}}\) and \({\rho }_{2}\,:\Omega \to {\mathbb{R}}\), respectively, and for every diffeomorphism *f* : *S*_{1} → *S*_{2} and \(z\in \Omega \) let *z*_{f} denote the unique point such that \(f((z,{\rho }_{1}(z)))=({z}_{f},{\rho }_{2}({z}_{f}))\). The *conformal spatiotemporal distance* between *S*_{1} and *S*_{2} is given by

where \(||\Omega ||\) denotes the area of Ω and \({f}_{\ast }\,=\,{{\rm{argmin}}}_{{\rm{conformal}}f}{E}_{sd}(f)\).

#### Implementation

To approximate the spatiotemporal distribution function for each fish, we subdivide the rectangular cross-section of the experimental enclosure into an *m* × *n* rectangular grid and assign to each subrectangle the percentage of time spent in that region throughout a specified duration of time. We model the surface corresponding to this function by triangulating each of the rectangular regions and taking the induced triangulation on the corresponding set of points in \({{\mathbb{R}}}^{3}\). To approximate a conformal mapping from this surface to the unit disk, it will be helpful to have a regular or uniform (all of the edge lengths are approximately equal) triangulation of the surface. Accordingly, we subdivide the edges of our preliminary triangulated surface so that all of the edge lengths are within a specified tolerance of equality and apply the Bowyer-Watson algorithm^{60,61} to obtain a Delaunay triangulation of the resulting vertex set.

We apporixmate the set of conformal mappings between two such triangulations with the Discrete Uniformization theorem^{62}. In particular, we use an algorithm developed by Collins and Stephenson^{63} to find a discrete conformal mapping \({f}_{i}:{S}_{i}\to {\mathbb{D}}\) from each triangulated surface / heat map to a triangulation of the unit disk. Once we have these conformal flattening maps, *f*_{1} and *f*_{2}, we can express every conformal mapping *f* : *S*_{1} → *S*_{2} as \(f={f}_{2}^{-1}\circ \,m\,\circ \,{f}_{1}\) where \(m\,:{\mathbb{D}}\to {\mathbb{D}}\) is a *Möbius transformation* of the unit disk. Finding an optimal alignment between *S*_{1} and *S*_{2} is then reduced to finding a Möbius transformation \(m\,:{\mathbb{D}}\to {\mathbb{D}}\) whose composition \({f}_{2}^{-1}\circ m\circ {f}_{1}\) minimizes the symmetric distortion energy. This is illustrated in Fig. 7.

A well known application of Schwarz’s Lemma^{64} in complex analysis is that every Möbius transformation from \({\mathbb{D}}\) to itself is determined by which point is sent to the origin and a rotation. For stability reasons, we map the centroid of each surface to the origin^{58}. This also reduces the minization problem to a single rotation, which we approximate by brute force, although there are algorithms in the literature for this^{29}. We use the following discrete analogue of the symmetric distortion energy presented in Koehl and Hass^{58}: If *T*_{1} and *T*_{2} are triangulations of smooth Riemannian surfaces *S*_{1} and *S*_{2}, respectively, and *f* : *S*_{1} → *S*_{2} is a conformal mapping, then

where *e*_{ij} denotes an edge in *T*_{1} or *T*_{2}, \(\ell \) denotes the length of an edge (or its image), and *A*_{ij} is the sum of the areas of the two triangles that contain the edge *e*_{ij}. Here the sums run over all of the interior edges in *T*_{1} and *T*_{2} respectively.

### Statistical analyses

All of the Kruskal-Wallis H, Mann-Whitney U, and Wilcoxon T tests presented in the Results section were executed in SciPy^{56}. A p value of 0.01 was considered significant. When multiple comparisons were made Bonferroni correction for multiple comparisons was applied to determine statistial significance. When reporting, the P values up to the third decimal place are presented instead of an asterisk sign.

## References

Beck, J. M., Ma, W. J., Pitkow, X., Latham, P. E. & Pouget, A. Not noisy, just wrong: the role of suboptimal inference in behavioral variability.

*Neuron***74**(2012).Marder, E. Variability, compensation, and modulation in neurons and circuits.

*Proc*.*Natl*.*Acad*.*Sci*.**108**, 15542–15548, https://doi.org/10.1073/pnas.1010674108, http://www.pnas.org/content/108/Supplement_3/15542.full.pdf (2011).Bucher, D., Prinz, A. A. & Marder, E. Animal-to-animal variability in motor pattern production in adults and during growth.

*J. Neurosci.***25**, 1611–1619, https://doi.org/10.1523/JNEUROSCI.3679-04.2005 (2005).Hooper, S. L., Guschlbauer, C., von Uckermann, G. & Büschges, A. Natural neural output that produces highly variable locomotory movements.

*J. Neurophysiol.***96**, 2072–2088, https://doi.org/10.1152/jn.00366.2006 (2006).Schleidt, W. M. How “Fixed” is the Fixed Action Pattern?

*Zeitschrift für Tierpsychologie***36**, 184–211, https://doi.org/10.1111/j.1439-0310.1974.tb02131.x (1974).Ayroles, J. F.

*et al*. Behavioral idiosyncrasy reveals genetic control of phenotypic variability.*Proc. Natl. Acad. Sci.***112**, 6706–6711, https://doi.org/10.1073/pnas.1503830112 (2015).Berman, G. J., Choi, D. M., Bialek, W. & Shaevitz, J. W. Mapping the stereotyped behaviour of freely moving fruit flies.

*J. The Royal Soc. Interface***11**, 20140672–20140672, https://doi.org/10.1098/rsif.2014.0672 (2014).Leshner, A. & Pfaff, D. W. Quantification of behavior.

*Proc*.*Natl*.*Acad*.*Sci*.**108**, 15537–15541, https://doi.org/10.1073/pnas.1010653108, http://www.pnas.org/content/108/Supplement_3/15537.full.pdf (2011).Han, S., Taralova, E., Dupre, C. & Yuste, R. Comprehensive machine learning analysis of Hydra behavior reveals a stable basal behavioral repertoire.

*eLife***7**, 413, https://doi.org/10.7554/eLife.32605 (2018).Kabra, M., Robie, A. A., Rivera-Alba, M., Branson, S. & Branson, K. JAABA: interactive machine learning for automatic annotation of animal behavior.

*Nat. Methods***10**, 64–67, https://doi.org/10.1038/nmeth.2281 (2013).Gomez-Marin, A.

*et al*. Generative rules of Drosophila locomotor behavior as a candidate homology across phyla.*Sci*.*reports*1–11, https://doi.org/10.1038/srep27555 (2016).Srivastava, N., Clark, D. A. & Samuel, A. D. T. Temporal analysis of stochastic turning behavior of swimming C. elegans.

*J. Neurophysiol.***102**, 1172–1179, https://doi.org/10.1152/jn.90952.2008 (2009).Hinz, R. C. & de Polavieja, G. G. Ontogeny of collective behavior reveals a simple attraction rule.

*Proc. Natl. Acad. Sci.***114**, 201616926–2300, https://doi.org/10.1073/pnas.1616926114 (2017).Wiltschko, A. B.

*et al*. Mapping Sub-Second Structure in Mouse Behavior.*Neuron***88**, 1121–1135, https://doi.org/10.1016/j.neuron.2015.11.031 (2015).Gallagher, T., Bjorness, T., Greene, R., You, Y.-J. & Avery, L. The geometry of locomotive behavioral states in C. elegans.

*PLoS One***8**, e59865, https://doi.org/10.1371/journal.pone.0059865 (2013).Sebastian, T. B., Klein, P. N. & Kimia, B. B. On aligning curves.

*IEEE Transactions on Pattern Analysis Mach. Intell.***25**, 116–125, https://doi.org/10.1109/TPAMI.2003.1159951 (2003).Berndt, D. J. & Clifford, J. Using dynamic time warping to find patterns in time series.

*AAAI Tech*.*Rep*.**WS-94-03**(1994).Shokoohi-Yekta, M., Hu, B., Jin, H., Wang, J. & Keogh, E. Generalizing DTW to the multi-dimensional case requires an adaptive approach.

*Data mining knowledge discovery***31**, 1–31, https://doi.org/10.1007/s10618-016-0455-0 (2016).Rakthanmanon, T.

*et al*.*Searching and mining trillions of time series subsequences under dynamic time warping*(ACM, New York, New York, USA, 2012).Sakoe, H. & Chiba, S. Dynamic programming algorithm optimization for spoken word recognition.

*IEEE Transactions on Acoust. Speech, Signal Process.***26**, 43–49, https://doi.org/10.1109/TASSP.1978.1163055 (1978).Caiani, E. G.

*et al*. Warped-average template technique to track on a cycle-by-cycle basis the cardiac filling phases on left ventricular volume. In*Computers in Cardiology*, vol. 25, 73–76, https://doi.org/10.1109/CIC.1998.731723 (IEEE, 1998).Fripp, D.

*et al*. Bottlenose dolphin (Tursiops truncatus) calves appear to model their signature whistles on the signature whistles of community members.*Animal Cogn.***8**, 17–26, https://doi.org/10.1007/s10071-004-0225-z (2005).Filatova, O. A.

*et al*. Call diversity in the North Pacific killer whale populations: implications for dialect evolution and population history.*Animal Behav.***83**, 595–603, https://doi.org/10.1016/j.anbehav.2011.12.013 (2012).Tan, L. N., Alwan, A., Kossan, G., Cody, M. L. & Taylor, C. E. Dynamic time warping and sparse representation classification for birdsong phrase classification using limited training dataa.

*The J. Acoust. Soc. Am.***137**, 1069–1080, https://doi.org/10.1121/1.4906168 (2015).Castellano, G., Villalba, S. D. & Camurri, A. Recognising Human Emotions from Body Movement and Gesture Dynamics. In

*Affective Computing and Intelligent Interaction*, 71–82, https://doi.org/10.1007/978-3-540-74889-2_7 (Springer, Berlin, Heidelberg, Berlin, Heidelberg, 2007).Gudmundsson, J., Laube, P. & Wolle, T. Computational Movement Analysis. In

*Springer Handbook of Geographic Information*, 423–438, https://doi.org/10.1007/978-3-540-72680-7_22 (Springer, Berlin, Heidelberg, Berlin, Heidelberg, 2011).Spivak, M.

*A comprehensive introduction to differential geometry*.*Vol*.*V*, second edn. (Publish or Perish, Inc., Wilmington, Del., 1979).Wang, S., Wang, Y., Jin, M., Gu, X. D. & Samaras, D. Conformal Geometry and Its Applications on 3D Shape Matching, Recognition, and Stitching.

*IEEE Transactions on Pattern Analysis Mach. Intell.***29**, 1209–1220, https://doi.org/10.1109/TPAMI.2007.1050 (2007).Le, H., Chin, T. & Suter, D. Conformal surface alignment with optimal möbius search. In 2016

*IEEE Conference on Computer Vision and Pattern Recognition (CVPR)*, 2507–2516, https://doi.org/10.1109/CVPR.2016.275 (2016).Koehl, P. & Hass, J. Landmark-free geometric methods in biological shape analysis.

*J. The Royal Soc. Interface***12**, 20150795, https://doi.org/10.1098/rsif.2015.0795 (2015).Gu, X., Wang, Y., Chan, T. F., Thompson, P. M. & Yau, S.-T. Genus Zero Surface Conformal Mapping and Its Application to Brain Surface Mapping. In

*Medical Image Computing and Computer-Assisted Intervention – MICCAI’99*, 172–184, https://doi.org/10.1007/978-3-540-45087-0_15 (Springer Berlin Heidelberg, Berlin, Heidelberg, 2003).Angenent, S., Haker, S., Tannenbaum, A. & Kikinis, R. Conformal Geometry and Brain Flattening. In

*Medical Image Computing and Computer-Assisted Intervention – MICCAI’99*, 271–278, https://doi.org/10.1007/10704282_30 (Springer Berlin Heidelberg, Berlin, Heidelberg, 1999).Hurdal, M. K. & Stephenson, K. Cortical cartography using the discrete conformal approach of circle packings.

*NeuroImage***23**, S119–S128, https://doi.org/10.1016/j.neuroimage.2004.07.018 (2004).Hurdal, M. K. & Stephenson, K. Discrete conformal methods for cortical brain flattening.

*NeuroImage***45**, S86–S98, https://doi.org/10.1016/j.neuroimage.2008.10.045 (2009).Jesuthasan, S. J. & Mathuru, A. S. The alarm response in zebrafish: innate fear in a vertebrate genetic model.

*J. neurogenetics***22**, 211–228, https://doi.org/10.1080/01677060802298475 (2008).Mathuru, A. S. Conspecific injury raises an alarm in medaka.

*Sci. reports***6**, 36615, https://doi.org/10.1038/srep36615 (2016).Mathuru, A. S.

*et al*. Chondroitin fragments are odorants that trigger fear behavior in fish.*Curr. biology: CB***22**, 538–544, https://doi.org/10.1016/j.cub.2012.01.061 (2012).Chivers, D. P. & Smith, R. Chemical alarm signalling in aquatic predator-prey systems: a review and prospectus.

*Ecoscience*(1998).Ferrari, M. C. O., Wisenden, B. D. & Chivers, D. P. Chemical ecology of predator–prey interactions in aquatic ecosystems: a review and prospectus.

*Can. J. Zool.***88**, 698–724, https://doi.org/10.1139/Z10-029 (2010).Wisenden, B. D., Karst, J., Miller, J. & Miller, S. Anti-predator behaviour in response to conspecific chemical alarm cues in an esociform fish, Umbra limi (Kirtland 1840).

*Environ. Biol. Fishes***83**, 85–92 (2008).von Frisch, K. Zur psychologie des fisch-schwarmes.

*Naturwissenschaften***26**, 601–606 (1938).Pfeiffer, W. The distribution of fright reaction and alarm substance cells in fishes.

*Copeia***4**, 15 (1977).Døving, K. B. & Lastein, S. The alarm reaction in fishes–odorants, modulations of responses, neural pathways.

*Annals New York Acad. Sci.***1170**, 413–423, https://doi.org/10.1111/j.1749-6632.2009.04111.x (2009).Nordell, S. E. The response of female guppies, Poecilia reticulata, to chemical stimuli from injured conspecifics.

*Environ. Biol. Fishes***51**, 331–338 (1998).Rehnberg, B. G. & Schreck, C. B. Chemosensory detection of predators by coho salmon (Oncorhynchus kisutch): behavioural reaction and the physiological stress response.

*Can. J. Zool.***65**, 481–485 (1987).Barreto, R. E.

*et al*. Blood cues induce antipredator behavior in Nile tilapia conspecifics.*PLoS One***8**, e54642, https://doi.org/10.1371/journal.pone.0054642 (2013).Mirza, R. S. & Chivers, D. P. Are chemical alarm cues conserved within salmonid fishes?

*J. Chem. Ecol.***27**, 1641–1655 (2001).Wisenden, B. D. & Smith, R. A re-evaluation of the effect of shoalmate familiarity on the proliferation of alarm substance cells in ostariophysan fishes.

*J*.*Fish Biol*(1998).Abreu, M. S.

*et al*. Behavioral responses of zebrafish depend on the type of threatening chemical cues.*J. Comp. Physiol. A: Neuroethol. Sensory, Neural, Behav. Physiol.***202**, 895–901, https://doi.org/10.1007/s00359-016-1129-5 (2016).LaFleur, B. & Greevy, R. Introduction to permutation and resampling-based hypothesis tests.

*J. clinical child adolescent psychology : official journal for Soc. Clin. Child Adolesc. Psychol. Am. Psychol. Assoc. Div. 53***38**, 286–94, https://doi.org/10.1080/15374410902740411 (2009).Frenet, M. F. Sur les courbes à double courbure.

*J. de mathématiques pures et appliquées***17**, 437–447 (1852).Serret, J. A. Sur quelques formules relatives à la théorie des courbes à double courbure.

*J. de mathématiques pures etappliquées***16**, 193–207 (1851).Albanese, D.

*et al*. Mlpy: Machine learning python, 1202.6548 (2012).Muller, M.

*Information Retrieval for Music and Motion*(Springer-Verlag Berlin Heidelberg, Berlin, Heidelberg, 2007).Oliphant, T. NumPy: A guide to NumPy. USA: Trelgol Publishing. [Online; accessed <today>] (2006–).

Jones, E.

*et al*. SciPy: Open source scientific tools for Python. [Online; accessed <today>] (2001–).Savitzky, A. & Golay, M. J. E. Smoothing and differentiation of data by simplified least squares procedures.

*Anal. Chem.***36**, 1627–1639, https://doi.org/10.1021/ac60214a047 (1964).Hass, J. & Koehl, P. Comparing shapes of genus-zero surfaces.

*J. Appl. Comput. Topol.***1**, 57–87, https://doi.org/10.1007/s41468-017-0004-y (2017).Bers, L. Uniformization, moduli, and Kleinian groups.

*Bull. Lond. Math. Soc.***4**, 257–300, https://doi.org/10.1112/blms/4.3.257 (1972).Bowyer, A. Computing dirichlet tessellations*.

*The Comput. J.***24**, 162–166, https://doi.org/10.1093/comjnl/24.2.162 (1981).Watson, D. F. Computing the n-dimensional delaunay tessellation with application to voronoi polytopes*.

*The Comput. J.***24**, 167–172, https://doi.org/10.1093/comjnl/24.2.167 (1981).Beardon, A. F. & Stephenson, K. The uniformization theorem for circle packings.

*Indiana Univ. Math. J.***39**, 1383–1425 (1990).Collins, C. R. & Stephenson, K. A circle packing algorithm.

*Comput. Geom.***25**, 233–256, https://doi.org/10.1016/S0925-7721(02)00099-8 (2003).Schwarz, H. A.

*Gesammelte mathematische Abhandlungen*.*Band I*,*II*Nachdruck in einem Band der Auflage von 1890 (Chelsea Publishing Co., Bronx, N.Y., 1972).

## Acknowledgements

This work was supported by Yale-NUS College through grants R-607-265-225-121 and IG16-LR003. The authors acknowledge the support from Haroun Chahed, Goh Rui Zhe and Maharshee Karia in the initial stages of the project.

## Author information

### Authors and Affiliations

### Contributions

A.S.M. and M.T.S. conceived and designed the project, and wrote the manuscript with assistance from S.G. A.S.M. provided the data-set to test the methods and interpreted the results. M.T.S. formulated the models and conducted the computational experiments. S.G. developed and implemented the software package with assistance from M.T.S.

### Corresponding author

## Ethics declarations

### Competing interests

The authors declare no competing interests.

## Additional information

**Publisher’s note** Springer Nature remains neutral with regard to jurisdictional claims in published maps and institutional affiliations.

## Supplementary information

## Rights and permissions

**Open Access** This article is licensed under a Creative Commons Attribution 4.0 International License, which permits use, sharing, adaptation, distribution and reproduction in any medium or format, as long as you give appropriate credit to the original author(s) and the source, provide a link to the Creative Commons license, and indicate if changes were made. The images or other third party material in this article are included in the article’s Creative Commons license, unless indicated otherwise in a credit line to the material. If material is not included in the article’s Creative Commons license and your intended use is not permitted by statutory regulation or exceeds the permitted use, you will need to obtain permission directly from the copyright holder. To view a copy of this license, visit http://creativecommons.org/licenses/by/4.0/.

## About this article

### Cite this article

Stamps, M.T., Go, S. & Mathuru, A.S. Computational geometric tools for quantitative comparison of locomotory behavior.
*Sci Rep* **9**, 16585 (2019). https://doi.org/10.1038/s41598-019-52300-8

Received:

Accepted:

Published:

DOI: https://doi.org/10.1038/s41598-019-52300-8

## Comments

By submitting a comment you agree to abide by our Terms and Community Guidelines. If you find something abusive or that does not comply with our terms or guidelines please flag it as inappropriate.