Пример #1
0
    def __init__(
        self,
        points_to_evaluate: Optional[List[Dict]] = None,
        max_concurrent: int = 0,
        constant_grid_search: bool = False,
        random_state: Optional[Union[int, "np_random_generator",
                                     np.random.RandomState]] = None,
    ):
        self._trial_generator = []
        self._iterators = []
        self._trial_iter = None
        self._finished = False
        self._random_state = _BackwardsCompatibleNumpyRng(random_state)

        self._points_to_evaluate = points_to_evaluate or []

        # Unique prefix for all trials generated, e.g., trial ids start as
        # 2f1e_00001, 2f1ef_00002, 2f1ef_0003, etc. Overridable for testing.
        force_test_uuid = os.environ.get("_TEST_TUNE_TRIAL_UUID")
        if force_test_uuid:
            self._uuid_prefix = force_test_uuid + "_"
        else:
            self._uuid_prefix = str(uuid.uuid1().hex)[:5] + "_"

        self._total_samples = 0
        self.max_concurrent = max_concurrent
        self._constant_grid_search = constant_grid_search
        self._live_trials = set()
Пример #2
0
 def sample(
     self,
     domain: "Categorical",
     spec: Optional[Union[List[Dict], Dict]] = None,
     size: int = 1,
     random_state: "RandomState" = None,
 ):
     if not isinstance(random_state, _BackwardsCompatibleNumpyRng):
         random_state = _BackwardsCompatibleNumpyRng(random_state)
     items = random_state.choice(domain.categories, size=size).tolist()
     return items if len(items) > 1 else domain.cast(items[0])
Пример #3
0
 def sample(
     self,
     domain: "Integer",
     spec: Optional[Union[List[Dict], Dict]] = None,
     size: int = 1,
     random_state: "RandomState" = None,
 ):
     if not isinstance(random_state, _BackwardsCompatibleNumpyRng):
         random_state = _BackwardsCompatibleNumpyRng(random_state)
     items = random_state.integers(domain.lower,
                                   domain.upper,
                                   size=size)
     return items if len(items) > 1 else domain.cast(items[0])
Пример #4
0
 def sample(
     self,
     domain: "Float",
     spec: Optional[Union[List[Dict], Dict]] = None,
     size: int = 1,
     random_state: "RandomState" = None,
 ):
     if not isinstance(random_state, _BackwardsCompatibleNumpyRng):
         random_state = _BackwardsCompatibleNumpyRng(random_state)
     assert domain.lower > float("-inf"), "Uniform needs a lower bound"
     assert domain.upper < float("inf"), "Uniform needs a upper bound"
     items = random_state.uniform(domain.lower, domain.upper, size=size)
     return items if len(items) > 1 else domain.cast(items[0])
Пример #5
0
 def sample(
     self,
     spec: Optional[Union[List[Dict], Dict]] = None,
     size: int = 1,
     random_state: "RandomState" = None,
 ):
     if not isinstance(random_state, _BackwardsCompatibleNumpyRng):
         random_state = _BackwardsCompatibleNumpyRng(random_state)
     sampler = self.get_sampler()
     return sampler.sample(self,
                           spec=spec,
                           size=size,
                           random_state=random_state)
Пример #6
0
 def sample(
     self,
     domain: "Float",
     spec: Optional[Union[List[Dict], Dict]] = None,
     size: int = 1,
     random_state: "RandomState" = None,
 ):
     if not isinstance(random_state, _BackwardsCompatibleNumpyRng):
         random_state = _BackwardsCompatibleNumpyRng(random_state)
     assert not domain.lower or domain.lower == float(
         "-inf"), "Normal sampling does not allow a lower value bound."
     assert not domain.upper or domain.upper == float(
         "inf"), "Normal sampling does not allow a upper value bound."
     items = random_state.normal(self.mean, self.sd, size=size)
     return items if len(items) > 1 else domain.cast(items[0])
Пример #7
0
 def sample(
     self,
     domain: Domain,
     spec: Optional[Union[List[Dict], Dict]] = None,
     size: int = 1,
     random_state: "RandomState" = None,
 ):
     if not isinstance(random_state, _BackwardsCompatibleNumpyRng):
         random_state = _BackwardsCompatibleNumpyRng(random_state)
     values = self.sampler.sample(domain,
                                  spec,
                                  size,
                                  random_state=random_state)
     quantized = np.round(np.divide(values, self.q)) * self.q
     if not isinstance(quantized, np.ndarray):
         return domain.cast(quantized)
     return list(quantized)
Пример #8
0
        def sample(
            self,
            domain: "Float",
            spec: Optional[Union[List[Dict], Dict]] = None,
            size: int = 1,
            random_state: "RandomState" = None,
        ):
            if not isinstance(random_state, _BackwardsCompatibleNumpyRng):
                random_state = _BackwardsCompatibleNumpyRng(random_state)
            assert domain.lower > 0, "LogUniform needs a lower bound greater than 0"
            assert (0 < domain.upper < float("inf")
                    ), "LogUniform needs a upper bound greater than 0"
            logmin = np.log(domain.lower) / np.log(self.base)
            logmax = np.log(domain.upper) / np.log(self.base)

            items = self.base**(random_state.uniform(logmin, logmax,
                                                     size=size))
            return items if len(items) > 1 else domain.cast(items[0])