22252225 " plt.show()"
22262226 ]
22272227 },
2228+ {
2229+ "cell_type" : " markdown" ,
2230+ "metadata" : {},
2231+ "source" : [
2232+ " ### Dimensionless Numbers: Intrusion and Avoidance\n " ,
2233+ " \n " ,
2234+ " The dimensionless Intrusion number $\\ mathcal{I}n$ and Avoidance number $\\ mathcal{A}v$\n " ,
2235+ " classify crowd flow regimes based on personal space intrusions and collision anticipation\n " ,
2236+ " ([Cordes et al., *PNAS Nexus*, 2024](https://doi.org/10.1093/pnasnexus/pgae120)).\n " ,
2237+ " \n " ,
2238+ " The **Intrusion number** quantifies encroachment on personal space:\n " ,
2239+ " \n " ,
2240+ " $$\n " ,
2241+ " \\ mathcal{I}n_i = \\ sum_{j \\ in \\ mathcal{N}_i}\n " ,
2242+ " \\ left(\\ frac{r_{\\ text{soc}} - \\ ell_{\\ text{min}}}{r_{ij} - \\ ell_{\\ text{min}}}\\ right)^2\n " ,
2243+ " $$\n " ,
2244+ " \n " ,
2245+ " The **Avoidance number** quantifies the imminence of collisions via the time-to-collision (TTC):\n " ,
2246+ " \n " ,
2247+ " $$\n " ,
2248+ " \\ mathcal{A}v_i = \\ max_{j \\ in \\ mathcal{N}'_i}\n " ,
2249+ " \\ frac{\\ tau_0}{\\ tau_{ij}}\n " ,
2250+ " $$\n " ,
2251+ " \n " ,
2252+ " where $r_{\\ text{soc}} = 0.8\\ ,$m is the social radius, $\\ ell_{\\ text{min}} = 0.2\\ ,$m the pedestrian diameter,\n " ,
2253+ " and $\\ tau_0 = 3\\ ,$s a reference timescale."
2254+ ]
2255+ },
2256+ {
2257+ "cell_type" : " code" ,
2258+ "execution_count" : null ,
2259+ "metadata" : {
2260+ "collapsed" : false
2261+ },
2262+ "outputs" : [],
2263+ "source" : [
2264+ " from pedpy import compute_intrusion, compute_avoidance, IntrusionMethod\n " ,
2265+ " \n " ,
2266+ " intrusion = compute_intrusion(traj_data=traj)\n " ,
2267+ " intrusion.head()"
2268+ ]
2269+ },
2270+ {
2271+ "cell_type" : " code" ,
2272+ "execution_count" : null ,
2273+ "metadata" : {
2274+ "collapsed" : false
2275+ },
2276+ "outputs" : [],
2277+ "source" : [
2278+ " avoidance = compute_avoidance(\n " ,
2279+ " traj_data=traj, frame_step=5, tau_0=3.0, radius=0.2\n " ,
2280+ " )\n " ,
2281+ " avoidance.head()"
2282+ ]
2283+ },
2284+ {
2285+ "cell_type" : " markdown" ,
2286+ "metadata" : {},
2287+ "source" : [
2288+ " #### Temporal evolution\n " ,
2289+ " \n " ,
2290+ " We can visualize how these numbers evolve over time by averaging over all pedestrians per frame:"
2291+ ]
2292+ },
2293+ {
2294+ "cell_type" : " code" ,
2295+ "execution_count" : null ,
2296+ "metadata" : {
2297+ "collapsed" : false
2298+ },
2299+ "outputs" : [],
2300+ "source" : [
2301+ " import matplotlib.pyplot as plt\n " ,
2302+ " \n " ,
2303+ " mean_in = intrusion.groupby(\" frame\" )[\" intrusion\" ].mean()\n " ,
2304+ " mean_av = avoidance.groupby(\" frame\" )[\" avoidance\" ].mean()\n " ,
2305+ " \n " ,
2306+ " fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(12, 4))\n " ,
2307+ " \n " ,
2308+ " ax1.plot(mean_in.index / traj.frame_rate, mean_in.values)\n " ,
2309+ " ax1.set_xlabel(\" Time / s\" )\n " ,
2310+ " ax1.set_ylabel(r\" $\\ langle \\ mathcal{I}n \\ rangle$\" )\n " ,
2311+ " ax1.set_title(\" Mean Intrusion Number\" )\n " ,
2312+ " \n " ,
2313+ " ax2.plot(mean_av.index / traj.frame_rate, mean_av.values)\n " ,
2314+ " ax2.set_xlabel(\" Time / s\" )\n " ,
2315+ " ax2.set_ylabel(r\" $\\ langle \\ mathcal{A}v \\ rangle$\" )\n " ,
2316+ " ax2.set_title(\" Mean Avoidance Number\" )\n " ,
2317+ " \n " ,
2318+ " fig.tight_layout()\n " ,
2319+ " plt.show()"
2320+ ]
2321+ },
22282322 {
22292323 "cell_type" : " markdown" ,
22302324 "metadata" : {},
33103404 },
33113405 "nbformat" : 4 ,
33123406 "nbformat_minor" : 0
3313- }
3407+ }
0 commit comments