pub struct TrialContext<'a> { /* private fields */ }Expand description
The handle passed into the user’s objective closure.
This is where define-by-run happens: the search space is discovered by
calling suggest_* methods here, not declared up front. Each call
(1) asks the active Sampler for a value given the study history and the
distribution, then (2) records the (name, distribution, value) on the
trial. Recording after asking keeps the trial’s history accurate for the
storage, pruning, and importance phases that depend on it.
The sampler is held behind a shared Mutex so the exact same context type
serves both sequential and parallel execution; under sequential runs the
lock is uncontended.
Implementations§
Source§impl<'a> TrialContext<'a>
impl<'a> TrialContext<'a>
Sourcepub fn suggest_float(&mut self, name: &str, low: f64, high: f64) -> f64
pub fn suggest_float(&mut self, name: &str, low: f64, high: f64) -> f64
Suggest a continuous value uniformly over [low, high].
Sourcepub fn suggest_loguniform(&mut self, name: &str, low: f64, high: f64) -> f64
pub fn suggest_loguniform(&mut self, name: &str, low: f64, high: f64) -> f64
Suggest a continuous value log-uniformly over [low, high]
(both must be > 0). Good for scale parameters like learning rates.
Sourcepub fn suggest_int(&mut self, name: &str, low: i64, high: i64) -> i64
pub fn suggest_int(&mut self, name: &str, low: i64, high: i64) -> i64
Suggest an integer uniformly over the inclusive range [low, high].
Sourcepub fn suggest_categorical(&mut self, name: &str, choices: &[&str]) -> String
pub fn suggest_categorical(&mut self, name: &str, choices: &[&str]) -> String
Suggest one of choices, returning the chosen label.
Sourcepub fn report(&mut self, step: usize, value: f64)
pub fn report(&mut self, step: usize, value: f64)
Report an intermediate objective value at step (e.g. per-epoch
validation score). Consumed by pruners via Self::should_prune.
Sourcepub fn should_prune(&self) -> bool
pub fn should_prune(&self) -> bool
Ask the active pruner whether this trial should stop early, based on the intermediate values reported so far versus the rest of the study.
Sourcepub fn study_state(&self) -> &StudyState
pub fn study_state(&self) -> &StudyState
Read-only access to the study snapshot this trial sees.
Trait Implementations§
Source§impl Suggest for TrialContext<'_>
impl Suggest for TrialContext<'_>
Source§fn suggest_float(&mut self, name: &str, low: f64, high: f64) -> f64
fn suggest_float(&mut self, name: &str, low: f64, high: f64) -> f64
[low, high].Source§fn suggest_loguniform(&mut self, name: &str, low: f64, high: f64) -> f64
fn suggest_loguniform(&mut self, name: &str, low: f64, high: f64) -> f64
[low, high].Source§fn suggest_int(&mut self, name: &str, low: i64, high: i64) -> i64
fn suggest_int(&mut self, name: &str, low: i64, high: i64) -> i64
[low, high].Source§fn suggest_categorical(&mut self, name: &str, choices: &[&str]) -> String
fn suggest_categorical(&mut self, name: &str, choices: &[&str]) -> String
choices, returning the chosen label.Source§fn report(&mut self, step: usize, value: f64)
fn report(&mut self, step: usize, value: f64)
step, for pruners.