block_diagonal
ReservoirComputing.block_diagonal — Function
block_diagonal([rng], [T], dims...;
block_weight=1, block_size=1,
radius=nothing, return_sparse=false)Creates a block‐diagonal matrix consisting of square blocks of size block_size along the main diagonal (Ma et al., 2023). Each block may be filled with
- a single scalar
- a vector of per‐block weights (length = number of blocks)
Equations
\[W_{i,j} = \begin{cases} w_b, & \text{if }\left\lfloor\frac{i-1}{s}\right\rfloor = \left\lfloor\frac{j-1}{s}\right\rfloor = b,\; s = \text{block_size},\; b=0,\dots,nb-1, \\ 0, & \text{otherwise,} \end{cases}\]
Arguments
rng: Random number generator. Default isUtils.default_rng()from WeightInitializers.T: Element type of the matrix. Default isFloat32.dims: Dimensions of the output matrix (must be two-dimensional).
Keyword arguments
block_weight:- scalar: every block is filled with that value
- vector: length = number of blocks, one constant per block
1.0.block_size: Size(s) of each square block on the diagonal. Default is1.0.radius: The desired spectral radius of the reservoir. Ifnothingis passed, no scaling takes place. Defaults tonothing.return_sparse: Iftrue, returns the matrix as sparse. SparseArrays.jl must be lodead. Default isfalse.
Examples
Changing the block size
julia> res_matrix = block_diagonal(10, 10; block_size=2)
10×10 Matrix{Float32}:
1.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
1.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
0.0 0.0 1.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0
0.0 0.0 1.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0
0.0 0.0 0.0 0.0 1.0 1.0 0.0 0.0 0.0 0.0
0.0 0.0 0.0 0.0 1.0 1.0 0.0 0.0 0.0 0.0
0.0 0.0 0.0 0.0 0.0 0.0 1.0 1.0 0.0 0.0
0.0 0.0 0.0 0.0 0.0 0.0 1.0 1.0 0.0 0.0
0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 1.0 1.0
0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 1.0 1.0Changing the weights, per block. Please note that you have to know the number of blocks that you are going to have (which usually is res_size/block_size).
julia> res_matrix = block_diagonal(10, 10; block_size=2, block_weight=[0.5, 2.0, -0.99, 1.0, -99.0])
10×10 Matrix{Float32}:
0.5 0.5 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
0.5 0.5 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
0.0 0.0 2.0 2.0 0.0 0.0 0.0 0.0 0.0 0.0
0.0 0.0 2.0 2.0 0.0 0.0 0.0 0.0 0.0 0.0
0.0 0.0 0.0 0.0 -0.99 -0.99 0.0 0.0 0.0 0.0
0.0 0.0 0.0 0.0 -0.99 -0.99 0.0 0.0 0.0 0.0
0.0 0.0 0.0 0.0 0.0 0.0 1.0 1.0 0.0 0.0
0.0 0.0 0.0 0.0 0.0 0.0 1.0 1.0 0.0 0.0
0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 -99.0 -99.0
0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 -99.0 -99.0References
- Ma, H.; Prosperino, D.; Haluszczynski, A. and Räth, C. (2023). Efficient forecasting of chaotic systems with block-diagonal and binary reservoir computing. Chaos: An Interdisciplinary Journal of Nonlinear Science 33.