Struct Linear

Source
pub struct Linear<A = f64, K = Biased, D = Ix2, S = OwnedRepr<A>>
where D: Dimension, S: RawData<Elem = A>,
{ /* private fields */ }
Expand description

An implementation of a linear model.

In an effort to streamline the api, the Linear model relies upon a ParamMode type (Biased or Unbiased) which enables the model to automatically determine whether or not to include a bias term. Doing so allows the model to inherit several methods familar to the underlying ndarray crate.

Implementations§

Source§

impl<A, K> Linear<A, K, Ix2, OwnedRepr<A>>
where K: ParamMode,

Source

pub fn std(inputs: usize, outputs: usize) -> Self
where A: Default,

Source§

impl<A, S, D, K> Linear<A, K, D, S>
where D: RemoveAxis, K: ParamMode, S: RawData<Elem = A>,

Source

pub fn new<Sh>(shape: Sh) -> Self
where Sh: ShapeBuilder<Dim = D>, A: Default, S: DataOwned,

Source

pub fn ones<Sh>(shape: Sh) -> Self
where Sh: ShapeBuilder<Dim = D>, A: Clone + One, S: DataOwned,

Source

pub fn zeros<Sh>(shape: Sh) -> Self
where Sh: ShapeBuilder<Dim = D>, A: Clone + Zero, S: DataOwned,

Source

pub fn from_config(config: Config<K, D>) -> Self
where A: Clone + Default, K: ParamMode, S: DataOwned,

Source

pub fn from_layout(layout: Layout<D>) -> Self
where A: Clone + Default, K: ParamMode, S: DataOwned,

Source

pub fn from_params(params: ParamsBase<S, D, K>) -> Self

Source

pub fn activate<X, Y, F>(&self, args: &X, func: F) -> Result<Y>
where F: Fn(Y) -> Y, Self: Predict<X, Output = Y>,

Applies an activcation function onto the prediction of the model.

Source

pub const fn config(&self) -> &Config<K, D>

Source

pub fn weights(&self) -> &ArrayBase<S, D>

Source

pub fn weights_mut(&mut self) -> &mut ArrayBase<S, D>

Source

pub const fn params(&self) -> &ParamsBase<S, D, K>

Source

pub fn params_mut(&mut self) -> &mut ParamsBase<S, D, K>

Source

pub fn into_biased(self) -> Linear<A, Biased, D, S>
where A: Default, K: 'static, S: DataOwned,

Source

pub fn into_unbiased(self) -> Linear<A, Unbiased, D, S>
where A: Default, K: 'static, S: DataOwned,

Source

pub fn is_biased(&self) -> bool
where K: 'static,

Source

pub fn with_params<E>(self, params: LinearParams<A, K, E>) -> Linear<A, K, E>
where E: RemoveAxis,

Source

pub fn with_name(self, name: impl ToString) -> Self

Source

pub fn dim(&self) -> D::Pattern

Return the pattern of the dimension

Source

pub fn ndim(&self) -> usize

Returns rank (ndim) of the dimension

Source

pub fn raw_dim(&self) -> D

Returns the raw dimension D

Source

pub fn shape(&self) -> &[usize]

Returns a reference to the current dimension, as a slice.

Source§

impl<A, S, D> Linear<A, Biased, D, S>
where D: RemoveAxis, S: RawData<Elem = A>,

Source

pub fn biased<Sh>(shape: Sh) -> Self
where A: Default, S: DataOwned, Sh: ShapeBuilder<Dim = D>,

Source

pub fn bias(&self) -> &ArrayBase<S, D::Smaller>

Source

pub fn bias_mut(&mut self) -> &mut ArrayBase<S, D::Smaller>

Source§

impl<A, S, D> Linear<A, Unbiased, D, S>
where D: RemoveAxis, S: RawData<Elem = A>,

Source

pub fn unbiased<Sh>(shape: Sh) -> Self
where A: Default, S: DataOwned, Sh: ShapeBuilder<Dim = D>,

Source§

impl<A, S, D, K> Linear<A, K, D, S>
where A: Clone + Float, D: RemoveAxis, K: ParamMode, S: DataOwned<Elem = A>, StandardNormal: Distribution<A>,

