In [2]:
%matplotlib inline
DEFAULT_FIGSIZE = (16, 12)

import gzip
import os
import pickle
import itertools
import sys

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.lines as mlines
import matplotlib.patches as mpatches
import seaborn as sns
sns.set_style('darkgrid', {'legend.frameon': True})
import pandas as pd

sys.path.append('..')
from antlia import dtc
from antlia import exp2
from antlia.record import Record, load_file
from antlia.dtype import load_converted_record
from antlia import plot_braking as braking
from antlia.plotdf import plotjoint

%load_ext autoreload
%autoreload 2

import matplotlib as mpl
mpl.rcParams['figure.figsize'] = DEFAULT_FIGSIZE
mpl.rcParams['legend.facecolor'] = 'white'

In [2]:
braking_df = pd.read_pickle('trial2_braking_ttc.p.gz')

# remove rows associated with rider 15
braking_df = braking_df.drop(
    braking_df[braking_df['rider id'] == 15].index)

# rename rider 16 to 15
braking_df.loc[braking_df['rider id'] == 16, 'rider id'] = 15
braking_df = braking_df.reset_index(drop=True)

In [8]:
steering_df = pd.read_pickle('trial2_steering_ttc.p.gz')

# rider 16 already dropped

In [9]:
with pd.option_context('display.max_rows', None,
                       'display.max_columns', None,
                       'float_format', '{:0.3f}'.format):
    print('braking dataframe')
    display(braking_df)
    print('steering dataframe')
    display(steering_df)


