mirror of
https://github.com/wassname/simpeg.git
synced 2026-07-01 07:45:52 +08:00
change modelObj2Deriv from (self) --> (self, m, v=None)
Had to change location of _bfgsH0 calculation, which now actually works.
This commit is contained in:
@@ -32,12 +32,6 @@ class BaseInversion(object):
|
||||
self.opt.printers.insert(2,IterationPrinters.phi_d)
|
||||
self.opt.printers.insert(3,IterationPrinters.phi_m)
|
||||
|
||||
if not hasattr(opt, '_bfgsH0') and hasattr(opt, 'bfgsH0'): # Check if it has been set by the user and the default is not being used.
|
||||
#TODO: I don't think that this if statement is working...
|
||||
print 'Setting bfgsH0 to the inverse of the modelObj2Deriv. Done using direct methods.'
|
||||
opt.bfgsH0 = SimPEG.Solver(objFunc.reg.modelObj2Deriv())
|
||||
|
||||
|
||||
#TODO: Move this to the data class?
|
||||
@property
|
||||
def phi_d_target(self):
|
||||
|
||||
@@ -97,7 +97,7 @@ class BaseObjFunction(object):
|
||||
if return_H:
|
||||
def H_fun(v):
|
||||
phi_d2Deriv = self.dataObj2Deriv(m, v, u=u)
|
||||
phi_m2Deriv = self.reg.modelObj2Deriv()*v
|
||||
phi_m2Deriv = self.reg.modelObj2Deriv(m, v=v)
|
||||
|
||||
return phi_d2Deriv + self.beta * phi_m2Deriv
|
||||
|
||||
|
||||
+10
-4
@@ -648,10 +648,16 @@ class BFGS(Minimize, Remember):
|
||||
|
||||
Must be a SimPEG.Solver
|
||||
"""
|
||||
_bfgsH0 = getattr(self,'_bfgsH0',None)
|
||||
if _bfgsH0 is None:
|
||||
return Solver(sp.identity(self.xc.size).tocsc(), flag='D')
|
||||
return _bfgsH0
|
||||
if getattr(self,'_bfgsH0',None) is None:
|
||||
# Check if it has been set by the user and the default is not being used.
|
||||
if self.parent is None:
|
||||
self._bfgsH0 = Solver(sp.identity(self.xc.size).tocsc(), flag='D')
|
||||
else:
|
||||
print 'Setting bfgsH0 to the inverse of the modelObj2Deriv. Done using direct methods.'
|
||||
objFunc = self.parent.objFunc
|
||||
self._bfgsH0 = Solver(objFunc.reg.modelObj2Deriv(objFunc.m_current))
|
||||
return self._bfgsH0
|
||||
|
||||
@bfgsH0.setter
|
||||
def bfgsH0(self, value):
|
||||
assert type(value) is Solver, 'bfgsH0 must be a SimPEG.Solver'
|
||||
|
||||
@@ -141,7 +141,7 @@ class BetaEstimate(Parameter):
|
||||
|
||||
x0 = np.random.rand(*m.shape)
|
||||
t = x0.dot(objFunc.dataObj2Deriv(m,x0,u=u))
|
||||
b = x0.dot(objFunc.reg.modelObj2Deriv()*x0)
|
||||
b = x0.dot(objFunc.reg.modelObj2Deriv(m, v=x0))
|
||||
return self.beta0_ratio*(t/b)
|
||||
|
||||
|
||||
|
||||
@@ -79,12 +79,18 @@ class BaseRegularization(object):
|
||||
R(m) = \mathbf{W^\\top W (m-m_\\text{ref})}
|
||||
|
||||
"""
|
||||
return self.W.T * ( self.W * self.model.transform(m - self.mref) )
|
||||
mTd = self.model.transformDeriv(m - self.mref)
|
||||
return mTd.T * ( self.W.T * ( self.W * self.model.transform(m - self.mref) ) )
|
||||
|
||||
@Utils.timeIt
|
||||
def modelObj2Deriv(self):
|
||||
def modelObj2Deriv(self, m, v=None):
|
||||
"""
|
||||
|
||||
:param numpy.array m: geophysical model
|
||||
:param numpy.array v: vector to multiply
|
||||
:rtype: scipy.sparse.csr_matrix or numpy.ndarray
|
||||
:return: WtW or WtW*v
|
||||
|
||||
The regularization is:
|
||||
|
||||
.. math::
|
||||
@@ -98,7 +104,12 @@ class BaseRegularization(object):
|
||||
R(m) = \mathbf{W^\\top W}
|
||||
|
||||
"""
|
||||
return self.W.T * self.W
|
||||
mTd = self.model.transformDeriv(m - self.mref)
|
||||
if v is None:
|
||||
return mTd.T * self.W.T * self.W * mTd
|
||||
|
||||
return mTd.T * ( self.W.T * ( self.W * ( mTd * v) ) )
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user