simple_cycle

ReservoirComputing.simple_cycleFunction
simple_cycle([rng], [T], dims...;
    cycle_weight=0.1, return_sparse=false,
    radius=nothing, kwargs...)

Create a simple cycle reservoir (Rodan and Tino, 2011).

\[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}}, \\[6pt] 0, & \text{otherwise.} \end{cases}\]

Arguments

  • rng: Random number generator. Default is Utils.default_rng()from WeightInitializers.
  • T: Type of the elements in the reservoir matrix. Default is Float32.
  • dims: Dimensions of the reservoir matrix.

Keyword arguments

  • cycle_weight: Weight of the connections in the reservoir matrix. 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.
  • radius: The desired spectral radius of the reservoir. If nothing is passed, no scaling takes place. Defaults to nothing.
  • return_sparse: flag for returning a sparse matrix. true requires SparseArrays to be loaded. Default is false.
  • signs: Controls sign flips. Use RandomSigns, RegularSigns, or IrrationalDigitSigns. Pass nothing to leave signs unchanged. Default is nothing.

Examples

Default call:

julia> res_matrix = simple_cycle(5, 5)
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.0  0.0  0.0  0.1  0.0

Changing weights:

julia> res_matrix = simple_cycle(5, 5; cycle_weight=0.99)
5×5 Matrix{Float32}:
 0.0   0.0   0.0   0.0   0.99
 0.99  0.0   0.0   0.0   0.0
 0.0   0.99  0.0   0.0   0.0
 0.0   0.0   0.99  0.0   0.0
 0.0   0.0   0.0   0.99  0.0

Changing weights to a custom array:

julia> cycle_weights = Float32[0.2, 0.4, 0.6, 0.8, 1.0];

julia> res_matrix = simple_cycle(5, 5; cycle_weight = cycle_weights);

julia> res_matrix[2, 1] == 0.2f0 && res_matrix[1, 5] == 1.0f0
true

Changing sign of the weights with different sign patterns:

julia> irrational_matrix = simple_cycle(5, 5; signs = IrrationalDigitSigns());

julia> bernoulli_matrix = simple_cycle(MersenneTwister(123), 5, 5; signs = RandomSigns());

julia> all(abs.(irrational_matrix[irrational_matrix .!= 0]) .== 0.1f0) && all(abs.(bernoulli_matrix[bernoulli_matrix .!= 0]) .== 0.1f0)
true

Returning as sparse:

julia> using SparseArrays

julia> res_matrix = simple_cycle(5, 5; return_sparse=true)
5×5 SparseMatrixCSC{Float32, Int64} with 5 stored entries:
  ⋅    ⋅    ⋅    ⋅   0.1
 0.1   ⋅    ⋅    ⋅    ⋅
  ⋅   0.1   ⋅    ⋅    ⋅
  ⋅    ⋅   0.1   ⋅    ⋅
  ⋅    ⋅    ⋅   0.1   ⋅
source

References