sampling
- class gen_classes.sampling.UniformSample(VOCS, random_seed=1, *args, **kwargs)
Samples over the domain specified in the VOCS.
Implements
suggest()andingest()identically to the other generators.- Parameters:
VOCS (VOCS)
random_seed (int)
- suggest(num_points=0)
Request the next set of points to evaluate.
- Parameters:
num_points (int | None)
- Return type:
List[dict]
- ingest(results)
Send the results of evaluations to the generator.
- Parameters:
results (List[dict])
- Return type:
None
- class gen_classes.external.sampling.UniformSample(VOCS)
This sampler adheres to the gest-api VOCS interface and data structures (no numpy).
Each variable is a scalar.
- Parameters:
VOCS (VOCS)
- suggest(n_trials)
Request the next set of points to evaluate.
Returns a list of points in the input space, to be evaluated next. Each element of the list is a separate point. Keys of the dictionary include the name of each input variable specified in VOCS (variables + constants). Values of the dictionaries are scalars unless the variable was declared with an array
dtypeattribute.- Parameters:
num_points(int | None): Optional number of points to generate. When not provided, the generator decides how many points to return.
- Returns:
list[dict]: A list of dictionaries, where each dictionary represents a point to evaluate. Each dictionary contains keys for all variables and constants from the VOCS, and optionally an"_id"key if the generator supports IDs.
- Raises:
ValueError: Ifnum_pointsis specified but the generator cannot produce that exact number of points.
- Notes:
When
num_pointsis passed, the generator should return exactly that number of points or raise aValueError.When
num_pointsis not passed, the generator decides how many points to return. Different generators will return different numbers of points. For instance, the simplex would return 1 or 3 points. A genetic algorithm could return the whole population. Batched Bayesian optimization would return the batch size (i.e., number of points that can be processed in parallel), which would be specified in the constructor.Some generators can assign a unique identifier to each generated point (indicated by the
returns_idclass attribute). If implemented, this identifier should appear in the dictionary under the key"_id".
>>> points = generator.suggest(2) >>> print(points) [{"x": 1.2, "y": 0.8}, {"x": -0.2, "y": 0.4}] >>> points = generator.suggest() # Generator decides >>> print(points) [{"x": 1.2, "y": 0.8}, {"x": -0.2, "y": 0.4}, {"x": 4.3, "y": -0.1}]
- ingest(calc_in)
Send the results of evaluations to the generator.
Feeds data (past evaluations) to the generator. Each element of the list is a separate point. Keys of the dictionary must include each named field specified in the VOCS provided to the generator on instantiation (variables, constants, objectives, constraints, and observables).
- Parameters:
results(list[dict]): A list of dictionaries, where each dictionary represents an evaluated point. Each dictionary must contain keys for all variables, constants, objectives, constraints, and observables from the VOCS.
- Raises:
ValueError: If points are given toingestwith an_idvalue that is not known internally (for generators that support IDs).
- Notes:
Any points provided to the generator via
ingestthat were not created by the current generator instance should omit the_idfield.If points are given to
ingestwith an_idvalue that is not known internally, aValueErrorerror should be raised.
>>> point = generator.suggest(1) >>> point [{"x": 1, "y": 1}] >>> point[0]["f"] = objective(point[0]) >>> point [{"x": 1, "y": 1, "f": 2}] >>> generator.ingest(point)