donadigo / gbxtools

Various scripts that I use for TrackMania replay analysis
GNU General Public License v3.0
58 stars 11 forks source link

Add script for power spectral density analysis #5

Open vilhub opened 3 years ago

vilhub commented 3 years ago

This is a possible approach to use power spectral densities to get a replay's frequency signature. Roughly it's similar to your idea of using spikes per second except that it captures the global player's steering movement over the whole replay and computes the typical frequencies at which the steering was done.

As an example, here's an output plot that shows the spectral density of racehans versus riolu on C05 Endurance which show very different diagrams. You can see on riolu's replay (blue), the higher frequencies are much more pronounced. Only by resampling to simulate a 0.5x slowdown on riolu's replay (green) do we get similar behavior in terms of frequencies image

The code includes an automatic sweep to try to match two replays by scanning slowdowns from 0.3x to 1x to try to find the optimal match. This by no means guarantees that a match with a slowdown factor of less than 1x is cheated as different players have different playstyles, short tracks will show more noise, the slowed down resampling will obviously not contain the same inputs as driving normally and this is an experimental script. However when the frequencies powers are so different, it certainly raises an eyebrow and it would be interesting if you could test it out on replays that you have created yourself by slowing down the game to see if you can retrieve the original slowdown factor with this tool.

Usage : python match_two_replays_power_spectral_density.py folder_with_two_replays/ or python match_two_replays_power_spectral_density.py replay_1 replay_2

Extra dependencies are matplotlib and scipy.

Thanks to @R00dRallec for the steering plotting that I based this on.

vilhub commented 3 years ago

To give a bit more context as to how strong the deviation from normal is for the run above, here are the two runs above from C05 Endurance along with other players' runs in the top 20 (controller only) :

image

More information on power spectral density.

donadigo commented 3 years ago

This is absolutely great. I will review all of the PR's a little bit later, as things will calm down a little bit. Thank you for your analysis & work.

no-trick-pony commented 3 years ago

Looks good, I was thinking about implementing something like that myself, because the "spikes per second" concept seemed a bit brittle.

derivator commented 3 years ago

@vilhub This is great! I think plotting a single suspicious run over a 2D histogram of e.g. the top 100 runs would be an even more powerful way to visualize this.