feat: add intermediate values and pruner integration to Trial

- Add report(step, value) and should_prune() methods to Trial
- Store intermediate_values in Trial, copied to CompletedTrial on completion
- Pass pruner through trial factory so trials can consult it
- Rebuild trial factory when pruner is changed via set_pruner()
This commit is contained in:
Manuel Raimann
2026-02-11 16:08:25 +01:00
parent 2651e61b2c
commit 4d8af3242b
3 changed files with 97 additions and 8 deletions
+22
View File
@@ -27,6 +27,8 @@ pub struct CompletedTrial<V = f64> {
pub param_labels: HashMap<ParamId, String>,
/// The objective value returned by the objective function.
pub value: V,
/// Intermediate objective values reported during the trial.
pub intermediate_values: Vec<(u64, f64)>,
}
impl<V> CompletedTrial<V> {
@@ -44,6 +46,26 @@ impl<V> CompletedTrial<V> {
distributions,
param_labels,
value,
intermediate_values: Vec::new(),
}
}
/// Creates a new completed trial with intermediate values.
pub fn with_intermediate_values(
id: u64,
params: HashMap<ParamId, ParamValue>,
distributions: HashMap<ParamId, Distribution>,
param_labels: HashMap<ParamId, String>,
value: V,
intermediate_values: Vec<(u64, f64)>,
) -> Self {
Self {
id,
params,
distributions,
param_labels,
value,
intermediate_values,
}
}