braking dataframe
linregress slope linregress intercept linregress r-value linregress p-value linregress stderr starting velocity braking duration braking distance braking starttime braking endtime window size lockup ranges rider id trial id distance-to-collision time-to-collision
0 -0.698 92.942 -0.967 0.000 0.008 3.694 4.401 8.091 128.370 132.770 55 0 0 0 7.815 2.115
1 -1.471 855.737 -0.997 0.000 0.006 4.713 3.296 8.010 578.273 581.570 55 0 0 1 8.705 1.847
2 -1.900 1257.373 -0.997 0.000 0.008 5.581 3.168 9.640 658.551 661.720 55 0 0 2 10.068 1.804
3 -1.717 1756.369 -0.994 0.000 0.010 4.524 2.864 7.395 1020.226 1023.090 55 0 0 6 7.788 1.722
4 -1.759 1944.489 -0.994 0.000 0.012 3.082 2.088 3.388 1103.388 1105.477 55 0 0 7 4.187 1.359
5 -2.140 2523.997 -0.996 0.000 0.009 5.799 3.072 9.353 1176.298 1179.370 55 0 0 8 9.950 1.716
6 -1.962 2990.284 -0.995 0.000 0.010 5.965 3.428 11.289 1520.923 1524.351 55 1 0 12 11.586 1.942
7 -1.589 2607.772 -0.995 0.000 0.011 2.877 1.656 2.942 1639.394 1641.050 55 0 0 13 3.300 1.147
8 -2.171 3731.208 -0.993 0.000 0.015 4.665 2.584 6.200 1716.346 1718.931 55 0 0 14 6.976 1.496
9 -0.799 422.680 -0.997 0.000 0.002 4.415 5.841 11.928 523.390 529.230 55 0 1 3 13.000 2.944
10 -0.761 470.122 -0.995 0.000 0.003 3.097 4.217 5.941 614.186 618.403 55 0 1 4 7.632 2.464
11 -2.897 2000.376 -0.998 0.000 0.010 5.660 2.216 6.502 688.387 690.604 55 0 1 5 10.631 1.878
12 -1.665 1728.205 -0.993 0.000 0.009 5.366 3.648 8.674 1034.890 1038.538 55 0 1 9 10.023 1.868
13 -1.199 1353.083 -1.000 0.000 0.002 3.189 2.876 4.631 1125.873 1128.750 55 0 1 10 5.929 1.859
14 -1.572 1888.155 -0.995 0.000 0.008 4.580 3.112 7.188 1198.314 1201.427 55 0 1 11 8.124 1.774
15 -1.097 1701.771 -0.996 0.000 0.005 3.167 3.392 4.646 1548.298 1551.691 55 0 1 15 6.138 1.938
16 -1.650 2690.049 -0.997 0.000 0.007 4.361 3.056 6.396 1627.961 1631.018 55 0 1 16 8.499 1.949
17 -2.085 3534.947 -0.998 0.000 0.007 5.309 2.848 8.023 1692.706 1695.554 55 0 1 17 9.444 1.779
18 -2.664 874.780 -0.993 0.000 0.020 4.468 2.088 4.051 326.617 328.706 55 1 2 0 7.307 1.635
19 -2.239 923.446 -0.998 0.000 0.010 3.064 1.628 2.462 411.032 412.660 55 0 2 1 4.532 1.479
20 -2.456 1180.750 -0.977 0.000 0.029 5.240 2.716 5.277 478.604 481.321 55 0 2 2 7.225 1.379
21 -1.661 1521.687 -0.972 0.000 0.019 5.210 3.512 11.018 912.317 915.829 55 0 2 6 12.463 2.392
22 -1.766 1750.998 -0.985 0.000 0.020 2.893 1.936 2.402 989.775 991.711 55 0 2 7 3.349 1.157
23 -2.699 2849.536 -0.995 0.000 0.018 3.732 1.696 2.750 1054.139 1055.835 55 0 2 8 4.713 1.263
24 -2.320 3192.325 -0.999 0.000 0.009 3.153 1.568 2.425 1374.486 1376.054 55 0 2 12 3.568 1.132
25 -2.395 3450.812 -0.985 0.000 0.027 4.012 1.976 3.600 1439.210 1441.186 55 0 2 13 4.943 1.232
26 -2.339 3509.115 -0.992 0.000 0.017 5.375 2.344 6.296 1497.958 1500.302 55 0 2 14 7.710 1.435
27 -1.029 409.654 -0.997 0.000 0.003 5.166 5.121 13.720 392.989 398.109 55 0 3 3 14.282 2.764
28 -0.768 380.569 -0.994 0.000 0.004 2.906 3.928 6.387 491.189 495.117 55 0 3 4 7.168 2.466
29 -0.825 477.448 -0.997 0.000 0.003 4.278 4.961 11.503 573.499 578.460 55 0 3 5 12.646 2.956
30 -0.678 648.883 -0.989 0.000 0.004 2.968 4.745 7.802 951.985 956.729 55 0 3 9 8.160 2.749
31 -1.044 1082.155 -0.998 0.000 0.003 4.287 4.393 10.007 1031.790 1036.182 55 0 3 10 10.891 2.540
32 -0.875 977.023 -0.996 0.000 0.003 5.592 6.905 17.434 1110.096 1117.001 55 0 3 11 18.276 3.268
33 -0.747 1116.402 -0.996 0.000 0.003 4.471 5.729 12.396 1487.791 1493.520 55 0 3 15 13.004 2.908
34 -0.715 1135.587 -0.995 0.000 0.003 3.107 4.513 7.031 1584.035 1588.548 55 0 3 16 7.911 2.546
35 -0.781 1305.584 -0.995 0.000 0.003 5.428 6.669 18.581 1664.706 1671.375 55 0 3 17 20.005 3.685
36 -2.276 315.000 -0.993 0.000 0.014 6.038 3.120 9.028 135.541 138.661 55 0 4 0 9.936 1.646
37 -2.309 512.403 -0.997 0.000 0.012 2.758 1.440 1.829 220.656 222.096 55 0 4 1 2.590 0.939
38 -2.360 708.105 -0.994 0.000 0.017 4.172 2.088 4.441 298.106 300.195 55 0 4 2 5.109 1.225
39 -2.060 1335.466 -0.988 0.000 0.022 3.041 1.840 2.462 646.778 648.618 55 0 4 6 3.223 1.060
40 -2.437 1757.017 -0.995 0.000 0.014 4.665 2.296 4.783 718.915 721.212 55 0 4 7 5.578 1.196
41 -2.489 1958.361 -0.982 0.000 0.027 5.762 2.592 8.968 784.071 786.664 55 0 4 8 10.321 1.791
42 -2.239 2525.286 -0.992 0.000 0.017 4.180 2.152 4.082 1125.984 1128.137 55 0 4 12 4.618 1.105
43 -1.850 2222.447 -0.998 0.000 0.008 3.161 1.960 3.137 1199.794 1201.754 55 0 4 13 3.809 1.205
44 -2.546 3242.381 -0.989 0.000 0.020 5.961 2.936 8.732 1271.107 1274.043 55 0 4 14 9.584 1.608
45 -1.505 606.491 -0.996 0.000 0.007 3.562 2.460 4.222 400.503 402.964 55 0 5 3 3.851 1.081
46 -1.382 648.815 -0.992 0.000 0.008 4.237 3.484 7.644 466.132 469.616 55 0 5 4 8.092 1.910
47 -1.757 949.192 -0.995 0.000 0.008 5.732 3.752 11.192 536.759 540.512 55 0 5 5 11.908 2.078
48 -1.188 943.546 -0.995 0.000 0.005 4.736 3.944 9.718 789.887 793.832 55 0 5 9 9.825 2.074
49 -1.145 972.177 -0.991 0.000 0.007 3.748 3.656 7.737 845.178 848.835 55 0 5 10 8.222 2.193
50 -1.331 1205.352 -0.989 0.000 0.008 6.451 5.069 19.664 900.353 905.422 55 0 5 11 20.318 3.150
51 -1.158 1359.104 -0.994 0.000 0.005 6.036 5.505 15.223 1168.697 1174.202 55 0 5 15 15.710 2.603
52 -1.377 1799.651 -0.992 0.000 0.008 4.688 3.664 8.700 1303.482 1307.146 55 0 5 17 9.020 1.924
53 -0.862 107.798 -0.998 0.000 0.003 2.586 3.040 3.939 121.978 125.018 55 0 6 0 5.057 1.955
54 -0.850 186.596 -0.996 0.000 0.003 4.134 5.073 10.924 214.413 219.486 55 0 6 1 12.656 3.061
55 -1.918 581.327 -0.994 0.000 0.010 5.734 3.480 8.665 300.016 303.496 55 0 6 2 10.744 1.874
56 -1.101 784.262 -0.993 0.000 0.006 4.170 4.121 7.740 708.401 712.522 55 0 6 6 9.675 2.320
57 -1.136 916.491 -0.987 0.000 0.010 2.966 2.928 3.882 804.493 807.422 55 0 6 7 5.098 1.719
58 -1.410 1247.596 -0.977 0.000 0.013 5.529 4.137 10.163 880.791 884.927 55 0 6 8 12.438 2.249
59 -1.677 2102.104 -0.992 0.000 0.010 5.630 3.724 9.993 1249.857 1253.582 55 0 6 12 12.647 2.246
60 -0.872 1173.544 -0.992 0.000 0.005 3.069 3.932 6.007 1341.844 1345.776 55 0 6 13 7.561 2.464
61 -1.103 1576.381 -0.992 0.000 0.006 4.462 4.105 9.233 1425.166 1429.271 55 0 6 14 11.124 2.493
62 -0.552 280.417 -0.995 0.000 0.002 4.300 7.465 17.035 500.147 507.612 55 0 7 3 18.955 4.408
63 -0.433 252.613 -0.981 0.000 0.003 3.030 6.313 9.887 576.600 582.913 55 0 7 4 11.339 3.742
64 -0.944 612.821 -0.999 0.000 0.002 5.271 5.409 15.990 643.137 648.546 55 0 7 5 19.598 3.718
65 -0.871 858.846 -0.997 0.000 0.002 5.274 6.369 17.488 979.376 985.745 55 0 7 9 19.805 3.755
66 -0.582 618.322 -0.961 0.000 0.007 2.987 4.073 7.090 1057.494 1061.566 55 0 7 10 7.791 2.608
67 -0.649 738.008 -0.996 0.000 0.002 4.484 6.525 15.604 1130.059 1136.584 55 0 7 11 18.271 4.075
68 -0.738 1080.689 -0.991 0.000 0.004 3.147 4.177 7.644 1459.348 1463.525 55 0 7 15 8.749 2.780
69 -0.595 912.279 -0.993 0.000 0.003 4.473 6.145 15.774 1526.393 1532.538 55 0 7 16 17.199 3.845
70 -0.920 1470.090 -0.998 0.000 0.002 5.791 5.941 18.937 1591.929 1597.870 55 0 7 17 20.576 3.553
71 -1.469 121.896 -0.997 0.000 0.006 4.180 3.088 7.064 79.879 82.967 55 0 8 0 9.772 2.338
72 -1.413 231.803 -0.991 0.000 0.010 3.447 2.864 4.529 161.517 164.381 55 0 8 1 9.991 2.898
73 -1.900 492.359 -0.980 0.000 0.019 5.607 3.344 8.834 256.126 259.470 55 0 8 2 12.495 2.228
74 -2.049 1111.708 -0.999 0.000 0.005 5.689 3.084 8.909 539.589 542.673 55 0 8 6 12.293 2.161
75 -0.857 528.155 -0.995 0.000 0.004 3.647 4.121 8.357 611.774 615.894 55 0 8 7 11.544 3.165
76 -1.407 955.226 -0.999 0.000 0.003 4.430 3.308 7.925 675.594 678.902 55 0 8 8 11.348 2.562
77 -1.417 1630.184 -0.991 0.000 0.011 2.983 2.504 4.068 1147.853 1150.357 55 0 8 12 7.399 2.480
78 -1.556 1884.997 -0.997 0.000 0.006 4.169 2.936 6.436 1208.904 1211.840 55 0 8 13 8.682 2.083
79 -2.419 3116.830 -0.996 0.000 0.012 5.619 2.696 7.751 1285.729 1288.426 55 0 8 14 10.538 1.875
80 -1.174 550.258 -0.974 0.000 0.011 5.973 5.385 16.763 463.278 468.663 55 0 9 3 18.235 3.053
81 -0.964 525.985 -0.992 0.000 0.006 3.053 3.160 5.034 542.260 545.421 55 0 9 4 5.825 1.908
82 -1.567 980.041 -0.995 0.000 0.008 4.466 3.112 7.769 622.322 625.435 55 0 9 5 8.517 1.907
83 -1.163 1122.452 -0.998 0.000 0.004 2.793 2.616 3.832 962.470 965.086 55 0 9 9 4.560 1.632
84 -1.068 1110.887 -0.996 0.000 0.004 4.016 3.880 8.729 1035.627 1039.508 55 0 9 10 9.404 2.342
85 -1.066 1179.394 -0.994 0.000 0.005 5.596 5.441 16.894 1100.543 1105.984 55 0 9 11 18.031 3.222
86 -0.813 1170.797 -0.897 0.000 0.017 4.227 4.545 10.232 1435.618 1440.162 55 0 9 15 10.233 2.421
87 -1.180 1787.490 -1.000 0.000 0.002 3.046 2.480 4.004 1511.892 1514.372 55 0 9 16 4.718 1.549
88 -1.260 1982.024 -0.975 0.000 0.011 5.860 5.033 18.420 1567.811 1572.844 55 0 9 17 20.075 3.426
89 -1.107 106.205 -0.975 0.000 0.011 4.954 4.429 10.150 91.688 96.116 55 0 10 0 15.892 3.208
90 -0.974 201.052 -0.994 0.000 0.005 3.112 3.284 5.496 203.008 206.292 55 0 10 1 6.555 2.106
91 -1.396 386.844 -0.993 0.000 0.007 4.850 3.780 8.176 273.756 277.537 55 0 10 2 10.348 2.133
92 -1.459 883.290 -0.994 0.000 0.009 3.432 2.376 4.666 602.778 605.154 55 0 10 6 5.736 1.671
93 -2.052 1378.571 -0.993 0.000 0.014 4.718 2.392 6.027 669.274 671.666 55 0 10 7 7.273 1.542
94 -2.142 1575.759 -0.999 0.000 0.006 6.024 2.960 9.579 732.598 735.559 55 0 10 8 11.009 1.828
95 -1.973 2065.474 -0.997 0.000 0.009 4.471 2.408 5.942 1044.289 1046.698 55 0 10 12 7.229 1.617
96 -1.299 1455.654 -0.989 0.000 0.010 3.356 2.896 5.466 1117.735 1120.631 55 0 10 13 6.199 1.847
97 -1.639 1943.597 -0.994 0.000 0.008 5.926 3.872 11.019 1182.272 1186.144 55 0 10 14 12.216 2.061
98 -0.412 194.188 -0.995 0.000 0.001 3.414 8.297 13.961 462.994 471.291 55 0 11 3 15.626 4.578
99 -0.979 541.301 -0.983 0.000 0.007 4.395 5.553 13.429 547.605 553.157 55 0 11 4 14.545 3.310
100 -1.824 1137.486 -0.995 0.000 0.009 5.357 3.600 9.406 620.394 623.994 55 0 11 5 10.585 1.976
101 -0.813 738.510 -0.982 0.000 0.005 4.865 7.406 18.697 902.015 909.421 55 0 11 9 20.217 4.155
102 -1.049 1025.522 -0.981 0.000 0.009 3.375 3.752 7.304 974.097 977.850 55 0 11 10 8.299 2.459
103 -1.235 1365.380 -0.989 0.000 0.007 6.022 5.497 18.480 1100.525 1106.022 55 0 11 11 19.693 3.270
104 -1.493 2067.773 -0.980 0.000 0.012 6.236 5.129 17.415 1379.763 1384.892 55 1 11 15 18.992 3.045
105 -0.819 1188.011 -0.966 0.000 0.009 3.528 4.537 10.709 1445.156 1449.692 55 0 11 16 11.320 3.209
106 -1.474 2230.398 -0.976 0.000 0.015 4.394 3.656 9.546 1509.688 1513.344 55 0 11 17 10.267 2.336
107 -1.799 219.657 -0.996 0.000 0.011 3.325 1.944 3.467 120.132 122.076 55 0 12 0 5.706 1.716
108 -2.014 394.981 -0.998 0.000 0.008 4.309 2.304 4.944 193.865 196.170 55 0 12 1 5.622 1.305
109 -1.720 447.930 -0.990 0.000 0.013 5.255 3.064 7.952 257.413 260.478 55 0 12 2 7.807 1.486
110 -1.894 1080.483 -0.995 0.000 0.010 4.616 2.704 6.021 567.981 570.685 55 0 12 6 6.767 1.466
111 -1.698 1088.046 -0.990 0.000 0.015 3.163 2.056 3.441 638.693 640.750 55 0 12 7 4.380 1.385
112 -2.253 1771.100 -0.997 0.000 0.009 5.480 2.800 7.141 783.419 786.219 55 0 12 8 7.651 1.396
113 -1.861 2046.511 -0.997 0.000 0.008 5.397 3.232 8.112 1096.752 1099.984 55 0 12 12 8.672 1.607
114 -1.780 2089.538 -0.993 0.000 0.013 3.177 2.048 3.488 1172.229 1174.278 55 0 12 13 4.088 1.287
115 -1.957 2444.415 -0.995 0.000 0.011 4.231 2.608 4.911 1246.684 1249.292 55 0 12 14 5.453 1.289
116 -2.376 772.052 -0.987 0.000 0.023 4.549 2.264 5.860 322.687 324.951 55 0 13 3 7.099 1.561
117 -2.779 1072.567 -0.994 0.000 0.024 3.192 1.376 2.297 384.735 386.111 55 1 13 4 2.787 0.873
118 -2.429 1084.167 -0.997 0.000 0.010 5.397 2.416 6.781 443.990 446.406 55 0 13 5 7.549 1.399
119 -2.837 2299.569 -0.992 0.000 0.022 5.375 2.088 6.493 808.445 810.533 55 0 13 9 7.417 1.380
120 -1.901 1674.395 -0.987 0.000 0.021 3.214 1.856 3.502 879.074 880.930 55 0 13 10 4.099 1.275
121 -2.321 2191.181 -0.994 0.000 0.016 4.150 2.000 4.424 942.258 944.258 55 0 13 11 4.618 1.113
122 -2.071 2836.442 -0.997 0.000 0.011 2.996 1.712 2.544 1367.827 1369.539 55 0 13 15 3.282 1.095
123 -2.610 3740.232 -0.996 0.000 0.016 4.328 1.800 4.232 1431.015 1432.815 55 0 13 16 5.061 1.169
124 -2.648 3960.863 -0.990 0.000 0.022 5.160 2.360 5.289 1493.751 1496.111 55 1 13 17 6.360 1.233
125 -1.937 218.084 -0.983 0.000 0.020 4.488 2.656 7.237 109.844 112.500 55 0 14 0 8.455 1.884
126 -2.568 460.625 -0.999 0.000 0.008 5.240 2.056 5.964 177.184 179.241 55 0 14 1 6.460 1.233
127 -1.156 293.206 -0.996 0.000 0.006 2.958 2.064 3.707 250.966 253.030 55 0 14 2 4.232 1.430
128 -1.955 1071.514 -0.998 0.000 0.006 5.239 2.664 7.719 545.346 548.010 55 0 14 6 8.452 1.613
129 -1.108 687.898 -0.982 0.000 0.010 3.107 3.608 5.862 617.707 621.315 55 0 14 7 6.735 2.167
130 -2.327 1602.791 -0.997 0.000 0.011 4.127 2.040 4.169 686.756 688.796 55 1 14 8 5.200 1.260
131 -1.244 1260.826 -0.999 0.000 0.004 2.702 1.840 2.859 1011.672 1013.513 55 0 14 12 3.829 1.417
132 -2.463 2656.729 -0.995 0.000 0.016 4.408 2.056 4.722 1076.777 1078.833 55 0 14 13 6.391 1.450
133 -2.593 2954.738 -0.994 0.000 0.017 5.751 2.504 7.550 1137.008 1139.512 55 0 14 14 8.843 1.538
134 -0.895 120.696 -0.992 0.000 0.004 5.706 6.181 18.708 128.348 134.528 55 0 15 0 20.011 3.507
135 -0.804 188.903 -0.982 0.000 0.007 3.267 4.265 8.137 230.536 234.801 55 0 15 1 9.369 2.868
136 -0.835 262.966 -0.991 0.000 0.004 4.245 5.273 12.000 309.405 314.678 55 0 15 2 13.693 3.226
137 -0.679 470.184 -0.990 0.000 0.004 3.109 5.065 8.900 687.450 692.515 55 0 15 6 9.994 3.215
138 -1.037 799.376 -0.990 0.000 0.006 4.401 4.809 11.103 766.006 770.814 55 0 15 7 12.251 2.784
139 -1.052 883.179 -0.987 0.000 0.006 5.808 5.457 18.065 833.450 838.907 55 0 15 8 19.556 3.367
140 -0.866 1077.894 -0.997 0.000 0.003 4.431 5.313 12.644 1238.839 1244.152 55 0 15 12 13.955 3.149
141 -0.876 1164.592 -0.997 0.000 0.003 3.118 3.769 6.252 1325.318 1329.087 55 0 15 13 7.676 2.462
142 -1.195 1675.873 -0.999 0.000 0.002 5.714 5.033 14.576 1397.739 1402.772 55 0 15 14 15.689 2.746
steering dataframe
index start index apex index end index minimum clearance event duration minimum y gaussianfit amplitude gaussianfit mean gaussianfit std gaussianfit offset gaussianfit nrmsd starting velocity distance-to-collision time-to-collision lateral clearance minimum clearance rider id trial id
0 585 918 1165 870 4.641 2.216 -0.918 -4.837 3.064 3.133 0.003 3.496 5.681 1.625 0.844 0.771 0 3
1 315 554 763 528 3.584 2.103 -1.040 -5.092 4.313 3.146 0.009 5.937 7.847 1.322 0.957 0.918 0 4
2 377 657 887 657 4.081 2.154 -0.965 -3.647 3.903 3.117 0.002 4.667 8.286 1.776 0.906 0.906 0 5
3 364 673 880 672 4.129 2.197 -0.882 -3.431 3.785 3.072 0.006 4.691 9.250 1.972 0.863 0.863 0 9
4 174 447 650 440 3.808 2.201 -0.875 -3.971 4.599 3.074 0.002 6.132 10.880 1.774 0.859 0.857 0 10
5 413 795 1100 821 5.497 2.060 -1.096 -3.150 3.109 3.158 0.004 3.389 8.745 2.581 1.000 0.977 0 11
6 268 503 728 504 3.684 2.176 -0.969 -3.878 4.506 3.145 0.004 6.055 8.955 1.479 0.884 0.884 0 15
7 195 664 944 648 5.993 2.132 -0.931 -3.977 4.370 3.067 0.007 4.666 14.768 3.165 0.928 0.920 0 16
8 398 882 1180 879 6.257 2.123 -1.113 -3.623 3.491 3.236 0.008 3.348 10.982 3.281 0.937 0.937 0 17
9 734 941 1127 971 3.144 2.082 -1.237 -2.979 2.938 3.295 0.011 3.228 3.683 1.141 0.978 0.946 1 0
10 240 568 807 578 4.561 1.797 -1.119 -3.300 4.707 2.929 0.008 6.114 14.174 2.318 1.263 1.257 1 1
11 356 692 880 709 4.193 1.851 -1.321 -2.797 4.287 3.146 0.023 4.557 10.232 2.245 1.209 1.199 1 2
12 275 553 821 581 4.377 1.867 -1.160 -2.992 4.169 3.024 0.010 4.832 9.428 1.951 1.193 1.167 1 6
13 205 499 769 549 4.513 1.668 -1.384 -1.492 5.422 3.048 0.010 5.994 14.436 2.408 1.392 1.275 1 7
14 209 805 1141 856 7.457 1.560 -1.541 -2.141 3.786 3.074 0.013 3.297 14.271 4.328 1.500 1.418 1 8
15 207 574 816 587 4.893 1.661 -1.187 -3.077 5.829 2.860 0.009 5.901 15.636 2.650 1.399 1.392 1 12
16 139 722 1038 745 7.193 1.729 -1.255 -1.480 6.177 3.000 0.026 4.551 21.036 4.622 1.331 1.318 1 13
17 558 1011 1359 1051 6.409 1.696 -1.358 -1.988 4.590 3.039 0.022 3.356 10.769 3.209 1.364 1.328 1 14
18 282 721 994 711 5.697 1.772 -1.232 -3.784 3.574 3.011 0.010 4.876 15.463 3.172 1.288 1.282 2 3
19 285 632 831 592 4.369 1.781 -1.341 -4.715 4.427 3.118 0.008 6.030 12.892 2.138 1.279 1.206 2 4
20 604 1091 1426 1038 6.577 1.859 -1.416 -4.923 3.583 3.294 0.014 3.118 9.188 2.947 1.201 1.107 2 5
21 294 541 694 458 3.200 1.760 -1.500 -7.685 5.224 3.249 0.010 5.939 6.023 1.014 1.300 0.923 2 9
22 274 791 1075 747 6.409 1.732 -1.485 -4.779 3.971 3.223 0.015 4.919 16.755 3.406 1.328 1.220 2 10
23 406 1064 1355 1036 7.605 1.960 -1.136 -3.693 2.689 3.089 0.031 3.362 14.217 4.229 1.100 1.081 2 11
24 808 1107 1343 1063 4.281 1.914 -1.481 -4.566 3.263 3.395 0.010 2.580 3.664 1.420 1.146 1.092 2 15
25 183 502 714 496 4.249 1.705 -1.389 -3.886 3.828 3.087 0.008 5.493 11.591 2.110 1.355 1.352 2 16
26 153 675 939 646 6.329 1.879 -1.298 -4.641 3.208 3.189 0.018 4.635 14.153 3.054 1.181 1.144 2 17
27 335 663 889 652 4.433 1.981 -1.113 -3.780 3.232 3.078 0.010 4.263 8.479 1.989 1.079 1.075 3 0
28 386 649 837 598 3.608 1.737 -1.628 -6.819 5.727 3.377 0.023 5.873 7.948 1.353 1.323 1.125 3 1
29 719 1026 1239 998 4.161 2.036 -1.126 -3.771 2.993 3.147 0.011 3.120 5.051 1.619 1.024 0.999 3 2
30 384 653 830 593 3.572 1.845 -1.284 -6.132 5.322 3.120 0.012 5.889 7.853 1.333 1.215 1.146 3 6
31 460 811 1058 775 4.785 1.920 -1.213 -4.780 4.004 3.140 0.011 4.548 9.460 2.080 1.140 1.093 3 7
32 743 1043 1274 1015 4.249 2.004 -1.258 -4.066 3.370 3.264 0.007 3.294 5.127 1.556 1.056 1.032 3 8
33 674 937 1143 932 3.752 1.981 -0.845 -3.787 2.445 2.821 0.004 3.125 4.375 1.400 1.079 1.078 3 12
34 328 655 843 591 4.121 1.691 -1.347 -6.501 5.137 3.052 0.007 5.671 9.934 1.752 1.369 1.172 3 13
35 385 654 930 608 4.393 1.930 -1.031 -5.775 4.067 2.972 0.017 4.545 6.192 1.362 1.130 1.032 3 14
36 270 633 837 575 4.537 1.724 -1.615 -6.756 4.537 3.329 0.024 5.619 11.903 2.118 1.336 1.090 4 3
37 462 744 1016 698 4.453 1.751 -1.557 -5.591 4.172 3.338 0.024 4.417 6.426 1.455 1.309 1.184 4 4
38 728 1069 1369 1035 5.129 1.858 -1.387 -4.841 4.045 3.234 0.013 3.333 6.312 1.894 1.202 1.179 4 5
39 565 1075 1368 1023 6.425 1.910 -1.400 -4.719 3.419 3.277 0.012 3.379 10.282 3.043 1.150 1.088 4 9
40 147 488 706 455 4.473 1.794 -1.359 -5.168 4.243 3.195 0.012 5.930 12.639 2.131 1.266 1.164 4 10
41 585 820 1076 766 3.964 1.796 -1.168 -5.717 3.102 2.970 0.029 4.543 4.760 1.048 1.264 1.077 4 11
42 447 755 1012 703 4.521 1.794 -1.467 -6.550 4.496 3.296 0.032 4.592 7.650 1.666 1.266 1.051 4 15
43 304 634 831 590 4.217 1.826 -1.499 -5.886 5.035 3.390 0.023 5.942 11.581 1.949 1.234 1.076 4 16
44 568 1132 1500 1082 7.457 1.789 -1.636 -5.172 4.260 3.444 0.012 3.491 11.997 3.436 1.271 1.196 4 17
45 135 434 619 410 3.872 1.846 -1.236 -5.292 7.073 3.076 0.006 6.954 12.725 1.830 1.214 1.192 5 0
46 457 689 870 629 3.336 1.875 -0.707 -5.908 3.805 2.576 0.006 5.058 5.133 1.015 1.185 1.078 5 1
47 592 990 1194 986 4.853 2.032 -0.795 -2.537 4.621 2.817 0.018 3.453 8.757 2.536 1.028 1.028 5 2
48 136 774 1032 742 7.169 1.894 -0.940 -3.574 4.302 2.864 0.030 3.777 16.300 4.315 1.166 1.143 5 6
49 165 479 707 499 4.337 1.894 -1.118 -2.936 8.244 3.013 0.002 6.467 15.164 2.345 1.166 1.160 5 7
50 223 526 685 527 3.696 1.858 -0.801 -3.031 4.094 2.650 0.015 5.124 10.379 2.026 1.202 1.202 5 8
51 54 613 868 568 6.513 1.857 -1.077 -4.212 4.931 2.960 0.029 5.124 17.608 3.436 1.203 1.145 5 12
52 189 488 639 483 3.600 1.857 -0.692 -2.690 5.134 2.553 0.021 5.742 11.297 1.967 1.203 1.203 5 13
53 79 794 1085 797 8.049 1.898 -0.917 -2.350 3.993 2.874 0.039 3.668 18.155 4.950 1.162 1.162 5 14
54 496 805 965 834 3.836 1.940 -0.845 -2.505 2.672 2.775 0.021 3.222 6.587 2.044 1.120 1.096 5 16
55 474 800 1012 847 4.305 1.828 -1.360 -2.478 2.875 3.169 0.018 3.135 6.869 2.191 1.232 1.161 6 3
56 211 442 603 459 3.136 1.877 -1.416 -2.277 4.949 3.249 0.015 5.894 9.493 1.611 1.183 1.175 6 4
57 278 527 758 583 3.932 1.856 -1.659 -1.847 5.434 3.506 0.010 4.635 8.932 1.927 1.204 1.085 6 5
58 309 548 733 572 3.400 1.845 -1.253 -2.679 3.896 3.105 0.009 4.684 7.686 1.641 1.215 1.164 6 9
59 197 423 605 448 3.264 1.768 -1.382 -2.463 4.945 3.122 0.012 6.061 9.813 1.619 1.292 1.264 6 10
60 242 764 1054 805 6.497 1.906 -1.384 -1.343 5.429 3.267 0.022 3.475 12.850 3.697 1.154 1.110 6 11
61 189 426 603 461 3.312 1.850 -1.461 -1.525 5.325 3.291 0.014 5.960 10.455 1.754 1.210 1.153 6 15
62 162 553 829 601 5.337 1.755 -1.465 -1.589 5.417 3.202 0.016 4.540 13.256 2.920 1.305 1.228 6 16
63 290 757 1100 798 6.513 1.776 -1.705 -2.211 5.387 3.450 0.016 3.446 11.238 3.261 1.284 1.259 6 17
64 357 857 1263 854 7.261 2.068 -1.132 -5.813 5.719 3.283 0.034 3.150 9.979 3.168 0.992 0.992 7 0
65 312 667 881 626 4.553 2.021 -1.001 -5.487 5.001 3.014 0.010 5.661 11.849 2.093 1.039 0.995 7 1
66 296 644 937 626 5.129 2.063 -1.006 -5.770 6.579 3.093 0.023 4.381 9.259 2.114 0.997 0.988 7 2
67 182 536 810 537 5.552 1.977 -1.243 -3.811 4.264 3.244 0.013 4.624 12.859 2.781 1.083 1.083 7 6
68 131 488 750 495 4.953 2.003 -1.342 -3.746 5.324 3.354 0.007 5.502 13.505 2.454 1.057 1.055 7 7
69 576 944 1236 948 5.281 2.054 -1.285 -3.492 3.575 3.335 0.006 3.238 7.427 2.294 1.006 1.006 7 8
70 194 485 719 474 4.201 2.025 -1.303 -4.253 4.932 3.327 0.009 5.823 10.618 1.823 1.035 1.031 7 12
71 271 566 794 571 4.184 1.926 -1.293 -3.384 3.751 3.214 0.004 4.706 8.922 1.896 1.134 1.133 7 13
72 429 918 1141 917 5.697 2.076 -1.132 -3.539 2.709 3.232 0.011 3.415 10.875 3.184 0.984 0.984 7 14
73 243 706 966 717 5.785 1.527 -1.227 -2.296 6.094 2.752 0.022 4.852 16.599 3.421 1.533 1.531 8 3
74 243 539 723 536 3.864 1.751 -1.035 -3.566 5.514 2.771 0.016 6.263 12.313 1.966 1.309 1.309 8 4
75 430 827 1136 827 5.673 1.472 -1.519 -3.843 5.036 2.965 0.015 3.232 8.344 2.582 1.588 1.588 8 5
76 253 557 753 556 4.001 1.686 -1.248 -3.179 5.752 2.928 0.017 6.013 12.088 2.010 1.374 1.374 8 9
77 258 612 814 576 4.449 1.502 -1.323 -4.332 4.257 2.810 0.021 4.750 9.862 2.076 1.558 1.520 8 10
78 362 802 1116 838 6.033 1.735 -1.305 -2.851 4.873 3.025 0.010 3.309 9.969 3.012 1.325 1.305 8 11
79 378 770 1064 828 5.489 1.437 -1.710 -2.457 4.232 3.098 0.022 3.331 9.493 2.850 1.623 1.562 8 15
80 267 555 764 560 3.976 1.627 -1.476 -3.204 6.024 3.087 0.014 5.794 10.951 1.890 1.433 1.433 8 16
81 266 617 871 605 4.841 1.642 -1.729 -4.072 5.484 3.337 0.016 4.515 9.875 2.187 1.418 1.415 8 17
82 383 665 839 609 3.648 1.595 -1.631 -4.646 3.902 3.216 0.027 4.402 5.794 1.316 1.465 1.333 9 0
83 374 602 807 603 3.540 1.666 -1.475 -3.709 4.560 3.151 0.012 5.708 7.819 1.370 1.394 1.394 9 1
84 795 1097 1295 1068 4.001 1.802 -1.522 -3.579 4.013 3.313 0.018 3.290 4.888 1.486 1.258 1.235 9 2
85 195 496 643 477 3.588 1.757 -1.283 -2.724 6.230 3.042 0.028 5.802 10.640 1.834 1.303 1.289 9 6
86 206 556 696 571 4.001 1.889 -0.964 -1.247 4.849 2.841 0.030 4.916 11.508 2.341 1.171 1.164 9 7
87 440 825 1010 812 4.561 1.851 -1.285 -2.381 4.450 3.148 0.033 3.145 7.623 2.424 1.209 1.203 9 8
88 641 1040 1233 999 4.737 1.901 -1.686 -2.814 5.536 3.578 0.032 3.395 7.327 2.158 1.159 1.130 9 12
89 257 590 758 601 4.045 1.730 -1.209 -1.399 6.537 2.963 0.034 6.189 13.861 2.239 1.330 1.325 9 13
90 371 693 855 710 3.872 1.917 -1.346 -1.237 5.901 3.234 0.023 4.794 10.353 2.160 1.143 1.134 9 14
91 153 446 664 450 4.117 1.836 -1.503 -3.132 5.323 3.325 0.010 6.013 12.268 2.040 1.224 1.224 10 3
92 273 558 856 570 4.665 1.991 -1.181 -3.546 4.151 3.182 0.015 4.766 9.324 1.956 1.069 1.062 10 4
93 475 799 1027 782 4.417 2.141 -0.988 -4.079 2.683 3.116 0.005 3.479 6.656 1.913 0.919 0.908 10 5
94 338 792 1110 793 6.177 1.954 -1.272 -3.846 3.721 3.217 0.009 3.406 10.555 3.099 1.106 1.106 10 9
95 97 450 681 450 4.673 1.933 -1.160 -4.053 6.122 3.113 0.008 6.157 15.100 2.452 1.127 1.127 10 10
96 193 569 881 583 5.505 1.918 -1.213 -4.051 5.465 3.169 0.030 4.721 12.648 2.679 1.142 1.136 10 11
97 311 626 907 594 4.769 1.981 -1.192 -5.234 3.968 3.184 0.018 4.683 8.375 1.788 1.079 1.032 10 15
98 191 467 718 476 4.217 1.863 -1.283 -3.536 4.983 3.170 0.017 5.737 11.010 1.919 1.197 1.191 10 16
99 398 811 1193 785 6.361 2.062 -0.900 -4.662 3.346 2.979 0.023 3.373 8.718 2.584 0.998 0.979 10 17
100 236 472 659 469 3.384 2.028 -0.861 -3.436 4.661 2.889 0.007 5.791 8.876 1.533 1.032 1.032 11 0
101 243 582 850 548 4.857 1.915 -1.185 -4.895 5.073 3.112 0.014 4.855 9.968 2.053 1.145 1.107 11 1
102 462 767 1061 765 4.793 1.816 -0.880 -3.457 3.233 2.695 0.010 3.514 6.617 1.883 1.244 1.244 11 2
103 423 746 997 739 4.593 1.891 -1.062 -3.576 3.574 2.963 0.007 3.698 7.218 1.952 1.169 1.167 11 6
104 261 482 636 477 3.000 2.088 -1.071 -3.386 3.834 3.145 0.007 5.563 7.566 1.360 0.972 0.971 11 7
105 321 602 759 596 3.504 1.919 -1.241 -3.530 2.746 3.130 0.015 4.542 7.929 1.746 1.141 1.139 11 8
106 364 614 868 580 4.033 2.030 -1.320 -4.943 4.125 3.347 0.021 4.628 5.998 1.296 1.030 0.983 11 12
107 283 506 705 479 3.376 1.880 -1.310 -4.981 4.084 3.185 0.027 5.663 6.809 1.202 1.180 1.136 11 13
108 328 708 949 723 4.969 1.915 -1.068 -3.031 3.571 2.970 0.011 3.722 9.812 2.636 1.145 1.138 11 14
109 450 709 981 657 4.249 1.955 -1.025 -5.518 2.784 2.991 0.011 4.098 4.982 1.216 1.105 0.898 12 3
110 323 486 649 461 2.608 2.014 -1.086 -4.765 3.478 3.087 0.006 5.800 4.486 0.773 1.046 1.011 12 4
111 445 605 759 579 2.512 1.946 -0.960 -4.537 2.360 2.921 0.013 4.520 2.910 0.644 1.114 1.047 12 5
112 571 757 1019 723 3.584 2.007 -0.994 -5.029 2.500 2.995 0.024 4.539 3.668 0.808 1.053 0.956 12 9
113 348 496 643 484 2.360 1.954 -1.099 -4.704 3.398 3.052 0.013 5.446 3.929 0.722 1.106 1.091 12 10
114 577 820 1054 777 3.816 2.046 -0.894 -5.074 2.568 2.961 0.023 3.392 3.677 1.084 1.014 0.917 12 11
115 357 532 719 493 2.896 1.963 -1.186 -5.390 3.447 3.164 0.010 5.357 4.016 0.750 1.097 0.960 12 15
116 581 748 993 713 3.296 1.977 -1.131 -5.134 2.684 3.108 0.020 4.572 2.850 0.623 1.083 0.955 12 16
117 520 852 1187 791 5.437 1.852 -1.249 -5.504 3.020 3.137 0.025 3.319 5.509 1.660 1.208 1.021 12 17
118 552 791 1168 796 4.933 2.212 -1.121 -3.597 2.241 3.310 0.006 3.370 4.469 1.326 0.848 0.847 13 0
119 265 473 608 445 2.744 2.128 -1.196 -4.617 2.856 3.310 0.012 5.958 6.539 1.097 0.932 0.843 13 1
120 343 592 729 568 3.088 2.163 -1.005 -4.193 2.638 3.149 0.014 4.772 6.638 1.391 0.897 0.861 13 2
121 290 613 774 577 3.872 2.114 -1.259 -4.752 2.572 3.347 0.010 4.689 8.681 1.851 0.946 0.840 13 6
122 299 507 661 463 2.896 2.036 -1.335 -5.169 3.257 3.353 0.011 5.742 5.469 0.952 1.024 0.876 13 7
123 453 763 974 745 4.253 2.135 -1.135 -4.217 2.521 3.265 0.009 3.689 6.602 1.790 0.925 0.908 13 8
124 334 501 630 485 2.368 2.150 -1.219 -4.172 2.924 3.354 0.008 5.669 4.739 0.836 0.910 0.885 13 12
125 393 593 765 572 2.976 2.125 -1.171 -4.429 3.017 3.282 0.005 4.696 4.646 0.989 0.935 0.905 13 13
126 487 802 1156 783 5.353 2.096 -1.290 -4.289 2.775 3.391 0.014 3.475 6.209 1.787 0.964 0.944 13 14
127 133 637 887 591 6.033 1.745 -2.151 -4.390 12.190 3.869 0.012 4.866 14.751 3.032 1.315 1.302 14 3
128 215 512 725 479 4.081 1.787 -1.456 -4.766 6.109 3.250 0.008 5.608 9.782 1.744 1.273 1.228 14 4
129 490 824 1256 826 6.129 1.943 -1.678 -3.642 4.200 3.602 0.013 3.298 6.630 2.010 1.117 1.117 14 5
130 234 484 691 450 3.720 1.801 -1.440 -5.424 6.542 3.257 0.009 6.081 8.181 1.345 1.259 1.210 14 9
131 354 649 904 596 4.401 1.908 -1.787 -5.919 7.036 3.704 0.018 4.581 6.493 1.417 1.152 1.096 14 10
132 481 853 1250 830 6.153 1.788 -1.480 -4.371 4.793 3.267 0.021 3.097 6.675 2.155 1.272 1.262 14 11
133 549 881 1195 860 5.169 2.040 -1.489 -4.175 4.314 3.507 0.010 3.190 5.479 1.717 1.020 1.012 14 15
134 285 510 706 469 3.368 1.894 -1.931 -6.245 7.314 3.830 0.020 5.910 6.279 1.062 1.166 1.095 14 16
135 326 652 882 584 4.449 1.765 -1.792 -6.467 6.438 3.535 0.013 4.501 7.384 1.641 1.295 1.173 14 17
136 208 461 654 455 3.576 2.016 -1.271 -3.446 4.382 3.300 0.009 5.769 9.384 1.627 1.044 1.042 15 3
137 294 606 860 594 4.529 2.111 -1.056 -3.761 5.485 3.171 0.010 4.567 8.950 1.960 0.949 0.945 15 4
138 264 769 985 815 5.769 1.914 -1.154 -1.516 3.940 3.092 0.037 3.423 12.861 3.757 1.146 1.079 15 5
139 359 787 1039 811 5.465 1.911 -1.216 -2.449 3.713 3.144 0.021 3.361 9.990 2.973 1.149 1.129 15 9
140 89 462 674 478 4.689 1.854 -1.238 -2.099 5.223 3.084 0.017 5.676 15.499 2.731 1.206 1.192 15 10
141 179 615 912 607 5.865 1.990 -1.281 -3.714 5.490 3.270 0.011 4.550 13.411 2.948 1.070 1.069 15 11
142 210 626 894 600 5.473 1.934 -1.435 -3.799 6.462 3.380 0.011 4.541 12.124 2.670 1.126 1.112 15 15
143 42 459 700 463 5.265 1.967 -1.330 -2.394 6.697 3.310 0.015 5.884 17.911 3.044 1.093 1.093 15 16
144 237 857 1160 829 7.385 2.024 -1.073 -3.573 4.332 3.104 0.022 3.260 13.708 4.205 1.036 1.021 15 17

