hyperlight
HyperLight
¶
Hyperparameter Tuning for Lightning.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
seed |
int
|
seed for the random number generator. See Numpy Random Sampling. |
126
|
log_level |
int
|
log level for the logger. |
50
|
Attributes:
Name | Type | Description |
---|---|---|
seed |
int
|
seed for the random number generator. |
rng |
Generator
|
random number generator. |
fun_control |
dict
|
dictionary containing control parameters for the hyperparameter tuning. |
log_level |
int
|
log level for the logger. |
Examples:
>>> hyper_light = HyperLight(seed=126, log_level=50)
>>> print(hyper_light.seed)
126
Source code in spotpython/fun/hyperlight.py
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 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
|
check_X_shape(X, fun_control)
¶
Checks the shape of the input array X and raises an exception if it is not valid.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
X |
ndarray
|
input array. |
required |
fun_control |
dict
|
dictionary containing control parameters for the hyperparameter tuning. |
required |
Returns:
Type | Description |
---|---|
ndarray
|
np.ndarray: input array with valid shape. |
Raises:
Type | Description |
---|---|
Exception
|
if the shape of the input array is not valid. |
Examples:
>>> import numpy as np
from spotpython.utils.init import fun_control_init
from spotpython.light.regression.netlightregression import NetLightRegression
from spotpython.hyperdict.light_hyper_dict import LightHyperDict
from spotpython.hyperparameters.values import add_core_model_to_fun_control
from spotpython.fun.hyperlight import HyperLight
from spotpython.hyperparameters.values import get_var_name
fun_control = fun_control_init()
add_core_model_to_fun_control(core_model=NetLightRegression,
fun_control=fun_control,
hyper_dict=LightHyperDict)
hyper_light = HyperLight(seed=126, log_level=50)
n_hyperparams = len(get_var_name(fun_control))
# generate a random np.array X with shape (2, n_hyperparams)
X = np.random.rand(2, n_hyperparams)
X == hyper_light.check_X_shape(X, fun_control)
array([[ True, True, True, True, True, True, True, True, True],
[ True, True, True, True, True, True, True, True, True]])
Source code in spotpython/fun/hyperlight.py
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 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
|
fun(X, fun_control=None)
¶
Evaluates the function for the given input array X and control parameters.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
X |
ndarray
|
input array. |
required |
fun_control |
dict
|
dictionary containing control parameters for the hyperparameter tuning. |
None
|
Returns:
Type | Description |
---|---|
ndarray
|
array containing the evaluation results. |
Examples:
>>> from spotpython.utils.init import fun_control_init
from spotpython.light.regression.netlightregression import NetLightRegression
from spotpython.hyperdict.light_hyper_dict import LightHyperDict
from spotpython.hyperparameters.values import (add_core_model_to_fun_control,
get_default_hyperparameters_as_array)
from spotpython.fun.hyperlight import HyperLight
from spotpython.data.diabetes import Diabetes
from spotpython.hyperparameters.values import set_control_key_value
import numpy as np
fun_control = fun_control_init(
_L_in=10,
_L_out=1,)
dataset = Diabetes()
set_control_key_value(control_dict=fun_control,
key="data_set",
value=dataset)
add_core_model_to_fun_control(core_model=NetLightRegression,
fun_control=fun_control,
hyper_dict=LightHyperDict)
hyper_light = HyperLight(seed=126, log_level=50)
X = get_default_hyperparameters_as_array(fun_control)
# combine X and X to a np.array with shape (2, n_hyperparams)
# so that two values are returned
X = np.vstack((X, X))
hyper_light.fun(X, fun_control)
array([27462.84179688, 20990.08007812])
Source code in spotpython/fun/hyperlight.py
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
|