pub struct ZeroShotSelector { /* private fields */ }Expand description
Zero-shot optimizer selector: an offline-fitted meta-model plus the meta-feature extractor it consumes.
The selector is fit once on a meta-dataset of MetaExamples (see
ZeroShotSelector::fit) and thereafter answers ZeroShotSelector::recommend
queries for brand-new tasks with no further training.
Implementations§
Source§impl ZeroShotSelector
impl ZeroShotSelector
Sourcepub fn new(config: ZeroShotConfig) -> Result<Self>
pub fn new(config: ZeroShotConfig) -> Result<Self>
Create an unfitted selector with the given configuration.
Sourcepub fn with_default_config() -> Result<Self>
pub fn with_default_config() -> Result<Self>
Create an unfitted selector with the default configuration.
Sourcepub fn is_fitted(&self) -> bool
pub fn is_fitted(&self) -> bool
Whether ZeroShotSelector::fit has been called successfully.
Sourcepub fn config(&self) -> &ZeroShotConfig
pub fn config(&self) -> &ZeroShotConfig
The active configuration.
Sourcepub fn extract_meta_features<P>(&self, probe: &P) -> Result<MetaFeatures>
pub fn extract_meta_features<P>(&self, probe: &P) -> Result<MetaFeatures>
Extract the meta-feature vector for a task by lightweight probing.
This performs only gradient evaluations (no optimization steps on the task) and
is deterministic: the random curvature directions are drawn from a generator seeded
by ZeroShotConfig::seed, and the noise estimate uses index-seeded gradient
samples, so repeated calls return identical features.
Sourcepub fn fit(&mut self, examples: &[MetaExample]) -> Result<()>
pub fn fit(&mut self, examples: &[MetaExample]) -> Result<()>
Fit the meta-model on an offline meta-dataset.
This learns the standardization statistics, the multinomial logistic-regression
classifier (softmax cross-entropy, full-batch gradient descent with L2), and the
linear log10(learning_rate) regressor (MSE, full-batch gradient descent with L2).
Sourcepub fn recommend<P>(&self, probe: &P) -> Result<OptimizerRecommendation>
pub fn recommend<P>(&self, probe: &P) -> Result<OptimizerRecommendation>
Recommend an optimizer and hyper-parameters for a brand-new task.
Extracts meta-features from the probe, standardizes them with the fitted statistics, and runs the classifier + regressor. Returns an error if the selector has not been fit yet.
Sourcepub fn predict(
&self,
features: &MetaFeatures,
) -> Result<OptimizerRecommendation>
pub fn predict( &self, features: &MetaFeatures, ) -> Result<OptimizerRecommendation>
Predict directly from an already-extracted meta-feature vector.
Returns an error if the selector has not been fit yet.
Sourcepub fn save_json(&self, path: &Path) -> Result<()>
pub fn save_json(&self, path: &Path) -> Result<()>
Serialize the fitted selector (including its learned parameters) to JSON on disk.
Sourcepub fn load_json(path: &Path) -> Result<Self>
pub fn load_json(path: &Path) -> Result<Self>
Load a previously-saved selector from JSON on disk.
The deserialized value is validated before it is handed back: JSON is
structurally permissive, so a file that parses can still carry a weight
matrix of the wrong shape, a zero/negative feature standard deviation
(which would divide by zero during standardization) or a non-finite
parameter. Those used to sail through and panic — or silently produce
garbage predictions — at the first predict call.
§Errors
Returns Err on I/O failure, on malformed JSON, or when
Self::validate_parameters rejects the loaded parameters.
Sourcepub fn validate_parameters(&self) -> Result<()>
pub fn validate_parameters(&self) -> Result<()>
Check that the learned parameters are internally consistent and usable.
Verifies the configuration, every array shape against NUM_FEATURES /
NUM_CLASSES, that no parameter is NaN/infinite, and that every feature
standard deviation is strictly positive.
§Errors
Returns Err describing the first inconsistency found.
Trait Implementations§
Source§impl Clone for ZeroShotSelector
impl Clone for ZeroShotSelector
Source§impl Debug for ZeroShotSelector
impl Debug for ZeroShotSelector
Source§impl<'de> Deserialize<'de> for ZeroShotSelector
impl<'de> Deserialize<'de> for ZeroShotSelector
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl Freeze for ZeroShotSelector
impl RefUnwindSafe for ZeroShotSelector
impl Send for ZeroShotSelector
impl Sync for ZeroShotSelector
impl Unpin for ZeroShotSelector
impl UnsafeUnpin for ZeroShotSelector
impl UnwindSafe for ZeroShotSelector
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.