In [4]:
def df_speed_subset(dataframe, speed):
    index = []
    for (i, j) in dataframe[['rider id', 'trial id']].values:
        if i == 15:
            i = 16
        index.append(speed == exp2.instructed_speed(i, j))
    return dataframe[index]

#df_speed_subset(steering_df, 12/3.6)

for name, df_type in zip(['braking', 'steering'], [braking_df, steering_df]):
    for speed in [None, 12, 17, 22]:
        if speed is None:
            df = df_type
            speed_str = ''
        else:
            df = df_speed_subset(df_type, speed/3.6)
            speed_str = str(speed)
            
        for xtc in ['time-to-collision', 'distance-to-collision']:
            xtc_short = xtc[0] + 'tc'
            print('{} {}{} {:0.2f}±{:0.2f}'.format(
                name, xtc_short, speed_str, df[xtc].mean(), df[xtc].std()))


braking ttc 2.16±0.82
braking dtc 9.65±4.66
braking ttc12 2.01±0.81
braking dtc12 6.45±2.76
braking ttc17 2.17±0.86
braking dtc17 9.57±3.90
braking ttc22 2.30±0.78
braking dtc22 12.87±4.69
steering ttc 2.12±0.85
steering dtc 9.51±3.64
steering ttc12 2.52±0.96
steering dtc12 8.52±3.40
steering ttc17 2.08±0.83
steering dtc17 9.73±3.98
steering ttc22 1.75±0.55
steering dtc22 10.31±3.34

