simple_cycle
ReservoirComputing.simple_cycle — Function
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 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: 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. Ifnothingis passed, no scaling takes place. Defaults tonothing.return_sparse: flag for returning asparsematrix.truerequiresSparseArraysto be loaded. Default isfalse.sampling_type: Sampling that decides the distribution ofcycle_weightnegative numbers. If set to:no_samplethe sign is unchanged. If set to:bernoulli_sample!then eachcycle_weightcan be positive with a probability set bypositive_prob. If set to:irrational_sample!thecycle_weightis 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 chosenstrides.stridescan be a single number or an array. Default is:no_sample.positive_prob: probability of thecycle_weightbeing positive whensampling_typeis set to:bernoulli_sample!. Default is 0.5.irrational: Irrational number whose decimals decide the sign ofcycle_weight. Default ispi.start: Which place after the decimal point the counting starts for theirrationalsign 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 = 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.0Changing 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.0Changing weights to a custom array:
julia> res_matrix = simple_cycle(5, 5; cycle_weight=rand(5))
5×5 Matrix{Float32}:
0.0 0.0 0.0 0.0 0.471823
0.534782 0.0 0.0 0.0 0.0
0.0 0.0764598 0.0 0.0 0.0
0.0 0.0 0.507883 0.0 0.0
0.0 0.0 0.0 0.546656 0.0Changing sign of the weights with different samplings:
julia> res_matrix = simple_cycle(5, 5; sampling_type=:irrational_sample!)
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
julia> res_matrix = simple_cycle(5, 5; sampling_type=:bernoulli_sample!)
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.0Returning 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 ⋅References
- Rodan, A. and Tino, P. (2011). Minimum Complexity Echo State Network. IEEE Transactions on Neural Networks 22, 131–144.