Skip to content

Commit e21ea8a

Browse files
docs
1 parent 832612c commit e21ea8a

File tree

2 files changed

+87
-10
lines changed

2 files changed

+87
-10
lines changed

docs/src/api/inits.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
weighted_init
88
informed_init
99
minimal_init
10+
chebyshev_mapping
1011
```
1112

1213
## Reservoirs
@@ -18,4 +19,5 @@
1819
cycle_jumps
1920
simple_cycle
2021
pseudo_svd
22+
chaotic_init
2123
```

src/esn/esn_inits.jl

Lines changed: 85 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,25 @@ Subsequent rows are generated by applying the mapping:
317317
- `chebyshev_parameter`: Control parameter for the Chebyshev mapping in
318318
subsequent rows. This parameter influences the distribution of the
319319
matrix elements. Default is one.
320-
- `return_sparse`: If `true`, the function returns the matrix as a sparse matrix. Default is `true`.
320+
- `return_sparse`: If `true`, the function returns the matrix as a sparse matrix. Default is `false`.
321+
322+
# Examples
323+
324+
```jldoctest
325+
julia> input_matrix = chebyshev_mapping(10, 3)
326+
10×3 Matrix{Float32}:
327+
0.866025 0.866025 1.22465f-16
328+
0.866025 0.866025 -4.37114f-8
329+
0.866025 0.866025 -4.37114f-8
330+
0.866025 0.866025 -4.37114f-8
331+
0.866025 0.866025 -4.37114f-8
332+
0.866025 0.866025 -4.37114f-8
333+
0.866025 0.866025 -4.37114f-8
334+
0.866025 0.866025 -4.37114f-8
335+
0.866025 0.866025 -4.37114f-8
336+
0.866025 0.866025 -4.37114f-8
337+
338+
```
321339
322340
[^xie2024]: Xie, Minzhi, Qianxue Wang, and Simin Yu.
323341
"Time Series Prediction of ESN Based on Chebyshev Mapping and Strongly
@@ -327,7 +345,7 @@ Subsequent rows are generated by applying the mapping:
327345
function chebyshev_mapping(rng::AbstractRNG, ::Type{T}, dims::Integer...;
328346
amplitude::AbstractFloat = one(T), sine_divisor::AbstractFloat = one(T),
329347
chebyshev_parameter::AbstractFloat = one(T),
330-
return_sparse::Bool = true) where {T <: Number}
348+
return_sparse::Bool = false) where {T <: Number}
331349
input_matrix = DeviceAgnostic.zeros(rng, T, dims...)
332350
n_rows, n_cols = dims[1], dims[2]
333351

@@ -752,23 +770,80 @@ function digital_chaotic_adjacency(rng::AbstractRNG, bit_precision::Integer;
752770
return adjacency_matrix
753771
end
754772

773+
"""
774+
chaotic_init([rng], [T], dims...;
775+
extra_edge_probability=T(0.1), spectral_radius=one(T),
776+
return_sparse_matrix=true)
777+
778+
Construct a chaotic reservoir matrix using a digital chaotic system [^xie2024].
779+
780+
The matrix topology is derived from a strongly connected adjacency
781+
matrix based on a digital chaotic system operating at finite precision.
782+
If the requested matrix order does not exactly match a valid order the
783+
closest valid order is used.
784+
785+
# Arguments
786+
- `rng`: Random number generator. Default is `Utils.default_rng()`
787+
from WeightInitializers.
788+
- `T`: Type of the elements in the reservoir matrix.
789+
Default is `Float32`.
790+
- `dims`: Dimensions of the reservoir matrix.
791+
792+
# Keyword arguments
793+
- `extra_edge_probability`: Probability of adding extra random edges in
794+
the adjacency matrix to enhance connectivity. Default is 0.1.
795+
- `desired_spectral_radius`: The target spectral radius for the
796+
reservoir matrix. Default is one.
797+
- `return_sparse_matrix`: If `true`, the function returns the
798+
reservoir matrix as a sparse matrix. Default is `true`.
799+
800+
# Examples
801+
802+
```jldoctest
803+
julia> res_matrix = chaotic_init(8, 8)
804+
┌ Warning:
805+
806+
│ Adjusting reservoir matrix order:
807+
│ from 8 (requested) to 4
808+
│ based on computed bit precision = 1.
809+
810+
└ @ ReservoirComputing ~/.julia/dev/ReservoirComputing/src/esn/esn_inits.jl:805
811+
4×4 SparseArrays.SparseMatrixCSC{Float32, Int64} with 6 stored entries:
812+
⋅ -0.600945 ⋅ ⋅
813+
⋅ ⋅ 0.132667 2.21354
814+
⋅ -2.60383 ⋅ -2.90391
815+
-0.578156 ⋅ ⋅ ⋅
816+
817+
```
818+
819+
[^xie2024]: Xie, Minzhi, Qianxue Wang, and Simin Yu.
820+
"Time Series Prediction of ESN Based on Chebyshev Mapping and Strongly
821+
Connected Topology."
822+
Neural Processing Letters 56.1 (2024): 30.
823+
"""
755824
function chaotic_init(rng::AbstractRNG, ::Type{T}, dims::Integer...;
756825
extra_edge_probability::AbstractFloat = T(0.1), spectral_radius::AbstractFloat = one(T),
757826
return_sparse_matrix::Bool = true) where {T <: Number}
758827

759828
requested_order = first(dims)
760829
if length(dims) > 1 && dims[2] != requested_order
761-
@warn "Using dims[1] = $requested_order for the chaotic reservoir matrix order."
830+
@warn """\n
831+
Using dims[1] = $requested_order for the chaotic reservoir matrix order.\n
832+
"""
762833
end
763-
D_estimate = log2(requested_order) / 2
764-
D_floor = max(floor(Int, D_estimate), 1)
765-
D_ceil = ceil(Int, D_estimate)
766-
candidate_order_floor = 2^(2 * D_floor)
767-
candidate_order_ceil = 2^(2 * D_ceil)
768-
chosen_bit_precision = abs(candidate_order_floor - requested_order) <= abs(candidate_order_ceil - requested_order) ? D_floor : D_ceil
834+
d_estimate = log2(requested_order) / 2
835+
d_floor = max(floor(Int, d_estimate), 1)
836+
d_ceil = ceil(Int, d_estimate)
837+
candidate_order_floor = 2^(2 * d_floor)
838+
candidate_order_ceil = 2^(2 * d_ceil)
839+
chosen_bit_precision = abs(candidate_order_floor - requested_order) <= abs(candidate_order_ceil - requested_order) ? d_floor : d_ceil
769840
actual_matrix_order = 2^(2 * chosen_bit_precision)
770841
if actual_matrix_order != requested_order
771-
@warn "Chaotic reservoir matrix order adjusted from $requested_order to $actual_matrix_order based on computed bit precision = $chosen_bit_precision."
842+
@warn """\n
843+
Adjusting reservoir matrix order:
844+
from $requested_order (requested) to $actual_matrix_order
845+
based on computed bit precision = $chosen_bit_precision. \n
846+
"""
772847
end
773848

774849
random_weight_matrix = T(2) * rand(rng, T, actual_matrix_order, actual_matrix_order) .- T(1)

0 commit comments

Comments
 (0)