more rules to directive changes.

This commit is contained in:
rowanc1
2014-05-16 12:27:58 -07:00
parent 7b22d0aa7a
commit ea5ad4dd34
3 changed files with 31 additions and 27 deletions
+15 -15
View File
@@ -42,13 +42,13 @@ class InversionDirective(object):
class DirectiveList(object):
rList = None #: The list of Directives
dList = None #: The list of Directives
def __init__(self, *rules, **kwargs):
self.rList = []
for r in rules:
assert isinstance(r, InversionDirective), 'All rules must be InversionDirectives not %s' % r.__name__
self.rList.append(r)
def __init__(self, *directives, **kwargs):
self.dList = []
for d in directives:
assert isinstance(d, InversionDirective), 'All directives must be InversionDirectives not %s' % d.__name__
self.dList.append(d)
Utils.setKwargs(self, **kwargs)
@property
@@ -56,8 +56,8 @@ class DirectiveList(object):
return getattr(self, '_debug', False)
@debug.setter
def debug(self, value):
for r in self.rList:
r.debug = value
for d in self.dList:
d.debug = value
self._debug = value
@property
@@ -69,18 +69,18 @@ class DirectiveList(object):
if self.inversion is i: return
if getattr(self,'_inversion',None) is not None:
print 'Warning: %s has switched to a new inversion.' % self.__name__
for r in self.rList:
r.inversion = i
for d in self.dList:
d.inversion = i
self._inversion = i
def call(self, ruleType):
if self.rList is None:
if self.debug: 'DirectiveList is None, no rules to call!'
if self.dList is None:
if self.debug: 'DirectiveList is None, no directives to call!'
return
rules = ['initialize', 'endIter', 'finish']
assert ruleType in rules, 'Directive type must be in ["%s"]' % '", "'.join(rules)
for r in self.rList:
directives = ['initialize', 'endIter', 'finish']
assert ruleType in directives, 'Directive type must be in ["%s"]' % '", "'.join(directives)
for r in self.dList:
getattr(r, ruleType)()
+12 -12
View File
@@ -17,16 +17,16 @@ class BaseInversion(object):
counter = None #: Set this to a SimPEG.Utils.Counter() if you want to count things
@property
def ruleList(self):
if getattr(self,'_ruleList', None) is None:
self._ruleList = Directives.DirectiveList(inversion=self)
return self._ruleList
def directiveList(self):
if getattr(self,'_directiveList', None) is None:
self._directiveList = Directives.DirectiveList(inversion=self)
return self._directiveList
@ruleList.setter
def ruleList(self, value):
assert isinstance(value, Directives.DirectiveList), 'Must be a RuleList'
self._ruleList = value
self._ruleList.inversion = self
@directiveList.setter
def directiveList(self, value):
assert isinstance(value, Directives.DirectiveList), 'Must be a DirectiveList'
self._directiveList = value
self._directiveList.inversion = self
def __init__(self, objFunc, opt, **kwargs):
Utils.setKwargs(self, **kwargs)
@@ -54,11 +54,11 @@ class BaseInversion(object):
"""
self.objFunc.startup(m0)
self.ruleList.call('initialize')
self.directiveList.call('initialize')
self.m = self.opt.minimize(self.objFunc.evalFunction, m0)
self.ruleList.call('finish')
self.directiveList.call('finish')
return self.m
def _optCallback(self, xt):
self.ruleList.call('endIter')
self.directiveList.call('endIter')
+4
View File
@@ -236,6 +236,10 @@ class Fields(object):
allFields = [k for k in self.knownFields] + [a for a in self.aliasFields]
assert len(allFields) == len(set(allFields)), 'Aliased fields and Known Fields have overlapping definitions.'
self.startup()
def startup(self):
pass
@property
def approxSize(self):