Ejemplo n.º 1
0
def test_deformatting():
    internal_space = format_search_space(user_space)
    assert deformat_parameters(internal_params_1,
                               internal_space) == user_params_1
    assert deformat_parameters(internal_params_2,
                               internal_space) == user_params_2
    assert deformat_parameters(internal_params_3,
                               internal_space) == user_params_3
Ejemplo n.º 2
0
def _deformat_single_parameter(x, spec):
    if math.isinf(x):
        return x
    spec_dict = spec._asdict()
    spec_dict['key'] = (spec.name,)
    spec = ParameterSpec(**spec_dict)
    params = deformat_parameters({spec.key: x}, {spec.key: spec})
    return params[spec.name]
Ejemplo n.º 3
0
def test_dedup_nested():
    space = format_search_space(nested_space)
    dedup = Deduplicator(space)
    params = set()
    for i in range(10):
        p = dedup(suggest(rng, space))
        s = nni.dump(deformat_parameters(p, space), sort_keys=True)
        assert s not in params
        params.add(s)
Ejemplo n.º 4
0
    def generate_parameters(self, *args, **kwargs):
        while True:
            params = self._suggest()
            if params is None:
                raise nni.NoMoreTrialError('Search space fully explored')
            params = deformat_parameters(params, self.space)

            params_str = nni.dump(params, sort_keys=True)
            if params_str not in self.history:
                self.history.add(params_str)
                return params
Ejemplo n.º 5
0
def test_dedup_finite():
    space = format_search_space(finite_space)
    dedup = Deduplicator(space)
    params = []
    exhausted = False
    try:
        for i in range(7):
            p = dedup(suggest(rng, space))
            params.append(deformat_parameters(p, space))
    except nni.NoMoreTrialError:
        exhausted = True
    params = sorted(params, key=(lambda p: (p['x'], p['y'], p['z'])))
    assert exhausted
    assert params == [
        {
            'x': 'a',
            'y': 0.0,
            'z': 1.0
        },
        {
            'x': 'a',
            'y': 0.6,
            'z': 1.0
        },
        {
            'x': 'a',
            'y': 1.0,
            'z': 1.0
        },
        {
            'x': 'b',
            'y': 0.0,
            'z': 1.0
        },
        {
            'x': 'b',
            'y': 0.6,
            'z': 1.0
        },
        {
            'x': 'b',
            'y': 1.0,
            'z': 1.0
        },
    ]
Ejemplo n.º 6
0
    def generate_parameters(self, parameter_id, **kwargs):
        if self.liar and self._running_params:
            # give a fake loss for each concurrently running paramater set
            history = {
                key: records.copy()
                for key, records in self._history.items()
            }  # copy history
            lie = self.liar.lie()
            for param in self._running_params.values():
                for key, value in param.items():
                    history[key].append(Record(value, lie))
        else:
            history = self._history

        params = suggest(self.args, self.rng, self.space, history)

        self._params[parameter_id] = params
        self._running_params[parameter_id] = params
        return deformat_parameters(params, self.space)
Ejemplo n.º 7
0
 def generate_parameters(self, *args, **kwargs):
     params = suggest(self.rng, self.space)
     params = self.dedup(params)
     return deformat_parameters(params, self.space)