block_diagonal
ReservoirComputing.block_diagonal — Functionblock_diagonal([rng], [T], dims...;
weight=1, block_size=1,
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().T: Element type of the matrix. Default isFloat32.dims: Dimensions of the output matrix (must be two-dimensional).
Keyword arguments
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.return_sparse: Iftrue, returns the matrix as sparse. SparseArrays.jl must be lodead. Default isfalse.
Examples
# 4×4 with two 2×2 blocks of 1.0
julia> W1 = block_diagonal(4, 4; block_size=2)
4×4 Matrix{Float32}:
1.0 1.0 0.0 0.0
1.0 1.0 0.0 0.0
0.0 0.0 1.0 1.0
0.0 0.0 1.0 1.0
# per-block weights [0.5, 2.0]
julia> W2 = block_diagonal(4, 4; block_size=2, weight=[0.5, 2.0])
4×4 Matrix{Float32}:
0.5 0.5 0.0 0.0
0.5 0.5 0.0 0.0
0.0 0.0 2.0 2.0
0.0 0.0 2.0 2.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.