Categorical
ConfigSpace.hyperparameters.categorical
#
CACHE_ARANGE_CATEGORICAL_SIZE
module-attribute
#
For sizes smaller than this, we cache the arange for faster neighbor generation.
CACHE_NEIGHBORS_CATEGORICAL_SIZE
module-attribute
#
For sizes smaller than this, we cache the possible neighbors for faster neighbor generation.
CategoricalHyperparameter
dataclass
#
CategoricalHyperparameter(
name: str,
choices: Sequence[Any],
default_value: Any | _NotSet = NotSet,
meta: Mapping[Hashable, Any] | None = None,
weights: Sequence[float] | Array[number] | None = None,
)
Bases: Hyperparameter[Any, Any]
A hyperparameter that can take on one of a fixed set of values.
It is assumed there is no inherent order between the choices. If you
know an order exists, use the
OrdinalHyperparameter
instead.
The values are sampled uniformly by default, but can be weighted using the
weights
parameter. The weights
parameter is a list of floats, one for
each choice, that determines the probability of each choice being sampled.
The probabilities are normalized to sum to 1.
PARAMETER | DESCRIPTION |
---|---|
name |
Name of the hyperparameter, with which it can be accessed.
TYPE:
|
choices |
The possible values the hyperparameter can take on. |
default_value |
The default value of this hyperparameter. If |
meta |
Field for holding meta data provided by the user. Not used by ConfigSpace. |
weights |
The weights of the choices. If |
Source code in src/ConfigSpace/hyperparameters/categorical.py
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 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 |
|
LEGAL_VALUE_TYPES
class-attribute
#
The types of values that are legal for this hyperparameter. If set to
"all"
any type is legal. Otherwise, a tuple of types can be provided.
choices
instance-attribute
#
The possible values the hyperparameter can take on.
lower_vectorized
property
#
lower_vectorized: f64
Lower bound of the hyperparameter in vector space.
meta
instance-attribute
#
Field for holding meta data provided by the user. Not used by ConfigSpace.
size
instance-attribute
#
size: int
The number of possible values for the categorical hyperparameter.
upper_vectorized
property
#
upper_vectorized: f64
Upper bound of the hyperparameter in vector space.
weights
instance-attribute
#
The weights of the choices. If None
, the choices are sampled uniformly.
copy
#
copy(**kwargs: Any) -> Self
Create a copy of the hyperparameter with updated attributes.
PARAMETER | DESCRIPTION |
---|---|
**kwargs |
The attributes to update.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Self
|
A copy of the hyperparameter with the updated attributes. |
Source code in src/ConfigSpace/hyperparameters/hyperparameter.py
get_neighbors
#
get_neighbors(
value: f64,
rs: RandomState,
number: int | None = None,
std: float | None = None,
transform: bool = False,
) -> Array[f64]
Deprecated.
Source code in src/ConfigSpace/hyperparameters/hyperparameter.py
get_num_neighbors
#
Get the number of neighbors to sample for a given value.
PARAMETER | DESCRIPTION |
---|---|
value |
The value to get the number of neighbors for. If |
RETURNS | DESCRIPTION |
---|---|
int | float
|
The number of neighbors to sample. |
Source code in src/ConfigSpace/hyperparameters/hyperparameter.py
get_size
#
is_legal
#
is_legal_vector
#
legal_vector
#
Check if a vectorized value is legal for this hyperparameter.
PARAMETER | DESCRIPTION |
---|---|
vector |
The vectorized value to check. |
RETURNS | DESCRIPTION |
---|---|
Mask | bool
|
|
Source code in src/ConfigSpace/hyperparameters/hyperparameter.py
neighbors_values
#
neighbors_values(
value: ValueT | DType,
n: int,
*,
std: float | None = None,
seed: RandomState | None = None
) -> Array[DType]
Sample neighbors of a value.
PARAMETER | DESCRIPTION |
---|---|
value |
The value to sample neighbors from. |
n |
The number of unique neighbors to sample. Warning If there are less than
TYPE:
|
std |
The standard deviation of the neighborhood. If Warning Hyperparameter subclasses are under no obligation to use
this if it does not make sense, i.e. for an
TYPE:
|
seed |
The random state to use for sampling. If
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Array[DType]
|
The sampled neighbors in value space. |
Source code in src/ConfigSpace/hyperparameters/hyperparameter.py
neighbors_vectorized
#
neighbors_vectorized(
vector: Number,
n: int,
*,
std: float | None = None,
seed: RandomState | None = None
) -> Array[f64]
Sample neighbors of a vectorized value.
PARAMETER | DESCRIPTION |
---|---|
vector |
The vectorized value to sample neighbors from.
TYPE:
|
n |
The number of unique neighbors to sample. Warning If there are less than
TYPE:
|
std |
The standard deviation of the neighborhood. If Warning Hyperparameter subclasses are under no obligation to use
this if it does not make sense, i.e. for an
TYPE:
|
seed |
The random state to use for sampling. If
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Array[f64]
|
The sampled neighbors in vectorized space. |
Source code in src/ConfigSpace/hyperparameters/hyperparameter.py
pdf
#
Deprecated.
Source code in src/ConfigSpace/hyperparameters/hyperparameter.py
pdf_vector
#
Get the probability density of an array of vectorized values.
PARAMETER | DESCRIPTION |
---|---|
vector |
The vectorized values to get the probability density of. |
RETURNS | DESCRIPTION |
---|---|
Array[f64]
|
The probability density of the vectorized values. Where vectorized values are not legal, the probability density is zero. |
Source code in src/ConfigSpace/hyperparameters/hyperparameter.py
rvs
#
rvs(
size: int | None = None,
*,
random_state: (
Generator | RandomState | int | None
) = None
) -> ValueT | Array[DType]
Sample a value from this hyperparameter, compatbile with scipy.stats.rvs.
PARAMETER | DESCRIPTION |
---|---|
size |
The number of values to sample. If
TYPE:
|
random_state |
The random state to use for sampling. If
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
ValueT | Array[DType]
|
The sampled value or an array of sampled values, depending on |
Source code in src/ConfigSpace/hyperparameters/hyperparameter.py
sample
#
sample(rs: RandomState) -> ValueT
sample_value
#
sample_value(
size: int | None = None,
*,
seed: RandomState | None = None
) -> ValueT | Array[DType]
Sample a value from this hyperparameter.
PARAMETER | DESCRIPTION |
---|---|
size |
The number of values to sample. If
TYPE:
|
seed |
The random state to use for sampling. If
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
ValueT | Array[DType]
|
The sampled value or an array of sampled values, depending on |
Source code in src/ConfigSpace/hyperparameters/hyperparameter.py
sample_vector
#
sample_vector(
size: int | None = None,
*,
seed: RandomState | None = None
) -> f64 | Array[f64]
Sample a vectorized value from this hyperparameter.
PARAMETER | DESCRIPTION |
---|---|
size |
The number of values to sample. If
TYPE:
|
seed |
The random state to use for sampling. If
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
f64 | Array[f64]
|
The sampled vector or an array of sampled vectors, depending on |
Source code in src/ConfigSpace/hyperparameters/hyperparameter.py
to_uniform
#
to_uniform() -> CategoricalHyperparameter
Converts this hyperparameter to have uniform weights.
Source code in src/ConfigSpace/hyperparameters/categorical.py
to_value
#
Transform a vectorized value to a value in value space.
PARAMETER | DESCRIPTION |
---|---|
vector |
The vectorized value to transform. |
RETURNS | DESCRIPTION |
---|---|
ValueT | Array[DType]
|
The value in value space. |
Source code in src/ConfigSpace/hyperparameters/hyperparameter.py
NeighborhoodCat
dataclass
#
NeighborhoodCat(
size: int,
_cached_arange: Array[f64] | None = None,
_cached_neighbors: list[Array[f64]] | None = None,
)
Bases: Neighborhood
Neighborhood for categorical hyperparameters.
Note
For
CategoricalHyperparameter
,
all values are considered equally distant from each other. Thus, the
possible neighbors is all other values except the current one.