diagonal_init
ReservoirComputing.diagonal_init — Function
diagonal_init([rng], [T], dims...;
return_sparse=false, weight=randn,
kwargs...)Creates a diagonal reservoir (Fette and Eggert, 2005).
Arguments
rng: Random number generator. Default isUtils.default_rng()from WeightInitializers.T: Type of the elements in the reservoir matrix. Default isFloat32.dims: Dimensions of the reservoir matrix.
Keyword arguments
weight: Weight used for the initial self-loop initialization. Can be a single number, vector, or function to generate an array. Default israndn.return_sparse: flag for returning asparsematrix.truerequiresSparseArraysto be loaded. Default isfalse.return_diag: flag for returning aDiagonalmatrix. If bothreturn_diagandreturn_sparseare set totruepriority is given toreturn_diag. Default isfalse.radius: The desired spectral radius of the reservoir. Ifnothingis passed, no scaling takes place. Defaults tonothing.signs: Controls sign flips. UseRandomSigns,RegularSigns, orIrrationalDigitSigns. Passnothingto leave signs unchanged. Default isnothing.
Examples
Default kwargs:
julia> rr = diagonal_init(5, 5)
5×5 Matrix{Float32}:
-0.359729 0.0 0.0 0.0 0.0
0.0 1.08721 0.0 0.0 0.0
0.0 0.0 -0.41959 0.0 0.0
0.0 0.0 0.0 0.71891 0.0
0.0 0.0 0.0 0.0 0.420247Changing the weights magnitudes to a different unique value:
julia> rr = diagonal_init(5, 5; weight=0.1)
5×5 Matrix{Float32}:
0.1 0.0 0.0 0.0 0.0
0.0 0.1 0.0 0.0 0.0
0.0 0.0 0.1 0.0 0.0
0.0 0.0 0.0 0.1 0.0
0.0 0.0 0.0 0.0 0.1Changing the weights signs with different sign patterns:
Changing the weights to random numbers. Note that the length of the given array must be at least as long as the subdiagonal one wants to fill:
julia> rr = diagonal_init(5, 5; weight=0.1, signs = RandomSigns())
5×5 Matrix{Float32}:
0.1 0.0 0.0 0.0 0.0
0.0 -0.1 0.0 0.0 0.0
0.0 0.0 0.1 0.0 0.0
0.0 0.0 0.0 -0.1 0.0
0.0 0.0 0.0 0.0 0.1
julia> rr = diagonal_init(5, 5; weight=0.1, signs = IrrationalDigitSigns())
5×5 Matrix{Float32}:
-0.1 0.0 0.0 0.0 0.0
0.0 0.1 0.0 0.0 0.0
0.0 0.0 -0.1 0.0 0.0
0.0 0.0 0.0 -0.1 0.0
0.0 0.0 0.0 0.0 -0.1Returning a sparse matrix:
julia> using SparseArrays
julia> rr = diagonal_init(5, 5; return_sparse=true)
5×5 SparseMatrixCSC{Float32, Int64} with 5 stored entries:
-0.359729 ⋅ ⋅ ⋅ ⋅
⋅ 1.08721 ⋅ ⋅ ⋅
⋅ ⋅ -0.41959 ⋅ ⋅
⋅ ⋅ ⋅ 0.71891 ⋅
⋅ ⋅ ⋅ ⋅ 0.420247Returning a diagonal matrix:
julia> rr = diagonal_init(MersenneTwister(123), 5, 5; return_diag=true);
julia> rr isa Diagonal{Float32} && size(rr) == (5, 5)
trueReferences
- Fette, G. and Eggert, J. (2005). Short Term Memory and Pattern Matching with Simple Echo State Networks. In: Artificial Neural Networks: Biological Inspirations – ICANN 2005 (Springer Berlin Heidelberg); pp. 13–18.