Skip to content

Commit

Permalink
Version 1.3.4 (#857)
Browse files Browse the repository at this point in the history
* Added reference to JMLR paper.
* Typos in documentations.
* Code more readable since all typings are imported at the beginning of the file.
* Updated stale bot options.

Co-authored-by: eddiebergman <[email protected]>
Co-authored-by: Carolin Benjamins <[email protected]>
Co-authored-by: Matthias Feurer <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
  • Loading branch information
5 people authored Jun 23, 2022
1 parent fc2fc14 commit 99d1129
Show file tree
Hide file tree
Showing 48 changed files with 378 additions and 376 deletions.
9 changes: 9 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
version: 2

updates:
# This will check for updates to github actions every day
# https://docs.github.com/en/[email protected]/code-security/dependabot/working-with-dependabot/keeping-your-actions-up-to-date-with-dependabot
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "daily"
11 changes: 8 additions & 3 deletions .github/stale.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,16 @@ daysUntilClose: 7

# Issues with these labels will never be considered stale
exemptLabels:
- pinned
- security
- bug
- dependency
- documentation
- enhancement
- feature
- test
- example

# Label to use when marking an issue as stale
staleLabel: wontfix
staleLabel: stale

# Comment to post when marking an issue as stale. Set to `false` to disable
markComment: >
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/citation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Check out a copy of the repository
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Check whether the citation metadata from CITATION.cff is valid
uses: citation-file-format/[email protected]
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/dist.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Setup Python
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: "3.9"

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Setup Python
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: "3.9"

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ jobs:
fail-fast: false

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Setup Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
submodules: recursive

- name: Setup Python 3.9
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: 3.9

Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Setup Python
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

Expand Down Expand Up @@ -101,7 +101,7 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Conda install
uses: conda-incubator/setup-miniconda@v2
Expand Down Expand Up @@ -137,10 +137,10 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Setup Python
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

Expand Down
32 changes: 12 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,20 +66,10 @@ X_val, y_val = np.random.randint(2, size=(5, 2)), np.random.randint(2, size=5)


def train_random_forest(config):
"""
Trains a random forest on the given hyperparameters, defined by config, and returns the accuracy
on the validation data.
Input:
config (Configuration): Configuration object derived from ConfigurationSpace.
Return:
cost (float): Performance measure on the validation data.
"""
model = RandomForestClassifier(max_depth=config["depth"])
model.fit(X_train, y_train)

# define the evaluation metric as return
# Define the evaluation metric as return
return 1 - model.score(X_val, y_val)


Expand Down Expand Up @@ -125,16 +115,18 @@ Freiburg](http://www.automl.org/).
If you have found a bug, please report to [issues](https://github.com/automl/SMAC3/issues). Moreover, we are appreciating any kind of help.
Find our guidlines for contributing to this package [here](https://github.com/automl/SMAC3/blob/master/.github/CONTRIBUTING.md).

If you use SMAC in one of your research projects, please cite us:
If you use SMAC in one of your research projects, please cite our [JMLR paper](https://jmlr.org/papers/v23/21-0888.html):
```
@misc{lindauer2021smac3,
title={SMAC3: A Versatile Bayesian Optimization Package for Hyperparameter Optimization},
author={Marius Lindauer and Katharina Eggensperger and Matthias Feurer and André Biedenkapp and Difan Deng and Carolin Benjamins and Tim Ruhkopf and René Sass and Frank Hutter},
year={2021},
eprint={2109.09831},
archivePrefix={arXiv},
primaryClass={cs.LG}
@article{JMLR:v23:21-0888,
author = {Marius Lindauer and Katharina Eggensperger and Matthias Feurer and André Biedenkapp and Difan Deng and Carolin Benjamins and Tim Ruhkopf and René Sass and Frank Hutter},
title = {SMAC3: A Versatile Bayesian Optimization Package for Hyperparameter Optimization},
journal = {Journal of Machine Learning Research},
year = {2022},
volume = {23},
number = {54},
pages = {1--9},
url = {http://jmlr.org/papers/v23/21-0888.html}
}
```

Copyright (C) 2016-2021 [AutoML Group](http://www.automl.org/).
Copyright (C) 2016-2022 [AutoML Group](http://www.automl.org/).
7 changes: 7 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# 1.3.4
* Added reference to JMLR paper.
* Typos in documentations.
* Code more readable since all typings are imported at the beginning of the file.
* Updated stale bot options.


# 1.3.3
* Hotfix: Since multi-objective implementation depends on normalized costs, it now is ensured that the
cached costs are updated everytime a new entry is added.
Expand Down
12 changes: 6 additions & 6 deletions docs/details/callbacks.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ How to add a new callback
^^^^^^^^^^^^^^^^^^^^^^^^^

* Implement a callback class in ``smac/callbacks.py``. There are no restrictions on how such a
callback must look like, but it is recommended to implement the main logic inside the `__call__`
function, such as for example in ``IncorporateRunResultCallback``.
callback must look like, but it is recommended to implement the main logic inside the `__call__`
function, such as for example in ``IncorporateRunResultCallback``.

* Add your callback to ``smac.smbo.optimizer.SMBO._callbacks``, using the name of your callback
as the key, and an empty list as the value.
as the key, and an empty list as the value.

* Add your callback to ``smac.smbo.optimizer.SMBO._callback_to_key``, using the callback class as
the key, and the name as value (the name used in 2.).
the key, and the name as value (the name used in 2.).

* Implement calling all registered callbacks at the correct place. This is as simple as
``for callback in self._callbacks['your_callback']: callback(*args, **kwargs)``, where you
obviously need to change the callback name and signature.
``for callback in self._callbacks['your_callback']: callback(*args, **kwargs)``, where you
obviously need to change the callback name and signature.
2 changes: 1 addition & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ efficiently decide which of two configurations performs better.
SMAC3 is written in Python3 and continuously tested with Python 3.7, 3.8 and 3.9. Its Random
Forest is written in C++. In further texts, SMAC is representatively mentioned for SMAC3.

If you use SMAC, please cite our paper:
If you use SMAC, please cite our `JMLR paper <https://jmlr.org/papers/v23/21-0888.html>`_:

.. code-block:: text
Expand Down
22 changes: 13 additions & 9 deletions examples/python/plot_svm_eips.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,25 @@
logging.basicConfig(level=logging.INFO)

import numpy as np
from ConfigSpace.hyperparameters import (
CategoricalHyperparameter,
UniformFloatHyperparameter,
)
from sklearn import datasets, svm
from sklearn.model_selection import cross_val_score

from ConfigSpace.hyperparameters import UniformFloatHyperparameter, CategoricalHyperparameter

from smac.configspace import ConfigurationSpace
from smac.epm.uncorrelated_mo_rf_with_instances import (
UncorrelatedMultiObjectiveRandomForestWithInstances,
)
from smac.facade.smac_ac_facade import SMAC4AC

# Import SMAC-utilities
from smac.scenario.scenario import Scenario

# EIPS related
from smac.optimizer.acquisition import EIPS
from smac.runhistory.runhistory2epm import RunHistory2EPM4EIPS
from smac.epm.uncorrelated_mo_rf_with_instances import UncorrelatedMultiObjectiveRandomForestWithInstances

# Import SMAC-utilities
from smac.scenario.scenario import Scenario

__copyright__ = "Copyright 2021, AutoML.org Freiburg-Hannover"
__license__ = "3-clause BSD"
Expand Down Expand Up @@ -91,10 +95,10 @@ def svm_from_cfg(cfg):
# It returns: Status, Cost, Runtime, Additional Infos
def_value = svm_from_cfg(cs.get_default_configuration())
print("Default Value: %.2f" % def_value)

# Optimize, using a SMAC-object
print("Optimizing! Depending on your machine, this might take a few minutes.")

# Besides the kwargs used for initializing UncorrelatedMultiObjectiveRandomForestWithInstances,
# we also need kwargs for initializing the model insides UncorrelatedMultiObjectiveModel
model_kwargs = {"target_names": ["loss", "time"], "model_kwargs": {"seed": 1}}
Expand All @@ -105,7 +109,7 @@ def svm_from_cfg(cfg):
model_kwargs=model_kwargs,
tae_runner=svm_from_cfg,
acquisition_function=EIPS,
runhistory2epm=RunHistory2EPM4EIPS
runhistory2epm=RunHistory2EPM4EIPS,
)

incumbent = smac.optimize()
Expand Down
14 changes: 0 additions & 14 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,6 @@


def read_file(filepath: str) -> str:
"""
Read in a files contents
Parameters
----------
filepath : str
The name of the file.
Returns
-------
str
The contents of the file.
"""

with open(filepath, "r", encoding="utf-8") as fh:
return fh.read()

Expand Down
2 changes: 1 addition & 1 deletion smac/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
Matthias Feurer, André Biedenkapp, Difan Deng, Carolin Benjamins, Tim Ruhkopf, René Sass
and Frank Hutter
"""
version = "1.3.3"
version = "1.3.4"


if os.name != "posix":
Expand Down
2 changes: 1 addition & 1 deletion smac/epm/base_uncorrelated_mo_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def _predict(self, X: np.ndarray, cov_return_type: Optional[str] = "diagonal_cov
----------
X : np.ndarray of shape = [n_samples, n_features (config + instance
features)]
cov_return_type: typing.Optional[str]
cov_return_type: Optional[str]
Specifies what to return along with the mean. Refer ``predict()`` for more information.
Returns
Expand Down
24 changes: 12 additions & 12 deletions smac/epm/gaussian_process_mcmc.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import typing
from typing import List, Optional, Tuple, Union, cast

import logging
import warnings
Expand Down Expand Up @@ -74,8 +74,8 @@ class GaussianProcessMCMC(BaseModel):
def __init__(
self,
configspace: ConfigurationSpace,
types: typing.List[int],
bounds: typing.List[typing.Tuple[float, float]],
types: List[int],
bounds: List[Tuple[float, float]],
seed: int,
kernel: Kernel,
n_mcmc_walkers: int = 20,
Expand All @@ -84,8 +84,8 @@ def __init__(
normalize_y: bool = True,
mcmc_sampler: str = "emcee",
average_samples: bool = False,
instance_features: typing.Optional[np.ndarray] = None,
pca_components: typing.Optional[int] = None,
instance_features: Optional[np.ndarray] = None,
pca_components: Optional[int] = None,
):
super().__init__(
configspace=configspace,
Expand All @@ -101,7 +101,7 @@ def __init__(
self.chain_length = chain_length
self.burned = False
self.burnin_steps = burnin_steps
self.models = [] # type: typing.List[GaussianProcess]
self.models = [] # type: List[GaussianProcess]
self.normalize_y = normalize_y
self.mcmc_sampler = mcmc_sampler
self.average_samples = average_samples
Expand Down Expand Up @@ -155,15 +155,15 @@ def _train(self, X: np.ndarray, y: np.ndarray, do_optimize: bool = True) -> "Gau
# Initialize the walkers by sampling from the prior
dim_samples = []

prior = None # type: typing.Optional[typing.Union[typing.List[Prior], Prior]]
prior = None # type: Optional[Union[List[Prior], Prior]]
for dim, prior in enumerate(self._all_priors):
# Always sample from the first prior
if isinstance(prior, list):
if len(prior) == 0:
prior = None
else:
prior = prior[0]
prior = typing.cast(typing.Optional[Prior], prior)
prior = cast(Optional[Prior], prior)
if prior is None:
raise NotImplementedError()
else:
Expand Down Expand Up @@ -325,7 +325,7 @@ def _ll(self, theta: np.ndarray) -> float:
else:
return lml

def _ll_w_grad(self, theta: np.ndarray) -> typing.Tuple[float, np.ndarray]:
def _ll_w_grad(self, theta: np.ndarray) -> Tuple[float, np.ndarray]:
"""Returns the marginal log likelihood (+ the prior) for a hyperparameter configuration
theta.
Expand Down Expand Up @@ -375,8 +375,8 @@ def _ll_w_grad(self, theta: np.ndarray) -> typing.Tuple[float, np.ndarray]:
return lml, grad

def _predict(
self, X_test: np.ndarray, cov_return_type: typing.Optional[str] = "diagonal_cov"
) -> typing.Tuple[np.ndarray, np.ndarray]:
self, X_test: np.ndarray, cov_return_type: Optional[str] = "diagonal_cov"
) -> Tuple[np.ndarray, np.ndarray]:
r"""
Returns the predictive mean and variance of the objective function
at X average over all hyperparameter samples.
Expand All @@ -389,7 +389,7 @@ def _predict(
----------
X_test: np.ndarray (N, D)
Input test points
cov_return_type: typing.Optional[str]
cov_return_type: Optional[str]
Specifies what to return along with the mean. Refer ``predict()`` for more information.
Returns
Expand Down
Loading

0 comments on commit 99d1129

Please sign in to comment.