working on implementing the cubic interpolation. need to split that routine out of the run_baker method
This commit is contained in:
parent
f089848a1b
commit
bd8f24d64f
@ -103,4 +103,4 @@ if __name__ == '__main__':
|
||||
errors.append(cur_error)
|
||||
|
||||
print rms(errors)
|
||||
print "%s of %s won" % (success, len(mesh_dest.points))
|
||||
print >>sys.stderr, "%s of %s won" % (success, len(mesh_dest.points))
|
||||
|
@ -27,7 +27,7 @@ exact = exact_func_3D(X)
|
||||
print "exact solution: %0.6f" % exact
|
||||
|
||||
phis = get_phis_3D(X, R.points)
|
||||
print "phi values (should all be positive): ", phis
|
||||
print "phi values (should all be positive): ", phis, sum(phis)
|
||||
if [i for i in phis if i < 0.0]:
|
||||
print "problems"
|
||||
sys.exit(1)
|
||||
|
@ -27,8 +27,8 @@ def get_phis(X, R):
|
||||
])
|
||||
try:
|
||||
phi = np.linalg.solve(A,b)
|
||||
except:
|
||||
print >> sys.stderr, "warning: get_phis: calculation of phis yielded a linearly dependant system"
|
||||
except LinAlgError as e:
|
||||
print >> sys.stderr, "warning: get_phis: calculation of phis yielded a linearly dependant system", e
|
||||
raise smberror('get_phis')
|
||||
phi = np.dot(np.linalg.pinv(A), b)
|
||||
|
||||
@ -65,8 +65,8 @@ def get_phis_3D(X, r):
|
||||
])
|
||||
try:
|
||||
phi = np.linalg.solve(A,b)
|
||||
except:
|
||||
print >> sys.stderr, "warning: get_phis_3D: calculation of phis yielded a linearly dependant system"
|
||||
except LinAlgError as e:
|
||||
print >> sys.stderr, "warning: get_phis_3D: calculation of phis yielded a linearly dependant system", e
|
||||
phi = np.dot(np.linalg.pinv(A), b)
|
||||
|
||||
return phi
|
||||
@ -152,8 +152,8 @@ def run_baker(X, R, S):
|
||||
# baker solve eq 10
|
||||
try:
|
||||
(a, b, c) = np.linalg.solve(A,b)
|
||||
except:
|
||||
print >> sys.stderr, "warning: run_baker: linear calculation went bad, resorting to np.linalg.pinv"
|
||||
except LinAlgError as e:
|
||||
print >> sys.stderr, "warning: run_baker: linear calculation went bad, resorting to np.linalg.pinv", e
|
||||
(a, b, c) = np.dot(np.linalg.pinv(A), b)
|
||||
|
||||
error_term = a * phi[0] * phi[1]\
|
||||
@ -230,8 +230,8 @@ def run_baker_3D(X, R, S):
|
||||
# baker solve eq 10
|
||||
try:
|
||||
(a, b, c, d, e, f) = np.linalg.solve(A,b)
|
||||
except:
|
||||
print >> sys.stderr, "warning: run_baker: linear calculation went bad, resorting to np.linalg.pinv"
|
||||
except np.linalg.LinAlgError as e:
|
||||
print >> sys.stderr, "warning: run_baker: linear calculation went bad, resorting to np.linalg.pinv", e
|
||||
(a, b, c, d, e, f) = np.dot(np.linalg.pinv(A), b)
|
||||
|
||||
error_term = a * phi[0] * phi[1]\
|
||||
|
@ -23,6 +23,7 @@ class TestSequenceFunctions(unittest.TestCase):
|
||||
]
|
||||
self.q = [1, 0, 0, 0, 0, 0, 0, 0, 0]
|
||||
self.X = [1.5, 10.25]
|
||||
self.accuracy = 8
|
||||
|
||||
def testImports(self):
|
||||
import numpy
|
||||
@ -36,9 +37,9 @@ class TestSequenceFunctions(unittest.TestCase):
|
||||
r = [[-1, -1], [0, 2], [1, -1]]
|
||||
|
||||
result = baker.get_phis(X, r)
|
||||
result = [round(i, 5) for i in result]
|
||||
result = [round(i, self.accuracy) for i in result]
|
||||
|
||||
right_answer = [round(i, 5) for i in [1/3.0, 1/3.0, 1/3.0]]
|
||||
right_answer = [round(i, self.accuracy) for i in [1/3.0, 1/3.0, 1/3.0]]
|
||||
|
||||
for a,b in zip(result, right_answer):
|
||||
self.assertEqual(a,b)
|
||||
@ -77,13 +78,13 @@ class TestSequenceFunctions(unittest.TestCase):
|
||||
self.q[size_of_simplex:size_of_simplex + extra_points])
|
||||
|
||||
answer = baker.run_baker(self.X, R, S)
|
||||
a = round(answer['a'], 5)
|
||||
b = round(answer['b'], 5)
|
||||
c = round(answer['c'], 5)
|
||||
a = round(answer['a'], self.accuracy)
|
||||
b = round(answer['b'], self.accuracy)
|
||||
c = round(answer['c'], self.accuracy)
|
||||
|
||||
self.assertEqual(a, c)
|
||||
self.assertEqual(c, round(0.00 , 5))
|
||||
self.assertEqual(b, round(1/3.0, 5))
|
||||
self.assertEqual(c, round(0.00 , self.accuracy))
|
||||
self.assertEqual(b, round(1/3.0, self.accuracy))
|
||||
|
||||
def testRunBaker_2(self):
|
||||
size_of_simplex = 3
|
||||
@ -144,4 +145,4 @@ class TestSequenceFunctions(unittest.TestCase):
|
||||
|
||||
if __name__ == '__main__':
|
||||
suite = unittest.TestLoader().loadTestsFromTestCase(TestSequenceFunctions)
|
||||
unittest.TextTestRunner(verbosity=2).run(suite)
|
||||
unittest.TextTestRunner(verbosity=3).run(suite)
|
||||
|
Loading…
Reference in New Issue
Block a user