In [11]:
fields = [
    ('braking duration', 'duration'),
    ('linregress slope', 'deceleration'),
]

for type_name, df_type in zip(['braking'], [braking_df]):
    for speed in [None, 12, 17, 22]:
        if speed is None:
            df = df_type
            speed_str = ''
        else:
            df = df_speed_subset(df_type, speed/3.6)
            speed_str = str(speed)
            
        for label, field_name in fields:
            print('{} \'{}\' {} {:0.2f}±{:0.2f}'.format(
                type_name, field_name, speed_str, df[label].mean(), df[label].std()))


braking 'duration'  3.57±1.45
braking 'deceleration'  -1.53±0.63
braking 'duration' 12 3.13±1.38
braking 'deceleration' 12 -1.31±0.59
braking 'duration' 17 3.64±1.52
braking 'deceleration' 17 -1.56±0.64
braking 'duration' 22 3.92±1.36
braking 'deceleration' 22 -1.73±0.60

In [12]:
fields = [
    ('event duration', 'duration'),
    ('minimum clearance', 'clearance'),
]

for type_name, df_type in zip(['steering'], [steering_df]):
    for speed in [None, 12, 17, 22]:
        if speed is None:
            df = df_type
            speed_str = ''
        else:
            df = df_speed_subset(df_type, speed/3.6)
            speed_str = str(speed)
            
        for label, field_name in fields:
            print('{} \'{}\' {} {:0.2f}±{:0.2f}'.format(
                type_name, field_name, speed_str, df[label].mean(), df[label].std()))


