toepliz_init
ReservoirComputing.toepliz_init — Function
toepliz_init([rng], [T], dims...; radius=1.0, sparsity=0.9, return_sparse=false)Create and return a sparse reservoir matrix with a Toeplitz-like topology (Cossu et al., Oct 2024). This function builds outward from the main diagonal, generating a single random uniform weight in the range (-1, 1) for each diagonal and applying that identical weight to every active element along that specific diagonal. This structure is highly beneficial for minimal-complexity Echo State Networks (ESNs).
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. Must be square.
Keyword arguments
radius: The desired spectral radius of the reservoir. Defaults to 1.0.sparsity: The approximate target fraction of zero elements in the matrix. To closely approximate this target, if the required number of connections does not completely fill the outermost active diagonals, the remaining weights are randomly distributed across the available indices. Note: because lower sub-diagonals (delay lines) are populated before their corresponding upper sub-diagonals (backward connections), there is an inherent structural bias where the final partial band may favor lower connections. Defaults to 0.9.return_sparse: Flag for returning aSparseMatrixCSCinstead of a dense matrix. Setting totruerequiresSparseArraysto be loaded. Defaults tofalse.
Examples
Default call (creating a dense matrix with shared weights along each diagonal):
julia> W = toepliz_init(5, 5; sparsity=0.5)
5×5 Matrix{Float32}:
0.512311 -0.812451 0.0 0.0 0.0
-0.214159 0.512311 -0.812451 0.0 0.0
0.115412 -0.214159 0.512311 -0.812451 0.0
0.0 0.115412 -0.214159 0.512311 -0.812451
0.0 0.0 0.115412 -0.214159 0.512311Returning a SparseMatrixCSC (showing the exact sparsity gap on the outer -0.7612 and -0.8123 bands):
julia> using SparseArrays
julia> W_sparse = toepliz_init(6, 6; sparsity=0.6, return_sparse=true)
6×6 SparseMatrixCSC{Float32, Int64} with 14 stored entries:
0.4512 -0.8123 ⋅ ⋅ ⋅ ⋅
-0.7612 0.4512 ⋅ ⋅ ⋅ ⋅
⋅ -0.7612 0.4512 -0.8123 ⋅ ⋅
⋅ ⋅ -0.7612 0.4512 -0.8123 ⋅
⋅ ⋅ ⋅ -0.7612 0.4512 -0.8123
⋅ ⋅ ⋅ ⋅ -0.7612 0.4512