cycle_jumps

ReservoirComputing.cycle_jumpsFunction
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 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: 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. 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.

  • cycle_kwargs and jump_kwargs: named tuples that control the kwargs for the cycle and jump weights respectively. The kwargs are as follows:

    • sampling_type: Sampling that decides the distribution of weight negative numbers. If set to :no_sample the sign is unchanged. If set to :bernoulli_sample! then each weight can be positive with a probability set by positive_prob. If set to :irrational_sample! the weight is negative if the decimal number of the irrational number chosen is odd. If set to :regular_sample!, each weight will be assigned a negative sign after the chosen strides. strides can be a single number or an array. Default is :no_sample.
    • positive_prob: probability of the weight being positive when sampling_type is set to :bernoulli_sample!. Default is 0.5.
    • irrational: Irrational number whose decimals decide the sign of weight. Default is pi.
    • start: Which place after the decimal point the counting starts for the irrational sign counting. Default is 1.
    • strides: number of strides for assigning negative value to a weight. It can be an integer or an array. Default is 2.

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.0

Changing weights:

julia> res_matrix = cycle_jumps(5, 5; jump_weight = 2, cycle_weight=-1)
5×5 Matrix{Float32}:
 0.0   0.0   0.0   2.0  -1.0
-1.0   0.0   0.0   0.0   0.0
 0.0  -1.0   0.0   0.0   0.0
 2.0   0.0  -1.0   0.0   0.0
 0.0   0.0   0.0  -1.0   0.0

Changing weights to custom arrays:

julia> res_matrix = cycle_jumps(5, 5; jump_weight = .-rand(3), cycle_weight=rand(5))
5×5 Matrix{Float32}:
  0.0       0.0       0.0        -0.453905  0.443731
  0.434804  0.0       0.0         0.0       0.0
  0.0       0.520551  0.0         0.0       0.0
 -0.453905  0.0       0.0665751   0.0       0.0
  0.0       0.0       0.0         0.57811   0.0

Changing sign of the weights with different samplings:

julia> res_matrix = cycle_jumps(5, 5; cycle_kwargs = (;sampling_type=:bernoulli_sample!))
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.0

julia> res_matrix = cycle_jumps(5, 5; jump_kwargs = (;sampling_type=:irrational_sample!))
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.0

Changing 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.0

Return 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   ⋅
source

References