Skip to content

Commit c5d47fa

Browse files
format
1 parent 5dd4df9 commit c5d47fa

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

src/esn/esn_inits.jl

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1127,25 +1127,27 @@ end
11271127
11281128
Construct an internal reservoir connectivity matrix with low connectivity.
11291129
1130-
This function creates a square reservoir matrix with the specified in-degree
1130+
This function creates a square reservoir matrix with the specified in-degree
11311131
for each node [^griffith2019]. When `in_degree` is 1, the function can enforce
11321132
a fully connected cycle if `connected` is `true`;
11331133
otherwise, it generates a random connectivity pattern.
11341134
11351135
# Arguments
1136+
11361137
- `rng`: Random number generator. Default is `Utils.default_rng()`
11371138
from WeightInitializers.
11381139
- `T`: Type of the elements in the reservoir matrix.
11391140
Default is `Float32`.
11401141
- `dims`: Dimensions of the reservoir matrix.
11411142
11421143
# Keyword Arguments
1144+
11431145
- `return_sparse`: If `true`, the function returns the
11441146
reservoir matrix as a sparse matrix. Default is `false`.
11451147
- `connected`: For `in_degree == 1`, if `true` a connected cycle is enforced.
11461148
Default is `false`.
11471149
- `in_degree`: The number of incoming connections per node.
1148-
Must not exceed the number of nodes. Default is 1.
1150+
Must not exceed the number of nodes. Default is 1.
11491151
- `radius`: The desired spectral radius of the reservoir.
11501152
Defaults to 1.0.
11511153
- `cut_cycle`: If `true`, removes one edge from the cycle to cut it.
@@ -1156,8 +1158,8 @@ otherwise, it generates a random connectivity pattern.
11561158
Chaos: An Interdisciplinary Journal of Nonlinear Science 29.12 (2019).
11571159
"""
11581160
function low_connectivity(rng::AbstractRNG, ::Type{T}, dims::Integer...;
1159-
return_sparse::Bool = false, connected::Bool=false,
1160-
in_degree::Int = 1, kwargs...) where {T <: Number}
1161+
return_sparse::Bool=false, connected::Bool=false,
1162+
in_degree::Int=1, kwargs...) where {T <: Number}
11611163
res_size = dims[1]
11621164
if length(dims) != 2 || dims[1] != dims[2]
11631165
error("""
@@ -1170,15 +1172,17 @@ function low_connectivity(rng::AbstractRNG, ::Type{T}, dims::Integer...;
11701172
""")
11711173
end
11721174
if in_degree == 1
1173-
reservoir_matrix = build_cycle(Val(connected), rng, T, res_size; in_degree=in_degree, kwargs...)
1175+
reservoir_matrix = build_cycle(
1176+
Val(connected), rng, T, res_size; in_degree=in_degree, kwargs...)
11741177
else
1175-
reservoir_matrix = build_cycle(Val(false), rng, T, res_size; in_degree=in_degree, kwargs...)
1178+
reservoir_matrix = build_cycle(
1179+
Val(false), rng, T, res_size; in_degree=in_degree, kwargs...)
11761180
end
11771181
return return_init_as(Val(return_sparse), reservoir_matrix)
11781182
end
11791183

11801184
function build_cycle(::Val{false}, rng::AbstractRNG, ::Type{T}, res_size::Int;
1181-
in_degree::Integer=1, radius::T = T(1.0), cut_cycle::Bool=false) where {T <: Number}
1185+
in_degree::Integer=1, radius::T=T(1.0), cut_cycle::Bool=false) where {T <: Number}
11821186
reservoir_matrix = DeviceAgnostic.zeros(rng, T, res_size, res_size)
11831187
for i in 1:res_size
11841188
selected = randperm(rng, res_size)[1:in_degree]
@@ -1191,11 +1195,11 @@ function build_cycle(::Val{false}, rng::AbstractRNG, ::Type{T}, res_size::Int;
11911195
end
11921196

11931197
function build_cycle(::Val{true}, rng::AbstractRNG, ::Type{T}, res_size::Int;
1194-
in_degree::Integer=1, radius::T = T(1.0), cut_cycle::Bool=false) where {T <: Number}
1198+
in_degree::Integer=1, radius::T=T(1.0), cut_cycle::Bool=false) where {T <: Number}
11951199
reservoir_matrix = DeviceAgnostic.zeros(rng, T, res_size, res_size)
11961200
perm = randperm(rng, res_size)
11971201
for i in 1:(res_size - 1)
1198-
reservoir_matrix[perm[i], perm[i+1]] = T(randn(rng))
1202+
reservoir_matrix[perm[i], perm[i + 1]] = T(randn(rng))
11991203
end
12001204
reservoir_matrix[perm[res_size], perm[1]] = T(randn(rng))
12011205
scale_radius!(reservoir_matrix, radius)
@@ -1205,7 +1209,8 @@ function build_cycle(::Val{true}, rng::AbstractRNG, ::Type{T}, res_size::Int;
12051209
return reservoir_matrix
12061210
end
12071211

1208-
function cut_cycle_edge!(reservoir_matrix::AbstractMatrix{T}, rng::AbstractRNG) where {T <: Number}
1212+
function cut_cycle_edge!(
1213+
reservoir_matrix::AbstractMatrix{T}, rng::AbstractRNG) where {T <: Number}
12091214
res_size = size(reservoir_matrix, 1)
12101215
row = rand(rng, 1:res_size)
12111216
for j in 1:res_size
@@ -1217,7 +1222,6 @@ function cut_cycle_edge!(reservoir_matrix::AbstractMatrix{T}, rng::AbstractRNG)
12171222
return reservoir_matrix
12181223
end
12191224

1220-
12211225
### fallbacks
12221226
#fallbacks for initializers #eventually to remove once migrated to WeightInitializers.jl
12231227
for initializer in (:rand_sparse, :delay_line, :delay_line_backward, :cycle_jumps,

test/esn/test_inits.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ reservoir_inits = [
2626
simple_cycle,
2727
pseudo_svd,
2828
chaotic_init,
29-
low_connectivity,
29+
low_connectivity
3030
]
3131
input_inits = [
3232
scaled_rand,

0 commit comments

Comments
 (0)