steering 'duration'  4.63±1.20
steering 'clearance'  1.12±0.16
steering 'duration' 12 5.48±1.19
steering 'clearance' 12 1.10±0.16
steering 'duration' 17 4.58±1.03
steering 'clearance' 17 1.11±0.15
steering 'duration' 22 3.81±0.68
steering 'clearance' 22 1.13±0.15

In [23]:
print(scipy.stats.linregress(steering_df[['starting velocity', 'time-to-collision']]))
X = steering_df[['starting velocity', 'time-to-collision']].as_matrix()
print(scipy.stats.linregress(*X.T))

#lr = scipy.stats.linregress(x, y)


LinregressResult(slope=-0.2611809926288291, intercept=3.3269232320606141, rvalue=-0.32387706507588682, pvalue=7.0706247570924031e-05, stderr=0.063801371926328024)
LinregressResult(slope=-0.2611809926288291, intercept=3.3269232320606141, rvalue=-0.32387706507588682, pvalue=7.0706247570924031e-05, stderr=0.063801371926328024)

In [46]:
def field_rvalue_stats(df_name, field):
    if df_name == 'braking':
        dataframe = braking_df
    else:
        dataframe = steering_df
        
    df = dataframe[['rider id', 'starting velocity', field]]
    rvalue = []
    for i in range(16):
        df_i = df[df['rider id'] == i].drop('rider id', axis=1)
        lr = scipy.stats.linregress(df_i)
        rvalue.append(lr.rvalue)
    rvalue = np.asarray(rvalue)
    
    float_format = '{:0.2f}'
    print('{}, {}'.format(df_name, field))
    print('rvalue min: {}'.format(float_format).format(rvalue.min()))
    print('rvalue max: {}'.format(float_format).format(rvalue.max()))
    print('rvalue mean: {}'.format(float_format).format(rvalue.mean()))
    print('rvalue median: {}'.format(float_format).format(np.median(rvalue)))
    
