Struct Sequential

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

Implementation of the neural network / sequential models of layers

Implementations§

Source§

impl Sequential

Source

pub fn new(num_inputs: usize) -> Sequential

Create a new instance of a sequential model num_inputs = the number of inputs to the model

Source

pub fn get_num_inputs(&self) -> usize

Returns the requested input dimension

Source

pub fn get_layers(&self) -> &Vec<Layer>

Get the layers (as ref)

Source

pub fn get_layers_mut(&mut self) -> &mut Vec<Layer>

Get the layers (as mut)

Source

pub fn get_params(&self) -> Vec<Float>

Return the flat parameters of the layers (including LReLU factors). Used for evolution-strategies

Source

pub fn set_params(&mut self, params: &[Float]) -> &mut Self

Set the layers’ parameters (including LReLU factors) by a flat input. Used for evolution-strategies. Panics if params’ size does not fit the layers

Source

pub fn add_layer(&mut self, layer: Layer) -> &mut Self

Add a layer to the sequential model. Be sure to have appropriate parameters inside the layer, they are not checked! You can use specific add_layer_ methods to get simple, correct creation of layers with parameters.

Source

pub fn add_layer_lrelu(&mut self, factor: Float) -> &mut Self

Add a LReLU layer: factor = factor to apply to x < 0

Source

pub fn add_layer_prelu(&mut self, factor: Float) -> &mut Self

Add a PReLU layer: factor = factor to apply to x < 0

Source

pub fn add_layer_pelu(&mut self, a: Float, b: Float) -> &mut Self

Add a PELU layer: a and b are the specific factors

Source

pub fn add_layer_dropout(&mut self, d: Float) -> &mut Self

Add a Dropout layer: d = fraction of nodes to drop

Source

pub fn add_layer_dense( &mut self, neurons: usize, init: Initializer, ) -> &mut Self

Add a Dense layer: neurons = number of neurons/units in the layer init = initializer to use (use He for ReLU, Glorot for Tanh)

Source

pub fn run(&self, input: &[Float]) -> Vec<Float>

Do a forward pass through the model

Source

pub fn predict(&self, inputs: &[Vec<Float>]) -> Vec<Vec<Float>>

Predict values (forward pass) for a vector of input data (Vec):

Source

pub fn to_json(&self) -> String

Encodes the model as a JSON string.

Source

pub fn from_json(encoded: &str) -> Sequential

Builds a new model from a JSON string.

Source

pub fn from_reader<R: Read>(encoded: R) -> Sequential

Builds a new model from a JSON reader (e.g. file).

Source

pub fn save(&self, file: &str) -> Result<(), Error>

Saves the model to a file

Source

pub fn load(file: &str) -> Result<Sequential, Error>

Creates a model from a previously saved file

Source

pub fn calc_mse(&self, target: &[(Vec<Float>, Vec<Float>)]) -> Float

Calculate the error to a target set (Vec<(x, y)>): Mean squared error (for regression) Potentially ignores different vector lenghts!

Source

pub fn calc_rmse(&self, target: &[(Vec<Float>, Vec<Float>)]) -> Float

Calculate the error to a target set (Vec<(x, y)>): Root mean squared error (for regression) Potentially ignores different vector lenghts!

Source

pub fn calc_mae(&self, target: &[(Vec<Float>, Vec<Float>)]) -> Float

Calculate the error to a target set (Vec<(x, y)>): Mean absolute error (for regression) Potentially ignores different vector lenghts!

Source

pub fn calc_mape(&self, target: &[(Vec<Float>, Vec<Float>)]) -> Float

Calculate the error to a target set (Vec<(x, y)>): Mean absolute percentage error (better don’t use if target has 0 values) (for regression) Potentially ignores different vector lenghts!

Source

pub fn calc_logcosh(&self, target: &[(Vec<Float>, Vec<Float>)]) -> Float

Calculate the error to a target set (Vec<(x, y)>): logcosh (for regression) Potentially ignores different vector lenghts!

Source

pub fn calc_binary_crossentropy( &self, target: &[(Vec<Float>, Vec<Float>)], ) -> Float

Calculate the error to a target set (Vec<(x, y)>): binary cross-entropy (be sure to use 0, 1 classifiers+labels) (for classification) Potentially ignores different vector lenghts!

Source

pub fn calc_categorical_crossentropy( &self, target: &[(Vec<Float>, Vec<Float>)], ) -> Float

Calculate the error to a target set (Vec<(x, y)>): categorical cross-entropy (be sure to use 0, 1 classifiers+labels) (for classification) Potentially ignores different vector lenghts!

Source

pub fn calc_hingeloss(&self, target: &[(Vec<Float>, Vec<Float>)]) -> Float

Calculate the error to a target set (Vec<(x, y)>): hinge loss (be sure to use 1, -1 classifiers+labels) (for classification) Potentially ignores different vector lenghts!

Trait Implementations§

Source§

impl Clone for Sequential

Source§

fn clone(&self) -> Sequential

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Sequential

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Sequential

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for Sequential

Source§

fn eq(&self, other: &Sequential) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for Sequential

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Sequential

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<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> 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> 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 = 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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,