Skip to content
Snippets Groups Projects
Commit 896b7b4e authored by Bas Nijholt's avatar Bas Nijholt
Browse files

move 'SKOptLearner' test to 'test_skopt_learner.py'

parent f24018d1
No related branches found
No related tags found
No related merge requests found
Pipeline #12186 passed
......@@ -14,12 +14,6 @@ import pytest
from ..learner import *
from ..runner import simple, replay_log
try:
import skopt
with_scikit_optimize = True
except ModuleNotFoundError:
with_scikit_optimize = False
def generate_random_parametrization(f):
"""Return a realization of 'f' with parameters bound to random values.
......@@ -129,24 +123,6 @@ def ask_randomly(learner, rounds, points):
return xs, ls
@pytest.mark.skipif(not with_scikit_optimize,
reason='scikit-optimize is not installed')
def test_skopt_learner_runs():
"""The SKOptLearner provides very few guarantees about its
behaviour, so we only test the most basic usage
"""
def g(x, noise_level=0.1):
return (np.sin(5 * x) * (1 - np.tanh(x ** 2))
+ np.random.randn() * noise_level)
learner = SKOptLearner(g, dimensions=[(-2., 2.)])
for _ in range(11):
(x,), _ = learner.ask(1)
learner.tell(x, learner.function(x))
@run_with(Learner1D)
def test_uniform_sampling1D(learner_type, f, learner_kwargs):
"""Points are sampled uniformly if no data is provided.
......
# -*- coding: utf-8 -*-
import random
import numpy as np
import pytest
try:
import skopt
with_scikit_optimize = True
from ..learner import SKOptLearner
except ModuleNotFoundError:
with_scikit_optimize = False
@pytest.mark.skipif(not with_scikit_optimize,
reason='scikit-optimize is not installed')
def test_skopt_learner_runs():
"""The SKOptLearner provides very few guarantees about its
behaviour, so we only test the most basic usage
"""
def g(x, noise_level=0.1):
return (np.sin(5 * x) * (1 - np.tanh(x ** 2))
+ np.random.randn() * noise_level)
learner = SKOptLearner(g, dimensions=[(-2., 2.)])
for _ in range(11):
(x,), _ = learner.ask(1)
learner.tell(x, learner.function(x))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment