pub struct EchoStateNetwork { /* private fields */ }Implementations§
Source§impl EchoStateNetwork
impl EchoStateNetwork
Sourcepub 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,
) -> Self
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, ) -> Self
Examples found in repository?
examples/xor.rs (lines 21-35)
12fn main() {
13 let (train_input, train_expected_output) = data_gen(TRAIN_STEP, RANDOM_SEED);
14 let (test_input, test_expected_output) = 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 );
36
37 let mut optimizer = Ridge::new(N_X, n_y, BETA);
38
39 model.train(&train_input, &train_expected_output, &mut optimizer);
40
41 let estimated_output = model.estimate(&test_input);
42
43 let (bits_l2_error, bits_l1_error) =
44 get_bits_error_rate(estimated_output.clone(), test_expected_output.clone());
45 let (l2_error, l1_error) =
46 get_error_rate(estimated_output.clone(), test_expected_output.clone());
47 println!("Bits Mean Squared Error: {}", bits_l2_error);
48 println!("Bits Mean Absolute Error: {}", bits_l1_error);
49 println!("Mean Squared Error: {}", l2_error);
50 println!("Mean Absolute Error: {}", l1_error);
51
52 let y_estimated = estimated_output.iter().map(|x| x[0]).collect::<Vec<f64>>();
53 let y_expected = test_expected_output
54 .clone()
55 .into_iter()
56 .flatten()
57 .collect::<Vec<f64>>();
58
59 plotter::plot(
60 "XOR",
61 (0..TEST_STEP).map(|v| v as f64).collect::<Vec<f64>>(),
62 vec![y_expected, y_estimated],
63 vec!["Expected".to_string(), "Output".to_string()],
64 Some(&path),
65 )
66 .unwrap();
67
68 write_as_serde(
69 model,
70 optimizer,
71 &train_input,
72 &train_expected_output,
73 &test_input,
74 &test_expected_output,
75 estimated_output,
76 None,
77 );
78}Sourcepub fn train(
&mut self,
teaching_input: &[Vec<f64>],
teaching_output: &[Vec<f64>],
optimizer: &mut Ridge,
) -> Vec<Vec<f64>>
pub fn train( &mut self, teaching_input: &[Vec<f64>], teaching_output: &[Vec<f64>], optimizer: &mut Ridge, ) -> Vec<Vec<f64>>
Examples found in repository?
examples/xor.rs (line 39)
12fn main() {
13 let (train_input, train_expected_output) = data_gen(TRAIN_STEP, RANDOM_SEED);
14 let (test_input, test_expected_output) = 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 );
36
37 let mut optimizer = Ridge::new(N_X, n_y, BETA);
38
39 model.train(&train_input, &train_expected_output, &mut optimizer);
40
41 let estimated_output = model.estimate(&test_input);
42
43 let (bits_l2_error, bits_l1_error) =
44 get_bits_error_rate(estimated_output.clone(), test_expected_output.clone());
45 let (l2_error, l1_error) =
46 get_error_rate(estimated_output.clone(), test_expected_output.clone());
47 println!("Bits Mean Squared Error: {}", bits_l2_error);
48 println!("Bits Mean Absolute Error: {}", bits_l1_error);
49 println!("Mean Squared Error: {}", l2_error);
50 println!("Mean Absolute Error: {}", l1_error);
51
52 let y_estimated = estimated_output.iter().map(|x| x[0]).collect::<Vec<f64>>();
53 let y_expected = test_expected_output
54 .clone()
55 .into_iter()
56 .flatten()
57 .collect::<Vec<f64>>();
58
59 plotter::plot(
60 "XOR",
61 (0..TEST_STEP).map(|v| v as f64).collect::<Vec<f64>>(),
62 vec![y_expected, y_estimated],
63 vec!["Expected".to_string(), "Output".to_string()],
64 Some(&path),
65 )
66 .unwrap();
67
68 write_as_serde(
69 model,
70 optimizer,
71 &train_input,
72 &train_expected_output,
73 &test_input,
74 &test_expected_output,
75 estimated_output,
76 None,
77 );
78}Sourcepub fn estimate(&mut self, input: &[Vec<f64>]) -> Vec<Vec<f64>>
pub fn estimate(&mut self, input: &[Vec<f64>]) -> Vec<Vec<f64>>
Examples found in repository?
examples/xor.rs (line 41)
12fn main() {
13 let (train_input, train_expected_output) = data_gen(TRAIN_STEP, RANDOM_SEED);
14 let (test_input, test_expected_output) = 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 );
36
37 let mut optimizer = Ridge::new(N_X, n_y, BETA);
38
39 model.train(&train_input, &train_expected_output, &mut optimizer);
40
41 let estimated_output = model.estimate(&test_input);
42
43 let (bits_l2_error, bits_l1_error) =
44 get_bits_error_rate(estimated_output.clone(), test_expected_output.clone());
45 let (l2_error, l1_error) =
46 get_error_rate(estimated_output.clone(), test_expected_output.clone());
47 println!("Bits Mean Squared Error: {}", bits_l2_error);
48 println!("Bits Mean Absolute Error: {}", bits_l1_error);
49 println!("Mean Squared Error: {}", l2_error);
50 println!("Mean Absolute Error: {}", l1_error);
51
52 let y_estimated = estimated_output.iter().map(|x| x[0]).collect::<Vec<f64>>();
53 let y_expected = test_expected_output
54 .clone()
55 .into_iter()
56 .flatten()
57 .collect::<Vec<f64>>();
58
59 plotter::plot(
60 "XOR",
61 (0..TEST_STEP).map(|v| v as f64).collect::<Vec<f64>>(),
62 vec![y_expected, y_estimated],
63 vec!["Expected".to_string(), "Output".to_string()],
64 Some(&path),
65 )
66 .unwrap();
67
68 write_as_serde(
69 model,
70 optimizer,
71 &train_input,
72 &train_expected_output,
73 &test_input,
74 &test_expected_output,
75 estimated_output,
76 None,
77 );
78}pub fn serde_json(&self) -> Result<String>
Auto Trait Implementations§
impl Freeze for EchoStateNetwork
impl RefUnwindSafe for EchoStateNetwork
impl Send for EchoStateNetwork
impl Sync for EchoStateNetwork
impl Unpin for EchoStateNetwork
impl UnwindSafe for EchoStateNetwork
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
Mutably borrows from an owned value. Read more
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>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
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
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
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.