Skip to content

Commit 0b229c4

Browse files
docs: update esn and deepesn tutorials page
1 parent 2b99b00 commit 0b229c4

File tree

7 files changed

+98
-410
lines changed

7 files changed

+98
-410
lines changed

docs/pages.jl

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,7 @@
11
pages = [
22
"ReservoirComputing.jl" => "index.md",
3-
"General Settings" => Any[
4-
"Changing Training Algorithms"=>"general/different_training.md",
5-
"Altering States"=>"general/states_variation.md",
6-
"Generative vs Predictive"=>"general/predictive_generative.md"],
7-
"Echo State Network Tutorials" => Any[
3+
"Tutorials" => Any[
84
"Lorenz System Forecasting"=>"esn_tutorials/lorenz_basic.md",
9-
#"Mackey-Glass Forecasting on GPU" => "esn_tutorials/mackeyglass_basic.md",
10-
"Using Different Layers"=>"esn_tutorials/change_layers.md",
11-
"Using Different Reservoir Drivers"=>"esn_tutorials/different_drivers.md",
125
#"Using Different Training Methods" => "esn_tutorials/different_training.md",
136
"Deep Echo State Networks"=>"esn_tutorials/deep_esn.md",
147
"Hybrid Echo State Networks"=>"esn_tutorials/hybrid.md"],

docs/src/esn_tutorials/change_layers.md

Lines changed: 0 additions & 85 deletions
This file was deleted.

docs/src/esn_tutorials/deep_esn.md

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
# Deep Echo State Networks
22

3-
Deep Echo State Network architectures started to gain some traction recently. In this guide, we illustrate how it is possible to use ReservoirComputing.jl to build a deep ESN.
4-
5-
The network implemented in this library is taken from [Gallicchio2017](@cite). It works by stacking reservoirs on top of each other, feeding the output from one into the next. The states are obtained by merging all the inner states of the stacked reservoirs. For a more in-depth explanation, refer to the paper linked above.
3+
In this example we showcase how to build a deep echo state network (DeepESN)
4+
following the work of [Gallicchio2017](@cite). The DeepESN stacks reservoirs
5+
on top of each other, feeding the output from one into the next.
6+
In the version implemented in ReservoirComputing.jl the final state is the state
7+
used for training.
68

79
## Lorenz Example
810

9-
For this example, we are going to reuse the Lorenz data used in the [Lorenz System Forecasting](@ref) example.
11+
We are going to reuse the Lorenz data used in the
12+
[Lorenz System Forecasting](@ref) example.
1013

1114
```@example deep_lorenz
1215
using OrdinaryDiffEq
@@ -34,35 +37,30 @@ target_data = data[:, (shift + 1):(shift + train_len)]
3437
test_data = data[:, (shift + train_len + 1):(shift + train_len + predict_len)]
3538
```
3639

37-
Again, it is *important* to notice that the data needs to be formatted in a matrix, with the features as rows and time steps as columns, as in this example. This is needed even if the time series consists of single values.
38-
39-
The construction of the ESN is also really similar. The only difference is that the reservoir can be fed as an array of reservoirs.
40+
The call for the DeepESN works similarly to the ESN.
41+
The only difference is that the reservoir (and corresponding kwargs)
42+
can be fed as an array.
4043

4144
```@example deep_lorenz
4245
using ReservoirComputing
46+
desn = DeepESN(input_size, [res_size, res_size], input_size;
47+
init_reservoir=rand_sparse(; radius=1.2, sparsity=6/300),
48+
state_modifiers=ExtendedSquare
49+
)
4350
44-
reservoirs = [rand_sparse(; radius=1.1, sparsity=0.1),
45-
rand_sparse(; radius=1.2, sparsity=0.1),
46-
rand_sparse(; radius=1.4, sparsity=0.1)]
47-
48-
esn = DeepESN(input_data, 3, 200;
49-
reservoir=reservoirs,
50-
reservoir_driver=RNN(),
51-
nla_type=NLADefault(),
52-
states_type=StandardStates())
5351
```
5452

55-
The input layer and bias can also be given as vectors, but of course, they have to be of the same size of the reservoirs vector. If they are not passed as a vector, the value passed will be used for all the layers in the deep ESN.
56-
57-
In addition to using the provided functions for the construction of the layers, the user can also choose to build their own matrix, or array of matrices, and feed that into the `ESN` in the same way.
58-
5953
The training and prediction follow the usual framework:
6054

6155
```@example deep_lorenz
62-
training_method = StandardRidge(0.0)
63-
output_layer = train(esn, target_data, training_method)
56+
using Random
57+
Random.seed!(42)
58+
rng = MersenneTwister(17)
59+
60+
ps, st = setup(rng, esn)
61+
ps, st = train!(esn, input_data, target_data, ps, st)
6462
65-
output = esn(Generative(predict_len), output_layer)
63+
output, st = predict(esn, 1250, ps, st; initialdata=test[:, 1])
6664
```
6765

6866
Plotting the results:
@@ -93,4 +91,4 @@ plot(p1, p2, p3; plot_title="Lorenz System Coordinates",
9391
```@bibliography
9492
Pages = ["deep_esn.md"]
9593
Canonical = false
96-
```
94+
```

0 commit comments

Comments
 (0)