pub struct ELM { /* private fields */ }
Expand description
Extreme Learning Machine (ELM) base struct.
Implementations§
Source§impl ELM
impl ELM
Sourcepub fn new(
input_size: usize,
hidden_size: usize,
output_size: usize,
activation_function: ActivationFunction,
epsilon: Epsilon,
) -> Self
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.
Sourcepub fn train<T: ToMatrix, I: ToMatrix + FromMatrix>(
&mut self,
inputs: &I,
targets: &T,
)
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.
Sourcepub fn predict<T: ToMatrix + FromMatrix>(
&self,
inputs: &T,
) -> <T as FromMatrix>::Output
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>>
Sourcepub fn input_size(&self) -> usize
pub fn input_size(&self) -> usize
ELM input layer size.
ELM hidden layer size.
Sourcepub fn output_size(&self) -> usize
pub fn output_size(&self) -> usize
ELM output layer size.
Sourcepub fn activation_function(&self) -> ActivationFunction
pub fn activation_function(&self) -> ActivationFunction
ELM activation function.
Trait Implementations§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self
from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self
is actually part of its subset T
(and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset
but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self
to the equivalent element of its superset.