field_rvalue_stats('braking', 'distance-to-collision')
print()
field_rvalue_stats('braking', 'time-to-collision')
print()
field_rvalue_stats('steering', 'distance-to-collision')
print()
field_rvalue_stats('steering', 'time-to-collision')
print()
field_rvalue_stats('steering', 'lateral clearance')
print()
field_rvalue_stats('steering', 'minimum clearance')


braking, distance-to-collision
rvalue min: 0.61
rvalue max: 0.97
rvalue mean: 0.86
rvalue median: 0.93

braking, time-to-collision
rvalue min: -0.68
rvalue max: 0.93
rvalue mean: 0.32
rvalue median: 0.47

steering, distance-to-collision
rvalue min: -0.22
rvalue max: 0.76
rvalue mean: 0.32
rvalue median: 0.33

steering, time-to-collision
rvalue min: -0.73
rvalue max: -0.09
rvalue mean: -0.48
rvalue median: -0.53

steering, lateral clearance
rvalue min: -0.62
rvalue max: 0.89
rvalue mean: 0.25
rvalue median: 0.40

steering, minimum clearance
rvalue min: -0.66
rvalue max: 0.83
rvalue mean: 0.16
rvalue median: 0.23

In [5]:
# categorical plots use a default saturation of 0.75
CATEGORICAL_PLOT_SATURATION = 0.75
helper = sns.categorical._CategoricalPlotter()
helper.hue_names = list(range(16))
helper.establish_colors(color=None, palette=None,
                        saturation=CATEGORICAL_PLOT_SATURATION)
