mirror of
https://github.com/wassname/simpeg.git
synced 2026-07-02 10:46:37 +08:00
fixes to inversion framework. DC problem is kinda working…?!
This commit is contained in:
+13
-11
@@ -140,8 +140,8 @@ if __name__ == '__main__':
|
||||
from SimPEG import inverse
|
||||
|
||||
# Create the mesh
|
||||
h1 = np.ones(10)
|
||||
h2 = np.ones(10)
|
||||
h1 = np.ones(100)
|
||||
h2 = np.ones(100)
|
||||
mesh = TensorMesh([h1,h2])
|
||||
|
||||
# Create some parameters for the model
|
||||
@@ -177,7 +177,7 @@ if __name__ == '__main__':
|
||||
dobs, Wd = synthetic.createData(mSynth, std=0.05)
|
||||
|
||||
u = synthetic.field(mSynth)
|
||||
mesh.plotImage(u[:,10], showIt=False)
|
||||
# mesh.plotImage(u[:,10], showIt=False)
|
||||
|
||||
# Now set up the problem to do some minimization
|
||||
problem = DCProblem(mesh)
|
||||
@@ -190,23 +190,25 @@ if __name__ == '__main__':
|
||||
# print problem.misfit(m0)
|
||||
# print problem.misfit(mSynth)
|
||||
|
||||
opt = inverse.InexactGaussNewton(maxIterLS=20)
|
||||
opt = inverse.InexactGaussNewton(maxIterLS=20, maxIter=1)
|
||||
reg = Regularization(mesh)
|
||||
|
||||
inv = inverse.Inversion(problem, reg, opt)
|
||||
|
||||
inv.run(m0)
|
||||
m = inv.run(m0)
|
||||
|
||||
mesh.plotImage(m,showIt=True)
|
||||
|
||||
# Check Derivative
|
||||
derChk = lambda m: [problem.misfit(m), problem.misfitDeriv(m)]
|
||||
derChk = lambda m: [inv.dataObj(m), inv.dataObjDeriv(m)]
|
||||
checkDerivative(derChk, mSynth)
|
||||
|
||||
# Adjoint Test
|
||||
u = np.random.rand(mesh.nC)
|
||||
v = np.random.rand(mesh.nC)
|
||||
w = np.random.rand(dobs.shape[0])
|
||||
print w.dot(problem.J(mSynth, v, u=u))
|
||||
print v.dot(problem.Jt(mSynth, w, u=u))
|
||||
# u = np.random.rand(mesh.nC)
|
||||
# v = np.random.rand(mesh.nC)
|
||||
# w = np.random.rand(dobs.shape[0])
|
||||
# print w.dot(problem.J(mSynth, v, u=u))
|
||||
# print v.dot(problem.Jt(mSynth, w, u=u))
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -22,6 +22,15 @@ class Inversion(object):
|
||||
self._Wd = 1/(abs(self.prob.dobs)*self.prob.std+eps)
|
||||
return self._Wd
|
||||
|
||||
@property
|
||||
def phi_d_target(self):
|
||||
if getattr(self, '_phi_d_target', None) is None:
|
||||
return self.prob.dobs.size
|
||||
return self._phi_d_target
|
||||
@phi_d_target.setter
|
||||
def phi_d_target(self, value):
|
||||
self._phi_d_target = value
|
||||
|
||||
def run(self, m0):
|
||||
m = m0
|
||||
self._iter = 0
|
||||
@@ -30,13 +39,14 @@ class Inversion(object):
|
||||
m = self.opt.minimize(self.evalFunction,m)
|
||||
if self.stoppingCriteria(): break
|
||||
self._iter += 1
|
||||
return m
|
||||
|
||||
def getBeta(self):
|
||||
return 1
|
||||
return 1e3
|
||||
|
||||
def stoppingCriteria(self):
|
||||
self._STOP = np.zeros(2,dtype=bool)
|
||||
self._STOP[0] = self._iter >= maxIter
|
||||
self._STOP[0] = self._iter >= self.maxIter
|
||||
self._STOP[1] = self._phi_d_last <= self.phi_d_target
|
||||
return np.any(self._STOP)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user