Пример #1
0
def _constraint_solver(parameter: p.Parameter, budget: int) -> p.Parameter:
    """Runs a suboptimization to solve the parameter constraints"""
    parameter_without_constraint = parameter.copy()
    parameter_without_constraint._constraint_checkers.clear()
    opt = registry["OnePlusOne"](parameter_without_constraint,
                                 num_workers=1,
                                 budget=budget)
    for _ in range(budget):
        cand = opt.ask()
        # Our objective function is minimum for the point the closest to
        # the original candidate under the constraints.
        penalty = sum(
            utils._float_penalty(func(cand.value))
            for func in parameter._constraint_checkers)

        # TODO: this may not scale well with dimension
        distance = np.tanh(
            np.sum(cand.get_standardized_data(reference=parameter)**2))
        # TODO: because of the return whenever constraints are satisfied, the first case never arises
        loss = distance if penalty <= 0 else penalty + distance + 1.0
        opt.tell(cand, loss)
        if penalty <= 0:  # constraints are satisfied
            break
    data = opt.recommend().get_standardized_data(
        reference=parameter_without_constraint)
    return parameter.spawn_child().set_standardized_data(data)
Пример #2
0
def _reset_copy(obj: p.Parameter) -> p.Parameter:
    """Copy a parameter and resets its random state to obtain variability"""
    out = obj.copy()
    out._set_random_state(None)  # propagates None to sub-parameters
    return out
Пример #3
0
def _reset_copy(obj: p.Parameter) -> p.Parameter:
    """Copy a parameter and resets its random state to obtain variability"""
    out = obj.copy()
    out.random_state = None
    return out