delaylinebackward
ReservoirComputing.delayline_backward — Function
delayline_backward([rng], [T], dims...;
delay_weight=0.1, fb_weight=0.1,
delay_shift=1, fb_shift=1, return_sparse=false,
radius=nothing, delay_kwargs=(), fb_kwargs=())Create a delay line backward reservoir with the specified by dims and weights. Creates a matrix with backward connections as described in (Rodan and Tino, 2011).
\[W_{i,j} = \begin{cases} r, & \text{if } i = j + 1,\;\; j \in [1, D_{\mathrm{res}} - 1], \\[4pt] b, & \text{if } j = i + 1,\;\; i \in [1, D_{\mathrm{res}} - 1], \\[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
delay_weight: The weight determines the absolute value of forward connections in the reservoir. 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 sub-diagonal you want to populate. Default is 0.1.fb_weight: Determines the absolute value of backward connections in the reservoir. 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 sub-diagonal you want to populate. Default is 0.1.fb_shift: How far the backward connection will be from the diagonal. Default is 1.delay_shift: delay line shift relative to the diagonal. Default is 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.delay_kwargsandfb_kwargs: named tuples that control the kwargs for the delay line weight and feedback weights respectively. The kwargs are as follows:sampling_type: Sampling that decides the distribution ofweightnegative numbers. If set to:no_samplethe sign is unchanged. If set to:bernoulli_sample!then eachweightcan be positive with a probability set bypositive_prob. If set to:irrational_sample!theweightis 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 theweightbeing positive whensampling_typeis set to:bernoulli_sample!. Default is 0.5.irrational: Irrational number whose decimals decide the sign ofweight. 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 = delayline_backward(5, 5)
5×5 Matrix{Float32}:
0.0 0.1 0.0 0.0 0.0
0.1 0.0 0.1 0.0 0.0
0.0 0.1 0.0 0.1 0.0
0.0 0.0 0.1 0.0 0.1
0.0 0.0 0.0 0.1 0.0Changing weights:
julia> res_matrix = delayline_backward(5, 5; delay_weight = 0.99, fb_weight=-1.0)
5×5 Matrix{Float32}:
0.0 -1.0 0.0 0.0 0.0
0.99 0.0 -1.0 0.0 0.0
0.0 0.99 0.0 -1.0 0.0
0.0 0.0 0.99 0.0 -1.0
0.0 0.0 0.0 0.99 0.0Changing weights to custom arrays:
julia> res_matrix = delayline_backward(5, 5; delay_weight = rand(4), fb_weight=.-rand(4))
5×5 Matrix{Float32}:
0.0 -0.294809 0.0 0.0 0.0
0.736006 0.0 -0.449479 0.0 0.0
0.0 0.10892 0.0 -0.60118 0.0
0.0 0.0 0.482435 0.0 -0.673392
0.0 0.0 0.0 0.177982 0.0Changing sign of the weights with different samplings:
julia> res_matrix = delayline_backward(5, 5; delay_kwargs=(;sampling_type=:irrational_sample!))
5×5 Matrix{Float32}:
0.0 0.1 0.0 0.0 0.0
-0.1 0.0 0.1 0.0 0.0
0.0 0.1 0.0 0.1 0.0
0.0 0.0 -0.1 0.0 0.1
0.0 0.0 0.0 -0.1 0.0
julia> res_matrix = delayline_backward(5, 5; fb_kwargs=(;sampling_type=:bernoulli_sample!))
5×5 Matrix{Float32}:
0.0 0.1 0.0 0.0 0.0
0.1 0.0 -0.1 0.0 0.0
0.0 0.1 0.0 0.1 0.0
0.0 0.0 0.1 0.0 -0.1
0.0 0.0 0.0 0.1 0.0Shifting:
julia> res_matrix = delayline_backward(5, 5; delay_shift=3, fb_shift=2)
5×5 Matrix{Float32}:
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.1 0.0 0.0 0.0 0.0
0.0 0.1 0.0 0.0 0.0Returning as sparse:
julia> using SparseArrays
julia> res_matrix = delayline_backward(5, 5; return_sparse=true)
5×5 SparseMatrixCSC{Float32, Int64} with 8 stored entries:
⋅ 0.1 ⋅ ⋅ ⋅
0.1 ⋅ 0.1 ⋅ ⋅
⋅ 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.