Modular Metric#
Overview Information Here: boa.metrics
- class boa.metrics.modular_metric.ModularMetric(metric_to_eval: Callable | str = None, metric_func_kwargs: Optional[dict] = None, param_names: list[str] = None, noise_sd: Optional[float] = 0.0, name: Optional[str] = None, wrapper: Optional[BaseWrapper] = None, properties: Optional[dict[str]] = None, **kwargs)[source]#
Bases:
NoisyFunctionMetricA wrappable metric defined by a generic deterministic function with the ability to inject a wrapper for higher customizability. The metric function can have some known or unknown noise such that each evaluation may be different, they will be centered around a true value with some
noise_sdThe deterministic metric function to compute is implemented by passing some callable (a function or class with
__call__) to argumentmetric_to_eval.You can further customize the behavior of your metric by passing a
Wrapper, which has will run methods such asBaseWrapper.fetch_trial_data()before calling the specified metric to evaluate, which can allow you to preprocess/prepare model output data for your metric calculation.- Parameters:
metric_to_eval (Callable | str) –
metric_func_kwargs (Optional[dict]) – dictionary of keyword arguments to pass to the metric to eval function
noise_sd (Optional[float]) – Scale of normal noise added to the function result. If None, interpret the function as noisy with unknown noise level.
param_names (list[str]) – An ordered list of names of parameters to be passed to the metric_to_eval Useful for filtering out parameters before those parameters are passed to your metric
name (Optional[str]) – The name of the metric, if not specified, defaults to name of
metric_to_evalwrapper (Optional[BaseWrapper]) – Boa wrapper to handle running the model and getting the data, allows injecting custom function in the middle of
ModularMetricproperties (Optional[dict[str]]) – Arbitrary dictionary of properties to store. Properties need to be json serializable
kwargs –
- classmethod is_available_while_running() bool[source]#
Whether metrics of this class are available while the trial is running. Metrics that are not available while the trial is running are assumed to be available only upon trial completion. For such metrics, data is assumed to never change once the trial is completed.
NOTE: If this method returns False, data-fetching via experiment.fetch_data will return the data cached on the experiment (for the metrics of the given class) whenever its available. Data is cached on experiment when attached via experiment.attach_data.
- Return type:
- fetch_trial_data(trial: BaseTrial, **kwargs)[source]#
Fetch data for one trial.
- Parameters:
trial (BaseTrial) –