lazymatrix::NormalizationChainParams
LazyMatrix for Rust · 0.9.0
pub struct NormalizationChainParams<A, B>Fitted stages retained in the same order and tree shape as their recipes.
Column stages contain ColumnNormalizationParams. Row stages contain FittedRowNormalization, retaining the recipe needed to prepare new samples. Application consumes owned stages or explicit borrowed views.
Chains deliberately require explicit application names:
use lazymatrix::{ColumnNormalizationParams, FittedRowNormalization,
MatrixShape, NormalizationChainParams, RowNormalizationParams};
fn ambiguous<M: MatrixShape>(
params: NormalizationChainParams<
FittedRowNormalization<RowNormalizationParams>, ColumnNormalizationParams>,
data: M,
) {
let _ = params.apply(data);
}Mixed chains do not acquire batched products:
use lazymatrix::{ColumnNormalization, MatMatInto, MatrixErrorType,
MatrixRead, MatrixWrite, RowNormalization};
fn batched<M: MatrixRead<f64> + MatrixErrorType,
D: MatrixRead<f64> + MatrixWrite<f64>>(data: M, rhs: &D, out: &mut D)
{
let op = RowNormalization::standardize()
.then(ColumnNormalization::standardize()).fit_apply(data).unwrap();
op.matmat_into(rhs, out).unwrap();
}Preparing new samples cannot extend borrowed column parameters' lifetime:
use lazymatrix::{ColumnNormalizationParams, ColumnNormalizationParamsView,
FittedRowNormalization, LazyMatrix, MatrixErrorType, MatrixRead,
NormalizationChainParams, RowNormalization, RowNormalizationParams};
fn escaped<M: MatrixRead<f64> + MatrixErrorType>(data: M)
-> LazyMatrix<M, NormalizationChainParams<
FittedRowNormalization<RowNormalizationParams>,
ColumnNormalizationParamsView<'static>>>
{
let rows = FittedRowNormalization::from_parts(RowNormalization::standardize(),
RowNormalizationParams::from_parts(data.nrows(), None, None));
let cols = ColumnNormalizationParams::from_parts(data.ncols(), None, None);
let params = NormalizationChainParams::from_parts(rows, cols);
params.view().for_new_samples(data).unwrap()
}Inherent implementation
impl<A, B> NormalizationChainParams<A, B> where A: Stage, B: Stage<Scalar = <A as NormalizationParams>::Scalar>, <A as >::Kind: Combine<<B as >::Kind>apply_frozen
pub fn apply_frozen<M: MatrixShape>(self, data: M) -> LazyMatrix<M, Self>Apply every saved stage unchanged to matching rows and columns.
This performs no fitting, data reads, or parameter copies.
Panics
Panics if any fitted axis has a different dimension from the data.
first
pub fn first(&self) -> &AInspect the first fitted stage or prefix.
for_new_samples
pub fn for_new_samples<M>(
self,
data: M
) -> Result<LazyMatrix<M, <Self as Stage>::NewRows>, <M as MatrixErrorType>::Error> where M: MatrixShape + MatrixErrorType, <Self as Stage>::Kind: Prepare<M, Self>Prepare new samples, refitting row stages and reusing column stages.
Row fitting occurs after the preceding prepared stages. Owned column parameters move into the result; a view lends its training columns to the result. Newly fitted row parameters are owned in both cases.
Errors
Returns the backend error from preparation.
Panics
Panics before reading data if a saved column count differs.
from_parts
pub fn from_parts(first: A, next: B) -> SelfAssemble explicit or previously fitted stages without fitting or copying.
Matrix dimensions are validated when the chain is applied.
into_parts
pub fn into_parts(self) -> (A, B)Recover both fitted stages without copying.
next
pub fn next(&self) -> &BInspect the next fitted stage or suffix.
view
pub fn view(
&self
) -> NormalizationChainParams<<A as >::View<'_>, <B as >::View<'_>>Borrow all saved parameter vectors without allocation or copying.
Implementation of Clone
impl<A: core::clone::Clone, B: core::clone::Clone> Clone for NormalizationChainParams<A, B>clone
fn clone(&self) -> SelfImplementation of Copy
impl<A: core::marker::Copy, B: core::marker::Copy> Copy for NormalizationChainParams<A, B>Implementation of Debug
impl<A: core::fmt::Debug, B: core::fmt::Debug> Debug for NormalizationChainParams<A, B>fmt
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::ResultImplementation of NormalizationParams
impl<A, B> NormalizationParams for NormalizationChainParams<A, B> where A: Stage, B: Stage<Scalar = <A as NormalizationParams>::Scalar>, <A as >::Kind: Combine<<B as >::Kind>Scalar
type Scalar = <A as NormalizationParams>::Scalar;Implementation of Params
impl<A, B> Params for NormalizationChainParams<A, B> where A: Stage, B: Stage<Scalar = <A as NormalizationParams>::Scalar>, <A as >::Kind: Combine<<B as >::Kind>assert_shape
fn assert_shape(&self, nrows: usize, ncols: usize)Implementation of PartialEq
impl<A: core::cmp::PartialEq, B: core::cmp::PartialEq> PartialEq for NormalizationChainParams<A, B>eq
fn eq(&self, other: &Self) -> boolImplementation of Recipe
impl<M, A, B, P, Q> Recipe<M, NormalizationChainParams<P, Q>> for NormalizationChain<A, B> where M: MatrixShape + MatrixErrorType, P: Stage, Q: Stage<Scalar = <P as NormalizationParams>::Scalar>, <P as >::Kind: Combine<<Q as >::Kind>, Self: Fit<M, <P as NormalizationParams>::Scalar, Params = NormalizationChainParams<P, Q>>Implementation of ReuseColumns
impl<A, B> ReuseColumns for NormalizationChainParams<A, B> where A: ReuseColumns<Kind = Columns>, B: ReuseColumns<Scalar = <A as NormalizationParams>::Scalar, Kind = Columns>reuse
fn reuse(self) -> <Self as >::NewRowsImplementation of Stage
impl<A, B> Stage for NormalizationChainParams<A, B> where A: Stage, B: Stage<Scalar = <A as NormalizationParams>::Scalar>, <A as >::Kind: Combine<<B as >::Kind>Kind
type Kind = <<A as Stage>::Kind as Combine<<B as Stage>::Kind>>::Output;NewRows
type NewRows = NormalizationChainParams<<A as Stage>::NewRows, <B as Stage>::NewRows>;View
type View<'a> = NormalizationChainParams<<A as Stage>::View<'a>, <B as Stage>::View<'a>> where Self: 'a;assert_columns
fn assert_columns(&self, ncols: usize)entry
fn entry(
&self,
value: <Self as NormalizationParams>::Scalar,
row: usize,
column: usize
) -> <Self as NormalizationParams>::Scalarprepare_dense
fn prepare_dense<M, P>(
self,
data: &M,
prefix: &P
) -> Result<<Self as >::NewRows, <M as MatrixErrorType>::Error> where M: MatrixRead<<Self as NormalizationParams>::Scalar> + MatrixErrorType, P: Stage<Scalar = <Self as NormalizationParams>::Scalar>stage_view
fn stage_view(&self) -> <Self as >::View<'_>Implementation of StructuralPartialEq
impl<A: core::cmp::PartialEq, B: core::cmp::PartialEq> StructuralPartialEq for NormalizationChainParams<A, B>Implementation of Freeze
impl<A, B> Freeze for NormalizationChainParams<A, B> where A: Freeze, B: FreezeImplementation of RefUnwindSafe
impl<A, B> RefUnwindSafe for NormalizationChainParams<A, B> where A: RefUnwindSafe, B: RefUnwindSafeImplementation of Send
impl<A, B> Send for NormalizationChainParams<A, B> where A: Send, B: SendImplementation of Sync
impl<A, B> Sync for NormalizationChainParams<A, B> where A: Sync, B: SyncImplementation of Unpin
impl<A, B> Unpin for NormalizationChainParams<A, B> where A: Unpin, B: UnpinImplementation of UnsafeUnpin
impl<A, B> UnsafeUnpin for NormalizationChainParams<A, B> where A: UnsafeUnpin, B: UnsafeUnpinImplementation of UnwindSafe
impl<A, B> UnwindSafe for NormalizationChainParams<A, B> where A: UnwindSafe, B: UnwindSafeImplementation of Any
impl<T> Any for T where T: 'static + ?SizedImplementation of Boilerplate
impl<T> Boilerplate for T where T: Copy + Send + Sync + Debug + PartialEq + 'staticImplementation of Borrow
impl<T> Borrow<T> for T where T: ?SizedImplementation of BorrowMut
impl<T> BorrowMut<T> for T where T: ?SizedImplementation of ByRef
impl<T> ByRef<T> for TImplementation of CastableFrom
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT where ST: ?Sized, DT: ?SizedImplementation of CastableFrom
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT where ST: ?Sized, DT: ?SizedImplementation of CloneToUninit
impl<T> CloneToUninit for T where T: CloneImplementation of From
impl<T> From<T> for TImplementation of Imply
impl<T, U> Imply<T> for U where T: ?Sized, U: ?SizedImplementation of Into
impl<T, U> Into<U> for T where U: From<T>Implementation of IntoEither
impl<T> IntoEither for TImplementation of Pointable
impl<T> Pointable for TImplementation of Read
impl<T> Read<Exclusive, BecauseExclusive> for T where T: ?SizedImplementation of Same
impl<T> Same for TImplementation of Scalar
impl<T> Scalar for T where T: 'static + Clone + PartialEq + DebugImplementation of SupersetOf
impl<SS, SP> SupersetOf<SS> for SP where SS: SubsetOf<SP>Implementation of ToOwned
impl<T> ToOwned for T where T: CloneImplementation of TryFrom
impl<T, U> TryFrom<U> for T where U: Into<T>Implementation of TryInto
impl<T, U> TryInto<U> for T where U: TryFrom<T>
