band_init
ReservoirComputing.band_init — Function
band_init([rng], [T], dims...; radius=1.0, sparsity=0.9, return_sparse=false)Create and return a sparse reservoir matrix with a band topology (Cossu et al., Oct 2024). This function populates the main diagonal (self-loops) and iteratively expands outward to the immediately adjacent lower (delay lines) and upper (backward connections) sub-diagonals with random uniform weights in the range (-1, 1) until the target sparsity is reached.
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 a banded structure):
julia> W = band_init(5, 5)
5×5 Matrix{Float32}:
-0.214159 0.812451 0.0 0.0 0.0
0.710328 0.655184 -0.412411 0.0 0.0
0.0 0.311545 0.551211 0.115412 0.0
0.0 0.0 -0.741211 0.914141 -0.512301
0.0 0.0 0.0 0.114112 0.311545Returning a SparseMatrixCSC (showing the exact sparsity random-allocation on the outer bands):
julia> using SparseArrays
julia> W_sparse = band_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.9123 ⋅ ⋅ ⋅ ⋅
⋅ 0.4412 -0.1124 0.8812 ⋅ ⋅
⋅ ⋅ -0.5123 0.3314 ⋅ ⋅
⋅ ⋅ ⋅ 0.1245 -0.2214 0.6123
⋅ ⋅ ⋅ ⋅ -0.1124 0.7712Scaling to a custom spectral radius with explicit typecasting:
julia> W_scaled = band_init(Float16, 4, 4; radius=2.5)
4×4 Matrix{Float16}:
2.145 -1.542 0.0 0.0
-1.123 1.854 2.014 0.0
0.0 -2.113 -1.953 -1.123
0.0 0.0 1.412 0.954