rand_sparse
ReservoirComputing.rand_sparse — Function
rand_sparse([rng], [T], dims...;
radius=1.0, sparsity=0.1, std=1.0, return_sparse=false)Create and return a random sparse reservoir matrix. The matrix will be of size specified by dims, with specified sparsity and scaled spectral radius according to radius.
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
radius: The desired spectral radius of the reservoir. Defaults to 1.0.sparsity: The sparsity level of the reservoir matrix, controlling the fraction of zero elements. Defaults to 0.1.return_sparse: flag for returning asparsematrix.truerequiresSparseArraysto be loaded. Default isfalse.
Examples
Changing the sparsity:
julia> res_matrix = rand_sparse(5, 5; sparsity = 0.5)
5×5 Matrix{Float32}:
0.0 0.0 0.0 0.0 0.0
0.0 0.794565 0.0 0.26164 0.0
0.0 0.0 -0.931294 0.0 0.553706
0.723235 -0.524727 0.0 0.0 0.0
1.23723 0.0 0.181824 -1.5478 0.465328
julia> res_matrix = rand_sparse(5, 5; sparsity = 0.2)
5×5 Matrix{Float32}:
0.0 0.0 0.0 0.0 0.0
0.0 0.853184 0.0 0.0 0.0
0.0 0.0 -1.0 0.0 0.0
0.776591 0.0 0.0 0.0 0.0
0.0 0.0 0.0 -1.66199 0.499657
julia> res_matrix = rand_sparse(5, 5; sparsity = 0.8)
5×5 Matrix{Float32}:
0.0 0.229011 0.625026 -0.660061 -1.39078
-0.295761 0.32544 0.0 0.107163 0.0
0.766352 1.44836 -0.381442 -0.435473 0.226788
0.296224 -0.214919 0.00956791 0.0 0.210393
0.506746 0.0 0.0744718 -0.633951 0.19059Returning a sparse matrix:
julia> using SparseArrays
julia> res_matrix = rand_sparse(5, 5; sparsity = 0.4, return_sparse = true)
5×5 SparseMatrixCSC{Float32, Int64} with 10 stored entries:
⋅ ⋅ ⋅ ⋅ ⋅
⋅ 0.794565 ⋅ 0.26164 ⋅
⋅ ⋅ -0.931294 ⋅ 0.553706
0.723235 -0.524727 ⋅ ⋅ ⋅
1.23723 ⋅ 0.181824 -1.5478 0.465328