def SetReducer(self, reducer, arraylike=False): """apply a reducer function to the cost function input:: - a reducer function of the form: y' = reducer(yk), where yk is a results vector and y' is a single value. Ideally, this method is applied to a cost function with a multi-value return, to reduce the output to a single value. If arraylike, the reducer provided should take a single array as input and produce a scalar; otherwise, the reducer provided should meet the requirements of the python's builtin 'reduce' method (e.g. lambda x,y: x+y), taking two scalars and producing a scalar.""" if not reducer: self._reducer = None elif not isinstance(reducer, collections.Callable): raise TypeError("'%s' is not a callable function" % reducer) elif not arraylike: self._reducer = wrap_reducer(reducer) else: #XXX: check if is arraylike? self._reducer = reducer return self._update_objective()
def SetReducer(self, reducer, arraylike=False): """apply a reducer function to the cost function input:: - a reducer function of the form: y' = reducer(yk), where yk is a results vector and y' is a single value. Ideally, this method is applied to a cost function with a multi-value return, to reduce the output to a single value. If arraylike, the reducer provided should take a single array as input and produce a scalar; otherwise, the reducer provided should meet the requirements of the python's builtin 'reduce' method (e.g. lambda x,y: x+y), taking two scalars and producing a scalar.""" if not reducer: self._reducer = None elif not callable(reducer): raise TypeError, "'%s' is not a callable function" % reducer elif not arraylike: self._reducer = wrap_reducer(reducer) else: #XXX: check if is arraylike? self._reducer = reducer return