FLOCK.DirectionalCorrelation
index
c:\users\james\gitrepos\gps-ruck\flock\directionalcorrelation.py

Functions for using directional correlation time delay metrics as leadership metrics

 
Modules
       
math
numpy
networkx
os
pandas
matplotlib.pyplot

 
Functions
       
dir_corr_graph_comparison(graphs)
Get metrics for the consistency of the leadership heirarchy graph over movement periods
get the edit distance between movement period graphs
also compare adjacency martrices across movement period graphs
 
Args:
    graphs (list): list of networkx directed graphs representing leadership heirarchies in different movement periods
 
Returns:
    G_consist (float): average edit diatance over all pairs of movement periods
    G_adj_consist (DataFrame): adjacency matrix differences for each pair of movement periods
get_directional_corr(movement_periods, names, UTM=True, threshold=10, window_length=9)
Get the Directional Correlation of soldiers
For finding the Directional Correlation time-delay as a leasership metric
and the ratio of time spent 'highly correlated' as a sychronicity metric (Highly Correlated Segments (HCS))
 
Finding the normalized velocity vectors and taking the dot product between pairs as 'correlation' for different time delays -4 to 4 seconds
Time delay of maximum correlation is the directional ingfluence time delay measure 
 
Returns time delay dfs for each soldier in each movement period, HCS ratios for each soldier in each period, and a graph representation of leadership heirarchy for each movement period
 
 
Args:
    movement_periods (list): list of DataFrames for each movement period that have been further smoothed
    names (list): list of names from this squad
    UTM (bool, optional): True if using UTM data, false if GPS data. Defaults to True.
    threshold (int, optional): Distance threshold, Directional Correlation only calculated if within this threshold (meters) for window_length of time (seconds). Defaults to 10.
    window_length (int, optional): Duration (in seconds) that two soldiers must be in proximity (below threshold distance) in order to calculate directional correlation. Defaults to 9.
 
Returns:
    time_delay_dfs (list): list of correaltional time delays over time as dfs for each soldier during each movement period
    HCS_ratio_dfs (list): list Series for each movement period, with an HSC ratio for each player
    graphs (list): list of networkx directed graphs representing leadership heirarchy, edges pointing from leader to follower
leadership_graph_ani(time_delay_dfs, graphs, names, sq_name, show=False)
Plot an animation of leadership graphs for each movememt period
One frame is one movement period leadership heirarchy
 
The leadership features have been extracted in get_directional_corr()
 
Args:
    time_delay_dfs (list): list of correaltional time delays over time as dfs for each soldier during each movement period
    graphs (list): list of networkx directed graphs representing leadership heirarchy, edges pointing from leader to follower
    names (list): list of names from this squad as list of str
    sq_name (str): name of squad as str
    show (bool, optional): if the plot should be displayed, saved if false. Defaults to False.
 
Returns:
    _type_: _description_