Descriptors
Descriptors specify what kinds of values are valid for a parameter.
There are currently, 2 variants:
RangeParameter
and
CategoryParameter
.(Note that even though their names end with Parameter, they are
actually descriptors, not parameters.)
from besos.parameters import (
RangeParameter,
CategoryParameter,
Parameter,
)
from besos.problem import Problem
from besos import sampling
from besos.evaluator import EvaluatorGeneric
RangeParameters
\(min \leq x \leq max\)
zero_to_one_exclusive = RangeParameter(min_val=0.01, max_val=0.99)
CategoryParameters
A list of options.
text_example = CategoryParameter(options=["a", "b", "c", "other"])
single_digit_integers = CategoryParameter(options=range(10))
Sampling
These descriptors can be used to make Parameters
. Then we can
generate samples.
parameters = [
Parameter(value_descriptors=zero_to_one_exclusive, name="0-1"),
Parameter(value_descriptors=single_digit_integers, name="single digit"),
Parameter(value_descriptors=text_example, name="text"),
]
problem = Problem(parameters, outputs=["output"])
samples = sampling.dist_sampler(sampling.lhs, problem, num_samples=10)
samples
0-1 | single digit | text | |
---|---|---|---|
0 | 0.731019 | 3 | other |
1 | 0.445608 | 5 | b |
2 | 0.347260 | 6 | b |
3 | 0.182080 | 9 | a |
4 | 0.213295 | 2 | c |
5 | 0.896126 | 1 | c |
6 | 0.578084 | 7 | a |
7 | 0.067447 | 4 | other |
8 | 0.811553 | 8 | a |
9 | 0.647950 | 0 | other |
Evaluation
Since we did not specify selectors for the parameters, we cannot evaluate them using an EnergyPlus simulation. Instead, we will use a custom evaluation function.
def evaluation_function(values):
x, y, z = values
if z == "other":
return (x,)
else:
return (x * y,)
evaluator = EvaluatorGeneric(evaluation_function, problem)
# The evaluator will use this objective by default
outputs = evaluator.df_apply(samples, keep_input=True)
# outputs is a pandas dataframe with one column since only one objective was requested
HBox(children=(FloatProgress(value=0.0, description='Executing', max=10.0, style=ProgressStyle(description_wid…
outputs
0-1 | single digit | text | output | |
---|---|---|---|---|
0 | 0.731019 | 3 | other | 0.731019 |
1 | 0.445608 | 5 | b | 2.228040 |
2 | 0.347260 | 6 | b | 2.083560 |
3 | 0.182080 | 9 | a | 1.638716 |
4 | 0.213295 | 2 | c | 0.426590 |
5 | 0.896126 | 1 | c | 0.896126 |
6 | 0.578084 | 7 | a | 4.046588 |
7 | 0.067447 | 4 | other | 0.067447 |
8 | 0.811553 | 8 | a | 6.492422 |
9 | 0.647950 | 0 | other | 0.647950 |