Exemplo n.º 1
0
def _init_objective(batch):
    negate, colspec = _objective_colspec(batch)
    try:
        cols = query.parse_colspec(colspec).cols
    except query.ParseError as e:
        raise batch_util.BatchError("cannot parse objective %r: %s" % (colspec, e))
    else:
        if len(cols) > 1:
            raise batch_util.BatchError(
                "invalid objective %r: only one column may " "be specified" % colspec
            )
        return negate, cols[0]
Exemplo n.º 2
0
def _function_dim(func_name, args, flag_name):
    if func_name is None:
        func_name = "uniform"
    if func_name == "uniform":
        return _uniform_dim(args, func_name, flag_name)
    elif func_name == "loguniform":
        return _real_dim(args, "log-uniform", func_name, flag_name)
    raise batch_util.BatchError("unsupported function %r for flag %s" %
                                (func_name, flag_name))
Exemplo n.º 3
0
def _uniform_dim(args, func_name, flag_name):
    from skopt.space import space
    if len(args) == 2:
        dim_args = args
        initial = None
    elif len(args) == 3:
        dim_args = args[:2]
        initial = args[2]
    else:
        raise batch_util.BatchError(
            "%s requires 2 or 3 args, got %r for flag %s" %
            (func_name, args, flag_name))
    return space.check_dimension(dim_args), initial
Exemplo n.º 4
0
 def previous_trials(self, trial_run_id):
     other_trial_runs = _prev_trial_candidates(self.batch, trial_run_id)
     if not other_trial_runs:
         return []
     trials = []
     self.run_index.refresh(other_trial_runs, ["scalar"])
     for run in other_trial_runs:
         loss = self._run_loss(run)
         if loss is None:
             raise batch_util.BatchError(
                 "could not get %r for run %s - quitting" % (self.loss_desc, run.id)
             )
         _try_append_prev_trial(run, self.dim_names, loss, trials)
     return trials
Exemplo n.º 5
0
def _objective_colspec(batch):
    objective = batch.proto_run.get("objective")
    if not objective:
        return 1, "loss"
    elif isinstance(objective, six.string_types):
        return 1, objective
    elif isinstance(objective, dict):
        minimize = objective.get("minimize")
        if minimize:
            return 1, minimize
        maximize = objective.get("maximize")
        if maximize:
            return -1, maximize
    raise batch_util.BatchError("unsupported objective type %r" % objective)
Exemplo n.º 6
0
def _real_dim(args, prior, func_name, flag_name):
    from skopt.space import space
    if len(args) == 2:
        dim_args = args
        initial = None
    elif len(args) == 3:
        dim_args = args[:2]
        initial = args[2]
    else:
        raise batch_util.BatchError(
            "%s requires 2 or 3 args, got %r for flag %s" %
            (func_name, args, flag_name))
    real_init_args = list(dim_args) + [prior]
    return space.Real(*real_init_args), initial