Updates to Solver Wrappers.

bug fix in dependentProperty
This commit is contained in:
rowanc1
2014-03-19 13:33:45 -07:00
parent 7402782541
commit ecc7aaf9b0
3 changed files with 12 additions and 9 deletions
+8 -6
View File
@@ -2,7 +2,7 @@ import numpy as np
from matutils import mkvc
import warnings
def DSolverWrap(fun, factorize=True, checkAccuracy=True, accuracyTol=1e-8):
def DSolverWrap(fun, factorize=True, checkAccuracy=True, accuracyTol=1e-6):
def __init__(self, A, **kwargs):
self.A = A.tocsc()
@@ -12,11 +12,12 @@ def DSolverWrap(fun, factorize=True, checkAccuracy=True, accuracyTol=1e-8):
def solve(self, b):
if len(b.shape) == 1 or b.shape[1] == 1:
b = b.flatten()
# Just one RHS
if factorize:
X = self.solver.solve(b.flatten(), **self.kwargs)
X = self.solver.solve(b, **self.kwargs)
else:
X = fun(self.A, b.flatten(), **self.kwargs)
X = fun(self.A, b, **self.kwargs)
else: # Multiple RHSs
X = np.empty_like(b)
for i in range(b.shape[1]):
@@ -26,7 +27,7 @@ def DSolverWrap(fun, factorize=True, checkAccuracy=True, accuracyTol=1e-8):
X[:,i] = fun(self.A, b[:,i], **self.kwargs)
if checkAccuracy:
nrm = np.linalg.norm(mkvc(self.A*X - b)) / np.linalg.norm(Utils.mkvc(b))
nrm = np.linalg.norm(mkvc(self.A*X - b)) / np.linalg.norm(mkvc(b))
if nrm > accuracyTol:
msg = '### SolverWarning ###: Accuracy on solve is above tolerance: %e > %e' % (nrm, accuracyTol)
print msg
@@ -45,8 +46,9 @@ def ISolverWrap(fun, checkAccuracy=True, accuracyTol=1e-5):
def solve(self, b):
if len(b.shape) == 1 or b.shape[1] == 1:
b = b.flatten()
# Just one RHS
out = fun(self.A, b.flatten(), **self.kwargs)
out = fun(self.A, b, **self.kwargs)
if type(out) is tuple and len(out) == 2:
# We are dealing with scipy output with an info!
X = out[0]
@@ -65,7 +67,7 @@ def ISolverWrap(fun, checkAccuracy=True, accuracyTol=1e-5):
X[:,i] = out
if checkAccuracy:
nrm = np.linalg.norm(mkvc(self.A*X - b)) / np.linalg.norm(Utils.mkvc(b))
nrm = np.linalg.norm(mkvc(self.A*X - b)) / np.linalg.norm(mkvc(b))
if nrm > accuracyTol:
msg = '### SolverWarning ###: Accuracy on solve is above tolerance: %e > %e' % (nrm, accuracyTol)
print msg
+2 -1
View File
@@ -136,7 +136,8 @@ def callHooks(match, mainFirst=False):
def dependentProperty(name, value, children, doc):
def fget(self): return getattr(self,name,value)
def fset(self, val):
if getattr(self,name,value) == val: return # it is the same!
if isScalar(val) and getattr(self,name,value) == val:
return # it is the same!
for child in children:
if hasattr(self, child):
delattr(self, child)
+2 -2
View File
@@ -3,8 +3,8 @@
:alt: SimPEG
:align: center
Simulation and Parameter Estimation in Geophysics (SimPEG)
**********************************************************
Simulation and Parameter Estimation in Geophysics
*************************************************
SimPEG is a python package for simulation and gradient
based parameter estimation in the context of geoscience applications.