Source

pub fn uniform(self) -> Linear<A, K, D, OwnedRepr<A>>

Source§

impl<A, K, S> Linear<A, K, Ix2, S>
where K: ParamMode, S: RawData<Elem = A>,

Source

pub fn from_features(inputs: usize, outputs: usize) -> Self
where A: Clone + Default, S: DataOwned,

Trait Implementations§

Source§

impl<A, S, D, K> Borrow<Config<K, D>> for Linear<A, K, D, S>
where D: RemoveAxis, S: RawData<Elem = A>,

Source§

fn borrow(&self) -> &Config<K, D>

Immutably borrows from an owned value. Read more
Source§

impl<A, S, D, K> Borrow<ParamsBase<S, D, K>> for Linear<A, K, D, S>
where D: RemoveAxis, S: RawData<Elem = A>,

Source§

fn borrow(&self) -> &ParamsBase<S, D, K>

Immutably borrows from an owned value. Read more
Source§

impl<A, S, D, K> BorrowMut<ParamsBase<S, D, K>> for Linear<A, K, D, S>
where D: RemoveAxis, S: RawData<Elem = A>,

Source§

fn borrow_mut(&mut self) -> &mut ParamsBase<S, D, K>

Mutably borrows from an owned value. Read more
Source§

impl<A, S, D, K> Initialize<A, D> for Linear<A, K, D, S>
where D: RemoveAxis, K: ParamMode, S: DataOwned<Elem = A>, StandardNormal: Distribution<A>,

Source§

type Data = OwnedRepr<A>

Source§

fn rand<Sh, Ds>(shape: Sh, distr: Ds) -> Self
where Sh: ShapeBuilder<Dim = D>, Ds: Clone + Distribution<A>,

Generate a random array using the given distribution
Source§

fn rand_with<Sh, Ds, R>(shape: Sh, distr: Ds, rng: &mut R) -> Self
where R: Rng + ?Sized, Ds: Clone + Distribution<A>, Sh: ShapeBuilder<Dim = D>,

Generate a random array using the given distribution and random number generator
Source§

fn init_rand<Ds>(self, distr: Ds) -> Self
where Ds: Clone + Distribution<A>, Self: Sized,

Initialize an array with random values using the given distribution and current shape
Source§

fn init_rand_with<Ds, R>(self, distr: Ds, rng: &mut R) -> Self
where R: Rng + ?Sized, Ds: Clone + Distribution<A>,

Initialize an array with random values from the current shape using the given distribution and random number generator
Source§

impl<A, K, D> Module for Linear<A, K, D>
where D: RemoveAxis,

Source§

type Config = Config<K, D>

Source§

type Params = ParamsBase<OwnedRepr<A>, D, K>

Source§

fn config(&self) -> &Self::Config

Source§

fn params(&self) -> &Self::Params

Source§

fn params_mut(&mut self) -> &mut Self::Params

Source§

impl<U, V, A, K, D> Predict<U> for Linear<A, K, D>
where D: RemoveAxis, LinearParams<A, K, D>: Predict<U, Output = V>,

Source§

type Output = V

Source§

fn predict(&self, input: &U) -> Result<Self::Output, PredictError>

Auto Trait Implementations§

§

impl<A, K, D, S> Freeze for Linear<A, K, D, S>
where D: Freeze, S: Freeze, <D as Dimension>::Smaller: Freeze,

§

impl<A, K, D, S> RefUnwindSafe for Linear<A, K, D, S>

§

impl<A, K, D, S> Send for Linear<A, K, D, S>
where K: Send, S: Send + Data,

§

impl<A, K, D, S> Sync for Linear<A, K, D, S>
where K: Sync, S: Sync + Data,

§

impl<A, K, D, S> Unpin for Linear<A, K, D, S>
where D: Unpin, K: Unpin, S: Unpin, <D as Dimension>::Smaller: Unpin,

§

impl<A, K, D, S> UnwindSafe for Linear<A, K, D, S>

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<X, Y, S> Forward<X> for S
where S: Predict<X, Output = Y>,

Source§

type Output = Y

Source§

