Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "ReservoirComputing"
uuid = "7c2d2b1e-3dd4-11ea-355a-8f6a8116e294"
authors = ["Francesco Martinuzzi"]
version = "0.10.11"
version = "0.10.12"

[deps]
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
Expand Down
1 change: 1 addition & 0 deletions docs/src/api/states.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
NLAT1
NLAT2
NLAT3
PartialSquare
```

## Internals
Expand Down
2 changes: 1 addition & 1 deletion src/ReservoirComputing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ include("esn/esn_predict.jl")
include("reca/reca.jl")
include("reca/reca_input_encodings.jl")

export NLADefault, NLAT1, NLAT2, NLAT3
export NLADefault, NLAT1, NLAT2, NLAT3, PartialSquare
export StandardStates, ExtendedStates, PaddedStates, PaddedExtendedStates
export StandardRidge
export scaled_rand, weighted_init, informed_init, minimal_init, chebyshev_mapping,
Expand Down
72 changes: 72 additions & 0 deletions src/states.jl
Original file line number Diff line number Diff line change
Expand Up @@ -654,3 +654,75 @@ function (::NLAT3)(x_old::AbstractVector)

return x_new
end

@doc raw"""
PartialSquare(eta)

Implement a partial squaring of the states as described in [^barbosa2021].

# Equations

```math
\begin{equation}
g(r_i) =
\begin{cases}
r_i^2, & \text{if } i \leq \eta_r N, \\
r_i, & \text{if } i > \eta_r N.
\end{cases}
\end{equation}
```

# Examples

```jldoctest
julia> ps = PartialSquare(0.6)
PartialSquare(0.6)


julia> x_old = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
10-element Vector{Int64}:
0
1
2
3
4
5
6
7
8
9

julia> x_new = ps(x_old)
10-element Vector{Int64}:
0
1
4
9
16
25
6
7
8
9


[^barbosa2021]: Barbosa, Wendson AS, et al.
"Symmetry-aware reservoir computing."
Physical Review E 104.4 (2021): 045307.
"""
struct PartialSquare <: NonLinearAlgorithm
eta::Number
end

function (ps::PartialSquare)(x_old::AbstractVector)
x_new = copy(x_old)
n_length = length(x_old)
threshold = floor(Int, ps.eta * n_length)
for idx in eachindex(x_old)
if idx <= threshold
x_new[idx] = x_old[idx]^2
end
end

return x_new
end
3 changes: 2 additions & 1 deletion test/test_states.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ test_types = [Float64, Float32, Float16]
nlas = [(NLADefault(), test_array),
(NLAT1(), [1, 2, 9, 4, 25, 6, 49, 8, 81]),
(NLAT2(), [1, 2, 2, 4, 12, 6, 30, 8, 9]),
(NLAT3(), [1, 2, 8, 4, 24, 6, 48, 8, 9])]
(NLAT3(), [1, 2, 8, 4, 24, 6, 48, 8, 9]),
(PartialSquare(0.6), [1, 4, 9, 16, 25, 6, 7, 8, 9])]

pes = [(StandardStates(), test_array),
(PaddedStates(; padding=padding),
Expand Down
Loading