Stopping Criteria and Printers generalized in Optimize.

This commit is contained in:
Rowan Cockett
2013-11-07 01:20:03 -08:00
parent f60017ff50
commit 318ca555c8
3 changed files with 665 additions and 121 deletions
+23 -7
View File
@@ -9,11 +9,27 @@ class Inversion(object):
name = 'SimPEG Inversion'
def __init__(self, prob, reg, opt, **kwargs):
self.setKwargs(**kwargs)
self.prob = prob
self.reg = reg
self.opt = opt
self.opt.parent = self
self.setKwargs(**kwargs)
# Check if we have inserted printers into the optimization
haveInserted = False
for printer in self.opt.printers:
haveInserted = haveInserted or printer["title"] == 'phi_d'
if not haveInserted:
self.opt.printers.insert(1,{"title": "beta",
"value": lambda M: M.parent._beta,
"width": 13, "format": "%1.2e"})
self.opt.printers.insert(2,{"title": "phi_d",
"value": lambda M: M.parent._phi_d_last,
"width": 13, "format": "%1.2e"})
self.opt.printers.insert(3,{"title": "phi_m",
"value": lambda M: M.parent._phi_m_last,
"width": 13, "format": "%1.2e"})
def setKwargs(self, **kwargs):
"""Sets key word arguments (kwargs) that are present in the object, throw an error if they don't exist."""
@@ -23,13 +39,13 @@ class Inversion(object):
else:
raise Exception('%s attr is not recognized' % attr)
def printInit(self):
print "%s %s %s" % ('='*22, self.name, '='*22)
print " # beta phi_d phi_m f norm(dJ) #LS"
print "%s" % '-'*62
# def printInit(self):
# print "%s %s %s" % ('='*22, self.name, '='*22)
# print " # beta phi_d phi_m f norm(dJ) #LS"
# print "%s" % '-'*62
def printIter(self):
print "%3d %1.2e %1.2e %1.2e %1.2e %1.2e %3d" % (self.opt._iter, self._beta, self._phi_d_last, self._phi_m_last, self.opt.f, np.linalg.norm(self.opt.g), self.opt._iterLS)
# def printIter(self):
# print "%3d %1.2e %1.2e %1.2e %1.2e %1.2e %3d" % (self.opt._iter, self._beta, self._phi_d_last, self._phi_m_last, self.opt.f, np.linalg.norm(self.opt.g), self.opt._iterLS)
@property
def Wd(self):