Added kwargs to the inversion. can use these to initiate your inversion object.

This commit is contained in:
Rowan Cockett
2013-10-26 14:16:50 -07:00
parent 3bbe258eab
commit dbd24b71c1
3 changed files with 19 additions and 17 deletions
+2 -8
View File
@@ -59,12 +59,6 @@ class LinearProblem(Problem):
def Jt(self, m, v, u=None):
return G.T.dot(v)
def modelTransform(self, m):
return m
def modelTransformDeriv(self, m):
return sp.eye(m.size)
prob = LinearProblem(M)
prob.G = G
prob.dobs = d_obs
@@ -72,9 +66,9 @@ prob.std = np.ones_like(d_obs)*0.1
reg = Regularization(M)
opt = InexactGaussNewton(maxIter=10)
opt = InexactGaussNewton(maxIter=20)
inv = Inversion(prob,reg,opt)
inv = Inversion(prob,reg,opt,beta0=1e-4)
m0 = np.zeros_like(m_true)
+14 -6
View File
@@ -1,18 +1,26 @@
import numpy as np
import scipy.sparse as sp
from SimPEG.utils import sdiag, mkvc
from SimPEG.inverse import BS
class Inversion(object, BetaSchedual.Cooling):
class Inversion(object):
"""docstring for Inversion"""
maxIter = 10
def __init__(self, prob, reg, opt):
def __init__(self, prob, reg, opt, **kwargs):
self.prob = prob
self.reg = reg
self.opt = opt
self.opt.parent = self
self.setKwargs(**kwargs)
def setKwargs(self, **kwargs):
# Set the variables, throw an error if they don't exist.
for attr in kwargs:
if hasattr(self, attr):
setattr(self, attr, kwargs[attr])
else:
raise Exception('%s attr is not recognized' % attr)
@property
def Wd(self):
@@ -51,13 +59,13 @@ class Inversion(object, BetaSchedual.Cooling):
self._iter += 1
return m
beta0 = 1.e6
beta0 = 1.e2
beta_coolingFactor = 5.
def getBeta(self):
if self._beta is None:
return beta0
return self._beta * beta_coolingFactor
return self.beta0
return self._beta * self.beta_coolingFactor
def stoppingCriteria(self):
self._STOP = np.zeros(2,dtype=bool)
+3 -3
View File
@@ -19,9 +19,9 @@ class Minimize(object):
maxIterLS = 10
LSreduction = 1e-4
LSshorten = 0.5
tolF = 1e-4
tolX = 1e-4
tolG = 1e-4
tolF = 1e-1
tolX = 1e-1
tolG = 1e-1
eps = 1e-5
printIter = [] # push to here if you want to print these on iter