-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutill.py
146 lines (114 loc) · 4.54 KB
/
utill.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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
55
56
57
58
59
60
61
62
63
64
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
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
# -*- coding: utf-8 -*-
"""computeTE_interaction
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/1ZTWfpXyGY-UMBbR7oyNs4LASfLvfCXQz
"""
import matplotlib.pyplot as plt
from sys import platform
from tqdm import tqdm
import pandas as pd
from jpype import *
import numpy as np
import pickle
import glob
import csv
import os
# +
"""
preprocessing output
data
normalzie_xy
agent
1
xy
time
id
oldid
type
2
3
...
p1
p2
...
"""
def preprocessing(scenario):
df = pd.read_csv(scenario, index_col = False)
ped_sceraio = scenario.replace("vehicle_tracks_", "pedestrian_tracks_")
print(ped_sceraio)
df_ped = []
try:# pedistrian 정보가 있으면 읽어옴
df_ped = pd.read_csv(ped_sceraio, index_col = False)
except FileNotFoundError:
print("SS")
# df = df.sort_values('timestamp_ms')
data = {}
new_id = 0
df['x'] = pd.to_numeric(df['x'])
df['y'] = pd.to_numeric(df['y'])
df['timestamp_ms'] = pd.to_numeric(df['timestamp_ms'])
# df['track_id'] = pd.to_numeric(df['track_id'])
min_x = min(df['x'])
min_y = min(df['y'])
min_x = 950
min_y = 950
data['normalize_xy'] = [min_x, min_y]
data['agent'] = {}
for i in range(len(df)):
id = str(df['track_id'][i])
try:
data['agent'][id]["xy"].append([df['x'][i]-min_x, df['y'][i]-min_y])
data['agent'][id]["time"].append(int(df['timestamp_ms'][i]))
except KeyError:
data['agent'][id] = {}
data['agent'][id]["xy"] = [[df['x'][i]-min_x, df['y'][i]-min_y]]
data['agent'][id]["time"] = [int(df['timestamp_ms'][i])]
data['agent'][id]["id"] = int(new_id)
data['agent'][id]["old_id"] = id
data['agent'][id]["type"] = df['agent_type'][i]
new_id += 1
for i in range(len(df_ped)):
id = str(df_ped['track_id'][i])
try:
data['agent'][id]["xy"].append([df_ped['x'][i]-min_x, df_ped['y'][i]-min_y])
data['agent'][id]["time"].append(int(df_ped['timestamp_ms'][i]))
except KeyError:
data['agent'][id] = {}
data['agent'][id]["xy"] = [[df_ped['x'][i]-min_x, df_ped['y'][i]-min_y]]
data['agent'][id]["time"] = [int(df_ped['timestamp_ms'][i])]
data['agent'][id]["id"] = int(new_id)
data['agent'][id]["old_id"] = id
data['agent'][id]["type"] = df_ped['agent_type'][i]
new_id += 1
return data
# -
class calc_TE():
def __init__(self, num = "6"):
jarLocation = "./infodynamics.jar"
if not os.path.isfile(jarLocation):
exit("infodynamics.jar not found (expected at " + os.path.abspath(
jarLocation) + ") - are you running from demos/python?")
# Start the JVM (add the "-Xmx" option with say 1024M if you get crashes due to not enough memory space)
startJVM(getDefaultJVMPath(), "-ea", "-Djava.class.path=" + jarLocation)
teCalcClass = JPackage("infodynamics.measures.continuous.kraskov").TransferEntropyCalculatorMultiVariateKraskov
self.teCalc = teCalcClass()
self.teCalc.setProperty(teCalcClass.PROP_AUTO_EMBED_METHOD, teCalcClass.AUTO_EMBED_METHOD_RAGWITZ)
#teCalc.setProperty(teCalcClass.PROP_AUTO_EMBED_METHOD, teCalcClass.AUTO_EMBED_METHOD_MAX_CORR_AIS_DEST_ONLY)
# b. Search range for embedding dimension (k) and delay (tau)
self.teCalc.setProperty(teCalcClass.PROP_K_SEARCH_MAX, num)
self.teCalc.setProperty(teCalcClass.PROP_TAU_SEARCH_MAX, num)
self.teCalc.initialise(2, 2)
def computeTE(self, data_source, data_desc):
self.teCalc.setObservations(data_source, data_desc)
teSourceToDesc = self.teCalc.computeAverageLocalOfObservations()
self.teCalc.setObservations(data_desc, data_source)
teDescToSource = self.teCalc.computeAverageLocalOfObservations()
return teSourceToDesc, teDescToSource
def computeTE_a2b(self, data_source, data_desc):
self.teCalc.setObservations(data_source, data_desc)
teSourceToDesc = self.teCalc.computeAverageLocalOfObservations()
return teSourceToDesc
# print("source to desc : ", teSourceToDesc)
# print("desc to source : ", teDescToSource)
return teSourceToDesc, teDescToSource