verify method added
This commit is contained in:
parent
a1014ed257
commit
f769986d80
34
main.py
34
main.py
@ -9,14 +9,17 @@ import random
|
|||||||
|
|
||||||
|
|
||||||
startTime = 0
|
startTime = 0
|
||||||
|
lastTime = 0
|
||||||
|
|
||||||
def log(msg, reset=False):
|
def log(msg, reset=False):
|
||||||
global startTime
|
global startTime, lastTime
|
||||||
currentTime = time.time()
|
currentTime = time.time()
|
||||||
if reset:
|
if reset:
|
||||||
startTime = currentTime
|
startTime = currentTime
|
||||||
print("%f: %s" % (currentTime - startTime, msg))
|
if lastTime == 0:
|
||||||
|
lastTime = currentTime
|
||||||
|
print("%f %f: %s" % (currentTime - startTime, currentTime - lastTime, msg))
|
||||||
|
lastTime = currentTime
|
||||||
|
|
||||||
def s_permutations(seq):
|
def s_permutations(seq):
|
||||||
items = [[]]
|
items = [[]]
|
||||||
@ -100,6 +103,28 @@ def generate(order, lowerBound, upperBound):
|
|||||||
return matrix
|
return matrix
|
||||||
|
|
||||||
|
|
||||||
|
def verify(m, v):
|
||||||
|
coeffs = m[:-1]
|
||||||
|
results = m[-1]
|
||||||
|
epsilons = []
|
||||||
|
good = True
|
||||||
|
MAX_EPSILON = 1E-10
|
||||||
|
worstEpsilon = 0.0
|
||||||
|
|
||||||
|
for i in range(len(results)):
|
||||||
|
res = 0.0
|
||||||
|
for j in range(len(results)):
|
||||||
|
res += coeffs[j][i] * v[j]
|
||||||
|
epsilon = res - results[i]
|
||||||
|
if epsilon > MAX_EPSILON:
|
||||||
|
good = False
|
||||||
|
if abs(epsilon) > worstEpsilon:
|
||||||
|
worstEpsilon = abs(epsilon)
|
||||||
|
epsilons.append(res - results[i])
|
||||||
|
|
||||||
|
return (good, worstEpsilon, epsilons)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#g = [[1.0,2.0,10.0], [5.0,3.0,11.0], [7.0,4.0,3.0], [8.0,9.0,13.0]]
|
#g = [[1.0,2.0,10.0], [5.0,3.0,11.0], [7.0,4.0,3.0], [8.0,9.0,13.0]]
|
||||||
#g = [[599.1290806728277, 80.40433203454268, 615.5120772027384], [187.33506822036273, 663.7490700388757, 677.5997857592452], [956.929845461785, 456.8619830134234, 419.21973493934263], [61.824473951393344, 342.8555419523176, 216.32654519677496]]
|
#g = [[599.1290806728277, 80.40433203454268, 615.5120772027384], [187.33506822036273, 663.7490700388757, 677.5997857592452], [956.929845461785, 456.8619830134234, 419.21973493934263], [61.824473951393344, 342.8555419523176, 216.32654519677496]]
|
||||||
@ -115,6 +140,9 @@ for i in range(2, 10+1):
|
|||||||
print(i)
|
print(i)
|
||||||
print(g)
|
print(g)
|
||||||
print(v)
|
print(v)
|
||||||
|
|
||||||
|
e = verify(g, v)
|
||||||
|
print(e)
|
||||||
print
|
print
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user