Exemple #1
0
 def _set_reward(self, reward_type, value):
     """Set the gain or loss to the given value."""
     if self._got_reward:
         raise ValueError("only one call to maximize or minimize is allowed")
     if isinstance(value, np.ndarray):
         if len(value.shape) != 1:
             raise ValueError("gain/loss must be a scalar or 1-dimensional array, not {_coconut_format_0}".format(_coconut_format_0=(value)))
         value = tuple(value)
     self._current_example[reward_type] = denumpy_all(value)
     if not self.is_serving:
         self._save_current_data()
Exemple #2
0
    def _set_reward(self, reward_type, value):
        """Set the gain or loss to the given value."""
        if self._got_reward:
            raise ValueError("only one call to maximize or minimize is allowed")
        if isinstance(value, np.ndarray):
            if len(value.shape) != 1:
                raise ValueError("gain/loss must be a scalar or 1-dimensional array, not {_coconut_format_0}".format(_coconut_format_0=(value)))
            value = tuple(value)
        self._current_example[reward_type] = denumpy_all(value)
        if not self.is_serving:
            self._save_current_data()
# _save_current_data ensures that _old_params has already been
#  updated with _new_params, so _new_params can safely be cleared
        self._new_params = {}
Exemple #3
0
    def standardize_args(self, func, args):
        """Standardize param func and args."""
        # denumpy args
        args = denumpy_all(args)

        # detect invalid funcs
        if func not in self.handlers:
            raise ValueError(
                "unknown parameter definition function {_coconut_format_0} (register with bbopt.params.param_processor.register)"
                .format(_coconut_format_0=(func)))

# run handler
        result = self.handlers[func](args)
        args = result if result is not None else args

        # standardize arguments to a list
        return list(args)
Exemple #4
0
 def standardize_kwargs(self, kwargs):
     """Standardizes param keyword args."""
     return fmap(lambda k, v: denumpy_all((k, v)), kwargs)