selfloopdelaylinebackward
ReservoirComputing.selfloop_delayline_backward — Function
selfloop_delayline_backward([rng], [T], dims...;
delay_weight=0.1, selfloop_weight=0.1, fb_weight=0.1,
fb_shift=2, delya_shift=1, radius=nothing, return_sparse=false,
fb_kwargs=(), selfloop_kwargs=(), delay_kwargs=())Creates a reservoir based on a delay line with the addition of self loops and backward connections shifted by one (Elsarraj et al., 2019).
This architecture is referred to as TP3 in the original paper.
\[W_{i,j} = \begin{cases} ll, & \text{if } i = j \text{ for } i = 1 \dots N \\ r, & \text{if } j = i - 1 \text{ for } i = 2 \dots N \\ r, & \text{if } j = i - 2 \text{ for } i = 3 \dots N \\ 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: Weight of the delay line 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.selfloop_weight: Weight of the self loops 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 diagonal you want to populate. Default is 0.1.fb_weight: Weight of the feedback 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 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_kwargs,selfloop_kwargs, andfb_kwargs: named tuples that control the kwargs for the weights generation. The kwargs are as follows:signs: Controls sign flips. UseRandomSigns,RegularSigns, orIrrationalDigitSigns. Passnothingto leave signs unchanged. Default isnothing.
Examples
Default call:
julia> res_matrix = selfloop_delayline_backward(5, 5)
5×5 Matrix{Float32}:
0.1 0.0 0.1 0.0 0.0
0.1 0.1 0.0 0.1 0.0
0.0 0.1 0.1 0.0 0.1
0.0 0.0 0.1 0.1 0.0
0.0 0.0 0.0 0.1 0.1Changing weights:
julia> res_matrix = selfloop_delayline_backward(5, 5; selfloop_weight=0.3, fb_weight=0.99, delay_weight=-0.5)
5×5 Matrix{Float32}:
0.3 0.0 0.99 0.0 0.0
-0.5 0.3 0.0 0.99 0.0
0.0 -0.5 0.3 0.0 0.99
0.0 0.0 -0.5 0.3 0.0
0.0 0.0 0.0 -0.5 0.3Changing weights to custom arrays:
julia> selfloop_weights = Float32[0.2, 0.4, 0.6, 0.8, 1.0];
julia> feedback_weights = Float32[0.1, 0.3, 0.5, 0.7, 0.9];
julia> delay_weights = -Float32[0.2, 0.4, 0.6, 0.8, 1.0];
julia> res_matrix = selfloop_delayline_backward(5, 5;
selfloop_weight = selfloop_weights, fb_weight = feedback_weights,
delay_weight = delay_weights);
julia> size(res_matrix) == (5, 5) && eltype(res_matrix) == Float32 &&
all(weight -> any(==(weight), diag(res_matrix)), selfloop_weights)
trueChanging sign of the weights with different sign patterns:
julia> res_matrix = selfloop_delayline_backward(
5, 5; selfloop_kwargs = (; signs = IrrationalDigitSigns()))
5×5 Matrix{Float32}:
-0.1 0.0 0.1 0.0 0.0
0.1 0.1 0.0 0.1 0.0
0.0 0.1 -0.1 0.0 0.1
0.0 0.0 0.1 -0.1 0.0
0.0 0.0 0.0 0.1 -0.1
julia> res_matrix = selfloop_delayline_backward(5, 5; delay_kwargs=(;signs = RandomSigns()))
5×5 Matrix{Float32}:
0.1 0.0 0.1 0.0 0.0
0.1 0.1 0.0 0.1 0.0
0.0 -0.1 0.1 0.0 0.1
0.0 0.0 0.1 0.1 0.0
0.0 0.0 0.0 -0.1 0.1
julia> res_matrix = selfloop_delayline_backward(5, 5; fb_kwargs=(;signs = RegularSigns()))
5×5 Matrix{Float32}:
0.1 0.0 0.1 0.0 0.0
0.1 0.1 0.0 -0.1 0.0
0.0 0.1 0.1 0.0 0.1
0.0 0.0 0.1 0.1 0.0
0.0 0.0 0.0 0.1 0.1Shifting the delay and the backward line:
julia> res_matrix = selfloop_delayline_backward(5, 5; delay_shift=3, fb_shift=2)
5×5 Matrix{Float32}:
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.1 0.0 0.0 0.1 0.0
0.0 0.1 0.0 0.0 0.1Returning as sparse:
julia> using SparseArrays
julia> res_matrix = selfloop_delayline_backward(5, 5; return_sparse=true)
5×5 SparseMatrixCSC{Float32, Int64} with 12 stored entries:
0.1 ⋅ 0.1 ⋅ ⋅
0.1 0.1 ⋅ 0.1 ⋅
⋅ 0.1 0.1 ⋅ 0.1
⋅ ⋅ 0.1 0.1 ⋅
⋅ ⋅ ⋅ 0.1 0.1References
- Elsarraj, D.; Qisi, M. A.; Rodan, A.; Obeid, N.; Sharieh, A. and Faris, H. (2019). Demystifying echo state network with deterministic simple topologies. International Journal of Computational Science and Engineering 19, 407–417.