From d13012fd5c4daa462058d30e291e455580ed6bf7 Mon Sep 17 00:00:00 2001 From: MartinuzziFrancesco Date: Thu, 22 Oct 2026 16:01:53 +0200 Subject: [PATCH] fix: extend LuxCore.parameterlength, docstring corrections, dead code - parameterlength for LinearReadout and SVMReadout now extends LuxCore.parameterlength instead of defining a separate unexported function. - ESNCell, EuSNCell and MemoryESNCell docstrings list init_bias = zeros32, matching the constructors. - self_loop! docstring describes what it does (it was copied from add_jumps!). - Extension load messages no longer ask to load SciMLBase, a hard dependency. - Initializer docstrings state the rng-less default rng, Xoshiro(1234), instead of attributing it to WeightInitializers. - RECA docstring documents readout_in_dims. - Remove RCFields, __set_readout, commented-out code lines, and __fillvec (replaced by fill). Co-Authored-By: Claude Opus 5.5 --- ext/RCCellularAutomataExt.jl | 3 -- src/ReservoirComputing.jl | 2 +- src/extensions/reca.jl | 2 + src/generics.jl | 1 - src/inits/inits_components.jl | 27 +++++--------- src/inits/inits_input.jl | 24 ++++-------- src/inits/inits_lsm.jl | 3 +- src/inits/inits_reservoir.jl | 66 +++++++++++---------------------- src/layers/esn_cell.jl | 5 +-- src/layers/eusn_cell.jl | 5 +-- src/layers/memoryesn_cell.jl | 4 +- src/models/esn_generics.jl | 18 +++------ src/predict.jl | 4 +- src/reservoircomputer.jl | 4 +- src/train.jl | 2 - test/Layers/svmreadout_tests.jl | 1 + test/basic_tests.jl | 1 + 17 files changed, 61 insertions(+), 111 deletions(-) diff --git a/ext/RCCellularAutomataExt.jl b/ext/RCCellularAutomataExt.jl index 2036d28ee..8625a59bb 100644 --- a/ext/RCCellularAutomataExt.jl +++ b/ext/RCCellularAutomataExt.jl @@ -16,7 +16,6 @@ end function encoding(rm::RandomMaps, input_vector, tot_encoded_vector) input_size = size(input_vector, 1) - #single_encoded_size = Int(size(tot_encoded_vector, 1)/permutations) new_tot_enc_vec = copy(tot_encoded_vector) for i in 1:(rm.permutations) @@ -52,7 +51,6 @@ end function init_maps(input_size, permutations, mapped_vector_size) maps = Array{Int}(undef, permutations, input_size) - #tot_size = input_size*permutations for i in 1:permutations maps[i, :] = mapping(input_size, mapped_vector_size) @@ -62,7 +60,6 @@ function init_maps(input_size, permutations, mapped_vector_size) end function mapping(input_size, mapped_vector_size) - #sample(1:mapped_vector_size, input_size; replace=false) return randperm(mapped_vector_size)[1:input_size] end diff --git a/src/ReservoirComputing.jl b/src/ReservoirComputing.jl index 6a72cf0b0..50b64a663 100644 --- a/src/ReservoirComputing.jl +++ b/src/ReservoirComputing.jl @@ -8,7 +8,7 @@ using LinearAlgebra: eigvals, eigen, I, Diagonal, diag, mul!, Symmetric, norm, using LinearSolve: LinearProblem, solve, QRFactorization using LuxCore: AbstractLuxLayer, AbstractLuxContainerLayer, AbstractLuxWrapperLayer, setup, apply, replicate -import LuxCore: initialparameters, initialstates, statelength, outputsize +import LuxCore: initialparameters, initialstates, parameterlength, statelength, outputsize using NNlib: tanh_fast using Random: Random, AbstractRNG, randperm using SciMLBase: AbstractLinearAlgorithm, AbstractSciMLAlgorithm, successful_retcode diff --git a/src/extensions/reca.jl b/src/extensions/reca.jl index d4b5da72e..478c21ea3 100644 --- a/src/extensions/reca.jl +++ b/src/extensions/reca.jl @@ -237,5 +237,7 @@ A linear [`LinearReadout`](@ref) maps these features to `out_dims`. Default is none. - `readout_activation`: Activation applied by the readout Default is `identity`. +- `readout_in_dims`: Readout input width for a custom dimension-changing + modifier. `nothing` infers the width for `Extend`. Default: `nothing`. """ RECA(::Any...) = error("RECA requires CellularAutomata.jl; use it to enable this constructor.") diff --git a/src/generics.jl b/src/generics.jl index 38147617b..9baacfccd 100644 --- a/src/generics.jl +++ b/src/generics.jl @@ -1,7 +1,6 @@ const BoolType = Union{StaticBool, Bool, Val{true}, Val{false}} const InputType = Tuple{<:AbstractArray, Tuple{<:AbstractArray}} const IntegerType = Union{Integer, StaticInt} -const RCFields = (:cells, :state_modifiers, :readout) __quote_keys(t) = Expr(:tuple, (QuoteNode(s) for s in t)...) diff --git a/src/inits/inits_components.jl b/src/inits/inits_components.jl index 4b1f1e3c3..01603b8d3 100644 --- a/src/inits/inits_components.jl +++ b/src/inits/inits_components.jl @@ -390,8 +390,7 @@ Adds a delay line in the `reservoir_matrix`, with given `shift` and # Arguments - - `rng`: Random number generator. Default is `Utils.default_rng()` - from WeightInitializers. + - `rng`: Random number generator. Default is `Xoshiro(1234)`. - `reservoir_matrix`: matrix to be changed. - `weight`: weight to add as a delay line. Can be either a single number or an array. @@ -453,8 +452,7 @@ Adds a backward connection in the `reservoir_matrix`, with given `shift` and # Arguments - - `rng`: Random number generator. Default is `Utils.default_rng()` - from WeightInitializers. + - `rng`: Random number generator. Default is `Xoshiro(1234)`. - `reservoir_matrix`: matrix to be changed. - `weight`: weight to add as a backward connection. Can be either a single number or an array. @@ -525,8 +523,7 @@ Adds a simple cycle in the `reservoir_matrix`, with given # Arguments - - `rng`: Random number generator. Default is `Utils.default_rng()` - from WeightInitializers. + - `rng`: Random number generator. Default is `Xoshiro(1234)`. - `reservoir_matrix`: matrix to be changed. - `weight`: weight to add as a simple cycle. Can be either a single number or an array. @@ -587,8 +584,7 @@ Adds a reverse simple cycle in the `reservoir_matrix`, with given # Arguments - - `rng`: Random number generator. Default is `Utils.default_rng()` - from WeightInitializers. + - `rng`: Random number generator. Default is `Xoshiro(1234)`. - `reservoir_matrix`: matrix to be changed. - `weight`: weight to add as a simple cycle. Can be either a single number or an array. @@ -650,8 +646,7 @@ Adds jumps to a given `reservoir_matrix` with chosen `weight` and determined `ju # Arguments - - `rng`: Random number generator. Default is `Utils.default_rng()` - from WeightInitializers. + - `rng`: Random number generator. Default is `Xoshiro(1234)`. - `reservoir_matrix`: matrix to be changed. - `weight`: weight to add as a simple cycle. Can be either a single number or an array. @@ -755,13 +750,13 @@ end """ self_loop!([rng], reservoir_matrix, weight; signs = nothing) -Adds jumps to a given `reservoir_matrix` with chosen `weight` and determined `jump_size`. -`weight` can be either a number or an array. +Sets the diagonal of `reservoir_matrix` to `weight`, adding a self loop to each node. +`weight` can be a number, a vector of length `size(reservoir_matrix, 1)`, or a function +`weight(rng, n)` returning such a vector. # Arguments - - `rng`: Random number generator. Default is `Utils.default_rng()` - from WeightInitializers. + - `rng`: Random number generator. Default is `Xoshiro(1234)`. - `reservoir_matrix`: matrix to be changed. - `weight`: weight to add as a self loop. Can be either a single number or an array. @@ -833,9 +828,7 @@ to a permutation matrix. ## Arguments - `rng`: Random number generator used when `permutation_matrix === nothing`. - Default is typically `Utils.default_rng()` from - [WeightInitializers](https://lux.csail.mit.edu/stable/api/Building_Blocks/WeightInitializers) - (if you provide a wrapper method without `rng`). + Default is `Xoshiro(1234)` when using the wrapper method without `rng`. - `reservoir_matrix`: The reservoir weight matrix to be permuted. - `permutation_matrix`: A square permutation matrix of matching size. If `nothing`, a random permutation is used. diff --git a/src/inits/inits_input.jl b/src/inits/inits_input.jl index f0ff735d4..9ee775c62 100644 --- a/src/inits/inits_input.jl +++ b/src/inits/inits_input.jl @@ -8,8 +8,7 @@ a range defined by `scaling`. ## Arguments - - `rng`: Random number generator. Default is `Utils.default_rng()` - from WeightInitializers. + - `rng`: Random number generator. Default is `Xoshiro(1234)`. - `T`: Type of the elements in the reservoir matrix. Default is `Float32`. - `dims`: Dimensions of the matrix. Should follow `res_size x in_size`. @@ -100,8 +99,7 @@ additional reservoir node. An `ArgumentError` is thrown if `res_size < in_size`. ## Arguments - - `rng`: Random number generator. Default is `Utils.default_rng()` - from WeightInitializers. + - `rng`: Random number generator. Default is `Xoshiro(1234)`. - `T`: Type of the elements in the reservoir matrix. Default is `Float32`. - `dims`: Dimensions of the matrix. Should follow `res_size x in_size`. @@ -226,8 +224,7 @@ inspired by [Lu2017](@cite). Blocks are distributed as in ## Arguments - - `rng`: Random number generator. Default is `Utils.default_rng()` - from WeightInitializers. + - `rng`: Random number generator. Default is `Xoshiro(1234)`. - `T`: Type of the elements in the reservoir matrix. Default is `Float32`. - `dims`: Dimensions of the matrix. Should follow `res_size x in_size`. @@ -306,8 +303,7 @@ networks [Pathak2018](@cite). ## Arguments - - `rng`: Random number generator. Default is `Utils.default_rng()` - from WeightInitializers. + - `rng`: Random number generator. Default is `Xoshiro(1234)`. - `T`: Type of the elements in the reservoir matrix. Default is `Float32`. - `dims`: Dimensions of the matrix. Should follow `res_size x in_size`. @@ -387,8 +383,7 @@ An optional sign pattern controls which weights have their signs flipped. ## Arguments - - `rng`: Random number generator. Default is `Utils.default_rng()` - from WeightInitializers. + - `rng`: Random number generator. Default is `Xoshiro(1234)`. - `T`: Type of the elements in the reservoir matrix. Default is `Float32`. - `dims`: Dimensions of the matrix. Should follow `res_size x in_size`. @@ -477,8 +472,7 @@ applying: ## Arguments - - `rng`: Random number generator. Default is `Utils.default_rng()` - from WeightInitializers. + - `rng`: Random number generator. Default is `Xoshiro(1234)`. - `T`: Type of the elements in the reservoir matrix. Default is `Float32`. - `dims`: Dimensions of the matrix. Should follow `res_size x in_size`. @@ -556,8 +550,7 @@ the logistic map recurrence: ``` ## Arguments - - `rng`: Random number generator. Default is `Utils.default_rng()` - from WeightInitializers. + - `rng`: Random number generator. Default is `Xoshiro(1234)`. - `T`: Type of the elements in the reservoir matrix. Default is `Float32`. - `dims`: Dimensions of the matrix. Should follow `res_size x in_size`. @@ -637,8 +630,7 @@ If the provided number of rows does not match `factor * in_size` the number of rows is overridden. ## Arguments - - `rng`: Random number generator. Default is `Utils.default_rng()` - from WeightInitializers. + - `rng`: Random number generator. Default is `Xoshiro(1234)`. - `T`: Type of the elements in the reservoir matrix. Default is `Float32`. - `dims`: Dimensions of the matrix. Should follow `res_size x in_size`. diff --git a/src/inits/inits_lsm.jl b/src/inits/inits_lsm.jl index 78814e7c8..2c4ce308f 100644 --- a/src/inits/inits_lsm.jl +++ b/src/inits/inits_lsm.jl @@ -12,8 +12,7 @@ can be scaled to `radius`. ## Arguments - - `rng`: Random number generator. Default is `Utils.default_rng()` from - [WeightInitializers](https://lux.csail.mit.edu/stable/api/Building_Blocks/WeightInitializers). + - `rng`: Random number generator. Default is `Xoshiro(1234)`. - `T`: Element type. Default is `Float32`. - `dims`: Square matrix dimensions. diff --git a/src/inits/inits_reservoir.jl b/src/inits/inits_reservoir.jl index 341696303..8598800da 100644 --- a/src/inits/inits_reservoir.jl +++ b/src/inits/inits_reservoir.jl @@ -11,8 +11,7 @@ the matrix is never all zero and can be scaled to `radius`. ## Arguments - - `rng`: Random number generator. Default is `Utils.default_rng()`from - [WeightInitializers](https://lux.csail.mit.edu/stable/api/Building_Blocks/WeightInitializers). + - `rng`: Random number generator. Default is `Xoshiro(1234)`. - `T`: Type of the elements in the reservoir matrix. Default is `Float32`. - `dims`: Dimensions of the reservoir matrix. @@ -93,8 +92,7 @@ the top `top_k` connections, and scales the spectral radius to `radius`. ## Arguments - - `rng`: Random number generator. Default is `Utils.default_rng()`from - [WeightInitializers](https://lux.csail.mit.edu/stable/api/Building_Blocks/WeightInitializers). + - `rng`: Random number generator. Default is `Xoshiro(1234)`. - `T`: Type of the elements in the reservoir matrix. Default is `Float32`. - `dims`: Dimensions of the reservoir matrix. @@ -222,8 +220,7 @@ Returns an initializer to build a sparse reservoir matrix with the given ## Arguments - - `rng`: Random number generator. Default is `Utils.default_rng()`from - [WeightInitializers](https://lux.csail.mit.edu/stable/api/Building_Blocks/WeightInitializers). + - `rng`: Random number generator. Default is `Xoshiro(1234)`. - `T`: Type of the elements in the reservoir matrix. Default is `Float32`. - `dims`: Dimensions of the reservoir matrix. @@ -395,8 +392,7 @@ closest valid order is used. ## Arguments - - `rng`: Random number generator. Default is `Utils.default_rng()`from - [WeightInitializers](https://lux.csail.mit.edu/stable/api/Building_Blocks/WeightInitializers). + - `rng`: Random number generator. Default is `Xoshiro(1234)`. - `T`: Type of the elements in the reservoir matrix. Default is `Float32`. - `dims`: Dimensions of the reservoir matrix. @@ -498,8 +494,7 @@ otherwise, it generates a random connectivity pattern. ## Arguments - - `rng`: Random number generator. Default is `Utils.default_rng()`from - [WeightInitializers](https://lux.csail.mit.edu/stable/api/Building_Blocks/WeightInitializers). + - `rng`: Random number generator. Default is `Xoshiro(1234)`. - `T`: Type of the elements in the reservoir matrix. Default is `Float32`. - `dims`: Dimensions of the reservoir matrix. @@ -627,8 +622,7 @@ W_{i,j} = ## Arguments - - `rng`: Random number generator. Default is `Utils.default_rng()`from - [WeightInitializers](https://lux.csail.mit.edu/stable/api/Building_Blocks/WeightInitializers). + - `rng`: Random number generator. Default is `Xoshiro(1234)`. - `T`: Type of the elements in the reservoir matrix. Default is `Float32`. - `dims`: Dimensions of the reservoir matrix. @@ -761,8 +755,7 @@ W_{i,j} = ## Arguments - - `rng`: Random number generator. Default is `Utils.default_rng()`from - [WeightInitializers](https://lux.csail.mit.edu/stable/api/Building_Blocks/WeightInitializers). + - `rng`: Random number generator. Default is `Xoshiro(1234)`. - `T`: Type of the elements in the reservoir matrix. Default is `Float32`. - `dims`: Dimensions of the reservoir matrix. @@ -925,8 +918,7 @@ W_{i,j} = ## Arguments - - `rng`: Random number generator. Default is `Utils.default_rng()`from - [WeightInitializers](https://lux.csail.mit.edu/stable/api/Building_Blocks/WeightInitializers). + - `rng`: Random number generator. Default is `Xoshiro(1234)`. - `T`: Type of the elements in the reservoir matrix. Default is `Float32`. - `dims`: Dimensions of the reservoir matrix. @@ -1080,8 +1072,7 @@ W_{i,j} = ## Arguments - - `rng`: Random number generator. Default is `Utils.default_rng()`from - [WeightInitializers](https://lux.csail.mit.edu/stable/api/Building_Blocks/WeightInitializers). + - `rng`: Random number generator. Default is `Xoshiro(1234)`. - `T`: Type of the elements in the reservoir matrix. Default is `Float32`. - `dims`: Dimensions of the reservoir matrix. @@ -1199,8 +1190,7 @@ W_{i,j} = ## Arguments - - `rng`: Random number generator. Default is `Utils.default_rng()`from - [WeightInitializers](https://lux.csail.mit.edu/stable/api/Building_Blocks/WeightInitializers). + - `rng`: Random number generator. Default is `Xoshiro(1234)`. - `T`: Type of the elements in the reservoir matrix. Default is `Float32`. - `dims`: Dimensions of the reservoir matrix. @@ -1288,8 +1278,7 @@ W_{i,j} = ## Arguments - - `rng`: Random number generator. Default is `Utils.default_rng()`from - [WeightInitializers](https://lux.csail.mit.edu/stable/api/Building_Blocks/WeightInitializers). + - `rng`: Random number generator. Default is `Xoshiro(1234)`. - `T`: Type of the elements in the reservoir matrix. Default is `Float32`. - `dims`: Dimensions of the reservoir matrix. @@ -1425,8 +1414,7 @@ W_{i,j} = ## Arguments - - `rng`: Random number generator. Default is `Utils.default_rng()`from - [WeightInitializers](https://lux.csail.mit.edu/stable/api/Building_Blocks/WeightInitializers). + - `rng`: Random number generator. Default is `Xoshiro(1234)`. - `T`: Type of the elements in the reservoir matrix. Default is `Float32`. - `dims`: Dimensions of the reservoir matrix. @@ -1570,8 +1558,7 @@ W_{i,j} = ## Arguments - - `rng`: Random number generator. Default is `Utils.default_rng()`from - [WeightInitializers](https://lux.csail.mit.edu/stable/api/Building_Blocks/WeightInitializers). + - `rng`: Random number generator. Default is `Xoshiro(1234)`. - `T`: Type of the elements in the reservoir matrix. Default is `Float32`. - `dims`: Dimensions of the reservoir matrix. @@ -1664,8 +1651,7 @@ W_{i,j} = ## Arguments - - `rng`: Random number generator. Default is `Utils.default_rng()`from - [WeightInitializers](https://lux.csail.mit.edu/stable/api/Building_Blocks/WeightInitializers). + - `rng`: Random number generator. Default is `Xoshiro(1234)`. - `T`: Type of the elements in the reservoir matrix. Default is `Float32`. - `dims`: Dimensions of the reservoir matrix. @@ -1844,8 +1830,7 @@ W_{i,j} = ## Arguments - - `rng`: Random number generator. Default is `Utils.default_rng()`from - [WeightInitializers](https://lux.csail.mit.edu/stable/api/Building_Blocks/WeightInitializers). + - `rng`: Random number generator. Default is `Xoshiro(1234)`. - `T`: Type of the elements in the reservoir matrix. Default is `Float32`. - `dims`: Dimensions of the reservoir matrix. @@ -1985,8 +1970,7 @@ W_{i,j} = ## Arguments - - `rng`: Random number generator. Default is `Utils.default_rng()`from - [WeightInitializers](https://lux.csail.mit.edu/stable/api/Building_Blocks/WeightInitializers). + - `rng`: Random number generator. Default is `Xoshiro(1234)`. - `T`: Type of the elements in the reservoir matrix. Default is `Float32`. - `dims`: Dimensions of the reservoir matrix. @@ -2114,8 +2098,7 @@ W_{i,j} = # Arguments - - `rng`: Random number generator. Default is `Utils.default_rng()` from - WeightInitializers. + - `rng`: Random number generator. Default is `Xoshiro(1234)`. - `T`: Element type of the matrix. Default is `Float32`. - `dims`: Dimensions of the output matrix (must be two-dimensional). @@ -2228,8 +2211,7 @@ This construction yields: ## Arguments - - `rng`: Random number generator. Default is `Utils.default_rng()`from - [WeightInitializers](https://lux.csail.mit.edu/stable/api/Building_Blocks/WeightInitializers). + - `rng`: Random number generator. Default is `Xoshiro(1234)`. - `T`: Type of the elements in the reservoir matrix. Default is `Float32`. - `dims`: Dimensions of the reservoir matrix. @@ -2327,8 +2309,7 @@ Creates a diagonal reservoir [Fette2005](@cite). ## Arguments - - `rng`: Random number generator. Default is `Utils.default_rng()`from - [WeightInitializers](https://lux.csail.mit.edu/stable/api/Building_Blocks/WeightInitializers). + - `rng`: Random number generator. Default is `Xoshiro(1234)`. - `T`: Type of the elements in the reservoir matrix. Default is `Float32`. - `dims`: Dimensions of the reservoir matrix. @@ -2526,8 +2507,7 @@ It guarantees structural symmetry by only adding complete diagonals. ## Arguments - - `rng`: Random number generator. Default is `Utils.default_rng()` from - [WeightInitializers](https://lux.csail.mit.edu/stable/api/Building_Blocks/WeightInitializers). + - `rng`: Random number generator. Default is `Xoshiro(1234)`. - `T`: Type of the elements in the reservoir matrix. Default is `Float32`. - `dims`: Dimensions of the reservoir matrix. Must be square. @@ -2625,8 +2605,7 @@ with random uniform weights in the range `(-1, 1)` until the target `sparsity` i ## Arguments - - `rng`: Random number generator. Default is `Utils.default_rng()` from - [WeightInitializers](https://lux.csail.mit.edu/stable/api/Building_Blocks/WeightInitializers). + - `rng`: Random number generator. Default is `Xoshiro(1234)`. - `T`: Type of the elements in the reservoir matrix. Default is `Float32`. - `dims`: Dimensions of the reservoir matrix. Must be square. @@ -2743,8 +2722,7 @@ minimal-complexity Echo State Networks (ESNs). ## Arguments - - `rng`: Random number generator. Default is `Utils.default_rng()` from - [WeightInitializers](https://lux.csail.mit.edu/stable/api/Building_Blocks/WeightInitializers). + - `rng`: Random number generator. Default is `Xoshiro(1234)`. - `T`: Type of the elements in the reservoir matrix. Default is `Float32`. - `dims`: Dimensions of the reservoir matrix. Must be square. diff --git a/src/layers/esn_cell.jl b/src/layers/esn_cell.jl index 105b54792..21941cc92 100644 --- a/src/layers/esn_cell.jl +++ b/src/layers/esn_cell.jl @@ -47,7 +47,7 @@ abstract type AbstractEchoStateNetworkCell <: AbstractReservoirRecurrentCell end @doc raw""" ESNCell(in_dims => out_dims, [activation]; - use_bias=false, init_bias=rand32, + use_bias=false, init_bias=zeros32, init_reservoir=rand_sparse, init_input=scaled_rand, init_state=randn32, leak_coefficient=1.0) @@ -72,7 +72,7 @@ Echo State Network (ESN) recurrent cell with optional leaky integration. - `use_bias`: Whether to include a bias term. Default: `false`. - `init_bias`: Initializer for the bias. Used only if `use_bias=true`. - Default is `rand32`. + Default is `zeros32`. - `init_reservoir`: Initializer for the reservoir matrix `W_res`. Default is [`rand_sparse`](@ref). - `init_input`: Initializer for the input matrix `W_in`. @@ -118,7 +118,6 @@ Created by `initialstates(rng, esn)`: init_bias init_reservoir init_input - #init_feedback::F init_state leak_coefficient use_bias <: StaticBool diff --git a/src/layers/eusn_cell.jl b/src/layers/eusn_cell.jl index 90860df19..c340b2a35 100644 --- a/src/layers/eusn_cell.jl +++ b/src/layers/eusn_cell.jl @@ -1,6 +1,6 @@ @doc raw""" EuSNCell(in_dims => out_dims, [activation]; - use_bias=false, init_bias=rand32, + use_bias=false, init_bias=zeros32, init_reservoir=rand_sparse, init_input=scaled_rand, init_state=zeros32, leak_coefficient=1.0, diffusion=1.0) @@ -26,7 +26,7 @@ Euler State Network (EuSN) cell [Gallicchio2024](@cite). - `use_bias`: Whether to include a bias term. Default: `false`. - `init_bias`: Initializer for the bias. Used only if `use_bias=true`. - Default is `rand32`. + Default is `zeros32`. - `init_reservoir`: Initializer for the reservoir matrix `W_res`. Default is [`rand_sparse`](@ref). - `init_input`: Initializer for the input matrix `W_in`. @@ -75,7 +75,6 @@ Created by `initialstates(rng, esn)`: init_bias init_reservoir init_input - #init_feedback::F init_state leak_coefficient diffusion diff --git a/src/layers/memoryesn_cell.jl b/src/layers/memoryesn_cell.jl index ff94be2eb..772689ed0 100644 --- a/src/layers/memoryesn_cell.jl +++ b/src/layers/memoryesn_cell.jl @@ -1,6 +1,6 @@ @doc raw""" MemoryESNCell(in_dims => out_dims, [activation]; - use_bias=false, init_bias=rand32, + use_bias=false, init_bias=zeros32, init_reservoir=rand_sparse, init_input=scaled_rand, init_memory=rand_sparse, init_state=randn32, leak_coefficient=1.0) @@ -32,7 +32,7 @@ Echo State Network (ESN) recurrent cell with memory matrix [Gallicchio2024b](@ci - `use_bias`: Whether to include a bias term. Default: `false`. - `init_bias`: Initializer for the bias. Used only if `use_bias=true`. - Default is `rand32`. + Default is `zeros32`. - `init_reservoir`: Initializer for the reservoir matrix `W_r`. Default is [`rand_sparse`](@ref). - `init_memory`: Initializer for the memory matrix `W_m`. diff --git a/src/models/esn_generics.jl b/src/models/esn_generics.jl index 819fa5711..882dc350b 100644 --- a/src/models/esn_generics.jl +++ b/src/models/esn_generics.jl @@ -40,22 +40,14 @@ abstract type AbstractEchoStateNetwork{Fields} <: AbstractReservoirComputer{Fiel __wrap_layer(x) = x isa Function ? WrappedFunction(x) : x __wrap_layers(xs::Tuple) = map(__wrap_layer, xs) -@inline function __fillvec(x, n::Integer) - v = Vector{typeof(x)}(undef, n) - @inbounds @simd for i in 1:n - v[i] = x - end - return v -end - -@inline __asvec(::Tuple{}, n::Integer) = __fillvec(nothing, n) +@inline __asvec(::Tuple{}, n::Integer) = fill(nothing, n) @inline function __asvec(comp::Tuple, n::Integer) len = length(comp) if len == n return collect(comp) elseif len == 1 - return __fillvec(comp[1], n) + return fill(comp[1], n) else throw(DimensionMismatch("Expected length $n or 1, got $len")) end @@ -66,15 +58,15 @@ end if len == n return collect(comp) elseif len == 1 - return __fillvec(comp[1], n) + return fill(comp[1], n) else throw(DimensionMismatch("Expected length $n or 1, got $len")) end end -@inline __asvec(::Nothing, n::Integer) = __fillvec(nothing, n) +@inline __asvec(::Nothing, n::Integer) = fill(nothing, n) -@inline __asvec(comp, n::Integer) = __fillvec(comp, n) +@inline __asvec(comp, n::Integer) = fill(comp, n) @inline __asvec(x) = (ndims(x) == 2 ? vec(x) : x) diff --git a/src/predict.jl b/src/predict.jl index 210d40419..b2b35fbad 100644 --- a/src/predict.jl +++ b/src/predict.jl @@ -136,7 +136,7 @@ function __predict( return error( "Autoregressive `predict(rc, steps, ps, st; initialdata)` for a " * "`SciMLProblemReservoir` requires the `RCODEReservoirExt` extension. " * - "Load `SciMLBase` and `DataInterpolations` (plus an OrdinaryDiffEq " * + "Load `DataInterpolations` (plus an OrdinaryDiffEq " * "solver package — `OrdinaryDiffEqTsit5`, `OrdinaryDiffEq`, …) to enable it." ) end @@ -148,7 +148,7 @@ function __predict( return error( "Teacher-forced `predict(rc, data, ps, st)` for a " * "`SciMLProblemReservoir` requires the `RCODEReservoirExt` extension. " * - "Load `SciMLBase` and `DataInterpolations` (plus an OrdinaryDiffEq " * + "Load `DataInterpolations` (plus an OrdinaryDiffEq " * "solver package — `OrdinaryDiffEqTsit5`, `OrdinaryDiffEq`, …) to enable it." ) end diff --git a/src/reservoircomputer.jl b/src/reservoircomputer.jl index bbfb59ff3..ea2395995 100644 --- a/src/reservoircomputer.jl +++ b/src/reservoircomputer.jl @@ -158,8 +158,8 @@ function __collectstates( ) return error( "collectstates for a `SciMLProblemReservoir` requires the " * - "`RCODEReservoirExt` extension. Load `OrdinaryDiffEq`, `SciMLBase`, " * - "and `DataInterpolations` to enable continuous-time reservoirs." + "`RCODEReservoirExt` extension. Load `OrdinaryDiffEq` and " * + "`DataInterpolations` to enable continuous-time reservoirs." ) end diff --git a/src/train.jl b/src/train.jl index 12893394d..135a72445 100644 --- a/src/train.jl +++ b/src/train.jl @@ -53,8 +53,6 @@ function __apply_washout(states::AbstractMatrix, targets::AbstractMatrix, washou return states_wo, targets_wo end -__set_readout(ps, m::ReservoirChain, W) = first(addreadout!(m, W, ps, NamedTuple())) - """ AbstractReservoirComputingSolver diff --git a/test/Layers/svmreadout_tests.jl b/test/Layers/svmreadout_tests.jl index ccbe2c4c0..e637f8d51 100644 --- a/test/Layers/svmreadout_tests.jl +++ b/test/Layers/svmreadout_tests.jl @@ -29,6 +29,7 @@ begin ro = SVMReadout(6 => 2; include_collect = True()) @test initialparameters(rng, ro) == NamedTuple() @test LuxCore.parameterlength(ro) == 0 + @test ReservoirComputing.parameterlength === LuxCore.parameterlength @test LuxCore.statelength(ro) == 0 @test LuxCore.outputsize(ro, nothing, rng) == (2,) end diff --git a/test/basic_tests.jl b/test/basic_tests.jl index 1fc4396ba..e5e5821d3 100644 --- a/test/basic_tests.jl +++ b/test/basic_tests.jl @@ -49,6 +49,7 @@ begin ro_b = LinearReadout(7 => 5; use_bias = True()) @test LuxCore.parameterlength(ro_b) == 5 * 7 + 5 + @test ReservoirComputing.parameterlength === LuxCore.parameterlength end @testset "forward pass: vector, no-bias, identity" begin