Util
ConfigSpace.util
#
deactivate_inactive_hyperparameters
#
deactivate_inactive_hyperparameters(
configuration: dict,
configuration_space: ConfigurationSpace,
vector: None | ndarray = None,
) -> Configuration
Remove inactive hyperparameters from a given configuration.
PARAMETER | DESCRIPTION |
---|---|
configuration |
a configuration as a dictionary.
TYPE:
|
configuration_space |
The defined configuration space. It is necessary to find the inactive hyperparameters by iterating through the conditions of the configuration space.
TYPE:
|
vector |
fficient represantation of a configuration. Either
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Configuration
|
A configuration that is equivalent to the given configuration, except that inactivate hyperparameters have been removed. |
Source code in src/ConfigSpace/util.py
433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 |
|
fix_types
#
fix_types(
configuration: dict[str, Any],
configuration_space: ConfigurationSpace,
) -> dict[str, Any]
Iterate over all hyperparameters in the ConfigSpace and fix the types of the parameter values in configuration.
configuration: A configuration as a dictionary.
* Key: name of the hyperparameter.
* Value: value of this hyperparamter
configuration_space
Configuration space which knows the types for all parameter values
RETURNS | DESCRIPTION |
---|---|
dict[str, Any]
|
Configuration with fixed types of parameter values |
Source code in src/ConfigSpace/util.py
generate_grid
#
generate_grid(
configuration_space: ConfigurationSpace,
num_steps_dict: dict[str, int] | None = None,
) -> list[Configuration]
Generates a grid of Configurations for a given ConfigurationSpace. Can be used, for example, for grid search.
configuration_spac: The Configuration space over which to create a grid of HyperParameter Configuration values. It knows the types for all parameter values.
num_steps_dic
A dict containing the number of points to divide the grid side formed by Hyperparameters which are either of type UniformFloatHyperparameter or type UniformIntegerHyperparameter. The keys in the dict should be the names of the corresponding Hyperparameters and the values should be the number of points to divide the grid side formed by the corresponding Hyperparameter in to.
RETURNS | DESCRIPTION |
---|---|
list[Configuration]
|
List containing Configurations. It is a cartesian product of tuples of HyperParameter values. Each tuple lists the possible values taken by the corresponding HyperParameter. Within the cartesian product, in each element, the ordering of HyperParameters is the same for the OrderedDict within the ConfigurationSpace. |
Source code in src/ConfigSpace/util.py
647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 |
|
get_one_exchange_neighbourhood
#
get_one_exchange_neighbourhood(
configuration: Configuration,
seed: int | RandomState,
num_neighbors: int = 4,
stdev: float = 0.2,
) -> Iterator[Configuration]
Return all configurations in a one-exchange neighborhood.
The method is implemented as defined by: Frank Hutter, Holger H. Hoos and Kevin Leyton-Brown Sequential Model-Based Optimization for General Algorithm Configuration In Proceedings of the conference on Learning and Intelligent Optimization(LION 5)
PARAMETER | DESCRIPTION |
---|---|
configuration |
for this Configuration object
TYPE:
|
seed |
Sets the random seed to a fixed value
TYPE:
|
num_neighbors |
number of configurations, which are sampled from the neighbourhood of the input configuration
TYPE:
|
stdev |
The standard deviation is used to determine the neigbours of hyperparameters which are continuous/integer
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Iterator[Configuration]
|
It contains configurations, with values being situated around the given configuration. |
Source code in src/ConfigSpace/util.py
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 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 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 |
|
get_random_neighbor
#
get_random_neighbor(
configuration: Configuration, seed: int
) -> Configuration
Draw a random neighbor by changing one parameter of a configuration.
- If the parameter is categorical, it changes it to another value.
- If the parameter is ordinal, it changes it to the next higher or lower value.
- If parameter is a float, draw a random sample
If changing a parameter activates new parameters or deactivates previously active parameters, the configuration will be rejected. If more than 10000 configurations were rejected, this function raises a ValueError.
PARAMETER | DESCRIPTION |
---|---|
configuration |
a configuration for which a random neigbour is calculated
TYPE:
|
seed |
Used to generate a random state.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Configuration
|
The new neighbor |
Source code in src/ConfigSpace/util.py
354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 |
|
impute_inactive_values
#
impute_inactive_values(
configuration: Configuration,
strategy: str | float = "default",
) -> Configuration
Impute inactive parameters.
Iterate through the hyperparameters of a Configuration
and set the
values of the inactive hyperparamters to their default values if the choosen
strategy
is 'default'. Otherwise strategy
contains a float number.
Set the hyperparameters' value to this number.
PARAMETER | DESCRIPTION |
---|---|
configuration |
For this configuration inactive values will be imputed.
TYPE:
|
strategy |
The imputation strategy. Defaults to 'default' If 'default', replace inactive parameters by their default. If float, replace inactive parameters by the given float value, which should be able to be splitted apart by a tree-based model. |
RETURNS | DESCRIPTION |
---|---|
Configuration
|
A new configuration with the imputed values. In this new configuration inactive values are included. |