def _find_similar_experiments(self):
        """After locating similar experiments by way of the parent's :meth:`_find_similar_experiments`, fit :attr:`optimizer`
        with the hyperparameters and results of each located experiment"""
        super()._find_similar_experiments()

        for _i, _experiment in enumerate(self.similar_experiments[::-1]):
            _hyperparameters = dimension_subset(
                _experiment[0], self.hyperparameter_space.get_names())
            _evaluation = _experiment[1]
            _experiment_id = _experiment[2] if len(_experiment) > 2 else None
            self.logger.print_result(_hyperparameters,
                                     _evaluation,
                                     experiment_id=_experiment_id)

            # FLAG: Resolve switching between below options depending on `target_metric`
            # self.optimizer_result = self.optimizer.tell(_hyperparameters, _evaluation)
            self.optimizer_result = self.optimizer.tell(
                _hyperparameters, -_evaluation)
            # FLAG: Resolve switching between above options depending on `target_metric`

            # self.optimizer_result = self.optimizer.tell(
            #     _hyperparameters, _evaluation, fit=(_i == len(self.similar_experiments) - 1))

            if eval_callbacks(self.callbacks, self.optimizer_result):
                return self.optimizer_result
def filter_by_space(hyperparameters_and_scores, hyperparameter_space):
    """Reject any `hyperparameters_and_scores` tuples whose hyperparameters do not fit within
    `hyperparameter_space`

    Parameters
    ----------
    hyperparameters_and_scores: List of tuples
        Each tuple in list should be a pair of form (hyperparameters <dict>, evaluation <float>),
        where the hyperparameter dict should contain at least the following keys:
        ['model_init_params', 'model_extra_params', 'preprocessing_pipeline',
        'preprocessing_params', 'feature_selector']
    hyperparameter_space: instance of :class:`space.Space`
        The boundaries of the hyperparameters to be searched

    Returns
    -------
    hyperparameters_and_scores: List of tuples
        Filtered to include only those whose hyperparameters fit within `hyperparameter_space`"""
    dimension_names = hyperparameter_space.names()
    hyperparameters_and_scores = list(
        filter(
            lambda _: dimension_subset(_[0], dimension_names) in
            hyperparameter_space,
            hyperparameters_and_scores,
        ))

    return hyperparameters_and_scores
    def _find_similar_experiments(self):
        """After locating similar experiments by way of the parent's
        :meth:`_find_similar_experiments`, fit :attr:`optimizer` with the hyperparameters and
        results of each located experiment"""
        super()._find_similar_experiments()

        # TODO: Remove below reversal of `similar_experiments` when `result_reader.ResultFinder.sort` finished
        for _i, _experiment in enumerate(self.similar_experiments[::-1]):
            _hyperparameters = dimension_subset(_experiment[0], self.space.names())
            _evaluation = _experiment[1]
            _experiment_id = _experiment[2] if len(_experiment) > 2 else None
            self.logger.print_result(_hyperparameters, _evaluation, experiment_id=_experiment_id)
            self._update_optimizer(_hyperparameters, _evaluation)

            # self.optimizer_result = self.optimizer.tell(
            #     _hyperparameters, _evaluation, fit=(_i == len(self.similar_experiments) - 1))

            if eval_callbacks(self.callbacks, self.optimizer_result):
                return self.optimizer_result
def does_fit_in_space(root, space):
    """Determine if the subset of `root` identified by `space` fits within dimensions of `space`

    Parameters
    ----------
    root: Object
        Iterable, whose values at the locations specified in `space` will be checked. For each
        dimension in `space`, the dimension's `location`/`name` is looked up in `root`, and the
        value is tested to see if it falls within the dimension's range of allowed values
    space: `space.Space`
        Instance of :class:`space.Space` that defines dimension choices for select hyperparameters.
        Each dimension in `space` should have an appropriate `name` (or `location`, if necessary)
        attribute to match `root`

    Returns
    -------
    Boolean
        True if `root` subset (at `space` locations) fits in `space` dimensions. Else, False"""
    return dimension_subset(root, space.names()) in space