wrapping up a night. there isn't enough consistent improvement to merit using this method. i must have a bug somewhere.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
from baker import *
|
||||
from baker.tools import logging as log
|
||||
from baker.tools import smblog
|
||||
import numpy as np
|
||||
import sys
|
||||
|
||||
@@ -30,8 +30,8 @@ def get_phis(X, R):
|
||||
try:
|
||||
phi = np.linalg.solve(A,b)
|
||||
except np.linalg.LinAlgError as e:
|
||||
msg = "warning: get_phis: calculation of phis yielded a linearly dependant system (%s)" % e
|
||||
log.error(msg)
|
||||
msg = "calculation of phis yielded a linearly dependant system (%s)" % e
|
||||
smblog.error(msg)
|
||||
raise smberror(msg)
|
||||
phi = np.dot(np.linalg.pinv(A), b)
|
||||
|
||||
@@ -69,7 +69,7 @@ def get_phis_3D(X, R):
|
||||
try:
|
||||
phi = np.linalg.solve(A,b)
|
||||
except np.linalg.LinAlgError as e:
|
||||
print >> sys.stderr, "warning: get_phis_3D: calculation of phis yielded a linearly dependant system", e
|
||||
smblog.error("calculation of phis yielded a linearly dependant system: %s" % e)
|
||||
phi = np.dot(np.linalg.pinv(A), b)
|
||||
|
||||
return phi
|
||||
@@ -130,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:
|
||||
print >> sys.stderr, "warning: run_baker: linear calculation went bad, resorting to np.linalg.pinv", e
|
||||
smblog.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]\
|
||||
@@ -171,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:
|
||||
print >> sys.stderr, "warning: run_baker: linear calculation went bad, resorting to np.linalg.pinv", e
|
||||
smblog.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]\
|
||||
@@ -280,7 +280,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:
|
||||
print >> sys.stderr, "warning: run_baker: linear calculation went bad, resorting to np.linalg.pinv", e
|
||||
smblog.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]\
|
||||
|
||||
+37
-13
@@ -1,15 +1,37 @@
|
||||
import os
|
||||
import logging
|
||||
|
||||
logging.basicConfig(
|
||||
level = logging.DEBUG,
|
||||
format = '%(asctime)s %(levelname)s %(message)s',
|
||||
filename = os.path.join(os.sep, 'tmp', 'baker.lol'),
|
||||
)
|
||||
|
||||
import inspect
|
||||
import numpy as np
|
||||
|
||||
|
||||
class smbLog(object):
|
||||
interpolator = "%s ==> %s"
|
||||
def __init__(self, level = logging.DEBUG):
|
||||
logging.basicConfig(
|
||||
level = level,
|
||||
format = '%(asctime)s %(levelname)s %(message)s',
|
||||
filename = os.path.join(os.sep, 'tmp', 'baker.lol'),
|
||||
)
|
||||
self.log = logging.getLogger()
|
||||
def debug(self, message = None):
|
||||
msg = smbLog.interpolator % (inspect.stack()[1][3], message)
|
||||
self.log.debug(msg)
|
||||
|
||||
def info(self, message = None):
|
||||
msg = smbLog.interpolator % (inspect.stack()[1][3], message)
|
||||
self.log.info(msg)
|
||||
|
||||
def warn(self, message = None):
|
||||
msg = smbLog.interpolator % (inspect.stack()[1][3], message)
|
||||
self.log.warn(msg)
|
||||
|
||||
def error(self, message = None):
|
||||
msg = smbLog.interpolator % (inspect.stack()[1][3], message)
|
||||
self.log.error(msg)
|
||||
|
||||
|
||||
smblog = smbLog(logging.DEBUG)
|
||||
|
||||
class smberror(Exception):
|
||||
"""
|
||||
this is a silly little exception subclass
|
||||
@@ -47,14 +69,16 @@ def exact_func_3D(X):
|
||||
return np.power((np.sin(x * np.pi / 2.0) * np.sin(y * np.pi / 2.0) * np.sin(z * np.pi / 2.0)), 2)
|
||||
|
||||
def improved_answer(answer, exact, verbose=False):
|
||||
if verbose:
|
||||
print 'qlin' , answer['qlin']
|
||||
print 'error', answer['error']
|
||||
print 'final', answer['final']
|
||||
if not answer['error']:
|
||||
return True
|
||||
smblog.debug('exact: %s' % exact)
|
||||
smblog.debug('qlin: %s' % answer['qlin'])
|
||||
smblog.debug('error: %s' % answer['error'])
|
||||
smblog.debug('final: %s' % answer['final'])
|
||||
|
||||
if abs(answer['final'] - exact) <= abs(answer['qlin'] - exact):
|
||||
if verbose: print ":) improved result"
|
||||
smblog.debug(":) improved result")
|
||||
return True
|
||||
else:
|
||||
if verbose: print ":( damaged result"
|
||||
smblog.debug(":( damaged result")
|
||||
return False
|
||||
|
||||
Reference in New Issue
Block a user