diff --git a/smac/runhistory/runhistory2epm.py b/smac/runhistory/runhistory2epm.py index 598f7f72f..05e23e17d 100644 --- a/smac/runhistory/runhistory2epm.py +++ b/smac/runhistory/runhistory2epm.py @@ -3,6 +3,7 @@ import typing import numpy as np +import scipy as sp from smac.tae.execute_ta_run import StatusType from smac.runhistory.runhistory import RunHistory, RunKey, RunValue @@ -10,13 +11,14 @@ from smac.epm.base_imputor import BaseImputor from smac.utils import constants from smac.scenario.scenario import Scenario +from smac.utils.constants import VERY_SMALL_NUMBER -__author__ = "Katharina Eggensperger" -__copyright__ = "Copyright 2015, ML4AAD" +__author__ = "Katharina Eggensperger, Marius Lindauer" +__copyright__ = "Copyright 2015-2020, AutoML.org" __license__ = "3-clause BSD" __maintainer__ = "Katharina Eggensperger" __email__ = "eggenspk@cs.uni-freiburg.de" -__version__ = "0.0.1" +__version__ = "0.0.3" class AbstractRunHistory2EPM(object): @@ -545,6 +547,57 @@ def transform_response_values(self, values: np.ndarray) -> np.ndarray: return values +class RunHistory2EPM4BiLogCost(RunHistory2EPM4Cost): + """TODO""" + + def transform_response_values(self, values: np.ndarray) -> np.ndarray: + """Transform function response values. + + Transform the response values by using a bilog transformation + + Source: "Scalable Constrained Bayesian Optimization" by Eriksson and Poloczek + https://arxiv.org/pdf/2002.08526.pdf + + Parameters + ---------- + values : np.ndarray + Response values to be transformed. + + Returns + ------- + np.ndarray + """ + return np.sign(values) * np.log(1 + np.abs(values)) + + +class RunHistory2EPM4GaussianCopula(RunHistory2EPM4Cost): + """TODO""" + + def transform_response_values(self, values: np.ndarray) -> np.ndarray: + """Transform function response values. + + Transform the response values by using a Gaussian Copula: + 1. compute quantiles of ECDF on given values + 2. compute inverse Gaussian CDF for these quantiles + + Source: "Scalable Constrained Bayesian Optimization" by Eriksson and Poloczek + https://arxiv.org/pdf/2002.08526.pdf + + Parameters + ---------- + values : np.ndarray + Response values to be transformed. + + Returns + ------- + np.ndarray + """ + # ECDF + quants = [sp.stats.percentileofscore(values, v)/100 - VERY_SMALL_NUMBER for v in values] + # Inverse Gaussian CDF + return np.array([sp.stats.norm.ppf(q) for q in quants]).reshape((-1, 1)) + + class RunHistory2EPM4EIPS(AbstractRunHistory2EPM): """TODO"""