Skip to main content

OnlineTuner

Struct OnlineTuner 

pub struct OnlineTuner { /* private fields */ }
Expand description

A real-time, in-loop hyperparameter tuner.

Construct one with OnlineTuner::builder; drive it with suggest/observe once per training round (or the combined drive_round). See the module documentation for the full contract.

Implementations§

§

impl OnlineTuner

pub fn builder() -> OnlineTunerBuilder

Starts building a tuner. The default direction is Direction::Maximize and the default policy is the clustered UCB bandit with the default window (Mabc::ucb_default).

pub fn suggest(&mut self) -> Choice<'_>

The hyperparameter choices for the coming round, one per cluster.

O(clusters × arms) (arms is a small constant) and allocation-free: it rewrites the preallocated choice buffer in place and returns a borrowed Choice. Call it once per round, before observe.

pub fn observe(&mut self, round_return: f64)

Credits round_return to the arms/knobs the last suggest chose, sliding the policy forward one round. O(clusters) and allocation-free.

Direction is honoured here: under Direction::Minimize a smaller return is better. Call once per round, after suggest.

pub fn drive_round<F>(&mut self, run: F)
where F: FnOnce(&Choice<'_>) -> f64,

Runs one round through the tuner: suggest, evaluate, observe.

The oniro-free shape of the per-round callback seam: run receives the round’s Choice and returns the round’s return, which is then observed. Exactly equivalent to a manual suggest/observe pair, but it keeps the borrow scoping correct for you.

pub const fn rounds(&self) -> u64

The number of rounds observed so far.

pub fn clusters(&self) -> usize

The number of clusters this tuner manages.

pub const fn direction(&self) -> Direction

The optimization direction.

pub fn is_flush_boundary(&self) -> bool

true when the round just observed lands on a flush interval boundary — the caller’s cue to snapshot the tuner into a journal (off the hot path). Always false if no interval was configured with OnlineTunerBuilder::flush_every.

pub fn snapshot(&self) -> Result<StateBlob>

Serializes the full tuner state into a versioned StateBlob.

This allocates (it builds JSON) and is meant to be called at interval boundaries — is_flush_boundary — never on the hot path. A caller persists the blob through any Storage::put_state to make the online run a replayable, resumable study.

§Errors

Error::Storage if the state cannot be serialized — which for JSON means a non-finite windowed sum, i.e. a non-finite return was observed.

pub fn restore(&mut self, blob: &StateBlob) -> Result<()>

Restores tuner state from a snapshot blob.

The snapshot must describe the same shape — same cluster names, same policy, same arm counts and window — as this tuner, or the restore is refused rather than silently loading mismatched state.

§Errors

Error::Storage if the blob is not an ONLINE_BLOB_KIND payload, cannot be decoded, or does not match this tuner’s shape.

Trait Implementations§

§

impl Debug for OnlineTuner

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more