TrajectoryMetric.ipynb 23.6 KB
Newer Older
1
2
3
4
5
{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
6
7
8
9
10
11
12
13
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
14
15
   "outputs": [],
   "source": [
16
    "# expand the cell of the notebook\n",
17
18
19
20
21
22
23
    "import json\n",
    "import numpy as np\n",
    "import pandas as pd\n",
    "import math\n",
    "import matplotlib.pyplot as plt\n",
    "from matplotlib.lines import Line2D\n",
    "\n",
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
    "from IPython.core.display import display, HTML\n",
    "display(HTML('<style>.container { width:100% !important; }</style>'))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Methods to convert Vadere trajectories into a DataFrame"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "def fs_append(pedestrianId, fs, llist):\n",
    "    llist.append([pedestrianId, fs['start']['x'], fs['start']['y'], fs['startTime'], fs['end']['x'], fs['end']['y'], fs['endTime']])\n",
    "   \n",
    "def trajectory_append(pedestrianId, trajectory, llist):\n",
    "    for fs in trajectory:\n",
    "        fs_append(pedestrianId, fs, llist)\n",
    "\n",
    "def trajectories_to_dataframe(trajectories):\n",
    "    llist = []\n",
    "    for pedId in trajectories:\n",
    "        trajectory_append(pedId, trajectories[pedId], llist)\n",
    "    dataframe = pd.DataFrame(llist, columns=['pedestrianId','startX','startY','startTime','endX','endY','endTime'])\n",
    "    return dataframe\n",
    "\n",
55
56
57
58
    "file = \"./data/trajectories_distance.txt\"\n",
    "f = open(file, \"r\")\n",
    "header = f.readline();\n",
    "trajectories = dict({});\n",
59
    "\n",
60
61
62
63
64
    "for row in f:\n",
    "    s = row.split(\" \");\n",
    "    pedId = int(s[0]);\n",
    "    footsteps = json.loads(s[1]);\n",
    "    trajectories[pedId] = footsteps[0]['footSteps'];\n",
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
    "\n",
    "ptrajectories = trajectories_to_dataframe(trajectories)\n",
    "ptrajectories.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Helpler method to access parts of the trajectory"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "def get_trajectory(pedId, trajectories):\n",
    "    \"\"\"returns a data frame containing the trajectory of one specific agent.\"\"\"\n",
    "    query = 'pedestrianId == ' + str(pedId)\n",
    "    return trajectories.query(query)\n",
    "\n",
    "def get_pedestrianIds(trajectories):\n",
    "    return trajectories['pedestrianId'].unique()\n",
90
91
    "\n",
    "def get_footstep(trajectory, i):\n",
92
93
    "    \"\"\"returns the i-ths footstep.\"\"\"\n",
    "    return trajectory.iloc[i];\n",
94
    "\n",
95
96
97
98
99
100
    "def get_footstep_by_time(trajectory, time):\n",
    "    \"\"\"returns the footstep which happens at time or nothing (None).\"\"\"\n",
    "    query = 'startTime <= ' + str(time) + ' and ' + str(time) + ' < endTime'\n",
    "    fs = trajectories.query(query)\n",
    "    assert len(fs) >= 1\n",
    "    return fs\n",
101
    "\n",
102
103
104
    "def start_time(trajectory):\n",
    "    \"\"\"returns the time of the first footstep of the trajectory.\"\"\"\n",
    "    return get_footstep(trajectory, 0)['startTime'];\n",
105
106
    "\n",
    "def end_time(trajectory):\n",
107
108
109
110
111
112
    "    return get_footstep(trajectory, len(trajectory)-1)['endTime'];\n",
    "\n",
    "def max_start_time(trajectories):\n",
    "    \"\"\"returns the time of the first footstep of the trajectory which starts last.\"\"\"\n",
    "    pedestrianIds = get_pedestrianIds(trajectories)\n",
    "    return max(map(lambda pedId: start_time(get_trajectory(pedId, trajectories)), pedestrianIds))\n",
113
114
    "\n",
    "def min_end_time(trajectories):\n",
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
    "    \"\"\"returns the time of the last footstep of the trajectory which ends first.\"\"\"\n",
    "    pedestrianIds = get_pedestrianIds(trajectories)\n",
    "    return min(map(lambda pedId: end_time(get_trajectory(pedId, trajectories)), pedestrianIds))\n",
    "\n",
    "def footstep_is_between(fs, time):\n",
    "    \"\"\"true if the foostep and the intersection with time is not empty.\"\"\"\n",
    "    startTime = fs['startTime'];\n",
    "    endTime = fs['endTime'];\n",
    "    return startTime <= time and time < endTime;\n",
    "\n",
    "def cut(trajectory, sTime, eTime):\n",
    "    query = 'startTime >= ' + str(sTime) + ' and endTime < ' + str(eTime)\n",
    "    return trajectory.query(query)\n",
    "\n",
    "def cut_soft(trajectory, sTime, eTime):\n",
    "    query = 'endTime > ' + str(sTime) + ' and startTime < ' + str(eTime)\n",
    "    return trajectory.query(query)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Helper methods to compute different metrices"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "def footstep_length(fs):\n",
    "    \"\"\"Euclidean length of a footstep.\"\"\"\n",
    "    x1 = fs['startX'];\n",
    "    y1 = fs['startY'];\n",
    "    x2 = fs['endX'];\n",
    "    y2 = fs['endY'];\n",
153
154
155
156
157
    "    dx = x1-x2;\n",
    "    dy = y1-y2;\n",
    "    return np.sqrt(dx*dx + dy*dy);\n",
    "\n",
    "def trajectory_length(trajectory):\n",
158
159
160
161
162
163
164
165
166
167
168
    "    \"\"\"Euclidean length of a trajectory.\"\"\"\n",
    "    dx = trajectory['startX']-trajectory['endX']\n",
    "    dy = trajectory['startY']-trajectory['endY']\n",
    "    return np.sqrt(dx*dx + dy*dy).sum();\n",
    "\n",
    "def footstep_direction(fs):\n",
    "    \"\"\"Vector from start to end position.\"\"\"\n",
    "    x1 = fs['startX'];\n",
    "    y1 = fs['startY'];\n",
    "    x2 = fs['endX'];\n",
    "    y2 = fs['endY'];\n",
169
170
    "    return np.array([x2-x1, y2-y1]);\n",
    "\n",
171
172
    "def footstep_duration(fs):\n",
    "    \"\"\"Duration of a footstep.\"\"\"\n",
173
174
175
176
    "    startTime = fs['startTime'];\n",
    "    endTime = fs['endTime'];\n",
    "    return endTime-startTime;\n",
    "\n",
177
178
179
    "def trajectory_duration(trajectory):\n",
    "    \"\"\"Euclidean length of a trajectory.\"\"\"\n",
    "    return (trajectory['endTime'] - trajectory['startTime']).sum();\n",
180
    "\n",
181
182
183
    "def footstep_speed(fs):\n",
    "    \"\"\"Speed of the footstep.\"\"\"\n",
    "    return footstep_length(fs) / footstep_duration(fs);\n",
184
    "\n",
185
186
187
    "def trajectory_speed(fs):\n",
    "    \"\"\"Speed of the trajectory.\"\"\"\n",
    "    return trajectory_length(fs) / trajectory_duration(fs);\n",
188
    "\n",
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
    "#def trajectory_positions(trajectory, times):\n",
    "#    mask = trajectory[['startTime', 'endTime']].mask(lambda x: x**2)\n",
    "#    (df['date'] > '2000-6-1') & (df['date'] <= '2000-6-10')\n",
    "#    duration = trajectory['endTime'] - trajectory['startTime']\n",
    "#    dx = trajectory['endX'] - trajectory['startX']\n",
    "#    dy = trajectory['endY'] - trajectory['startY']\n",
    "#    direction = \n",
    "    \n",
    "def filter_trajectories(trajectories, times):\n",
    "    \"\"\"Filters trajectory by times.\"\"\"\n",
    "    rows = []\n",
    "    for row in trajectories.itertuples():\n",
    "        if len(list(filter(lambda b: b, map(lambda t: row.startTime <= t and t < row.endTime, times)))) > 0:\n",
    "            rows.append(row)\n",
    "    return pd.DataFrame(rows)\n",
    "\n",
    "def trajectories_position(trajectories, times):\n",
    "    \"\"\"Transforms trajectories into positions at each time in times such that each position is computed by linear interpolation.\"\"\"\n",
    "    rows = []\n",
    "    #print(trajectories)\n",
    "    for row in trajectories.itertuples():\n",
    "        llist = list(filter(lambda t: row.startTime <= t and t < row.endTime, times))\n",
    "        assert len(llist) == 1 or len(llist) == 0\n",
    "        if len(llist) > 0:\n",
    "            time = llist[0]\n",
    "            dur = row.endTime - row.startTime\n",
    "            partial_dur = time - row.startTime\n",
    "            ratio = partial_dur / dur\n",
    "            direction = np.array([row.endX - row.startX, row.endY - row.startY])\n",
    "            l = np.linalg.norm(direction)\n",
    "            if l > 0:\n",
    "                partial_l = l * ratio;\n",
    "                v = direction / l * partial_l;\n",
    "                pos = np.array([row.startX, row.startY]) + v;\n",
    "                rows.append([row.pedestrianId, pos[0], pos[1], time])\n",
    "            else:\n",
    "                rows.append([row.pedestrianId, np.nan, np.nan, time])\n",
    "    dataframe = pd.DataFrame(rows, columns=['pedestrianId','x','y','time'])\n",
    "    return dataframe\n",
    "    \n",
    "def euclid_d(trajPos1, trajPos2):\n",
    "    \"\"\"Computes the total (Euclidean) distance between two trajectories.\n",
    "       Assumption: trajectories are both cut acccordingly!   \n",
    "    \"\"\"\n",
    "    assert len(trajPos1) == len(trajPos2)\n",
    "    dx = trajPos1['x'] - trajPos2['x']\n",
    "    dy = trajPos1['y'] - trajPos2['y']\n",
    "    norm = np.sqrt(dx**2 + dy**2)\n",
    "    return norm.sum() / len(dx)\n",
    "\n",
    "def euclid_path_length(trajPos1, trajPos2):\n",
    "    \"\"\"Computes the total (Euclidean) path length difference between two trajectories.\n",
    "       Assumption: trajectories are both cut acccordingly!\n",
    "    \"\"\"\n",
    "    count = len(trajPos1)\n",
    "    pad = pd.DataFrame([[np.nan, np.nan, np.nan, np.nan]], columns=['pedestrianId','x','y','time'])\n",
    "    trajPos1Pad = pd.concat([pad, trajPos1], ignore_index=True)\n",
    "    trajPos2Pad = pd.concat([pad, trajPos1], ignore_index=True)\n",
    "    dx1 = trajPos1['x'] - trajPos1Pad['x']\n",
    "    dy1 = trajPos1['y'] - trajPos1Pad['y']\n",
    "    dx2 = trajPos2['x'] - trajPos2Pad['x']\n",
    "    dy2 = trajPos2['y'] - trajPos2Pad['y']\n",
    "    dx = dx1 - dx2\n",
    "    dy = dy1 - dy2\n",
    "    diff = np.sqrt(dx**2 + dy**2)\n",
    "    return diff.sum()\n",
    "\n",
    "def euclid_len(trajectory, sTime, eTime):\n",
    "    \"\"\"Computes the total (Euclidean) length of the trajectory in between [sTime;eTime].\"\"\"\n",
    "    cut_traj = cut_soft(trajectory, sTime, eTime);\n",
    "    return trajectory_length(cut_traj)\n",
    "    \n",
    "def inter_agent_d(trajPos):\n",
    "    \"\"\"Computes the inter agent (Euclidean) distance between all pairs of agents.\n",
    "       Assumption: the trajectory is cut accordingly, ie the time is equal for\n",
    "       each position.\n",
    "    \"\"\"\n",
    "    s = 0\n",
    "    min_index = min(trajectories.keys())\n",
    "    c = 0\n",
    "    llen = len(trajPos)\n",
    "    for index1, row1 in trajPos.iterrows():\n",
    "        for index2, row2 in trajPos.tail(llen-1-index1).iterrows():\n",
    "            x1 = row1['x']\n",
    "            y1 = row1['y']\n",
    "            x2 = row2['x']\n",
    "            y2 = row2['y']\n",
    "            dx = x1 - x2\n",
    "            dy = y1 - y2\n",
    "            s = s + np.sqrt(dx**2 + dy**2)\n",
    "            c = c + 1\n",
    "    if c == 0:\n",
    "        return 0\n",
    "    else:\n",
    "        return s / c\n",
    "    \n",
    "def total_inter_agent(trajectories1, trajectories2, times):\n",
    "    \"\"\"too expensive! TODO!\"\"\"\n",
    "    return sum(map(lambda t: inter_agent_d(trajectories_position(trajectories1, [t])) - inter_agent_d(trajectories_position(trajectories2, [t])), times)) / len(times)\n",
    "    \n",
    "#start_time(get_trajectory(1, ptrajectories))\n",
    "#max_start_time(ptrajectories)\n",
    "#end_time(get_trajectory(1, ptrajectories))\n",
    "#foot_step_length(get_footstep(get_trajectory(1, ptrajectories), 0))\n",
    "#trajectory_length(get_trajectory(1, ptrajectories))\n",
    "#trajectory_speed(get_trajectory(1, ptrajectories))\n",
    "cutTraj = cut(get_trajectory(1, ptrajectories), 0.0, 10.0)[['startTime', 'endTime']]\n",
    "#cutTraj.mask(cutTraj['startTime'] <= 4 and 4 > cutTraj['endTime'])\n",
    "#start_time(get_trajectory(1, ptrajectories))\n",
    "#trajectories_position(ptrajectories, [1,2,3,4]).head()\n",
    "trajPos1 = trajectories_position(get_trajectory(2, ptrajectories), [1,2,3,4,5,6,8,9,10,11,12,13])\n",
    "trajPos2 = trajectories_position(get_trajectory(7, ptrajectories), [1,2,3,4,5,6,8,9,10,11,12,13])\n",
    "trajPos1 = trajPos1[~np.isnan(trajPos1.x)]\n",
    "trajPos2 = trajPos2[~np.isnan(trajPos2.x)]\n",
    "euclid_path_length(trajPos1, trajPos2)\n",
    "euclid_len(ptrajectories,0,10000)\n",
    "#print(total_inter_agent(ptrajectories, ptrajectories, [1,2]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "trajPos2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "code_folding": []
   },
   "outputs": [],
   "source": [
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
    "def position(trajectory, time):\n",
    "    fs = footstep(trajectory, time);\n",
    "    if fs != None:\n",
    "        startTime = fs['startTime'];\n",
    "        endTime = fs['endTime'];\n",
    "        dur = duration(fs);\n",
    "        partial_dur = time - startTime;\n",
    "        ratio = partial_dur / dur;\n",
    "        start = fs['start'];\n",
    "        x1 = start['x'];\n",
    "        y1 = start['y'];\n",
    "        l = length(fs);\n",
    "        if l == 0.0:\n",
    "            return np.array([x1, y1])\n",
    "        else:    \n",
    "            partial_l = l * ratio;\n",
    "            v = direction(fs) / l * partial_l;\n",
    "            return np.array([x1, y1]) + v;\n",
    "\n",
    "\n",
    "def euclid_d(traj1, traj2, times):\n",
    "    \"\"\"Computes the total (Euclidean) distance between two trajectories at certain times.\"\"\"\n",
    "    return 0\n",
    "    sT = max([start_time(traj1), start_time(traj2)])\n",
    "    eT = min([end_time(traj1), end_time(traj2)])\n",
    "    filtered_times = list(filter(lambda t: t >= sT and t <= eT, times))\n",
    "    overlaps = len(filtered_times)\n",
    "    if overlaps == 0:\n",
    "        return 0\n",
    "    return sum(map(lambda t: np.linalg.norm(position(traj1, t)- position(traj2, t)), filtered_times)) / overlaps\n",
    "    \n",
    "def euclid_path_length(traj1, traj2, times):\n",
    "    sT = max([start_time(traj1), start_time(traj2)]);\n",
    "    eT = min([end_time(traj1), end_time(traj2)]);\n",
    "    filtered_times = list(filter(lambda t: t >= sT and t <= eT, times));\n",
    "    s = np.array([0, 0])\n",
    "    for i in range(len(filtered_times)-1):\n",
    "        t1 = filtered_times[i]\n",
    "        t2 = filtered_times[i+1]\n",
    "        d1 = position(traj1, t1) - position(traj1, t2)\n",
    "        d2 = position(traj2, t1) - position(traj2, t2)\n",
    "        diff = d1 - d2\n",
    "        s = s + diff\n",
    "    return s;\n",
    "\n",
    "def inter_agent_d(trajectories, t):\n",
    "    s = 0\n",
    "    min_index = min(trajectories.keys())\n",
    "    c = 0\n",
    "    for i in range(len(trajectories)):\n",
    "        pos1 = position(trajectories[i+min_index], t)\n",
    "        for j in range(i+1, len(trajectories)):\n",
    "            pos2 = position(trajectories[j+min_index], t)\n",
    "            if pos1 is not None and pos2 is not None:\n",
    "                s = s + np.linalg.norm(pos1 - pos2)\n",
    "                c = c + 1\n",
    "    if c == 0:\n",
    "        return 0\n",
    "    else:\n",
    "        return s / c\n",
    "    \n",
    "def total_inter_agent(trajectories1, trajectories2, times):\n",
    "    return sum(map(lambda t: inter_agent_d(trajectories1, t) - inter_agent_d(trajectories2, t), times)) / len(times)\n",
    "    \n",
    "def euclid_len(trajectory, sTime, eTime):\n",
    "    \"\"\"Computes the total (Euclidean) length of the trajectory in between [sTime;eTime].\"\"\"\n",
    "    cut_traj = cut_soft(trajectory, sTime, eTime);\n",
    "    return trajectory_length(cut_traj)\n",
    "\n",
    "def greedy_match(trajectories1, trajectories2, times, f):\n",
    "    \"\"\"Computes a match of trajectories by using a greedy algorithm.\"\"\"\n",
    "    assert len(trajectories1) == len(trajectories2)\n",
    "    min_index1 = min(trajectories1.keys())\n",
    "    min_index2 = min(trajectories2.keys())\n",
    "    match = {}\n",
    "    indexSet = set(range(min_index2, len(trajectories2)))\n",
    "    for i in range(min_index1, len(trajectories1)):\n",
    "        traj1 = trajectories1[i]\n",
    "        minVal = None\n",
    "        minIndex = None\n",
    "        for j in indexSet:\n",
    "            traj2 = trajectories2[j]\n",
    "            if overlap(traj1, traj2, 0.4):\n",
    "                val = f(traj1, traj2, times)\n",
    "                if(minVal == None or val < minVal):\n",
    "                    minIndex = j\n",
    "                    minVal = val\n",
    "        match[i] = minIndex\n",
    "        indexSet.remove(minIndex)\n",
    "    return match\n",
    "        \n",
    "def overlap(traj1, traj2, dt):\n",
    "    return True\n",
    "    \n",
    "def load_experiment(file):\n",
    "    fps = 16\n",
428
    "    pad = pd.DataFrame([[np.nan, np.nan, np.nan, np.nan, np.nan]], columns=['pedestrianId', 'timeStep', 'x', 'y', 'e'])\n",
429
430
431
432
433
434
435
    "    data = pd.read_csv(\n",
    "        file, \n",
    "        sep=' ', \n",
    "        names=['pedestrianId', 'timeStep', 'x', 'y', 'e'], \n",
    "        index_col=False, \n",
    "        header=None, \n",
    "        skiprows=0)\n",
436
437
    "    \n",
    "    cc = pd.concat([pad, data], ignore_index=True)\n",
438
    "        \n",
439
440
441
442
443
444
445
    "    data['endX'] = data['x'] / 100 + 18.7\n",
    "    data['endY'] = data['y'] / 100 + 4.2\n",
    "    data['startX'] = cc['x'] / 100 + 18.7\n",
    "    data['startY'] = cc['y'] / 100 + 4.2\n",
    "    data['startTime'] = data['timeStep'] / fps - 1/fps\n",
    "    data['endTime'] = data['timeStep'] / fps\n",
    "    data = data.drop(columns=['timeStep','x','y','e'])\n",
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
    "    return data\n",
    "    \n",
    "def to_trajectories(data):\n",
    "    trajectories = dict({})\n",
    "    trajectory = []\n",
    "    for i in range(len(data)-1):\n",
    "        pedId = data['pedestrianId'][i]\n",
    "        if pedId == data['pedestrianId'][i+1]:\n",
    "            pedId = data['pedestrianId'][i]\n",
    "            x1 = data['x'][i]\n",
    "            y1 = data['y'][i]\n",
    "            x2 = data['x'][i+1]\n",
    "            y2 = data['y'][i+1]\n",
    "            startTime = data['timeStep'][i] \n",
    "            endTime = data['timeStep'][i+1]\n",
    "            fs = {'startTime':startTime, 'endTime': endTime, 'start':{'x':x1, 'y':y1}, 'end':{'x':x2, 'y':y2}}\n",
    "            trajectory.append(fs)\n",
    "        else:\n",
    "            trajectories[pedId] = trajectory\n",
    "            trajectory = []\n",
    "            pedId = data['pedestrianId'][i]\n",
    "    return trajectories\n",
    "\n",
469
470
471
472
473
474
475
476
477
    "def to_postVis(df):\n",
    "    simTimeStep = 0.4\n",
    "    fps = 16\n",
    "    df['timeStep'] = np.ceil(df['endTime'] / (1/fps)).astype(np.int)\n",
    "    df['x'] = df['endX']\n",
    "    df['y'] = df['endY']\n",
    "    df['simTime'] = df['endTime']\n",
    "    df = df.drop(columns=['startX','startY','endX','endY','startTime', 'endTime'])    \n",
    "    return df\n",
478
479
    "#times = np.linspace(4,10,10)\n",
    "#euclid_d(get_trajectory(1), get_trajectory(1), times)\n",
480
481
482
483
    "#to_trajectories(load_experiment(real_file))[1]\n",
    "\n",
    "file = \"./data/trajectories_distance.txt\"\n",
    "real_file = \"./data/KO/ko-240-120-240/ko-240-120-240_combined_MB.txt\""
484
485
486
487
488
489
490
491
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
492
493
494
495
496
    "data = load_experiment(real_file)\n",
    "#trajectoriesReal = to_trajectories(data)\n",
    "data.query('pedestrianId == 1').head()\n",
    "to_postVis(data).to_csv('expteriment_2.trajectories',index=False,sep=' ')\n",
    "to_postVis(data).head(10)"
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import seaborn as sns\n",
    "sns.set(style=\"ticks\")\n",
    "\n",
    "current_palette = sns.color_palette()\n",
    "\n",
    "def to_line(trajectory, xleft):\n",
    "    x = []\n",
    "    y = []\n",
    "    for fs in trajectory:\n",
    "        x.append(fs['start']['x'])\n",
    "        y.append(fs['start']['y'])\n",
    "    if x[0] < xleft:\n",
    "        c = current_palette[2]\n",
    "    else:\n",
    "        c = current_palette[0]\n",
    "    return x, y, Line2D(x, y, color=c, linewidth=0.2)\n",
    "\n",
    "fig1 = plt.figure(figsize=(10,10))\n",
    "ax1 = fig1.add_subplot(111)\n",
    "\n",
    "\n",
    "x_vcenter = 17.5\n",
    "y_vcenter = 5.2\n",
    "for i in range(len(trajectoriesReal)):\n",
529
    "    x, y, line = to_line(trajectoriesReal[i+1], 14)\n",
530
531
    "    ax1.add_line(line)\n",
    "    \n",
532
533
    "ax1.set_xlim(x_vcenter-5, x_vcenter+5)\n",
    "ax1.set_ylim(y_vcenter-4, y_vcenter+4)\n",
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
    "ax1.set_aspect(1)\n",
    "\n",
    "fig2 = plt.figure(figsize=(10,10))\n",
    "ax2 = fig2.add_subplot(111)\n",
    "\n",
    "for i in range(len(trajectories)):\n",
    "    x, y, line = to_line(trajectories[i+1], 14)\n",
    "    ax2.add_line(line)\n",
    "\n",
    "ax2.set_xlim(x_vcenter-5, x_vcenter+5)\n",
    "ax2.set_ylim(y_vcenter-4, y_vcenter+4)\n",
    "ax2.set_aspect(1)\n",
    "\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "times = np.arange(0,80,2)\n",
    "y = list(map(lambda t: inter_agent_d(trajectories, t), times))\n",
    "plt.plot(times, y, 'o')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "start_time(trajectories[1])\n",
    "print(max_start_time(trajectories))\n",
    "print(min_end_time(trajectories))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "print(position(map(lambda traj: traj[\"startTime\"], trajectories)[1], 0))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
587
    "pd.DataFrame([[1,2,3,4,5],[6,7,8,9,10]], columns=['pedestrianId','timeStep','x','y','time'])"
588
589
590
591
592
593
594
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
595
   "source": []
596
597
598
599
600
601
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
602
   "source": []
603
604
605
606
607
608
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
624
625
626
627
628
629
630
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
631
    "to_postVis(data)"
632
633
634
635
636
637
638
639
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
640
    "1 in [1,2,3]"
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}