middle of refactor
This commit is contained in:
+19
-20
@@ -1,10 +1,9 @@
|
||||
from baker import *
|
||||
from baker.tools import smblog
|
||||
import numpy as np
|
||||
import sys
|
||||
|
||||
import numpy as np
|
||||
|
||||
import itertools
|
||||
from tools import smberror
|
||||
from interp.tools import log, smberror
|
||||
|
||||
def get_phis(X, R):
|
||||
"""
|
||||
@@ -32,7 +31,7 @@ def get_phis(X, R):
|
||||
phi = np.linalg.solve(A,b)
|
||||
except np.linalg.LinAlgError as e:
|
||||
msg = "calculation of phis yielded a linearly dependant system (%s)" % e
|
||||
smblog.error(msg)
|
||||
log.error(msg)
|
||||
raise smberror(msg)
|
||||
phi = np.dot(np.linalg.pinv(A), b)
|
||||
|
||||
@@ -70,7 +69,7 @@ def get_phis_3D(X, R):
|
||||
try:
|
||||
phi = np.linalg.solve(A,b)
|
||||
except np.linalg.LinAlgError as e:
|
||||
smblog.error("calculation of phis yielded a linearly dependant system: %s" % e)
|
||||
log.error("calculation of phis yielded a linearly dependant system: %s" % e)
|
||||
phi = np.dot(np.linalg.pinv(A), b)
|
||||
|
||||
return phi
|
||||
@@ -131,7 +130,7 @@ def get_error_quadratic(phi, R, S):
|
||||
try:
|
||||
(a, b, c) = np.linalg.solve(A,b)
|
||||
except np.linalg.LinAlgError as e:
|
||||
smblog.error("linear calculation went bad, resorting to np.linalg.pinv: %s" % e)
|
||||
log.error("linear calculation went bad, resorting to np.linalg.pinv: %s" % e)
|
||||
(a, b, c) = np.dot(np.linalg.pinv(A), b)
|
||||
|
||||
error_term = a * phi[0] * phi[1]\
|
||||
@@ -172,7 +171,7 @@ def get_error_cubic(phi, R, S):
|
||||
try:
|
||||
(a, b, c, d, e, f, g) = np.linalg.solve(A,b)
|
||||
except np.linalg.LinAlgError as e:
|
||||
smblog.error("linear calculation went bad, resorting to np.linalg.pinv: %s" % e)
|
||||
log.error("linear calculation went bad, resorting to np.linalg.pinv: %s" % e)
|
||||
(a, b, c, d, e, f, g) = np.dot(np.linalg.pinv(A), b)
|
||||
|
||||
error_term = a * phi[0] * phi[1] * phi[1]\
|
||||
@@ -186,12 +185,12 @@ def get_error_cubic(phi, R, S):
|
||||
return error_term
|
||||
|
||||
def get_error_sauron(phi, R, S, order = 2):
|
||||
smblog.debug("len(phi): %d"% len(phi))
|
||||
log.debug("len(phi): %d"% len(phi))
|
||||
B = [] # baker eq 9
|
||||
w = [] # baker eq 11
|
||||
|
||||
p = pattern(order, len(phi), offset = -1)
|
||||
smblog.debug("pattern: %s" % p)
|
||||
log.debug("pattern: %s" % p)
|
||||
|
||||
for (s,q) in zip(S.points, S.q):
|
||||
cur_phi, cur_qlin = qlinear(s, R)
|
||||
@@ -205,9 +204,9 @@ def get_error_sauron(phi, R, S, order = 2):
|
||||
B.append(l)
|
||||
w.append(q - cur_qlin)
|
||||
|
||||
smblog.debug("B: %s" % B)
|
||||
smblog.debug("w: %s" % w)
|
||||
|
||||
log.debug("B: %s" % B)
|
||||
log.debug("w: %s" % w)
|
||||
|
||||
|
||||
B = np.array(B)
|
||||
w = np.array(w)
|
||||
@@ -219,10 +218,10 @@ def get_error_sauron(phi, R, S, order = 2):
|
||||
try:
|
||||
abc = np.linalg.solve(A,b)
|
||||
except np.linalg.LinAlgError as e:
|
||||
smblog.error("linear calculation went bad, resorting to np.linalg.pinv: %s" % e)
|
||||
log.error("linear calculation went bad, resorting to np.linalg.pinv: %s" % e)
|
||||
abc = np.dot(np.linalg.pinv(A), b)
|
||||
|
||||
smblog.debug(len(abc) == len(p))
|
||||
log.debug(len(abc) == len(p))
|
||||
|
||||
error_term = 0.0
|
||||
for (a, i) in zip(abc, p):
|
||||
@@ -230,8 +229,8 @@ def get_error_sauron(phi, R, S, order = 2):
|
||||
for j in i:
|
||||
cur_sum *= phi[j]
|
||||
error_term += cur_sum
|
||||
|
||||
smblog.debug("error_term smb: %s" % error_term)
|
||||
|
||||
log.debug("error_term smb: %s" % error_term)
|
||||
return error_term, abc
|
||||
|
||||
def run_baker(X, R, S, order=2):
|
||||
@@ -244,7 +243,7 @@ def run_baker(X, R, S, order=2):
|
||||
R = Simplex
|
||||
S = extra points
|
||||
"""
|
||||
smblog.debug("order = %d" % order)
|
||||
log.debug("order = %d" % order)
|
||||
|
||||
answer = {
|
||||
'qlin': None,
|
||||
@@ -328,7 +327,7 @@ def run_baker_3D(X, R, S):
|
||||
try:
|
||||
(a, b, c, d, e, f) = np.linalg.solve(A,b)
|
||||
except np.linalg.LinAlgError as e:
|
||||
smblog.error("linear calculation went bad, resorting to np.linalg.pinv: %s", e)
|
||||
log.error("linear calculation went bad, resorting to np.linalg.pinv: %s", e)
|
||||
(a, b, c, d, e, f) = np.dot(np.linalg.pinv(A), b)
|
||||
|
||||
error_term = a * phi[0] * phi[1]\
|
||||
@@ -374,7 +373,7 @@ def _samples_ur(items, k, offset = 0):
|
||||
yield tuple([x + offset for sel in selections for x in sel])
|
||||
|
||||
def pattern(power, phicount, offset = 0):
|
||||
smblog.debug("(power = %s, phicount = %s)" % (power, phicount))
|
||||
log.debug("(power = %s, phicount = %s)" % (power, phicount))
|
||||
r = []
|
||||
for i in _samples_ur(range(1, phicount + 1), power, offset):
|
||||
if not len(set(i)) == 1:
|
||||
|
||||
Reference in New Issue
Block a user