fn forward(&self, args: &X) -> <S as Forward<X>>::Output

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<K, S> Id<K> for S
where S: Borrow<K>, K: Identifier,

Source§

type Item = S

Source§

fn get(&self) -> &<S as Id<K>>::Item

Source§

impl<U, A, S, D> InitializeExt<A, S, D> for U
where A: Clone, D: Dimension, S: RawData<Elem = A>, U: Initialize<A, D, Data = S>,

Source§

fn bernoulli<Sh>(shape: Sh, p: f64) -> Result<Self, BernoulliError>
where S: DataOwned, Sh: ShapeBuilder<Dim = D>, Bernoulli: Distribution<A>,

Source§

fn lecun_normal<Sh>(shape: Sh, n: usize) -> Self
where A: Float, S: DataOwned, Sh: ShapeBuilder<Dim = D>, StandardNormal: Distribution<A>,

Initialize the object according to the Lecun Initialization scheme. LecunNormal distributions are truncated Normal distributions centered at 0 with a standard deviation equal to the square root of the reciprocal of the number of inputs.
Source§

fn normal<Sh>(shape: Sh, mean: A, std: A) -> Result<Self, Error>
where A: Float, S: DataOwned, Sh: ShapeBuilder<Dim = D>, StandardNormal: Distribution<A>,

Given a shape, mean, and standard deviation generate a new object using the Normal distribution
Source§

fn randc<Sh>(shape: Sh, re: A, im: A) -> Self
where S: DataOwned, Sh: ShapeBuilder<Dim = D>, ComplexDistribution<A>: Distribution<A>,

Source§

fn stdnorm<Sh>(shape: Sh) -> Self
where S: DataOwned, Sh: ShapeBuilder<Dim = D>, StandardNormal: Distribution<A>,

Generate a random array using the StandardNormal distribution
Source§

fn stdnorm_from_seed<Sh>(shape: Sh, seed: u64) -> Self
where S: DataOwned, Sh: ShapeBuilder<Dim = D>, StandardNormal: Distribution<A>,

Generate a random array using the StandardNormal distribution with a given seed
Source§

fn truncnorm<Sh>(shape: Sh, mean: A, std: A) -> Result<Self, Error>
where A: Float, S: DataOwned, Sh: ShapeBuilder<Dim = D>, StandardNormal: Distribution<A>,

Initialize the object using the TruncatedNormal distribution
Source§

fn uniform<Sh>(shape: Sh, dk: A) -> Self
where A: Neg<Output = A> + SampleUniform, S: DataOwned, Sh: ShapeBuilder<Dim = D>, <A as SampleUniform>::Sampler: Clone,

A uniform generator with values between u(-dk, dk)
Source§

fn uniform_from_seed<Sh>(shape: Sh, start: A, stop: A, key: u64) -> Self
where A: SampleUniform, S: DataOwned, Sh: ShapeBuilder<Dim = D>, <A as SampleUniform>::Sampler: Clone,

Source§

fn uniform_along<Sh>(shape: Sh, axis: usize) -> Self
where A: Copy + Float + SampleUniform, S: DataOwned, Sh: ShapeBuilder<Dim = D>, <A as SampleUniform>::Sampler: Clone,

Generate a random array with values between u(-a, a) where a is the reciprocal of the value at the given axis
Source§

fn uniform_between<Sh>(shape: Sh, a: A, b: A) -> Self
where A: SampleUniform, S: DataOwned, Sh: ShapeBuilder<Dim = D>, <A as SampleUniform>::Sampler: Clone,

A uniform generator with values between u(-dk, dk)
Source§

impl<T> Instrument for T

Source§

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

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

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.

Source§

impl<T> IsBiased for T
where T: 'static,

Source§

fn is_biased(&self) -> bool

Source§

impl<T> IsType for T
where T: 'static,

Source§

fn of<T>() -> bool
where T: 'static,

Source§

fn is<T>(&self) -> bool
where T: 'static,

Source§

impl<T> OfType for T

Source§

fn of<T>() -> bool
where T: 'static, Self: 'static,

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

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

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

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

fn with_current_subscriber(self) -> WithDispatch<Self>

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

impl<T, M> ModuleExt<T> for M
where M: Module + Predict<T>,