Moved parameters to separate file. Documentation updates.

This commit is contained in:
rowanc1
2014-01-24 09:36:01 -07:00
parent 18476e53c2
commit cae723eb0e
14 changed files with 218 additions and 184 deletions
+2 -83
View File
@@ -1,11 +1,11 @@
from SimPEG import Utils, np, sp
import Utils, Parameters, numpy as np, scipy.sparse as sp
class BaseObjFunction(object):
"""BaseObjFunction(data, reg, **kwargs)"""
__metaclass__ = Utils.Save.Savable
beta = Utils.ParameterProperty('beta', default=1, doc='Regularization trade-off parameter')
beta = Parameters.ParameterProperty('beta', default=1, doc='Regularization trade-off parameter')
debug = False #: Print debugging information
counter = None #: Set this to a SimPEG.Utils.Counter() if you want to count things
@@ -213,84 +213,3 @@ class BaseObjFunction(object):
dmisfit = self.data.prob.Jt_approx(m, self.data.Wd * self.data.Wd * self.data.prob.J_approx(m, v, u=u), u=u)
return dmisfit
class BetaSchedule(Utils.Parameter):
"""BetaSchedule"""
beta0 = 'guess' #: The initial Beta (regularization parameter)
beta0_ratio = 0.1 #: When beta0 is set to 'guess', estimateBeta0 is used with this ratio
coolingFactor = 2.
coolingRate = 3
beta = None #: Beta parameter
def __init__(self, *args, **kwargs):
Utils.Parameter.__init__(self, *args, **kwargs)
Utils.setKwargs(self, **kwargs)
def initialize(self):
self.beta = self.beta0
@Utils.requires('parent')
def nextIter(self):
if self.beta is 'guess':
if self.debug: print 'BetaSchedule is estimating Beta0.'
self.beta = self.estimateBeta0()
opt = self.parent.parent.opt
if opt.iter > 0 and opt.iter % self.coolingRate == 0:
if self.debug: print 'BetaSchedule is cooling Beta. Iteration: %d' % opt.iter
self.beta /= self.coolingFactor
return self.beta
@Utils.requires('parent')
def estimateBeta0(self):
"""estimateBeta0(u=None)
The initial beta is calculated by comparing the estimated
eigenvalues of JtJ and WtW.
To estimate the eigenvector of **A**, we will use one iteration
of the *Power Method*:
.. math::
\mathbf{x_1 = A x_0}
Given this (very course) approximation of the eigenvector,
we can use the *Rayleigh quotient* to approximate the largest eigenvalue.
.. math::
\lambda_0 = \\frac{\mathbf{x^\\top A x}}{\mathbf{x^\\top x}}
We will approximate the largest eigenvalue for both JtJ and WtW, and
use some ratio of the quotient to estimate beta0.
.. math::
\\beta_0 = \gamma \\frac{\mathbf{x^\\top J^\\top J x}}{\mathbf{x^\\top W^\\top W x}}
:param numpy.array u: fields
:param float ratio: desired ratio of the eigenvalues, default is 0.1
:rtype: float
:return: beta0
"""
objFunc = self.parent
data = objFunc.data
m = objFunc.m_current
u = objFunc.u_current
if u is None:
u = data.prob.field(m)
x0 = np.random.rand(*m.shape)
t = x0.dot(objFunc.dataObj2Deriv(m,x0,u=u))
b = x0.dot(objFunc.reg.modelObj2Deriv()*x0)
return self.beta0_ratio*(t/b)