Skip to main content

MultinomialLogisticRegression

Struct MultinomialLogisticRegression 

Source
pub struct MultinomialLogisticRegression { /* private fields */ }
Expand description

Multinomial (softmax) logistic regression over an ordered K >= 2 label set.

See the module documentation for the objective, the sklearn C relation, and the deliberate omissions.

Implementations§

Source§

impl MultinomialLogisticRegression

Source

pub fn new(n_classes: usize) -> MultinomialLogisticRegression

Creates an unfitted head for n_classes classes.

n_classes is validated at fit time, not here, so that every rejection travels through the same typed channel.

Source

pub fn from_stored_coefficients( ordered_labels: Vec<String>, n_features: usize, weights: Vec<f32>, intercepts: Vec<f32>, ) -> Result<MultinomialLogisticRegression, HeadFitError>

Rebuild a head from stored coefficients — the RELOAD door (plan 03-08).

§This is not a fit, and it does not claim to be one

Self::report stays None: no optimizer ran in this process, and a synthesized report would assert a convergence status nobody observed. The provenance of the coefficients belongs to whatever artifact carried them, and it is that artifact’s job to record the fit that produced them.

Every input is validated before the head exists, through the SAME label-set rule the fit path uses ([validate_label_set]) plus the coefficient-arity and finiteness checks a fit cannot get wrong. A head returned from here therefore satisfies predict_proba’s preconditions by construction, exactly as a fitted one does.

§Errors

HeadFitError::InvalidInput carrying the offending HeadInputError: too few classes, a mis-sized label map, an empty or duplicated label, a zero feature dimension, a weight or intercept array of the wrong length, or a non-finite coefficient.

Source

pub fn with_max_iter(self, max_iter: usize) -> MultinomialLogisticRegression

Sets the maximum L-BFGS iteration budget (default DEFAULT_MAX_ITER).

Source

pub fn with_tol(self, tol: f64) -> MultinomialLogisticRegression

Sets the gradient-norm convergence tolerance (default DEFAULT_TOL).

Source

pub fn with_history_size( self, history_size: usize, ) -> MultinomialLogisticRegression

Sets the L-BFGS correction-pair history size (default DEFAULT_HISTORY_SIZE).

Source

pub fn n_classes(&self) -> usize

Number of classes this head is configured for.

Source

pub fn n_features(&self) -> Option<usize>

Fitted feature dimension, or None before a successful fit.

Source

pub fn weights(&self) -> &[f32]

Fitted weights as K * d values in row-major order, or an empty slice.

Source

pub fn intercepts(&self) -> &[f32]

Fitted intercepts (K values), or an empty slice.

Source

pub fn labels(&self) -> &[String]

Ordered labels; index == weight-matrix row.

Source

pub fn report(&self) -> Option<&HeadFitReport>

Report from the last successful fit.

Source

pub fn fit( &mut self, features: &[Vec<f32>], class_indices: &[usize], ordered_labels: &[String], regularization: Regularization, ) -> Result<HeadFitReport, HeadFitError>

Fits the head.

Returns the HeadFitReport on convergence, or a typed HeadFitError otherwise. Non-convergence is an error, not a warning.

§A failed fit leaves the head UNFITTED

The fitted state is discarded on entry, before anything can fail. Otherwise a head that fitted once and was then re-fitted with data the gate rejects would keep the PREVIOUS fit’s weights, n_features, labels and report — so predict would answer with a model the caller believes it failed to build, and report() would describe a converged run that the last call did not perform. NotFitted is the honest answer after a rejected fit, and it is only reachable if the state is cleared here.

Source

pub fn predict_logits( &self, features: &[Vec<f32>], ) -> Result<Vec<Vec<f64>>, HeadFitError>

Per-row class logits, accumulated in f64 from the f32 store.

THE single logit implementation: Self::predict_proba is this plus a softmax, so a caller that needs both — VerifiedSetFitModel::classify, which reports logits alongside probabilities — cannot obtain a pair that disagrees with itself. Extracting it also removed the standing temptation to write a second copy of the accumulation loop next to the caller that wanted logits.

The accumulation ORDER is unchanged from the original predict_proba: intercept first, then j ascending. That order is what the artifact writer recorded its probe logits in, so it is load-bearing rather than incidental.

Source

pub fn predict_proba( &self, features: &[Vec<f32>], ) -> Result<Vec<Vec<f64>>, HeadFitError>

Per-row class probabilities, computed with f64 logit accumulation.

Each returned row is finite and sums to 1 within 1e-6.

Source

pub fn predict_indices( &self, features: &[Vec<f32>], ) -> Result<Vec<usize>, HeadFitError>

Per-row predicted class indices, breaking exact ties to the lowest index.

Source

pub fn predict( &self, features: &[Vec<f32>], ) -> Result<Vec<String>, HeadFitError>

Per-row predicted labels, breaking exact ties to the lowest label index.

Trait Implementations§

Source§

impl Clone for MultinomialLogisticRegression

Source§

fn clone(&self) -> MultinomialLogisticRegression

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for MultinomialLogisticRegression

Source§

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

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
Source§

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

Source§

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

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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 more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

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

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

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

Source§

fn vzip(self) -> V

Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,