forked from automl/SMAC3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
random_epm.py
72 lines (57 loc) · 2.09 KB
/
random_epm.py
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import logging
import numpy as np
from smac.epm.base_epm import AbstractEPM
__author__ = "Katharina Eggensperger"
__copyright__ = "Copyright 2015, ML4AAD"
__license__ = "3-clause BSD"
__maintainer__ = "Katharina Eggensperger"
__email__ = "[email protected]"
__version__ = "0.0.1"
class RandomEPM(AbstractEPM):
"""EPM which returns random values on a call to ``fit``.
Attributes
----------
logger : logging.Logger
rng : np.random.RandomState
"""
def __init__(self, rng: np.random.RandomState, **kwargs):
"""Constructor
Parameters
----------
rng: np.random.RandomState
"""
super().__init__(**kwargs)
self.logger = logging.getLogger(self.__module__ + "." + self.__class__.__name__)
self.rng = rng
def _train(self, X: np.ndarray, Y: np.ndarray, **kwargs):
"""
Pseudo training on X and Y.
Parameters
----------
X : np.ndarray (N, D)
Input data points. The dimensionality of X is (N, D),
with N as the number of points and D is the number of features.
Y : np.ndarray (N, 1)
The corresponding target values.
"""
if not isinstance(X, np.ndarray):
raise NotImplementedError("X has to be of type np.ndarray")
if not isinstance(Y, np.ndarray):
raise NotImplementedError("Y has to be of type np.ndarray")
self.logger.debug("(Pseudo) Fit model to data")
def _predict(self, X: np.ndarray):
"""
Predict means and variances for given X.
Parameters
----------
X : np.ndarray of shape = [n_samples, n_features (config + instance features)]
Returns
-------
means : np.ndarray of shape = [n_samples, n_objectives]
Predictive mean
vars : np.ndarray of shape = [n_samples, n_objectives]
Predictive variance
"""
if not isinstance(X, np.ndarray):
raise NotImplementedError("X has to be of type np.ndarray")
return self.rng.rand(len(X), 1), self.rng.rand(len(X), 1)