array_sampler
Overview
The array sampler will generate samples by taking the Cartesian product of the provided discrete values for each parameter. The samples are directly specified in 'bounds' in the config file.
ArraySampler
ArraySampler(bounds, parameters, **kwargs)
Bases: Sampler
Configuration
To use the ArraySampler, specify it in the configuration file as in following example:
sampler:
type: Array
bounds: [[5, 7, 77, 199], [0.02, 0.2]]
num_samples: [4, 2]
parameters: ['a', 'b']
This configuration would create the following sample space:
[[5, 0.02], [5, 0.2], [7, 0.02], [7, 0.2], [77, 0.02], [77, 0.2], [199, 0.02], [199, 0.2]].
Attributes:
| Name | Type | Description |
|---|---|---|
bounds |
list of list of float or int
|
The bounds of each parameter. |
num_samples |
list of int
|
The number of samples for each parameter. |
parameters |
list of str
|
The names of the parameters. |
budget |
int
|
The total number of parameter combinations. |
num_initial_points |
int
|
The number of initial points in the sample space. |
samples |
list of list of float or int
|
The generated parameter combinations. |
current_index |
int
|
The index of the current parameter combination. |
Assumption and notes
- This throws errors if you are asking for something insane, e.g., 10 parameters for 10 samples each -> 10 billion so hard limit at 100.000
Initializes the ArraySampler.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bounds
|
list of list of float or int
|
The bounds of each parameter. |
required |
num_samples
|
list of int
|
The number of samples for each parameter. |
required |
parameters
|
list of str
|
The names of the parameters. |
required |
Source code in src/enchanted_surrogates/samplers/array_sampler.py
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | |
generate_parameters
generate_parameters()
Generates the parameter combinations.
Yields:
| Type | Description |
|---|---|
|
list of float or int: The next parameter combination. |
Source code in src/enchanted_surrogates/samplers/array_sampler.py
79 80 81 82 83 84 85 86 87 88 89 90 91 | |
get_next_samples
get_next_samples()
Gets the next batch of parameter combinations.
Returns:
| Type | Description |
|---|---|
list[dict]
|
list[dict]: List of parameter dicts for the batch, or empty list if no samples remain. |
Source code in src/enchanted_surrogates/samplers/array_sampler.py
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 | |
register_future
register_future(future)
Doesn't matter for random sampler TODO: Probably?
Source code in src/enchanted_surrogates/samplers/array_sampler.py
114 115 116 | |