mirror of
https://github.com/wassname/simpeg.git
synced 2026-08-13 12:40:08 +08:00
Moved things around! Packages should now all be capitalized. may need to to tweak git to ensure this...
This commit is contained in:
@@ -0,0 +1,94 @@
|
||||
from SimPEG import Utils, np, sp
|
||||
|
||||
|
||||
class BaseModel(object):
|
||||
"""SimPEG Model"""
|
||||
|
||||
__metaclass__ = Utils.Save.Savable
|
||||
|
||||
counter = None #: A SimPEG.Utils.Counter object
|
||||
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
def transform(self, m):
|
||||
"""
|
||||
:param numpy.array m: model
|
||||
:rtype: numpy.array
|
||||
:return: transformed model
|
||||
|
||||
The *transform* changes the model into the physical property.
|
||||
|
||||
A common example of this is to invert for electrical conductivity
|
||||
in log space. In this case, your model will be log(sigma) and to
|
||||
get back to sigma, you can take the exponential:
|
||||
|
||||
"""
|
||||
return m
|
||||
|
||||
def transformDeriv(self, m):
|
||||
"""
|
||||
:param numpy.array m: model
|
||||
:rtype: scipy.csr_matrix
|
||||
:return: derivative of transformed model
|
||||
|
||||
The *transform* changes the model into the physical property.
|
||||
The *transformDeriv* provides the derivative of the *transform*.
|
||||
"""
|
||||
return sp.identity(m.size)
|
||||
|
||||
def example(self, mesh, type=None):
|
||||
return np.random.rand(mesh.nC)
|
||||
|
||||
|
||||
|
||||
class LogModel(BaseModel):
|
||||
"""SimPEG LogModel"""
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
BaseModel.__init__(self, **kwargs)
|
||||
|
||||
def transform(self, m):
|
||||
"""
|
||||
:param numpy.array m: model
|
||||
:rtype: numpy.array
|
||||
:return: transformed model
|
||||
|
||||
The *transform* changes the model into the physical property.
|
||||
|
||||
A common example of this is to invert for electrical conductivity
|
||||
in log space. In this case, your model will be log(sigma) and to
|
||||
get back to sigma, you can take the exponential:
|
||||
|
||||
.. math::
|
||||
|
||||
m = \log{\sigma}
|
||||
|
||||
\exp{m} = \exp{\log{\sigma}} = \sigma
|
||||
"""
|
||||
return np.exp(Utils.mkvc(m))
|
||||
|
||||
def transformDeriv(self, m):
|
||||
"""
|
||||
:param numpy.array m: model
|
||||
:rtype: scipy.csr_matrix
|
||||
:return: derivative of transformed model
|
||||
|
||||
The *transform* changes the model into the physical property.
|
||||
The *transformDeriv* provides the derivative of the *transform*.
|
||||
|
||||
If the model *transform* is:
|
||||
|
||||
.. math::
|
||||
|
||||
m = \log{\sigma}
|
||||
|
||||
\exp{m} = \exp{\log{\sigma}} = \sigma
|
||||
|
||||
Then the derivative is:
|
||||
|
||||
.. math::
|
||||
|
||||
\\frac{\partial \exp{m}}{\partial m} = \\text{sdiag}(\exp{m})
|
||||
"""
|
||||
return Utils.sdiag(np.exp(Utils.mkvc(m)))
|
||||
Reference in New Issue
Block a user