mirror of
https://github.com/wassname/simpeg.git
synced 2026-06-30 15:36:14 +08:00
Fixed Example Problems.
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
+14
-12
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user