forked from sbu-python-class/test-repo-2018
-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.py
129 lines (94 loc) · 3.86 KB
/
functions.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
import numpy as np
import math
import matplotlib.pyplot as plt
import minmaxradiuscircle
from operator import itemgetter
def generate_one_traj(length, delMux, delSigx, xStartPoint, xEndPoint, delMuy, delSigy,yStartPoint, yEndPoint):
#xStartPoint = 0
#xStartPoint = 30
#yStartPoint = 0
#yEndPoint = 0.2
delx = np.random.normal(delMux, delSigx, length);
tempx = np.linspace(xStartPoint, xEndPoint, length);
x = tempx + delx;
dely = np.random.normal(delMuy, delSigy, length);
#dely = np.random.uniform(delMuy, delSigy, length);
tempy = np.linspace(yStartPoint, yEndPoint, length);
y = tempy + dely;
return x, y
def multiple_traj(numData, xTraj, yTraj, delSigx, delSigy):
#delSigx = 0.3
#delSigy = 0.3
length = len(xTraj)
tData = np.linspace(0, 1000, length)
xData = np.zeros((numData, length))
yData = np.zeros((numData, length))
for a in range(numData):
for b in range(length):
if a == 0:
xData[0][b] = xTraj[b]
yData[0][b] = yTraj[b]
else:
xData[a][b] = xData[0][b] + np.random.normal(0, delSigx)
yData[a][b] = yData[0][b] + np.random.normal(0, delSigy)
return xData, yData, tData
def average_traj(xData, yData):
numData = xData.shape[0]
length = xData.shape[1]
xAverTraj = np.zeros(length)
yAverTraj = np.zeros(length)
for a in range(length):
xAverTraj[a] = np.mean(xData[:, a])
yAverTraj[a] = np.mean(yData[:, a])
return xAverTraj, yAverTraj
def minmax_Traj(xData, yData):
numData = xData.shape[0]
length = xData.shape[1]
xMinmaxTraj = np.zeros(length)
yMinmaxTraj = np.zeros(length)
for a in range(length):
c = minmaxradiuscircle.make_circle2(xData[:, a], yData[:, a], numData)
xMinmaxTraj[a] = c[0]
yMinmaxTraj[a] = c[1]
return xMinmaxTraj, yMinmaxTraj
def mean_squre_error(orgDatax, orgDatay, estDatax, estDatay):
length = len(orgDatax)
squareDst = np.zeros(length)
for a in range(length):
squareDst[a] = math.sqrt(math.pow(orgDatax[a] - estDatax[a], 2) + math.pow(orgDatay[a] - estDatay[a], 2))
return np.mean(squareDst)
def max_dist_error(orgDatax, orgDatay, estDatax, estDatay):
length = len(orgDatax)
squareDst = np.zeros(length)
for a in range(length):
squareDst[a] = math.sqrt(math.pow(orgDatax[a] - estDatax[a], 2) + math.pow(orgDatay[a] - estDatay[a], 2))
return np.max(squareDst)
def dist(x,y):
return math.sqrt(math.pow(x[0] - y[0], 2) + math.pow(x[1] - y[1], 2))
def distCordwise(x0, x1, y0, y1):
return math.sqrt(math.pow(x0 - y0, 2) + math.pow(x1 - y1, 2))
#Compute square-root sum distance of one point to all points
def sqrt_sum_dist(x, y, xCoord, yCoord):
sum = 0
for a in range(len(xCoord)):
sum += distCordwise(x,y, xCoord[a], yCoord[a])
return sum
def percent_minmax_Traj(xData, yData, percent):
numData = xData.shape[0]
length = xData.shape[1]
validNumData = round(numData * (percent / 100.0))
xPercMinmaxTraj = np.zeros(length)
yPercMinmaxTraj = np.zeros(length)
for a in range(length):
fixedTimeData = np.zeros((numData, 3))
for b in range(numData):
fixedTimeData[b][0] = xData[b][a]
fixedTimeData[b][1] = yData[b][a]
fixedTimeData[b][2] = sqrt_sum_dist(fixedTimeData[b][0], fixedTimeData[b][1], xData[:, a], yData[:,a])
listFixedTimeData = fixedTimeData.tolist()
sortedlistFixedTimeData = sorted(listFixedTimeData, key=itemgetter(2))
newfixedTimeData = np.asarray(sortedlistFixedTimeData)
c = minmaxradiuscircle.make_circle2(newfixedTimeData[0:validNumData, 0], newfixedTimeData[0:validNumData, 1], validNumData)
xPercMinmaxTraj[a] = c[0]
yPercMinmaxTraj[a] = c[1]
return xPercMinmaxTraj, yPercMinmaxTraj, validNumData