11module ReservoirComputing
22
3- using Adapt
4- using CellularAutomata
5- using Distances
6- using LinearAlgebra
7- using NNlib
8- using PartialFunctions
9- using Random
3+ using Adapt: adapt
4+ using CellularAutomata: CellularAutomaton
5+ using LinearAlgebra: eigvals, mul!, I
6+ using NNlib: fast_act, sigmoid
7+ using Random: Random, AbstractRNG
108using Reexport: Reexport, @reexport
11- using Statistics
129using StatsBase: sample
1310using WeightInitializers: DeviceAgnostic, PartialFunction, Utils
1411@reexport using WeightInitializers
1512
16- # define global types
1713abstract type AbstractReservoirComputer end
18- abstract type AbstractOutputLayer end
19- abstract type AbstractPrediction end
20- # should probably move some of these
21- abstract type AbstractGRUVariant end
22-
23- # general output layer struct
24- struct OutputLayer{T, I, S, L} <: AbstractOutputLayer
25- training_method:: T
26- output_matrix:: I
27- out_size:: S
28- last_value:: L
29- end
30-
31- # prediction types
32- """
33- Generative(prediction_len)
34-
35- A prediction strategy that enables models to generate autonomous multi-step
36- forecasts by recursively feeding their own outputs back as inputs for
37- subsequent prediction steps.
38-
39- # Parameters
40-
41- - `prediction_len::Int`: The number of future steps to predict.
42-
43- # Description
44-
45- The `Generative` prediction method allows a model to perform multi-step
46- forecasting by using its own previous predictions as inputs for future predictions.
47- This approach is especially useful in time series analysis, where each prediction
48- depends on the preceding data points.
49-
50- At each step, the model takes the current input, generates a prediction,
51- and then incorporates that prediction into the input for the next step.
52- This recursive process continues until the specified
53- number of prediction steps (`prediction_len`) is reached.
54- """
55- struct Generative{T} <: AbstractPrediction
56- prediction_len:: T
57- end
58-
59- struct Predictive{I, T} <: AbstractPrediction
60- prediction_data:: I
61- prediction_len:: T
62- end
63-
64- """
65- Predictive(prediction_data)
66-
67- A prediction strategy for supervised learning tasks,
68- where a model predicts labels based on a provided set
69- of input features (`prediction_data`).
70-
71- # Parameters
72-
73- - `prediction_data`: The input data used for prediction, typically structured as a matrix
74- where each column represents a sample, and each row represents a feature.
75-
76- # Description
77-
78- The `Predictive` prediction method is a standard approach
79- in supervised machine learning tasks. It uses the provided input data
80- (`prediction_data`) to produce corresponding labels or outputs based
81- on the learned relationships in the model. Unlike generative prediction,
82- this method does not recursively feed predictions into the model;
83- instead, it operates on fixed input data to produce a single batch of predictions.
84-
85- This method is suitable for tasks like classification,
86- regression, or other use cases where the input features
87- and the number of steps are predefined.
88- """
89- function Predictive (prediction_data)
90- prediction_len = size (prediction_data, 2 )
91- Predictive (prediction_data, prediction_len)
92- end
93-
94- # fallbacks for initializers #eventually to remove once migrated to WeightInitializers.jl
95- for initializer in (:rand_sparse , :delay_line , :delay_line_backward , :cycle_jumps ,
96- :simple_cycle , :pseudo_svd ,
97- :scaled_rand , :weighted_init , :informed_init , :minimal_init )
98- @eval begin
99- function ($ initializer)(dims:: Integer... ; kwargs... )
100- return $ initializer (Utils. default_rng (), Float32, dims... ; kwargs... )
101- end
102- function ($ initializer)(rng:: AbstractRNG , dims:: Integer... ; kwargs... )
103- return $ initializer (rng, Float32, dims... ; kwargs... )
104- end
105- function ($ initializer)(:: Type{T} , dims:: Integer... ; kwargs... ) where {T <: Number }
106- return $ initializer (Utils. default_rng (), T, dims... ; kwargs... )
107- end
108-
109- # Partial application
110- function ($ initializer)(rng:: AbstractRNG ; kwargs... )
111- return PartialFunction. Partial {Nothing} ($ initializer, rng, kwargs)
112- end
113- function ($ initializer)(:: Type{T} ; kwargs... ) where {T <: Number }
114- return PartialFunction. Partial {T} ($ initializer, nothing , kwargs)
115- end
116- function ($ initializer)(rng:: AbstractRNG , :: Type{T} ; kwargs... ) where {T <: Number }
117- return PartialFunction. Partial {T} ($ initializer, rng, kwargs)
118- end
119- function ($ initializer)(; kwargs... )
120- return PartialFunction. Partial {Nothing} ($ initializer, nothing , kwargs)
121- end
122- end
123- end
12414
12515# general
12616include (" states.jl" )
@@ -130,8 +20,7 @@ include("predict.jl")
13020include (" train/linear_regression.jl" )
13121
13222# esn
133- include (" esn/esn_input_layers.jl" )
134- include (" esn/esn_reservoirs.jl" )
23+ include (" esn/esn_inits.jl" )
13524include (" esn/esn_reservoir_drivers.jl" )
13625include (" esn/esn.jl" )
13726include (" esn/deepesn.jl" )
@@ -155,9 +44,7 @@ export scaled_rand, weighted_init, informed_init, minimal_init
15544export rand_sparse, delay_line, delay_line_backward, cycle_jumps, simple_cycle, pseudo_svd
15645export RNN, MRNN, GRU, GRUParams, FullyGated, Minimal
15746export train
158- export ESN
159- export HybridESN, KnowledgeModel
160- export DeepESN
47+ export ESN, HybridESN, KnowledgeModel, DeepESN
16148export RECA, sample
16249export RandomMapping, RandomMaps
16350export Generative, Predictive, OutputLayer
0 commit comments