cycle_jumps
ReservoirComputing.cycle_jumps — Function
cycle_jumps([rng], [T], dims...;
cycle_weight=0.1, jump_weight=0.1, jump_size=3, return_sparse=false,
radius=nothing, cycle_kwargs=(), jump_kwargs=())Create a cycle reservoir with jumps (Rodan and Tiňo, 2012).
\[W_{i,j} = \begin{cases} r, & \text{if } i = j + 1,\;\; j \in [1, D_{\mathrm{res}} - 1], \\[4pt] r, & \text{if } i = 1,\;\; j = D_{\mathrm{res}}, \\[8pt] r_j, & \text{if } i = j + \ell, \\[4pt] r_j, & \text{if } j = i + \ell, \\[4pt] r_j, & \text{if } (i,j) = (1+\ell, 1), \\[4pt] r_j, & \text{if } (i,j) = (1,\, D_{\mathrm{res}}+1-\ell), \\[8pt] 0, & \text{otherwise.} \end{cases}\]
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
cycle_weight: The weight of cycle connections. This can be provided as a single value or an array. In case it is provided as an array please make sure that the length of the array matches the length of the cycle you want to populate. Default is 0.1.jump_weight: The weight of jump connections. This can be provided as a single value or an array. In case it is provided as an array please make sure that the length of the array matches the length of the jumps you want to populate. Default is 0.1.jump_size: The number of steps between jump connections. Default is 3.radius: The desired spectral radius of the reservoir. Ifnothingis passed, no scaling takes place. Defaults tonothing.return_sparse: flag for returning asparsematrix.truerequiresSparseArraysto be loaded. Default isfalse.cycle_kwargsandjump_kwargs: named tuples that control the kwargs for the cycle and jump weights respectively. The kwargs are as follows:signs: Controls sign flips. UseRandomSigns,RegularSigns, orIrrationalDigitSigns. Passnothingto leave signs unchanged. Default isnothing.
Examples
Default call:
julia> res_matrix = cycle_jumps(5, 5)
5×5 Matrix{Float32}:
0.0 0.0 0.0 0.1 0.1
0.1 0.0 0.0 0.0 0.0
0.0 0.1 0.0 0.0 0.0
0.1 0.0 0.1 0.0 0.0
0.0 0.0 0.0 0.1 0.0Changing weights:
julia> res_matrix = cycle_jumps(5, 5; jump_weight = 2, cycle_weight = -1);
julia> size(res_matrix) == (5, 5) && count(==(2.0f0), res_matrix) == 2 && count(==(-1.0f0), res_matrix) == 5
trueChanging weights to custom arrays:
julia> jump_weights = -Float32[0.2, 0.4, 0.6];
julia> cycle_weights = Float32[0.1, 0.3, 0.5, 0.7, 0.9];
julia> res_matrix = cycle_jumps(5, 5; jump_weight = jump_weights, cycle_weight = cycle_weights);
julia> size(res_matrix) == (5, 5) && eltype(res_matrix) == Float32 && count(!iszero, res_matrix) == 7
trueChanging sign of the weights with different sign patterns:
julia> cycle_sampled = cycle_jumps(
MersenneTwister(123), 5, 5;
cycle_kwargs = (; signs = RandomSigns()));
julia> jump_sampled = cycle_jumps(5, 5; jump_kwargs = (; signs = IrrationalDigitSigns()));
julia> all(abs.(cycle_sampled[cycle_sampled .!= 0]) .== 0.1f0) && all(abs.(jump_sampled[jump_sampled .!= 0]) .== 0.1f0)
trueChanging cycle jumps length:
julia> res_matrix = cycle_jumps(5, 5; jump_size = 2)
5×5 Matrix{Float32}:
0.0 0.0 0.1 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.0 0.0 0.1 0.0 0.0
0.0 0.0 0.1 0.1 0.0
julia> res_matrix = cycle_jumps(5, 5; jump_size = 4)
5×5 Matrix{Float32}:
0.0 0.0 0.0 0.0 0.1
0.1 0.0 0.0 0.0 0.0
0.0 0.1 0.0 0.0 0.0
0.0 0.0 0.1 0.0 0.0
0.1 0.0 0.0 0.1 0.0Return as a sparse matrix:
julia> using SparseArrays
julia> res_matrix = cycle_jumps(5, 5; return_sparse=true)
5×5 SparseMatrixCSC{Float32, Int64} with 7 stored entries:
⋅ ⋅ ⋅ 0.1 0.1
0.1 ⋅ ⋅ ⋅ ⋅
⋅ 0.1 ⋅ ⋅ ⋅
0.1 ⋅ 0.1 ⋅ ⋅
⋅ ⋅ ⋅ 0.1 ⋅References
- Rodan, A. and Tiňo, P. (2012). Simple Deterministically Constructed Cycle Reservoirs with Regular Jumps. Neural Computation 24, 1822–1852.