示例#1
0
文件: space.py 项目: obilaniu/orion
def unpack_point(point, space):
    """Flatten `point` in `space` and convert it to a 1D list.

    This function is deprecated and will be removed in v0.2.0. Use
    `orion.core.utils.points.flatten_dims` instead.
    """
    logger.warning(
        "`unpack_point` is deprecated and will be removed in v0.2.0. Use "
        "`orion.core.utils.points.regroup_dims` instead.")
    return flatten_dims(point, space)
示例#2
0
文件: tpe.py 项目: vincehass/orion
    def suggest(self, num=1):
        """Suggest a `num` of new sets of parameters. Randomly draw samples
        from the import space and return them.

        :param num: how many sets to be suggested.

        .. note:: New parameters must be compliant with the problem's domain
           `orion.algo.space.Space`.
        """
        if num > 1:
            raise ValueError("TPE should suggest only one point.")

        samples = []
        if len(self._trials_info) < self.n_initial_points:
            new_point = self.space.sample(1,
                                          seed=tuple(
                                              self.rng.randint(0,
                                                               1000000,
                                                               size=3)))[0]
            samples.append(new_point)
        else:
            point = []
            below_points, above_points = self.split_trials()

            below_points = [
                flatten_dims(point, self.space) for point in below_points
            ]
            above_points = [
                flatten_dims(point, self.space) for point in above_points
            ]
            below_points = list(map(list, zip(*below_points)))
            above_points = list(map(list, zip(*above_points)))

            idx = 0
            for dimension in self.space.values():

                shape = dimension.shape
                if not shape:
                    shape = (1, )

                if dimension.type == 'real':
                    points = self._sample_real_dimension(
                        dimension, shape[0], below_points[idx:idx + shape[0]],
                        above_points[idx:idx + shape[0]])
                elif dimension.type == 'integer' and dimension.prior_name == 'int_uniform':
                    points = self.sample_one_dimension(
                        dimension, shape[0], below_points[idx:idx + shape[0]],
                        above_points[idx:idx + shape[0]],
                        self._sample_int_point)
                elif dimension.type == 'categorical' and dimension.prior_name == 'choices':
                    points = self.sample_one_dimension(
                        dimension, shape[0], below_points[idx:idx + shape[0]],
                        above_points[idx:idx + shape[0]],
                        self._sample_categorical_point)
                elif dimension.type == 'fidelity':
                    # fidelity dimension
                    points = dimension.sample(num)
                else:
                    raise NotImplementedError()

                if len(points) < shape[0]:
                    logger.warning(
                        'TPE failed to sample new point with configuration %s',
                        self.configuration)
                    return None

                idx += shape[0]
                point += points

            point = regroup_dims(point, self.space)
            samples.append(point)

        return samples