test_plotting.py
1.27 KB
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
"""
Verify that the plotting routines can at least run.
If environment variable HYPEROPT_SHOW is defined and true,
then the plots actually appear.
"""
from __future__ import print_function
from __future__ import absolute_import
import unittest
import os
try:
import matplotlib
matplotlib.use("svg") # -- prevents trying to connect to X server
except ImportError:
import nose
raise nose.SkipTest()
from hyperopt import Trials
import hyperopt.plotting
from hyperopt import rand, fmin
from .test_domains import many_dists
def get_do_show():
rval = int(os.getenv("HYPEROPT_SHOW", "0"))
print("do_show =", rval)
return rval
class TestPlotting(unittest.TestCase):
def setUp(self):
domain = self.domain = many_dists()
trials = self.trials = Trials()
fmin(
lambda x: x,
space=domain.expr,
trials=trials,
algo=rand.suggest,
max_evals=200,
)
def test_plot_history(self):
hyperopt.plotting.main_plot_history(self.trials, do_show=get_do_show())
def test_plot_histogram(self):
hyperopt.plotting.main_plot_histogram(self.trials, do_show=get_do_show())
def test_plot_vars(self):
hyperopt.plotting.main_plot_vars(self.trials, self.domain)