@@ -1222,12 +1222,69 @@ function cut_cycle_edge!(
12221222 return reservoir_matrix
12231223end
12241224
1225+ """
1226+ double_cycle([rng], [T], dims...;
1227+ cycle_weight=0.1, second_cycle_weight=0.1,
1228+ return_sparse=false)
1229+
1230+ Creates a double cycle reservoir[^fu2023] with the specified dimensions and weights.
1231+
1232+ # Arguments
1233+
1234+ - `rng`: Random number generator. Default is `Utils.default_rng()`
1235+ from WeightInitializers.
1236+ - `T`: Type of the elements in the reservoir matrix. Default is `Float32`.
1237+ - `dims`: Dimensions of the reservoir matrix.
1238+
1239+ # Keyword arguments
1240+
1241+ - `cycle_weight`: Weight of the upper cycle connections in the reservoir matrix.
1242+ Default is 0.1.
1243+ - `second_cycle_weight`: Weight of the lower cycle connections in the reservoir matrix.
1244+ Default is 0.1.
1245+ - `return_sparse`: flag for returning a `sparse` matrix.
1246+ Default is `false`.
1247+
1248+ # Examples
1249+
1250+ ```jldoctest
1251+ julia> reservoir_matrix = double_cycle(5, 5; cycle_weight=0.1, second_cycle_weight=0.3)
1252+ 5×5 Matrix{Float32}:
1253+ 0.0 0.3 0.0 0.0 0.3
1254+ 0.1 0.0 0.3 0.0 0.0
1255+ 0.0 0.1 0.0 0.3 0.0
1256+ 0.0 0.0 0.1 0.0 0.3
1257+ 0.1 0.0 0.0 0.1 0.0
1258+ ```
1259+
1260+ [^fu2023]: Fu, Jun, et al.
1261+ "A double-cycle echo state network topology for time series prediction."
1262+ Chaos: An Interdisciplinary Journal of Nonlinear Science 33.9 (2023).
1263+ """
1264+ function double_cycle (rng:: AbstractRNG , :: Type{T} , dims:: Integer... ;
1265+ cycle_weight= T (0.1 ), second_cycle_weight= T (0.1 ),
1266+ return_sparse:: Bool = false ) where {T <: Number }
1267+ throw_sparse_error (return_sparse)
1268+ reservoir_matrix = DeviceAgnostic. zeros (rng, T, dims... )
1269+
1270+ for uidx in 1 : (dims[1 ] - 1 )
1271+ reservoir_matrix[uidx + 1 , uidx] = cycle_weight
1272+ end
1273+ for lidx in 2 : dims[1 ]
1274+ reservoir_matrix[lidx - 1 , lidx] = second_cycle_weight
1275+ end
1276+
1277+ reservoir_matrix[1 , dims[1 ]] = second_cycle_weight
1278+ reservoir_matrix[dims[1 ], 1 ] = cycle_weight
1279+ return return_init_as (Val (return_sparse), reservoir_matrix)
1280+ end
1281+
12251282# ## fallbacks
12261283# fallbacks for initializers #eventually to remove once migrated to WeightInitializers.jl
12271284for initializer in (:rand_sparse , :delay_line , :delay_line_backward , :cycle_jumps ,
12281285 :simple_cycle , :pseudo_svd , :chaotic_init ,
12291286 :scaled_rand , :weighted_init , :informed_init , :minimal_init , :chebyshev_mapping ,
1230- :logistic_mapping , :modified_lm , :low_connectivity )
1287+ :logistic_mapping , :modified_lm , :low_connectivity , :double_cycle )
12311288 @eval begin
12321289 function ($ initializer)(dims:: Integer... ; kwargs... )
12331290 return $ initializer (Utils. default_rng (), Float32, dims... ; kwargs... )
0 commit comments