本文整理汇总了Python中cache.Cache.lookup方法的典型用法代码示例。如果您正苦于以下问题:Python Cache.lookup方法的具体用法?Python Cache.lookup怎么用?Python Cache.lookup使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cache.Cache
的用法示例。
在下文中一共展示了Cache.lookup方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Optimizer
# 需要导入模块: from cache import Cache [as 别名]
# 或者: from cache.Cache import lookup [as 别名]
#.........这里部分代码省略.........
def getEvaluator(self, x):
"""
Returns a tuple holding the evaluator function and its positional
arguments that evaluate the problem at *x*. This tuple can be
sent to a remote computing node and evaluation is invoked using::
# Tuple t holds the function and its arguments
func,args=t
retval=func(*args)
# Send retval back to the master
The first positional argument is the point to be evaluated.
The evaluator returns a tuple of the form (f,annotations).
"""
return UCEvaluator, [x, self.function, self.annGrp, self.nanBarrier]
def fun(self, x, count=True):
"""
Evaluates the cost function at *x* (array). If *count* is ``True`` the
:meth:`newResult` method is invoked with *x*, the obtained cost
function value, and *annotations* argument set to ``None``. This means
that the result is registered (best-yet point information are updated),
the plugins are calls and the annotators are invoked to produce
annotations.
Use ``False`` for *count* if you need to evaluate the cost function
for debugging purposes.
Returns the value of the cost function at *x*.
"""
data=None
if self.cache is not None:
data=self.cache.lookup(x)
if data is not None:
f,annot,it=data
else:
# Evaluate
evf, args = self.getEvaluator(x)
f,annot=evf(*args)
# Do the things that need to be done with a new result
# No annotation is provided telling the newResult() method that the
# function evaluation actually happened in this process.
if count:
self.newResult(x, f, annot)
return np.array(f)
def updateBest(self, x, f):
"""
Updates best yet function value.
Returns ``True`` if an update takes place.
"""
if (self.f is None) or (self.f>f):
self.f=f
self.x=x
self.bestIter=self.niter
return True
return False
def newResult(self, x, f, annotations=None):
"""
Registers the cost function value *f* obtained at point *x* with