Utils
cheminformatics
smiles2fingerprints(smiles, bond_radius=5, n_bits=2048)
Transforms a list of smiles to an array of morgan fingerprints.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
smiles
|
List[str]
|
List of smiles |
required |
bond_radius
|
int
|
Bond radius to use. Defaults to 5. |
5
|
n_bits
|
int
|
Number of bits. Defaults to 2048. |
2048
|
Returns:
Type | Description |
---|---|
ndarray
|
np.ndarray: Numpy array holding the fingerprints |
Source code in bofire/utils/cheminformatics.py
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
|
smiles2fragments(smiles, fragments_list=None)
Transforms smiles to an array of fragments.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
smiles
|
list[str]
|
List of smiles |
required |
fragments_list
|
list[str]
|
List of desired fragments. Defaults to None. |
None
|
Returns:
Type | Description |
---|---|
ndarray
|
np.ndarray: Array holding the fragment information. |
Source code in bofire/utils/cheminformatics.py
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 |
|
smiles2mol(smiles)
Transforms a smiles string to an rdkit mol object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
smiles
|
str
|
Smiles string. |
required |
Raises:
Type | Description |
---|---|
ValueError
|
If string is not a valid smiles. |
Returns:
Type | Description |
---|---|
rdkit.Mol: rdkit.mol object |
Source code in bofire/utils/cheminformatics.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
|
smiles2mordred(smiles, descriptors_list)
Transforms list of smiles to mordred moelcular descriptors.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
smiles
|
List[str]
|
List of smiles |
required |
descriptors_list
|
List[str]
|
List of desired mordred descriptors |
required |
Returns:
Type | Description |
---|---|
ndarray
|
np.ndarray: Array holding the mordred moelcular descriptors. |
Source code in bofire/utils/cheminformatics.py
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 |
|
doe
apply_block_generator(design, gen)
Applies blocking to a design matrix.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
design
|
ndarray
|
The design matrix. |
required |
gen
|
str
|
The generator. |
required |
Returns:
Type | Description |
---|---|
List[int]
|
List of integers which assigns an experiment in the design matrix to a block. |
Source code in bofire/utils/doe.py
423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 |
|
compute_generator(n_factors, n_generators)
Computes a generator for a given number of factors and generators.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
n_factors
|
int
|
The number of factors. |
required |
n_generators
|
int
|
The number of generators. |
required |
Returns:
Type | Description |
---|---|
str
|
The generator. |
Source code in bofire/utils/doe.py
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 |
|
ff2n(n_factors)
Computes the full factorial design for a given number of factors.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
n_factors
|
int
|
The number of factors. |
required |
Returns:
Type | Description |
---|---|
ndarray
|
The full factorial design. |
Source code in bofire/utils/doe.py
72 73 74 75 76 77 78 79 80 81 82 |
|
fracfact(gen)
Computes the fractional factorial design for a given generator.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
gen
|
str
|
The generator. |
required |
Returns:
Type | Description |
---|---|
ndarray
|
The fractional factorial design. |
Source code in bofire/utils/doe.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 |
|
get_alias_structure(gen, order=4)
Computes the alias structure of the design matrix. Works only for generators with positive signs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
gen
|
str
|
The generator. |
required |
order
|
int
|
The order up to which the alias structure should be calculated. Defaults to 4. |
4
|
Returns:
Type | Description |
---|---|
List[str]
|
The alias structure of the design matrix. |
Source code in bofire/utils/doe.py
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 |
|
get_block_generator(n_factors, n_generators, n_repetitions, n_blocks)
Gets the block generator for a given number of factors, generators, repetitions, and blocks.
Should be only used if blocking cannot be reached by repetitions only.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
n_factors
|
int
|
number of factors |
required |
n_generators
|
int
|
number of generators/reducing factors |
required |
n_repetitions
|
int
|
number of repetitions |
required |
n_blocks
|
int
|
number of blocks that should be realized |
required |
Raises:
Type | Description |
---|---|
ValueError
|
If blocking can be reached by repetitions only. |
Returns:
Type | Description |
---|---|
str
|
The blocking generator. |
Source code in bofire/utils/doe.py
337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 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 |
|
get_confounding_matrix(inputs, design, powers=None, interactions=None)
Analyzes the confounding of a design and returns the confounding matrix.
Only takes continuous features into account.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
inputs
|
Inputs
|
Input features. |
required |
design
|
DataFrame
|
Design matrix. |
required |
powers
|
List[int]
|
List of powers of the individual factors/features that should be considered. Integers has to be larger than 1. Defaults to []. |
None
|
interactions
|
List[int]
|
List with interaction levels to be considered. Integers has to be larger than 1. Defaults to [2]. |
None
|
Returns:
Name | Type | Description |
---|---|---|
_type_ |
description |
Source code in bofire/utils/doe.py
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 |
|
get_default_generator(n_factors, n_generators)
Returns the default generator for a given number of factors and generators.
In case the combination is not available, the function will raise an error.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
n_factors
|
int
|
The number of factors. |
required |
n_generators
|
int
|
The number of generators. |
required |
Returns:
Type | Description |
---|---|
str
|
The generator. |
Source code in bofire/utils/doe.py
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 |
|
get_generator(n_factors, n_generators)
Returns a generator for a given number of factors and generators.
If the requested combination is available in the default generators, it will return
this one. Otherwise, it will compute a new one using get_bofire_generator
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
n_factors
|
int
|
The number of factors. |
required |
n_generators
|
int
|
The number of generators. |
required |
Returns:
Type | Description |
---|---|
str
|
The generator. |
Source code in bofire/utils/doe.py
317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 |
|
get_n_blocks(n_factors, n_generators, n_repetitions)
Computes the number of possible blocks for a given number of factors, generators, and repetitions.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
n_factors
|
int
|
number of factors |
required |
n_generators
|
int
|
number of generators/reducing factors |
required |
n_repetitions
|
int
|
number of repetitions |
required |
Returns:
Type | Description |
---|---|
List[int]
|
List[int]: List of possible number of blocks. |
Source code in bofire/utils/doe.py
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 |
|
validate_generator(n_factors, generator)
Validates the generator and thows an error if it is not valid.
Source code in bofire/utils/doe.py
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 |
|
multiobjective
compute_hypervolume(domain, optimal_experiments, ref_point)
Method to compute the hypervolume for a given domain and pareto optimal experiments.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
domain
|
Domain
|
Domain for which the hypervolume should be computed. |
required |
optimal_experiments
|
DataFrame
|
Pareto optimal experiments for which the hypervolume should be computed. |
required |
ref_point
|
dict
|
Unmasked reference point for the hypervolume computation. Masking is happening inside the method. |
required |
Returns:
Type | Description |
---|---|
float
|
Hypervolume for the given domain and pareto optimal experiments. |
Source code in bofire/utils/multiobjective.py
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 |
|
get_pareto_front(domain, experiments, output_feature_keys=None)
Method to compute the pareto optimal experiments for a given domain and experiments.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
domain
|
Domain
|
Domain for which the pareto front should be computed. |
required |
experiments
|
DataFrame
|
Experiments for which the pareto front should be computed. |
required |
output_feature_keys
|
Optional[list]
|
Key of output feature that should be considered
in the pareto front. If |
None
|
Returns:
Type | Description |
---|---|
DataFrame
|
DataFrame with pareto optimal experiments. |
Source code in bofire/utils/multiobjective.py
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 |
|
get_ref_point_mask(domain, output_feature_keys=None)
Method to get a mask for the reference points taking into account if we want to maximize or minimize an objective. In case it is maximize the value in the mask is 1, in case we want to minimize it is -1.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
domain
|
Domain
|
Domain for which the mask should be generated. |
required |
output_feature_keys
|
Optional[list]
|
Name of output feature keys
that should be considered in the mask. If |
None
|
Returns:
Type | Description |
---|---|
ndarray
|
Array of ones for maximization and array of negative ones for minimization. |
Source code in bofire/utils/multiobjective.py
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 |
|
infer_ref_point(domain, experiments, return_masked=False, reference_point=None)
Method to infer the reference point for a given domain and experiments.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
domain
|
Domain
|
Domain for which the reference point should be inferred. |
required |
experiments
|
DataFrame
|
Experiments for which the reference point should be inferred. |
required |
return_masked
|
bool
|
If True, the masked reference point is returned. If False, the unmasked reference point is returned. Defaults to False. |
False
|
reference_point
|
Optional[ExplicitReferencePoint]
|
Reference point to be used. If None is provided, the reference value is inferred by the worst values seen so far for every objective. Defaults to None. |
None
|
Source code in bofire/utils/multiobjective.py
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 |
|
naming_conventions
get_column_names(outputs)
Specifies column names for given Outputs type.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
outputs
|
Outputs
|
The Outputs object containing the individual outputs. |
required |
Returns:
Type | Description |
---|---|
Tuple[List[str], List[str]]
|
Tuple[List[str], List[str]]: A tuple containing the prediction column names and the standard deviation column names |
Source code in bofire/utils/naming_conventions.py
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 |
|
postprocess_categorical_predictions(predictions, outputs)
Postprocess categorical predictions by finding the maximum probability location
Parameters:
Name | Type | Description | Default |
---|---|---|---|
predictions
|
DataFrame
|
The dataframe containing the predictions. |
required |
outputs
|
Outputs
|
The Outputs object containing the individual outputs. |
required |
Returns:
Name | Type | Description |
---|---|---|
predictions |
DataFrame
|
The (potentially modified) original dataframe with categorical predictions added |
Source code in bofire/utils/naming_conventions.py
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 |
|
reduce
AffineTransform
Class to switch back and forth from the reduced to the original domain.
Source code in bofire/utils/reduce.py
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 |
|
__init__(equalities)
Initializes a AffineTransformation
object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
equalities
|
List[Tuple[str, List[str], List[float]]]
|
List of equalities. Every equality is defined as a tuple, in which the first entry is the key of the reduced feature, the second one is a list of feature keys that can be used to compute the feature and the third list of floats are the corresponding coefficients. |
required |
Source code in bofire/utils/reduce.py
25 26 27 28 29 30 31 32 33 34 35 |
|
augment_data(data)
Restore the eliminated features in a dataframe
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
DataFrame
|
Dataframe that should be restored. |
required |
Returns:
Type | Description |
---|---|
DataFrame
|
pd.DataFrame: Restored dataframe |
Source code in bofire/utils/reduce.py
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
|
drop_data(data)
Drop eliminated features from a dataframe.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
DataFrame
|
Dataframe with features to be dropped. |
required |
Returns:
Type | Description |
---|---|
DataFrame
|
pd.DataFrame: Reduced dataframe. |
Source code in bofire/utils/reduce.py
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
|
adjust_boundary(feature, coef, rhs)
Adjusts the boundaries of a feature.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
feature
|
ContinuousInput
|
Feature to be adjusted. |
required |
coef
|
float
|
Coefficient. |
required |
rhs
|
float
|
Right-hand-side of the constraint. |
required |
Source code in bofire/utils/reduce.py
421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 |
|
check_domain_for_reduction(domain)
Check if the reduction can be applied or if a trivial case is present.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
domain
|
Domain
|
Domain to be checked. |
required |
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if reducable, else False. |
Source code in bofire/utils/reduce.py
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 |
|
check_existence_of_solution(A_aug)
Given an augmented coefficient matrix this function determines the existence (and uniqueness) of solution using the rank theorem.
Source code in bofire/utils/reduce.py
255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 |
|
reduce_domain(domain)
Reduce a domain with linear equality constraints to a subdomain where linear equality constraints are eliminated.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
domain
|
Domain
|
Domain to be reduced. |
required |
Returns:
Type | Description |
---|---|
Tuple[Domain, AffineTransform]
|
Tuple[Domain, AffineTransform]: reduced domain and the according transformation to switch between the reduced and original domain. |
Source code in bofire/utils/reduce.py
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 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 |
|
remove_eliminated_inputs(domain, transform)
Eliminates remaining occurrences of eliminated inputs in linear constraints.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
domain
|
Domain
|
Domain in which the linear constraints should be purged. |
required |
transform
|
AffineTransform
|
Affine transformation object that defines the obsolete features. |
required |
Raises:
Type | Description |
---|---|
ValueError
|
If feature occurs in a constraint different from a linear one. |
Returns:
Name | Type | Description |
---|---|---|
Domain |
Domain
|
Purged domain. |
Source code in bofire/utils/reduce.py
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 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 |
|
rref(A, tol=1e-08)
Computes the reduced row echelon form of a Matrix
Parameters:
Name | Type | Description | Default |
---|---|---|---|
A
|
ndarray
|
2d array representing a matrix. |
required |
tol
|
float
|
tolerance for rounding to 0. Defaults to 1e-8. |
1e-08
|
Returns:
Type | Description |
---|---|
ndarray
|
(A_rref, pivots), where A_rref is the reduced row echelon form of A and pivots |
List[int]
|
is a numpy array containing the pivot columns of A_rref |
Source code in bofire/utils/reduce.py
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 |
|
subdomain
get_subdomain(domain, feature_keys)
Removes all features not defined as argument creating a subdomain of the provided domain
Parameters:
Name | Type | Description | Default |
---|---|---|---|
domain
|
Domain
|
the original domain wherefrom a subdomain should be created |
required |
feature_keys
|
List
|
List of features that shall be included in the subdomain |
required |
Raises:
Type | Description |
---|---|
Assert
|
when in total less than 2 features are provided |
ValueError
|
when a provided feature key is not present in the provided domain |
Assert
|
when no output feature is provided |
Assert
|
when no input feature is provided |
ValueError
|
description |
Returns:
Name | Type | Description |
---|---|---|
Domain |
Domain
|
A new domain containing only parts of the original domain |
Source code in bofire/utils/subdomain.py
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 |
|
torch_tools
InterpolateTransform
Bases: InputTransform
, Module
Botorch input transform that interpolates values between given x and y values.
Source code in bofire/utils/torch_tools.py
929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 |
|
constrained_objective2botorch(idx, objective, x_adapt, eps=1e-08)
Create a callable that can be used by botorch.utils.objective.apply_constraints
to setup output constrained optimizations.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
idx
|
int
|
Index of the constraint objective in the list of outputs. |
required |
objective
|
BotorchConstrainedObjective
|
The objective that should be transformed. |
required |
x_adapt
|
Optional[Tensor]
|
The tensor that should be used to adapt the objective,
for example in case of a moving turning point in the |
required |
eps
|
float
|
Small value to avoid numerical instabilities in case of the |
1e-08
|
Returns:
Type | Description |
---|---|
Tuple[List[Callable[[Tensor], Tensor]], List[float], int]
|
Tuple[List[Callable[[Tensor], Tensor]], List[float], int]: List of callables that can be used by botorch for setting up the constrained objective, list of the corresponding botorch eta values, final index used by the method (to track for categorical variables) |
Source code in bofire/utils/torch_tools.py
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 352 353 354 355 356 357 |
|
get_initial_conditions_generator(strategy, transform_specs, ask_options=None, sequential=True)
Takes a strategy object and returns a callable which uses this
strategy to return a generator callable which can be used in botorchs
gen_batch_initial_conditions` to generate samples.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
strategy
|
Strategy
|
Strategy that should be used to generate samples. |
required |
transform_specs
|
Dict
|
Dictionary indicating how the samples should be transformed. |
required |
ask_options
|
Dict
|
Dictionary of keyword arguments that are
passed to the |
None
|
sequential
|
bool
|
If True, samples for every q-batch are
generate independent from each other. If False, the |
True
|
Returns:
Type | Description |
---|---|
Callable[[int, int, int], Tensor]
|
Callable[[int, int, int], Tensor]: Callable that can be passed to
|
Source code in bofire/utils/torch_tools.py
843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 |
|
get_interpoint_constraints(domain, n_candidates)
Converts interpoint equality constraints to linear equality constraints,
that can be processed by botorch. For more information, see the docstring
of optimize_acqf
in botorch
(https://github.com/pytorch/botorch/blob/main/botorch/optim/optimize.py).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
domain
|
Domain
|
Optimization problem definition. |
required |
n_candidates
|
int
|
Number of candidates that should be requested. |
required |
Returns:
Type | Description |
---|---|
List[Tuple[Tensor, Tensor, float]]
|
List[Tuple[Tensor, Tensor, float]]: List of tuples, each tuple consists of a tensor with the feature indices, coefficients and a float for the rhs. |
Source code in bofire/utils/torch_tools.py
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 |
|
get_linear_constraints(domain, constraint, unit_scaled=False)
Converts linear constraints to the form required by BoTorch. For inequality constraints, this is A * x >= b (!).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
domain
|
Domain
|
Optimization problem definition. |
required |
constraint
|
Union[Type[LinearEqualityConstraint], Type[LinearInequalityConstraint]]
|
Type of constraint that should be converted. |
required |
unit_scaled
|
bool
|
If True, transforms constraints by assuming that the bound for the continuous features are [0,1]. Defaults to False. |
False
|
Returns:
Type | Description |
---|---|
List[Tuple[Tensor, Tensor, float]]
|
List[Tuple[Tensor, Tensor, float]]: List of tuples, each tuple consists of a tensor with the feature indices, coefficients and a float for the rhs. |
Source code in bofire/utils/torch_tools.py
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 |
|
get_multiobjective_objective(outputs, experiments)
Returns a callable that can be used by botorch for multiobjective optimization.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
outputs
|
Outputs
|
Outputs object for which the callable should be generated. |
required |
experiments
|
DataFrame
|
DataFrame containing the experiments that are used for
adapting the objectives on the fly, for example in the case of the
|
required |
Returns:
Type | Description |
---|---|
Callable[[Tensor, Optional[Tensor]], Tensor]
|
Callable[[Tensor], Tensor]: description |
Source code in bofire/utils/torch_tools.py
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 |
|
get_multiplicative_additive_objective(outputs, experiments, exclude_constraints=True, additive_features=None, adapt_weights_to_1_inf=True)
Computes the objective as a mix of multiplicative and additive objectives. By default, all objectives are multiplicative.
Additive features (inputs or outputs) can be specified in the additive_features
list.
The formular for a mixed objective with two multiplicative features (f1, and f2 with weights w1 and w2) and two additive features (f3 and f4 with weights w3 and w4) is:
additive_objective = 1 + f3*w3 + f4*w4
objective = f1^w1 * f2^w2 * additive_objective
Parameters:
Name | Type | Description | Default |
---|---|---|---|
additive_features
|
List[str]
|
list of features that should be treated as additive |
None
|
adapt_weights_to_1_inf
|
bool
|
will transform weights from [0,1] to [1,inf) space |
True
|
Returns:
Name | Type | Description |
---|---|---|
objective |
callable
|
callable that can be used by botorch for optimization |
Source code in bofire/utils/torch_tools.py
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 835 836 837 838 839 840 |
|
get_nchoosek_constraints(domain)
Transforms NChooseK constraints into a list of non-linear inequality constraint callables that can be parsed by pydantic. For this purpose the NChooseK constraint is continuously relaxed by countig the number of zeros in a candidate by a sum of narrow gaussians centered at zero.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
domain
|
Domain
|
Optimization problem definition. |
required |
Returns:
Type | Description |
---|---|
List[Tuple[Callable[[Tensor], float], bool]]
|
List[Callable[[Tensor], float]]: List of callables that can be used as nonlinear equality constraints in botorch. |
Source code in bofire/utils/torch_tools.py
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 |
|
get_nonlinear_constraints(domain, includes=None)
Returns a list of callable functions that represent the nonlinear constraints for the given domain that can be processed by botorch.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
domain
|
Domain
|
The domain for which to generate the nonlinear constraints. |
required |
Returns:
Type | Description |
---|---|
List[Tuple[Callable[[Tensor], float], bool]]
|
List[Callable[[Tensor], float]]: A list of callable functions that take a tensor |
List[Tuple[Callable[[Tensor], float], bool]]
|
as input and return a float value representing the constraint evaluation. |
Source code in bofire/utils/torch_tools.py
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 |
|
get_output_constraints(outputs, experiments)
Method to translate output constraint objectives into a list of callables and list of etas for use in botorch.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
outputs
|
Outputs
|
Output feature object that should be processed. |
required |
experiments
|
DataFrame
|
DataFrame containing the experiments that are used for
adapting the objectives on the fly, for example in the case of the
|
required |
Returns:
Type | Description |
---|---|
Tuple[List[Callable[[Tensor], Tensor]], List[float]]
|
Tuple[List[Callable[[Tensor], Tensor]], List[float]]: List of constraint callables, list of associated etas. |
Source code in bofire/utils/torch_tools.py
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 |
|
get_product_constraints(domain)
Returns a list of nonlinear constraint functions that can be processed by botorch based on the given domain.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
domain
|
Domain
|
The domain object containing the constraints. |
required |
Returns:
Type | Description |
---|---|
List[Tuple[Callable[[Tensor], float], bool]]
|
List[Callable[[Tensor], float]]: A list of product constraint functions. |
Source code in bofire/utils/torch_tools.py
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 |
|
interp1d(x, y, x_new)
Interpolates values in the y tensor based on the x tensor using linear interpolation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
Tensor
|
The x-coordinates of the data points. |
required |
y
|
Tensor
|
The y-coordinates of the data points. |
required |
x_new
|
Tensor
|
The x-coordinates at which to interpolate the values. |
required |
Returns:
Type | Description |
---|---|
Tensor
|
torch.Tensor: The interpolated values at the x_new x-coordinates. |
Source code in bofire/utils/torch_tools.py
901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 |
|