@@ -1411,7 +1411,7 @@ end
14111411
14121412"""
14131413 selfloop_delayline_backward([rng], [T], dims...;
1414- cycle_weight =0.1, selfloop_weight=0.1,
1414+ weight =0.1, selfloop_weight=0.1,
14151415 return_sparse=false)
14161416
14171417Creates a reservoir based on a delay line with the addition of self loops and
@@ -1474,13 +1474,76 @@ function selfloop_delayline_backward(rng::AbstractRNG, ::Type{T}, dims::Integer.
14741474 return return_init_as (Val (return_sparse), reservoir_matrix)
14751475end
14761476
1477+ """
1478+ selfloop_forward_connection([rng], [T], dims...;
1479+ weight=0.1, selfloop_weight=0.1,
1480+ return_sparse=false)
1481+
1482+ Creates a reservoir based on a forward connection of weights between even nodes
1483+ with the addition of self loops [^elsarraj2019].
1484+
1485+ This architecture is referred to as TP4 in the original paper.
1486+
1487+ # Arguments
1488+
1489+ - `rng`: Random number generator. Default is `Utils.default_rng()`
1490+ from WeightInitializers.
1491+ - `T`: Type of the elements in the reservoir matrix. Default is `Float32`.
1492+ - `dims`: Dimensions of the reservoir matrix.
1493+
1494+ # Keyword arguments
1495+
1496+ - `weight`: Weight of the cycle connections in the reservoir matrix.
1497+ Default is 0.1.
1498+ - `selfloop_weight`: Weight of the self loops in the reservoir matrix.
1499+ Default is 0.1.
1500+ - `return_sparse`: flag for returning a `sparse` matrix.
1501+ Default is `false`.
1502+
1503+ # Examples
1504+
1505+ ```jldoctest
1506+ julia> reservoir_matrix = selfloop_forward_connection(5, 5)
1507+ 5×5 Matrix{Float32}:
1508+ 0.1 0.0 0.0 0.0 0.0
1509+ 0.0 0.1 0.0 0.0 0.0
1510+ 0.1 0.0 0.1 0.0 0.0
1511+ 0.0 0.1 0.0 0.1 0.0
1512+ 0.0 0.0 0.1 0.0 0.1
1513+
1514+ julia> reservoir_matrix = selfloop_forward_connection(5, 5; weight=0.5)
1515+ 5×5 Matrix{Float32}:
1516+ 0.1 0.0 0.0 0.0 0.0
1517+ 0.0 0.1 0.0 0.0 0.0
1518+ 0.5 0.0 0.1 0.0 0.0
1519+ 0.0 0.5 0.0 0.1 0.0
1520+ 0.0 0.0 0.5 0.0 0.1
1521+
1522+ ```
1523+
1524+ [^elsarraj2019]: Elsarraj, Duaa, et al.
1525+ "Demystifying echo state network with deterministic simple topologies."
1526+ International Journal of Computational Science and Engineering 19.3 (2019): 407-417.
1527+ """
1528+ function selfloop_forward_connection (rng:: AbstractRNG , :: Type{T} , dims:: Integer... ;
1529+ weight= T (0.1f0 ), selfloop_weight= T (0.1f0 ),
1530+ return_sparse:: Bool = false ) where {T <: Number }
1531+ throw_sparse_error (return_sparse)
1532+ reservoir_matrix = DeviceAgnostic. zeros (rng, T, dims... )
1533+ reservoir_matrix += T (selfloop_weight) .* I (dims[1 ])
1534+ for idx in first (axes (reservoir_matrix, 1 )): (last (axes (reservoir_matrix, 1 )) - 2 )
1535+ reservoir_matrix[idx + 2 , idx] = T (weight)
1536+ end
1537+ return return_init_as (Val (return_sparse), reservoir_matrix)
1538+ end
1539+
14771540# ## fallbacks
14781541# fallbacks for initializers #eventually to remove once migrated to WeightInitializers.jl
14791542for initializer in (:rand_sparse , :delay_line , :delay_line_backward , :cycle_jumps ,
14801543 :simple_cycle , :pseudo_svd , :chaotic_init ,
14811544 :scaled_rand , :weighted_init , :informed_init , :minimal_init , :chebyshev_mapping ,
14821545 :logistic_mapping , :modified_lm , :low_connectivity , :double_cycle , :self_loop_cycle ,
1483- :selfloop_feedback_cycle , :selfloop_delayline_backward )
1546+ :selfloop_feedback_cycle , :selfloop_delayline_backward , :selfloop_forward_connection )
14841547 @eval begin
14851548 function ($ initializer)(dims:: Integer... ; kwargs... )
14861549 return $ initializer (Utils. default_rng (), Float32, dims... ; kwargs... )
0 commit comments