sns.palplot(helper.colors)
helper.gray


Out[5]:
'#464646'

In [35]:
#from antlia import trial2
#
#for tr in r.trials:
#    if tr.event.type == trial2.EventType.Overtaking:
#        print(tr.event)


<antlia.trial2.Event object at 0x11445eba8>
<antlia.trial2.Event object at 0x11446aba8>
<antlia.trial2.Event object at 0x1139d3940>
<antlia.trial2.Event object at 0x132cd9a90>
<antlia.trial2.Event object at 0x132ce6828>
<antlia.trial2.Event object at 0x1382e98d0>
<antlia.trial2.Event object at 0x1376d8ac8>
<antlia.trial2.Event object at 0x140d688d0>
<antlia.trial2.Event object at 0x140d73940>

In [18]:
from antlia import exp2

#with gzip.open('exp2record00.p.gz', 'rb') as f:
#    r0 = pickle.load(f)

# Create braking plot for trial 0-6
plt.close('all')
mpl.rcParams.update({'font.size': 12})
fig, ax = braking.plot_trial_braking_event(
    r0.trials[6].event,
    metrics_kw=exp2.METRICS_KW,
    use_kalman=True,
    figsize=DEFAULT_FIGSIZE)

# recreate legend
# ignore last line as it is the x-axis
lines = ax.lines[:-1]
# using known order for this example
handles = [
    'filtered measured velocity, gaussian moving average',
    'filtered measured acceleration, gaussian moving average',
    'linear regression of filtered measured velocity during braking event',
    'Kalman estimate velocity',
    'linear regression of Kalman estimate velocity during braking event',
    'raw measured velocity',
    'raw measured acceleration',
]

# get handle for vspan (only 1)
lines.extend(ax.patches)
handles.append('detected braking event')

# update legend
ax.legend(lines, handles, loc='upper right')

# update title and label
ax.set_ylabel('velocity [m/s], deceleration [m/s^2]')
ax.set_title('')

plt.show()



In [72]:
from antlia import trial2

#with gzip.open('exp2record11.p.gz', 'rb') as f:
#    r11 = pickle.load(f)
j = 7
event = r11.trials[j].event

colors = sns.color_palette('Paired', 10)
    
plt.close('all')

fig, ax = plt.subplots()
region = trial2.find_steering_region(event, ax=ax, obstacle_origin=True)
ax.lines[0].set_color(colors[9])

p = ax.patches[0]
p.set_label('detected overtaking event')
p.set_hatch('')
p.set_fill(True)
p.set_alpha(0.2)

c0 = ax.collections[0]
c0.set_label('detected trajectory local y-maxima')
c0.set_color(colors[3])

c1 = ax.collections[1]
c1.set_label('detected trajectory local y-minima')
c1.set_color(colors[3])

plot_kw = {
    'label': 'gaussian fit of Kalman estimate \ntrajectory during steering event',
    'color': colors[9],
    'linestyle': '--',
    #'linewidth': 3
}
params = trial2.fit_steering_model(event,
                                   region,
                                   ax=ax,
                                   obstacle_origin=True,
                                   **plot_kw)

ax.scatter(event.x - trial2.OBSTACLE_POINT[0],
           event.y - trial2.OBSTACLE_POINT[1],
           label='lidar point cloud',
           marker='.',
           color=colors[1],
           alpha=0.05,
           zorder=-1)

ax.scatter(
    0,
    0,
    s=100,
    marker='x',
    linewidth=5,
    color=colors[5],
    label='Obstacle point'
)

ax.legend()
ax.set_xlabel('x-coordinate [m]')
ax.set_ylabel('y-coordinate [m]')

plt.show()



In [43]:
def boxswarmplot(x, y, data, ax):
    # Don't plot outliers in boxplot as they will show up in the swarmplot.
    sns.boxplot(x=x, y=y, data=data,
                ax=ax, showfliers=False)
    
    # Set alpha transparency of the boxes (excluding edges).
    for patch in ax.artists:
        r, g, b, a = patch.get_facecolor()
        patch.set_facecolor((r, g, b, 0.2))
    
    # Plot swarmplot in front of box face but behind median and IQR lines.
    # zorder for box is 0.9 while others are 2 or 2.1.
    sns.swarmplot(x=x, y=y, data=data,
                  ax=ax, zorder=1, alpha=1)

In [44]:
# results 1.1 - increase in speed results in larger braking distance
#
# Calculate pearson correlation coefficient for each person for distance-to-collision and starting velocity
# Range, median of PCC.

# How should we show this?
# Maybe we should calculate the linear regression, and then the error from the linear regression for each trial?

import scipy.stats

# Calculate Pearson correlation coefficient for each rider
pcc = []
x = []
y = []
num_riders = 16
for i in range(num_riders):
    df = braking_df[braking_df['rider id'] == i]
    xi = df['starting velocity'].values
    yi = df['distance-to-collision'].values
    reg = scipy.stats.linregress(xi, yi)
    x.append(xi)
    y.append(yi)
    pcc.append(reg)
    
# create PCC dataframe
dtype = list(zip(pcc[0]._fields, len(pcc[0]._fields)*('float',)))
pcc = np.asarray(pcc, dtype=dtype).view(np.recarray)
print(pcc.dtype)
print('pcc median: ', np.median(pcc.rvalue))
print('pcc range: ', np.ptp(pcc.rvalue))
pcc_df = pd.DataFrame(data=pcc).transpose()
print('Pearson correlation coefficient table')
display(pcc_df)

plt.close('all')
fig, ax = plt.subplots()

# Plot velocity vs. dtc for all trials
colors = sns.color_palette('husl', num_riders)
for i in range(num_riders):
    ax.plot(x[i], y[i], color=colors[i], linestyle=' ', marker='.')
    x_sorted = np.sort(x[i])
    ax.plot(x_sorted, pcc[i].slope*x_sorted + pcc[i].intercept,
            color=colors[i], label='rider {}'.format(i))
ax.set_xlabel('starting velocity')
ax.set_ylabel('distance-to-collision')
ax.legend()
plt.show()

fig2, ax2 = plt.subplots(1, 2,
                         gridspec_kw={'width_ratios': [4, 1]},
                         sharey=True)

sns.swarmplot(x=list(range(num_riders)), y=pcc.rvalue, ax=ax2[0])

sns.boxplot(pcc.rvalue, color=helper.gray, ax=ax2[1], 
            orient='v',
            showfliers=False,
            boxprops={'facecolor': (0, 0, 0, 0)})
sns.swarmplot(x=pcc.rvalue, orient='v',
              color=helper.gray, ax=ax2[1],
              alpha=0.7)
    
ax2[0].set_ylabel('Pearson r-value')
ax2[0].set_xlabel('rider id')

# Calculate residuals for each rider


(numpy.record, [('slope', '<f8'), ('intercept', '<f8'), ('rvalue', '<f8'), ('pvalue', '<f8'), ('stderr', '<f8')])
pcc median:  0.931432935293
pcc range:  0.366201160204
Pearson correlation coefficient table
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
slope 2.246774 1.531933 2.389854 4.103385 2.299145 4.473979 2.172291 4.490928 1.156980 4.792374 2.303861 2.514621 1.560870 1.777634 1.324952 3.643813
intercept -2.390966 2.161814 -3.662683 -4.935937 -4.065891 -11.048589 0.426769 -3.530376 5.338575 -9.716519 -1.293544 2.774654 -0.517199 -2.213206 0.913343 -2.536004
rvalue 0.941819 0.685747 0.828221 0.952290 0.972079 0.938188 0.853133 0.932628 0.694939 0.973025 0.716317 0.606823 0.930237 0.936753 0.790619 0.945785
pvalue 0.000148 0.041430 0.005822 0.000075 0.000012 0.000563 0.003452 0.000245 0.037718 0.000010 0.029936 0.083141 0.000276 0.000197 0.011193 0.000116
stderr 0.303066 0.614558 0.611188 0.497053 0.209771 0.673851 0.502075 0.656736 0.452481 0.429465 0.848239 1.244913 0.232724 0.251029 0.387842 0.472955
Out[44]:
Text(0.5,0,'rider id')

