@@ -1518,7 +1518,6 @@ julia> reservoir_matrix = selfloop_forward_connection(5, 5; weight=0.5)
15181518 0.5 0.0 0.1 0.0 0.0
15191519 0.0 0.5 0.0 0.1 0.0
15201520 0.0 0.0 0.5 0.0 0.1
1521-
15221521```
15231522
15241523[^elsarraj2019]: Elsarraj, Duaa, et al.
@@ -1537,13 +1536,71 @@ function selfloop_forward_connection(rng::AbstractRNG, ::Type{T}, dims::Integer.
15371536 return return_init_as (Val (return_sparse), reservoir_matrix)
15381537end
15391538
1539+ """
1540+ forward_connection([rng], [T], dims...;
1541+ weight=0.1, selfloop_weight=0.1,
1542+ return_sparse=false)
1543+
1544+ Creates a reservoir based on a forward connection of weights [^elsarraj2019].
1545+
1546+ This architecture is referred to as TP5 in the original paper.
1547+
1548+ # Arguments
1549+
1550+ - `rng`: Random number generator. Default is `Utils.default_rng()`
1551+ from WeightInitializers.
1552+ - `T`: Type of the elements in the reservoir matrix. Default is `Float32`.
1553+ - `dims`: Dimensions of the reservoir matrix.
1554+
1555+ # Keyword arguments
1556+
1557+ - `weight`: Weight of the cycle connections in the reservoir matrix.
1558+ Default is 0.1.
1559+ - `return_sparse`: flag for returning a `sparse` matrix.
1560+ Default is `false`.
1561+
1562+ # Examples
1563+
1564+ ```jldoctest
1565+ julia> reservoir_matrix = forward_connection(5, 5)
1566+ 5×5 Matrix{Float32}:
1567+ 0.0 0.0 0.0 0.0 0.0
1568+ 0.0 0.0 0.0 0.0 0.0
1569+ 0.1 0.0 0.0 0.0 0.0
1570+ 0.0 0.1 0.0 0.0 0.0
1571+ 0.0 0.0 0.1 0.0 0.0
1572+
1573+ julia> reservoir_matrix = forward_connection(5, 5; weight=0.5)
1574+ 5×5 Matrix{Float32}:
1575+ 0.0 0.0 0.0 0.0 0.0
1576+ 0.0 0.0 0.0 0.0 0.0
1577+ 0.5 0.0 0.0 0.0 0.0
1578+ 0.0 0.5 0.0 0.0 0.0
1579+ 0.0 0.0 0.5 0.0 0.0
1580+ ```
1581+
1582+ [^elsarraj2019]: Elsarraj, Duaa, et al.
1583+ "Demystifying echo state network with deterministic simple topologies."
1584+ International Journal of Computational Science and Engineering 19.3 (2019): 407-417.
1585+ """
1586+ function forward_connection (rng:: AbstractRNG , :: Type{T} , dims:: Integer... ;
1587+ weight= T (0.1f0 ), return_sparse:: Bool = false ) where {T <: Number }
1588+ throw_sparse_error (return_sparse)
1589+ reservoir_matrix = DeviceAgnostic. zeros (rng, T, dims... )
1590+ for idx in first (axes (reservoir_matrix, 1 )): (last (axes (reservoir_matrix, 1 )) - 2 )
1591+ reservoir_matrix[idx + 2 , idx] = T (weight)
1592+ end
1593+ return return_init_as (Val (return_sparse), reservoir_matrix)
1594+ end
1595+
15401596# ## fallbacks
15411597# fallbacks for initializers #eventually to remove once migrated to WeightInitializers.jl
15421598for initializer in (:rand_sparse , :delay_line , :delay_line_backward , :cycle_jumps ,
15431599 :simple_cycle , :pseudo_svd , :chaotic_init ,
15441600 :scaled_rand , :weighted_init , :informed_init , :minimal_init , :chebyshev_mapping ,
15451601 :logistic_mapping , :modified_lm , :low_connectivity , :double_cycle , :self_loop_cycle ,
1546- :selfloop_feedback_cycle , :selfloop_delayline_backward , :selfloop_forward_connection )
1602+ :selfloop_feedback_cycle , :selfloop_delayline_backward , :selfloop_forward_connection ,
1603+ :forward_connection )
15471604 @eval begin
15481605 function ($ initializer)(dims:: Integer... ; kwargs... )
15491606 return $ initializer (Utils. default_rng (), Float32, dims... ; kwargs... )
0 commit comments