Brought inversion into line with optimize changes.

This commit is contained in:
Rowan Cockett
2013-11-07 16:27:12 -08:00
parent 0dc3b02c45
commit bc71b184aa
2 changed files with 25 additions and 20 deletions
+10 -20
View File
@@ -1,6 +1,7 @@
import numpy as np import numpy as np
import scipy.sparse as sp import scipy.sparse as sp
from SimPEG.utils import sdiag, mkvc, setKwargs import SimPEG
from SimPEG.utils import sdiag, mkvc, setKwargs, checkStoppers
class Inversion(object): class Inversion(object):
"""docstring for Inversion""" """docstring for Inversion"""
@@ -15,21 +16,14 @@ class Inversion(object):
self.opt = opt self.opt = opt
self.opt.parent = self self.opt.parent = self
# Check if we have inserted printers into the optimization self.stoppers = [SimPEG.inverse.StoppingCriteria.iteration, SimPEG.inverse.StoppingCriteria.phi_d_target_Inversion]
haveInserted = False
for printer in self.opt.printers:
haveInserted = haveInserted or printer["title"] == 'phi_d'
if not haveInserted: # Check if we have inserted printers into the optimization
self.opt.printers.insert(1,{"title": "beta", if not np.any([p is SimPEG.inverse.IterationPrinters.phi_d for p in self.opt.printers]):
"value": lambda M: M.parent._beta, self.opt.printers.insert(1,SimPEG.inverse.IterationPrinters.beta)
"width": 10, "format": "%1.2e"}) self.opt.printers.insert(2,SimPEG.inverse.IterationPrinters.phi_d)
self.opt.printers.insert(2,{"title": "phi_d", self.opt.printers.insert(3,SimPEG.inverse.IterationPrinters.phi_m)
"value": lambda M: M.parent.phi_d, self.opt.stoppers.append(SimPEG.inverse.StoppingCriteria.phi_d_target_Minimize)
"width": 10, "format": "%1.2e"})
self.opt.printers.insert(3,{"title": "phi_m",
"value": lambda M: M.parent.phi_m,
"width": 10, "format": "%1.2e"})
@property @property
def Wd(self): def Wd(self):
@@ -77,11 +71,7 @@ class Inversion(object):
return self._beta / self.beta_coolingFactor return self._beta / self.beta_coolingFactor
def stoppingCriteria(self): def stoppingCriteria(self):
self._STOP = np.zeros(2,dtype=bool) return checkStoppers(self, self.stoppers)
self._STOP[0] = self._iter >= self.maxIter
self._STOP[1] = self.phi_d <= self.phi_d_target
return np.any(self._STOP)
def evalFunction(self, m, return_g=True, return_H=True): def evalFunction(self, m, return_g=True, return_H=True):
+15
View File
@@ -51,6 +51,15 @@ class StoppingCriteria(object):
"left": lambda M: M._LS_xt.size, "right": lambda M: np.sum(M.bindingSet(M._LS_xt)), "left": lambda M: M._LS_xt.size, "right": lambda M: np.sum(M.bindingSet(M._LS_xt)),
"stopType": "critical"} "stopType": "critical"}
phi_d_target_Minimize = { "str": "%d : phi_d = %1.4e <= phi_d_target = %1.4e ",
"left": lambda M: M.parent.phi_d, "right": lambda M: M.parent.phi_d_target,
"stopType": "critical"}
phi_d_target_Inversion = { "str": "%d : phi_d = %1.4e <= phi_d_target = %1.4e ",
"left": lambda I: I.phi_d, "right": lambda I: I.phi_d_target,
"stopType": "critical"}
class IterationPrinters(object): class IterationPrinters(object):
"""docstring for IterationPrinters""" """docstring for IterationPrinters"""
@@ -69,6 +78,11 @@ class IterationPrinters(object):
bSet = {"title": "bSet", "value": lambda M: np.sum(M.bindingSet(M.xc)), "width": 8, "format": "%d"} bSet = {"title": "bSet", "value": lambda M: np.sum(M.bindingSet(M.xc)), "width": 8, "format": "%d"}
comment = {"title": "Comment", "value": lambda M: M.projComment, "width": 7, "format": "%s"} comment = {"title": "Comment", "value": lambda M: M.projComment, "width": 7, "format": "%s"}
beta = {"title": "beta", "value": lambda M: M.parent._beta, "width": 10, "format": "%1.2e"}
phi_d = {"title": "phi_d", "value": lambda M: M.parent.phi_d, "width": 10, "format": "%1.2e"}
phi_m = {"title": "phi_m", "value": lambda M: M.parent.phi_m, "width": 10, "format": "%1.2e"}
class Minimize(object): class Minimize(object):
""" """
@@ -393,6 +407,7 @@ class Minimize(object):
:rtype: numpy.ndarray,bool :rtype: numpy.ndarray,bool
:return: (xt, breakCaught) :return: (xt, breakCaught)
""" """
self.printDone(inLS=True)
print 'The linesearch got broken. Boo.' print 'The linesearch got broken. Boo.'
return p, False return p, False