I have two animal running trajectories. A regular one with repeated back and forth running between point A and B, like the one on top in the figure. The other one is very irregular, animal paused and turned around a lot in the middle. Is there any algorithm to measure the regularity of a trajectory, like repeated activity on the top? And compare the extend of regularity between the two trajectories? Thanks in advance.
In the world of physics, you can distinguish between random motion (e.g. thermal Brownian walk) and directed motion (called ballistic: think of a cannon ball) by studying the mean square displacement of the object: you'll be able to fit this displacement as a function of time by a linear law if it is random, and by a quadratic one if it is directed. Exponents in between will give you an indication of the degree of randomness. The advantage of this (even if it is not specialized for your case) is that there's a large body of work using this, including for living organisms.
Note also that if your motion is as in the first case above, you'll have ballistic motion for times smaller than the travel time from left to right, and diffusive (random) for times larger than that. This has been used e.g. to analyse the run-and-tumble motion of bacteria who have a short-time ballistic motion and then after some time tumble to explore another randomly-chosen direction.
Example of this type of coexistence of two regimes:
In the field of biophysics, much of this was initiated by Howard Berg and coworkers
In your first case, you'll have an initial ballistic regime and then something that plateaus (because you stay between A and B). The transition time-lag will be the travel time between A and B.
In your second case, you'll be able to characterize the random walk: if the animal is aiming at going from A to B but randomly errs for short times, you'll have a short-time diffusive behaviour, and an intermediate time ballistic one. (And then again a plateau, as in the first case and for the same reasons). If the animal reaches B by mere chance, on the contrary, you'll have a diffusive regime only before this plateau.