-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b312b82
commit 1c8c0ae
Showing
8 changed files
with
156 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,13 @@ | ||
mod echo_state_network; | ||
mod model; | ||
mod optimizer; | ||
mod physical_reservoir; | ||
mod plot; | ||
mod reservoir_computing; | ||
mod serialize; | ||
mod utils; | ||
|
||
pub use echo_state_network::*; | ||
pub(crate) use model::*; | ||
pub use optimizer::*; | ||
pub use physical_reservoir::*; | ||
pub use plot::*; | ||
pub use reservoir_computing::*; | ||
pub use serialize::*; | ||
pub use utils::*; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
mod echo_state_network; | ||
mod physical_reservoir; | ||
|
||
pub use echo_state_network::*; | ||
pub use physical_reservoir::*; | ||
|
||
pub trait ReservoirComputing { | ||
/// Online training method. | ||
fn train(&mut self, teaching_input: &[f64], teaching_output: &[f64]); | ||
/// Offline training method. | ||
fn offline_train(&mut self, teaching_input: &[Vec<f64>], teaching_output: &[Vec<f64>]); | ||
/// Estimate method. | ||
fn estimate(&mut self, input: &[f64]) -> Vec<f64>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
use nalgebra as na; | ||
|
||
use crate::*; | ||
|
||
pub struct PhysicalReservoir { | ||
output: Output, | ||
rls: Option<RLS>, | ||
ridge: Option<Ridge>, | ||
} | ||
|
||
impl PhysicalReservoir { | ||
pub fn new(n_y: u64, n_x: u64) -> Self { | ||
PhysicalReservoir { | ||
output: Output::new(n_y, n_x), | ||
rls: Some(RLS::new(n_x, n_y, 1.0, 1.0)), | ||
ridge: Some(Ridge::new(n_x, n_y, 0.1)), | ||
} | ||
} | ||
|
||
pub fn readout_weight(&self) -> &na::DMatrix<f64> { | ||
self.output.output_weight() | ||
} | ||
} | ||
|
||
impl ReservoirComputing for PhysicalReservoir { | ||
/// Online training method. | ||
/// teaching_input: Input data for training. In this case, it is a sensor data from the physical reservoir. | ||
fn train(&mut self, teaching_input: &[f64], teaching_output: &[f64]) { | ||
match &mut self.rls { | ||
Some(rls) => { | ||
let x = na::DVector::from_vec(teaching_input.to_vec()); | ||
let d = na::DVector::from_vec(teaching_output.to_vec()); | ||
rls.set_data(&x, &d); | ||
let weight = rls.fit(); | ||
self.output.set_weight(weight); | ||
} | ||
None => panic!("RLS is not initialized"), | ||
} | ||
} | ||
|
||
fn offline_train(&mut self, teaching_input: &[Vec<f64>], teaching_output: &[Vec<f64>]) { | ||
match &mut self.ridge { | ||
Some(ridge) => { | ||
for (input, output) in teaching_input.iter().zip(teaching_output.iter()) { | ||
let x = na::DVector::from_vec(input.clone()); | ||
let d = na::DVector::from_vec(output.clone()); | ||
ridge.set_data(&x, &d); | ||
} | ||
|
||
let weight = ridge.fit(); | ||
self.output.set_weight(weight); | ||
} | ||
None => panic!("Ridge is not initialized"), | ||
} | ||
} | ||
|
||
/// Estimate method. | ||
/// input: Input data for estimating. In this case, it is a sensor data from the physical reservoir. | ||
fn estimate(&mut self, input: &[f64]) -> Vec<f64> { | ||
let x = na::DVector::from_vec(input.to_vec()); | ||
let output = self.output.call(&x); | ||
output.data.as_slice().to_vec() | ||
} | ||
} |
Oops, something went wrong.