-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add space filling sobol sequence based optimizer (#51)
* add space filling sobol sequence based optimizer Signed-off-by: Grossberger Lukas (CR/PJ-AI-R32) <Lukas.Grossberger@de.bosch.com>
- Loading branch information
Showing
4 changed files
with
288 additions
and
216 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# Copyright (c) 2020 - for information on the respective copyright owner | ||
# see the NOTICE file and/or the repository https://github.com/boschresearch/blackboxopt | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
from typing import List | ||
|
||
try: | ||
from scipy.stats.qmc import Sobol | ||
except ImportError as e: | ||
raise ImportError( | ||
"Unable to import SpaceFilling optimizer specific dependencies. " | ||
+ "Make sure to install blackboxopt[space-fill]" | ||
) from e | ||
from blackboxopt.base import MultiObjectiveOptimizer, Objective, SearchSpace | ||
from blackboxopt.evaluation import EvaluationSpecification | ||
|
||
|
||
class SpaceFilling(MultiObjectiveOptimizer): | ||
"""Sobol sequence based, space filling optimizer. | ||
Args: | ||
search_space: The search space to optimize | ||
objectives: The objectives of the optimization | ||
seed: The sobol sequence is Owen scrambled and can be seeded for reproducibility | ||
""" | ||
|
||
def __init__( | ||
self, search_space: SearchSpace, objectives: List[Objective], seed: int = None | ||
) -> None: | ||
super().__init__(search_space=search_space, objectives=objectives, seed=seed) | ||
self.sobol = Sobol(d=len(self.search_space), scramble=True, seed=seed) | ||
|
||
def generate_evaluation_specification(self) -> EvaluationSpecification: | ||
vector = self.sobol.random().flatten() | ||
configuration = self.search_space.from_numerical(vector) | ||
return EvaluationSpecification(configuration=configuration) |
Oops, something went wrong.