I want to quantify the complexity of the street network of different cities.
For each city I have the angle distribution of its streets.
My hypothesis that the more complex the street network, the closer to the uniform distribution its street angle distribution. In the above plots, London's street network is much more complex than Chicago's.
To compute the distance to the uniform distribution I used the Kullback Leibler divergence and the Total Variation Distance but I get counter-intuitive results: London's KLD and TVD are higher than Chicago's, so I'm not sure these are valid for angle distributions...
Is there any specific distance I should use for this kind of data?
Edit #1: here is the code I used
import numpy as np import osmnx as ox, pandas as pd, matplotlib.pyplot as plt %matplotlib inline ox.config(log_console=True, use_cache=True) place='Chicago, USA' G = ox.graph_from_place(place, network_type='drive') fig, ax = ox.plot_graph(ox.project_graph(G), node_size=0) # calculate edge bearings and visualize their frequency G = ox.add_edge_bearings(G) bearings = pd.Series([data['bearing'] for u, v, k, data in G.edges(keys=True, data=True)]) ax = bearings.hist(bins=30, zorder=2, alpha=0.8) xlim = ax.set_xlim(0, 360) ax.set_title(place + ' street network edge bearings') plt.show() def KL(a, b): a = np.asarray(a, dtype=np.float) b = np.asarray(b, dtype=np.float) return np.sum(np.where(a != 0, a * np.log(a / b), 0)) def tvd(a, b): a = np.asarray(a, dtype=np.float) b = np.asarray(b, dtype=np.float) return sum(abs(a-b))/2 #uniform distribution unif_array=np.full((bearings.size), 1/float(bearings.size)) unif_array=unif_array/np.sum(unif_array) #normalized angle distribution bearing_norm=bearings/np.sum(bearings) print KL(bearing_norm,unif_array) print tvd(bearing_norm,unif_array) # for Chicago, KL = 0.138 and TVD = 0.218 # for London, KL = 0.194 and TVD = 0.249
Edit #2: I found my mistake, I defined the uniform distribution as
when it should be
unif_array = np.random.uniform(0,360,bearings.size)