In [45]:
def calculate_linregress_residuals(data, x, y):
    x_ = data[x].values
    y_ = data[y].values
    
    reg = scipy.stats.linregress(x_, y_)
    #print(reg)
    
    sorted_index = np.argsort(x_)
    sorted_x = x_[sorted_index]
    
    observed_y = y_[sorted_index]
    predicted_y = reg.slope*sorted_x + reg.intercept
    
    residual = observed_y - predicted_y
    # print normalized residual error
    #print(np.sqrt(np.sum(residual**2))/len(residual))
    return sorted_x, residual


d = {
    'rider id': [],
    'starting velocity': [],
    'linregress residual': [],
}
for i in range(num_riders):
    sorted_velocity, residual = calculate_linregress_residuals(
        braking_df[braking_df['rider id'] == i],
        'starting velocity',
        'distance-to-collision')
    
    d['rider id'].extend(len(residual)*[i])
    d['starting velocity'].extend(sorted_velocity)
    d['linregress residual'].extend(residual)

pcc_residual_df = pd.DataFrame(data=d)
print('PCC residual table (per rider)')
display(pcc_residual_df.transpose())

fig, ax = plt.subplots()
boxswarmplot(x='rider id', y='linregress residual',
             data=pcc_residual_df,
             ax=ax)
ax.set_ylabel('v-dtc linregress residual')

# plot velocity vs. residuals for each rider
grid = sns.FacetGrid(pcc_residual_df, col='rider id', hue='rider id',
                     col_wrap=4)
grid.map(plt.plot, 'starting velocity', 'linregress residual', marker='o')

# plot boxswarm of all data
velocity_all, residual_all = calculate_linregress_residuals(
    braking_df, 'starting velocity', 'distance-to-collision')

fig, ax = plt.subplots()
sns.boxplot(residual_all,
            color=helper.gray, ax=ax, 
            #orient='v',
            showfliers=False,
            boxprops={'facecolor': (0, 0, 0, 0)})
sns.swarmplot(residual_all,
              color=helper.gray, ax=ax,
              alpha=0.7)
sns.distplot(residual_all,
             color=helper.gray, ax=ax,
             fit=scipy.stats.norm)
ax.autoscale(axis='y')


PCC residual table (per rider)
0 1 2 3 4 5 6 7 8 9 ... 133 134 135 136 137 138 139 140 141 142
linregress residual -0.774412 -0.345737 1.904900 0.014951 -1.113502 0.506417 -0.080228 -0.687502 0.575115 0.725164 ... 0.309851 1.202729 -1.148525 -0.000293 0.761983 -1.247694 0.343834 1.754792 -2.596297 0.929472
rider id 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 1.000000 ... 14.000000 15.000000 15.000000 15.000000 15.000000 15.000000 15.000000 15.000000 15.000000 15.000000
starting velocity 2.877462 3.081553 3.694465 4.523917 4.664880 4.713384 5.580908 5.798840 5.964732 3.097177 ... 5.751383 3.108715 3.117717 3.267400 4.244716 4.400665 4.431446 5.706208 5.714244 5.807667

3 rows × 143 columns

/Users/oliver/miniconda3/envs/dev/lib/python3.5/site-packages/matplotlib/axes/_axes.py:6462: UserWarning: The 'normed' kwarg is deprecated, and has been replaced by the 'density' kwarg.
  warnings.warn("The 'normed' kwarg is deprecated, and has been "

In [48]:
# results 1.2 - increase in speed results in earlier braking
#
# Braking decleration is independent from speed.

# Add deceleration column
f = lambda row: -row['linregress slope']
braking_df['deceleration'] = braking_df.apply(f, axis=1)

num_riders = 16
d = {'median': [], 'std': []}
for i in range(num_riders):
    df = braking_df[braking_df['rider id'] == i]
    v = df['deceleration'].values
    d['median'].append(np.median(v))
    d['std'].append(np.std(v))
    
    # print PCC for velocity-deceleration
    reg = scipy.stats.linregress(
        df['starting velocity'], v)
    for k in reg._fields:
        dictkey = 'linregress ' + k
        dictvalue = getattr(reg, k)
        if dictkey in d:
            d[dictkey].append(dictvalue)
        else:
            d[dictkey] = [dictvalue]
    
deceleration_df = pd.DataFrame(data=d).transpose()
print('braking deceleration table')
display(deceleration_df)

print('overall')
v = braking_df['deceleration'].values
print('median: ', np.median(v))
print('std: ', np.std(v))
    
fig, ax = plt.subplots(1, 2, sharey=True,
                       gridspec_kw={'width_ratios': [5, 1]})
                       
plot_swarm_overlay = True
                       
if not plot_swarm_overlay:
    # get a ligher gray for the box face color
    c = sns.light_palette(helper.gray)[3]
    sns.boxplot(x='deceleration', data=braking_df,
                color=helper.gray, ax=ax[1], 
                orient='v',
                boxprops={'facecolor': c})
else:
    sns.boxplot(x='deceleration', data=braking_df,
                color=helper.gray, ax=ax[1], 
                orient='v',
                showfliers=False,
                boxprops={'facecolor': (0, 0, 0, 0)})
    sns.swarmplot(y='deceleration', data=braking_df,
                  color=helper.gray, ax=ax[1],
                  alpha=0.7)
    #sns.distplot(braking_df['deceleration'].values,
    #             color=helper.gray, ax=ax[1],
    #             fit=scipy.stats.norm,
    #             vertical=True)
    #ax[1].autoscale(axis='x')

if not plot_swarm_overlay:
    sns.boxplot(x='rider id', y='deceleration',
                data=braking_df,
                ax=ax[0])
else:
    boxswarmplot(x='rider id', y='deceleration',
                 data=braking_df,
                 ax=ax[0])
ax[0].set_ylabel('braking decleration [m/s^2]')
ax[1].get_yaxis().set_visible(False)
ax[0].set_xlabel('rider id')
ax[1].set_xlabel('all riders')

# plot velocity vs. deceleration for each rider
grid = sns.FacetGrid(braking_df, col='rider id', hue='rider id',
                     col_wrap=4)

# plot deceleration for each trial
grid.map(plt.plot, 'starting velocity', 'deceleration',
         marker='o', linestyle=' ', alpha=0.5)

# plot deceleration linear regression
## we need a function that takes the 'starting velocity' dataframe column,
## sorts it, and then accesses the deceleration linear regression in order
## to plot the linefit
def sorted_plot(x, *args, **kwargs):
    i = int(kwargs['label'])
    sorted_x = np.sort(x.values)
    slope = deceleration_df[i]['linregress slope']
    intercept = deceleration_df[i]['linregress intercept']
    return plt.plot(sorted_x, slope*sorted_x + intercept, *args, **kwargs)

grid.map(sorted_plot, 'starting velocity',
         linestyle='--')

# add text with r-value to each facet
for i, axis in enumerate(grid.axes.flat):
    r = deceleration_df[i]['linregress rvalue']
    axis.set_title(axis.get_title() + '\nr-value = {:0.3f}'.format(r))
    
grid.fig.tight_layout()
grid.set_xlabels('starting velocity [m/s]')
grid.set_ylabels('braking deceleration [m/s^2]')
plt.show()

print('overall linear regression, onset velocity vs. deceleration constant')
print(scipy.stats.linregress(
    df['starting velocity'],
    df['deceleration']
))


braking deceleration table
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
linregress intercept 0.789803 -0.791514 2.182335 0.548833 1.780558 1.283708 0.097014 0.136237 0.007897 1.000685 0.536691 -0.062473 1.482130 1.684636 -0.120572 0.462993
linregress pvalue 0.154345 0.010887 0.863880 0.141483 0.047104 0.857821 0.005204 0.017044 0.008089 0.622357 0.107406 0.059195 0.161449 0.134291 0.002567 0.022060
linregress rvalue 0.516715 0.792379 0.067069 0.530789 0.672670 0.076122 0.833924 0.761827 0.810292 0.191095 0.572194 0.647840 0.509233 0.538987 0.865544 0.742062
linregress slope 0.202898 0.532589 0.024180 0.066062 0.114260 0.014637 0.262710 0.130510 0.362463 0.032020 0.225520 0.256330 0.093375 0.177521 0.484909 0.102344
linregress stderr 0.127067 0.154975 0.135957 0.039868 0.047505 0.078272 0.065712 0.041944 0.099081 0.062165 0.122171 0.113923 0.059646 0.104857 0.106051 0.034943
median 1.759153 1.571708 2.338976 0.781034 2.308894 1.353796