mirror of
https://github.com/wassname/simpeg.git
synced 2026-09-11 12:44:29 +08:00
to get working..
This commit is contained in:
@@ -105,6 +105,10 @@ class DCProblem(Problem):
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
||||||
|
from SimPEG.regularization import Regularization
|
||||||
|
from SimPEG import inverse
|
||||||
|
|
||||||
# Create the mesh
|
# Create the mesh
|
||||||
h1 = np.ones(100)
|
h1 = np.ones(100)
|
||||||
h2 = np.ones(100)
|
h2 = np.ones(100)
|
||||||
@@ -143,7 +147,7 @@ if __name__ == '__main__':
|
|||||||
dobs, Wd = synthetic.createData(mSynth, std=0.05)
|
dobs, Wd = synthetic.createData(mSynth, std=0.05)
|
||||||
|
|
||||||
u = synthetic.field(mSynth)
|
u = synthetic.field(mSynth)
|
||||||
mesh.plotImage(u[:,10], showIt=True)
|
mesh.plotImage(u[:,10], showIt=False)
|
||||||
|
|
||||||
# Now set up the problem to do some minimization
|
# Now set up the problem to do some minimization
|
||||||
problem = DCProblem(mesh)
|
problem = DCProblem(mesh)
|
||||||
@@ -153,8 +157,15 @@ if __name__ == '__main__':
|
|||||||
problem.dobs = dobs
|
problem.dobs = dobs
|
||||||
m0 = mesh.gridCC[:,0]*0+sig1
|
m0 = mesh.gridCC[:,0]*0+sig1
|
||||||
|
|
||||||
print problem.misfit(m0)
|
# print problem.misfit(m0)
|
||||||
print problem.misfit(mSynth)
|
# print problem.misfit(mSynth)
|
||||||
|
|
||||||
|
opt = inverse.InexactGaussNewton()
|
||||||
|
reg = Regularization(mesh)
|
||||||
|
|
||||||
|
inv = inverse.Inversion(problem, reg, opt)
|
||||||
|
|
||||||
|
inv.run(m0)
|
||||||
|
|
||||||
# Check Derivative
|
# Check Derivative
|
||||||
derChk = lambda m: [problem.misfit(m), problem.misfitDeriv(m)]
|
derChk = lambda m: [problem.misfit(m), problem.misfitDeriv(m)]
|
||||||
@@ -166,3 +177,5 @@ if __name__ == '__main__':
|
|||||||
w = np.random.rand(dobs.shape[0])
|
w = np.random.rand(dobs.shape[0])
|
||||||
print w.dot(problem.J(mSynth, v, u=u))
|
print w.dot(problem.J(mSynth, v, u=u))
|
||||||
print v.dot(problem.Jt(mSynth, w, u=u))
|
print v.dot(problem.Jt(mSynth, w, u=u))
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -62,6 +62,15 @@ class Problem(object):
|
|||||||
def P(self, value):
|
def P(self, value):
|
||||||
self._P = value
|
self._P = value
|
||||||
|
|
||||||
|
@property
|
||||||
|
def std(self):
|
||||||
|
"""
|
||||||
|
Estimated Standard Deviations.
|
||||||
|
"""
|
||||||
|
return self._std
|
||||||
|
@std.setter
|
||||||
|
def std(self, value):
|
||||||
|
self._std = value
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def dobs(self):
|
def dobs(self):
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import numpy as np
|
import numpy as np
|
||||||
|
from SimPEG.utils import sdiag
|
||||||
|
|
||||||
class Inversion(object):
|
class Inversion(object):
|
||||||
"""docstring for Inversion"""
|
"""docstring for Inversion"""
|
||||||
@@ -11,20 +12,18 @@ class Inversion(object):
|
|||||||
self.opt = opt
|
self.opt = opt
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def W(self):
|
def Wd(self):
|
||||||
"""
|
"""
|
||||||
Standard deviation weighting matrix.
|
Standard deviation weighting matrix.
|
||||||
"""
|
"""
|
||||||
return self._W
|
return sdiag(1/self.prob.std)
|
||||||
@W.setter
|
|
||||||
def W(self, value):
|
|
||||||
self._W = value
|
|
||||||
|
|
||||||
def run(self, m0):
|
def run(self, m0):
|
||||||
|
m = m0
|
||||||
self._iter = 0
|
self._iter = 0
|
||||||
while True:
|
while True:
|
||||||
self._beta = self.getBeta()
|
self._beta = self.getBeta()
|
||||||
self.opt.minimize(self.evalFunction,m)
|
m = self.opt.minimize(self.evalFunction,m)
|
||||||
if self.stoppingCriteria(): break
|
if self.stoppingCriteria(): break
|
||||||
self._iter += 1
|
self._iter += 1
|
||||||
|
|
||||||
|
|||||||
@@ -111,13 +111,16 @@ class Minimize(object):
|
|||||||
self._STOP[4] = self._iter >= self.maxIter
|
self._STOP[4] = self._iter >= self.maxIter
|
||||||
return all(self._STOP[0:3]) | any(self._STOP[3:])
|
return all(self._STOP[0:3]) | any(self._STOP[3:])
|
||||||
|
|
||||||
|
def projection(self, p):
|
||||||
|
return p
|
||||||
|
|
||||||
def linesearch(self, p):
|
def linesearch(self, p):
|
||||||
# Armijo linesearch
|
# Armijo linesearch
|
||||||
descent = np.inner(self.g, p)
|
descent = np.inner(self.g, p)
|
||||||
t = 1
|
t = 1
|
||||||
iterLS = 0
|
iterLS = 0
|
||||||
while iterLS < self.maxIterLS:
|
while iterLS < self.maxIterLS:
|
||||||
xt = self.xc + t*p
|
xt = self.projection(self.xc + t*p)
|
||||||
ft = self.evalFunction(xt, return_g=False, return_H=False)
|
ft = self.evalFunction(xt, return_g=False, return_H=False)
|
||||||
if ft < self.f + t*self.LSreduction*descent:
|
if ft < self.f + t*self.LSreduction*descent:
|
||||||
break
|
break
|
||||||
|
|||||||
@@ -1 +1,2 @@
|
|||||||
from Optimize import *
|
from Optimize import *
|
||||||
|
from Inversion import *
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
from Regularization import Regularization
|
||||||
Reference in New Issue
Block a user