MCPcopy Create free account
hub / github.com/comaps/comaps / findBest

Function findBest

tools/python/city_radius.py:54–84  ·  view source on GitHub ↗
(popul, data, minBase = 5, maxBase = 100, stepBase = 0.1, minMult = 0.01, maxMult = 1, stepMult = 0.01)

Source from the content-addressed store, hash-verified

52 return dist / float(len(data))
53
54def findBest(popul, data, minBase = 5, maxBase = 100, stepBase = 0.1, minMult = 0.01, maxMult = 1, stepMult = 0.01):
55
56 # try to find best parameters
57 base = minBase
58
59 minDist = -1
60 bestMult = minMult
61 bestBase = base
62
63 while base <= maxBase:
64 print "%.02f%% best mult: %f, best base: %f, best dist: %f" % (100 * (base - minBase) / (maxBase - minBase), bestMult, bestBase, minDist)
65 mult = minMult
66
67 while mult <= maxMult:
68 approx = []
69
70 for p in popul:
71 approx.append(formula(p, base, mult))
72
73 dist = avgDistance(approx, data)
74
75 if minDist < 0 or minDist > dist:
76 minDist = dist
77 bestBase = base
78 bestMult = mult
79
80 mult += stepMult
81
82 base += stepBase
83
84 return (bestBase, bestMult)
85
86def process_data(steps_count, base, mult, bestFind = False, dataFlag = 0):
87 avgData = []

Callers 1

process_dataFunction · 0.85

Calls 3

formulaFunction · 0.85
avgDistanceFunction · 0.85
appendMethod · 0.45

Tested by

no test coverage detected