From cffb0762beba51ff6c0e241b366f4620902b9ba7 Mon Sep 17 00:00:00 2001 From: rowanc1 Date: Fri, 24 Jan 2014 10:17:00 -0700 Subject: [PATCH] Fixed Example Problems. --- SimPEG/Examples/DC.py | 17 ++++++++--------- SimPEG/Examples/Linear.py | 26 ++++++++++++++------------ 2 files changed, 22 insertions(+), 21 deletions(-) diff --git a/SimPEG/Examples/DC.py b/SimPEG/Examples/DC.py index 28b1466f..074f5e3d 100644 --- a/SimPEG/Examples/DC.py +++ b/SimPEG/Examples/DC.py @@ -208,7 +208,7 @@ if __name__ == '__main__': q, Q, rxmidloc = genTxRxmat(nelec, spacelec, surfloc, elecini, M) P = Q.T - model = Model.LogModel() + model = Model.LogModel(M) prob = DCProblem(M, model) # Create some data @@ -224,18 +224,17 @@ if __name__ == '__main__': # prob.std = dobs*0 + 0.05 m0 = M.gridCC[:,0]*0+sig2 - opt = Inverse.InexactGaussNewton(maxIterLS=20, maxIter=3, tolF=1e-6, tolX=1e-6, tolG=1e-6, maxIterCG=6) - reg = Inverse.Regularization(M) - inv = Inverse.Inversion(prob, reg, opt, data, beta0=1e4) + reg = Regularization.Tikhonov(model) + objFunc = ObjFunction.BaseObjFunction(data, reg) + opt = Optimization.InexactGaussNewton(maxIterLS=20, maxIter=3, tolF=1e-6, tolX=1e-6, tolG=1e-6, maxIterCG=6) + inv = Inversion.BaseInversion(objFunc, opt) # Check Derivative - derChk = lambda m: [inv.dataObj(m), inv.dataObjDeriv(m)] + derChk = lambda m: [objFunc.dataObj(m), objFunc.dataObjDeriv(m)] # Tests.checkDerivative(derChk, mSynth) - - - print inv.dataObj(m0) - print inv.dataObj(mSynth) + print objFunc.dataObj(m0) + print objFunc.dataObj(mSynth) m = inv.run(m0) diff --git a/SimPEG/Examples/Linear.py b/SimPEG/Examples/Linear.py index acaaf38b..a83b26f1 100644 --- a/SimPEG/Examples/Linear.py +++ b/SimPEG/Examples/Linear.py @@ -1,14 +1,15 @@ -from SimPEG import Mesh, Model, Problem, Data, Inversion, np +from SimPEG import * import matplotlib.pyplot as plt class LinearProblem(Problem.BaseProblem): """docstring for LinearProblem""" - def __init__(self, *args, **kwargs): - problem.BaseProblem.__init__(self, *args, **kwargs) + def __init__(self, mesh, model, G, **kwargs): + Problem.BaseProblem.__init__(self, mesh, model, **kwargs) + self.G = G - def dpred(self, m, u=None): + def field(self, m, u=None): return self.G.dot(m) def J(self, m, v, u=None): @@ -20,7 +21,7 @@ class LinearProblem(Problem.BaseProblem): def example(N): h = np.ones(N)/N - M = mesh.TensorMesh([h]) + M = Mesh.TensorMesh([h]) nk = 20 jk = np.linspace(1.,20.,nk) @@ -41,21 +42,22 @@ def example(N): - prob = LinearProblem(M, None) - prob.G = G + model = Model.BaseModel(M) + prob = LinearProblem(M, model, G) data = prob.createSyntheticData(mtrue, std=0.01) - return prob, data + return prob, data, model if __name__ == '__main__': - prob, data = example(100) + prob, data, model = example(100) M = prob.mesh - reg = inverse.Regularization(M) - opt = inverse.InexactGaussNewton(maxIter=20) - inv = inverse.Inversion(prob,reg,opt,data) + reg = Regularization.Tikhonov(model) + objFunc = ObjFunction.BaseObjFunction(data, reg) + opt = Optimization.InexactGaussNewton(maxIter=20) + inv = Inversion.BaseInversion(objFunc, opt) m0 = np.zeros_like(data.mtrue) mrec = inv.run(m0)