Optimizer
amltk.optimization.optimizer
#
The base Optimizer class,
defines the API we require optimizers to implement.
ask()- Ask the optimizer for a newTrialto evaluate.tell()- Tell the optimizer the result of the sampled config. This comes in the form of aTrial.Report.
Additionally, to aid users from switching between optimizers, the
preferred_parser()
method should return either a parser function or a string that can be used
with node.search_space(parser=..._) to
extract the search space for the optimizer.
Optimizer
#
Optimizer(
metrics: Sequence[Metric],
bucket: PathBucket | None = None,
)
Bases: Generic[I]
An optimizer protocol.
An optimizer is an object that can be asked for a trail using ask and a
tell to inform the optimizer of the report from that trial.
| PARAMETER | DESCRIPTION |
|---|---|
metrics |
The metrics to optimize. |
bucket |
The bucket to store results of individual trials from this optimizer.
TYPE:
|
Source code in src/amltk/optimization/optimizer.py
bucket
instance-attribute
#
bucket: PathBucket = (
bucket
if bucket is not None
else PathBucket(f"{__name__}-{isoformat()}")
)
The bucket to give to trials generated by this optimizer.
metrics
instance-attribute
#
metrics: MetricCollection = from_collection(metrics)
The metrics to optimize.
CreateSignature
#
Bases: Protocol
A Protocol which defines the keywords required to create an optimizer with deterministic behavior at a desired location.
This protocol matches the Optimizer.create classmethod, however we also
allow any function which accepts the keyword arguments to create an
Optimizer.
__call__
#
__call__(
*,
space: Node,
metrics: Metric | Sequence[Metric],
bucket: PathBucket | None = None,
seed: Seed | None = None
) -> Optimizer
A function which creates an optimizer for node.optimize should accept the following keyword arguments.
| PARAMETER | DESCRIPTION |
|---|---|
space |
The node to optimize
TYPE:
|
metrics |
The metrics to optimize |
bucket |
The bucket to store the results in
TYPE:
|
seed |
The seed to use for the optimization
TYPE:
|
Source code in src/amltk/optimization/optimizer.py
ask
abstractmethod
#
create
abstractmethod
classmethod
#
create(
*,
space: Node,
metrics: Metric | Sequence[Metric],
bucket: str | Path | PathBucket | None = None,
seed: Seed | None = None
) -> Self
Create this optimizer.
Note
Subclasses should override this with more specific configuration but these arguments should be all that's necessary to create the optimizer.
| PARAMETER | DESCRIPTION |
|---|---|
space |
The space to optimize over.
TYPE:
|
bucket |
The bucket for where to store things related to the trial.
TYPE:
|
metrics |
The metrics to optimize. |
seed |
The seed to use for the optimizer.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Self
|
The optimizer. |
Source code in src/amltk/optimization/optimizer.py
preferred_parser
classmethod
#
preferred_parser() -> (
str
| Callable[Concatenate[Node, ...], Any]
| Callable[[Node], Any]
| None
)
The preferred parser for this optimizer.
Note
Subclasses should override this as required.