Struct ELM

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

Extreme Learning Machine (ELM) base struct.

Implementations§

Source§

impl ELM

Source

pub fn to_json(&self, path: &Path) -> Result<(), Error>

Serializes ELM into IOELM (intermediate format) and saves it into JSON a file.

Source

pub fn from_json(path: &Path) -> Result<ELM, Error>

Deserializes IOELM (intermediate format) into ELM from a given JSON file.

Source§

impl ELM

Source

pub fn new( input_size: usize, hidden_size: usize, output_size: usize, activation_function: ActivationFunction, epsilon: Epsilon, ) -> Self

Constructs an ELM Neural Network based on the specified architecture.

input_size refers to the number of inputs for each data point, i.e. features.

hidden_size refers to the number of nodes in the hidden layer.

output_size refers to the number of outputs in the output layer.

Source

pub fn train<T: ToMatrix, I: ToMatrix + FromMatrix>( &mut self, inputs: &I, targets: &T, )

Train ELM to predict the targets based on inputs.

inputs shape: (n_data_points x input_size)

targets shape: (n_data_points x output_size)

§Data types:

This function accepts inputs and targets as Vec<Vec<f64>> or nalgebra::DMatrix<f64>.

§Examples

Basic usage:

use elm::{ELM, Epsilon};
use elm::activation_functions::ActivationFunction;

let mut elm = ELM::new(
    2,
    4,
    2,
    ActivationFunction::LeakyReLU,
    Epsilon::Default,
);

// Each row is a data point. Note input size = 2
let inputs: Vec<Vec<f64>> = vec![
    vec![1.0, 0.0],
    vec![1.0, 0.0],
    vec![1.0, 0.0],
    vec![0.0, 1.0],
    vec![0.0, 1.0],
    vec![1.0, 1.0],
    vec![0.0, 0.0],
];

// Each row is a data point. Note output size = 2
let targets: Vec<Vec<f64>> = vec![
    vec![1.0, 1.0],
    vec![1.0, 1.5],
    vec![1.0, 1.5],
    vec![1.0, 0.0],
    vec![1.0, 0.2],
    vec![0.0, 2.0],
    vec![0.0, 0.0],
];

elm.train(&inputs, &targets);
§Panics:

Panics if inputs and targets have different number of data points.

§Performance:

If failed to calculate pseudo inverse, Beta will be set to None and no training metrics will be available.

Source

pub fn predict<T: ToMatrix + FromMatrix>( &self, inputs: &T, ) -> <T as FromMatrix>::Output

Forward pass on ELM, used to predict values based on inputs provided and once the ELM has already being trained.

§Data types:

This function accepts inputs as Vec<Vec<f64>> or nalgebra::DMatrix<f64>. Outputs will have the same type as the inputs.

§Examples

Basic usage:

use elm::{ELM, Epsilon};
use elm::activation_functions::ActivationFunction;

let mut elm = ELM::new(2, 4, 2, ActivationFunction::LeakyReLU, Epsilon::Default);
let inputs: Vec<Vec<f64>> = vec![vec![1.0, 0.0], vec![1.0, 0.0]];
let targets: Vec<Vec<f64>> = vec![vec![1.0, 1.0], vec![1.0, 1.5]];
elm.train(&inputs, &targets);

let new_inputs: Vec<Vec<f64>> = vec![vec![1.0, 4.0], vec![1.3, 0.6]];
let prediction = elm.predict(&new_inputs);   // Type: Vec<Vec<f64>>
Source

pub fn input_size(&self) -> usize

ELM input layer size.

Source

pub fn hidden_size(&self) -> usize

ELM hidden layer size.

Source

pub fn output_size(&self) -> usize

ELM output layer size.

Source

pub fn activation_function(&self) -> ActivationFunction

ELM activation function.

Trait Implementations§

Source§

impl Clone for ELM

Source§

fn clone(&self) -> ELM

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

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

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

impl Freeze for ELM

§

impl RefUnwindSafe for ELM

§

impl Send for ELM

§

impl Sync for ELM

§

impl Unpin for ELM

§

impl UnwindSafe for ELM

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, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
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