EchoStateNetwork

Struct EchoStateNetwork 

Source
pub struct EchoStateNetwork { /* private fields */ }

Implementations§

Source§

impl EchoStateNetwork

Source

pub fn new( n_u: u64, n_y: u64, n_x: u64, density: f64, input_scale: f64, rho: f64, activation: fn(f64) -> f64, feedback_scale: Option<f64>, noise_level: Option<f64>, leaking_rate: f64, output_function: fn(&DVector<f64>) -> DVector<f64>, inverse_output_function: fn(&DVector<f64>) -> DVector<f64>, is_classification: bool, ridge_beta: f64, ) -> Self

Examples found in repository?
examples/narma.rs (lines 30-45)
19fn main() {
20    let (train_input, train_expected_output) =
21        narma_n_data_gen(TRAIN_STEP, RANDOM_SEED, NARMA_STEP);
22    let (test_input, test_expected_output) =
23        narma_n_data_gen(TEST_STEP, TEST_RANDOM_SEED, NARMA_STEP);
24
25    let path = format!("{}/examples/graph", env!("CARGO_MANIFEST_DIR"));
26
27    let n_u = train_input.first().unwrap().len() as u64;
28    let n_y = train_expected_output.first().unwrap().len() as u64;
29
30    let mut model = EchoStateNetwork::new(
31        n_u,
32        n_y,
33        N_X,
34        0.1,
35        1.0,
36        0.9,
37        |x| x.tanh(),
38        None,
39        None,
40        1.0,
41        |x| x.clone_owned(),
42        |x| x.clone_owned(),
43        false,
44        BETA,
45    );
46
47    model.offline_train(&train_input, &train_expected_output);
48
49    let mut estimated_output = vec![];
50    for input in test_input.iter() {
51        estimated_output.push(model.estimate(input));
52    }
53
54    let (l2_error, l1_error) = get_error_rate(
55        estimated_output.clone(),
56        test_expected_output.clone(),
57        NARMA_STEP,
58    );
59    println!("Mean Squared Error: {}", l2_error);
60    println!("Mean Absolute Error: {}", l1_error);
61
62    let y_estimated = estimated_output.iter().map(|x| x[0]).collect::<Vec<f64>>();
63    let y_expected = test_expected_output
64        .clone()
65        .into_iter()
66        .flatten()
67        .collect::<Vec<f64>>();
68
69    plotter::plot(
70        "NARMA",
71        (0..TEST_STEP).map(|v| v as f64).collect::<Vec<f64>>(),
72        vec![y_expected, y_estimated],
73        vec!["Expected".to_string(), "Estimated".to_string()],
74        Some(&path),
75    )
76    .unwrap();
77}
More examples
Hide additional examples
examples/xor.rs (lines 21-36)
12fn main() {
13    let (train_input, train_expected_output) = xor_data_gen(TRAIN_STEP, RANDOM_SEED);
14    let (test_input, test_expected_output) = xor_data_gen(TEST_STEP, TEST_RANDOM_SEED);
15
16    let path = format!("{}/examples/graph", env!("CARGO_MANIFEST_DIR"));
17
18    let n_u = train_input.first().unwrap().len() as u64;
19    let n_y = train_expected_output.first().unwrap().len() as u64;
20
21    let mut model = EchoStateNetwork::new(
22        n_u,
23        n_y,
24        N_X,
25        0.1,
26        1.0,
27        0.9,
28        |x| x.tanh(),
29        None,
30        None,
31        1.0,
32        |x| x.clone_owned(),
33        |x| x.clone_owned(),
34        false,
35        BETA,
36    );
37
38    model.offline_train(&train_input, &train_expected_output);
39
40    let mut estimated_output = vec![];
41    for input in test_input.iter() {
42        estimated_output.push(model.estimate(input));
43    }
44
45    let (bits_l2_error, bits_l1_error) =
46        get_bits_error_rate(estimated_output.clone(), test_expected_output.clone(), 2);
47    let (l2_error, l1_error) =
48        get_error_rate(estimated_output.clone(), test_expected_output.clone(), 2);
49    println!("Bits Mean Squared Error: {}", bits_l2_error);
50    println!("Bits Mean Absolute Error: {}", bits_l1_error);
51    println!("Mean Squared Error: {}", l2_error);
52    println!("Mean Absolute Error: {}", l1_error);
53
54    let y_estimated = estimated_output.iter().map(|x| x[0]).collect::<Vec<f64>>();
55    let y_expected = test_expected_output
56        .clone()
57        .into_iter()
58        .flatten()
59        .collect::<Vec<f64>>();
60
61    plotter::plot(
62        "XOR",
63        (0..TEST_STEP).map(|v| v as f64).collect::<Vec<f64>>(),
64        vec![y_expected, y_estimated],
65        vec!["Expected".to_string(), "Output".to_string()],
66        Some(&path),
67    )
68    .unwrap();
69
70    write_as_serde(
71        model,
72        &train_input,
73        &train_expected_output,
74        &test_input,
75        &test_expected_output,
76        estimated_output,
77        None,
78    );
79}
Source

pub fn serde_json(&self) -> Result<String>

Trait Implementations§

Source§

impl ReservoirComputing for EchoStateNetwork

Source§

fn train(&mut self, teaching_input: &[f64], teaching_output: &[f64])

Online training method.
Source§

fn offline_train( &mut self, teaching_input: &[Vec<f64>], teaching_output: &[Vec<f64>], )

Offline training method.
Source§

fn estimate(&mut self, input: &[f64]) -> Vec<f64>

Estimate method.

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> 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, 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