Lower Triangular Topology
ReservoirComputing.lower_triangular — Function
lower_triangular([rng], [T], dims...; radius=1.0, sparsity=0.9, return_sparse=false)Create and return a sparse reservoir matrix with a lower triangular topology (Cossu et al., Oct 2024). This function populates the main diagonal and the immediately adjacent lower sub-diagonals with random uniform weights in the range (-1, 1) until the target sparsity is reached. It guarantees structural symmetry by only adding complete diagonals.
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 exact target fraction of zero elements in the matrix. To hit this target precisely while preventing spatial bias, any remaining weights needed for the final partial sub-diagonal are randomly distributed across its indices. Defaults to 0.9.return_sparse: Flag for returning aSparseMatrixCSCinstead of a dense matrix. Setting totruerequiresSparseArraysto be loaded. Defaults tofalse.
Examples
Default call:
julia> W = lower_triangular(5, 5)
5×5 Matrix{Float32}:
-0.214159 0.0 0.0 0.0 0.0
0.710328 0.655184 0.0 0.0 0.0
-0.912441 0.311545 -0.412411 0.0 0.0
0.0 0.114112 0.551211 0.812451 0.0
0.0 0.0 -0.741211 0.914141 0.115412Returning a SparseMatrixCSC:
julia> using SparseArrays
julia> W_sparse = lower_triangular(6, 6; sparsity=0.8, return_sparse=true)
6×6 SparseMatrixCSC{Float32, Int64} with 7 stored entries:
0.4512 ⋅ ⋅ ⋅ ⋅ ⋅
0.1245 -0.8123 ⋅ ⋅ ⋅ ⋅
-0.7612 0.9123 -0.1124 ⋅ ⋅ ⋅
⋅ ⋅ 0.4412 -0.5123 ⋅ ⋅
⋅ ⋅ ⋅ ⋅ 0.8812 ⋅
⋅ ⋅ ⋅ ⋅ ⋅ 0.3314Scaling to a custom spectral radius:
julia> W_scaled = lower_triangular(Float16, 4, 4; radius=2.5)
4×4 Matrix{Float16}:
2.145 0.0 0.0 0.0
-1.123 1.854 0.0 0.0
0.954 -2.113 -1.542 0.0
0.0 1.412 2.014 -1.953