File: test_dummy_opt.py

package info (click to toggle)
scikit-optimize 0.10.2-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 7,736 kB
  • sloc: python: 10,668; javascript: 438; makefile: 139; sh: 6
file content (26 lines) | stat: -rw-r--r-- 719 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import pytest

from skopt import dummy_minimize
from skopt.benchmarks import bench1, bench2, bench3


def check_minimize(func, y_opt, dimensions, margin, n_calls):
    r = dummy_minimize(func, dimensions, n_calls=n_calls, random_state=1)
    assert r.fun < y_opt + margin


@pytest.mark.slow_test
def test_dummy_minimize():
    check_minimize(bench1, 0.0, [(-2.0, 2.0)], 0.05, 100)
    check_minimize(bench2, -5, [(-6.0, 6.0)], 0.05, 100)
    check_minimize(bench3, -0.9, [(-2.0, 2.0)], 0.05, 100)


@pytest.mark.fast_test
def test_dummy_categorical_integer():
    def f(params):
        return 0

    dims = [[1]]
    res = dummy_minimize(f, dims, n_calls=1, random_state=1)
    assert res.x_iters[0][0] == dims[0][0]