-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExecution.py
More file actions
67 lines (56 loc) · 1.74 KB
/
Copy pathExecution.py
File metadata and controls
67 lines (56 loc) · 1.74 KB
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
from Utility import Point
def find_values(plist):
intercept = 0
xcent = 0
for p in plist:
intercept += p.y
xcent += p.x
return intercept / len(plist), xcent / len(plist)
def alter_list(plist, intercept, xcent):
newlist = []
for p in plist:
newlist.append(Point(p.x - xcent, p.y - intercept))
return newlist
def find_slope(altlist):
slope, maxpt, minpt = 1, altlist[0], altlist[0]
maesn = [maes(slope, altlist)]
for p in altlist:
if p.y > maxpt.y:
maxpt = p
if p.y < minpt.y:
minpt = p
range = maxpt.y - minpt.y
avg = roll10avg(maesn)
while maesn[-1] >= avg + avg / 100:
betaval = (maesn[-1] * slope) / range
lslope, gslope = slope - betaval, slope + betaval
lmaes = maes(lslope, altlist)
gmaes = maes(gslope, altlist)
while (lmaes > maesn[-1] and gmaes > maesn[-1]):
betaval = betaval / 2
lslope, gslope = slope - betaval, slope + betaval
lmaes = maes(lslope, altlist)
gmaes = maes(gslope, altlist)
if lmaes > gmaes:
slope = gslope
else:
slope = lslope
maesn.append(maes(slope, altlist))
avg = roll10avg(maesn)
return slope
def roll10avg(maesn):
sum, bound = 0, 11
if len(maesn) < bound:
bound = len(maesn)
for i in range(1, bound):
sum += maesn[-1 * i]
return sum / (bound)
def maes(slope, altlist):
aes = 0
for p in altlist:
aes += (p.y - (slope * p.x)) ** 2
return aes / len(altlist)
def exec_regression(plist):
intercept, xcent = find_values(plist)
slope = find_slope(alter_list(plist, intercept, xcent))
return slope, intercept, xcent