-
-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7530157
commit ba9ec64
Showing
5 changed files
with
42 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,79 +1,36 @@ | ||
using ReservoirComputing | ||
using LinearAlgebra | ||
using Random | ||
include("../utils.jl") | ||
|
||
const res_size = 20 | ||
const radius = 1.0 | ||
const sparsity = 0.1 | ||
const weight = 0.2 | ||
const jump_size = 3 | ||
const rng = Random.default_rng() | ||
|
||
dtypes = [Float16, Float32, Float64] | ||
reservoir_inits = [rand_sparse] | ||
|
||
@testset "Sizes and types" begin | ||
for init in reservoir_inits | ||
for dt in dtypes | ||
#sizes | ||
@test size(init(res_size, res_size)) == (res_size, res_size) | ||
@test size(init(rng, res_size, res_size)) == (res_size, res_size) | ||
#types | ||
@test eltype(init(dt, res_size, res_size)) == dt | ||
@test eltype(init(rng, dt, res_size, res_size)) == dt | ||
#closure | ||
cl = init(rng) | ||
@test cl(dt, res_size, res_size) isa AbstractArray{dt} | ||
end | ||
end | ||
end | ||
|
||
@testset "rand_sparse" begin | ||
sp = rand_sparse(res_size, res_size) | ||
@test check_radius(sp, radius) | ||
end | ||
|
||
#testing RandSparseReservoir implicit and esplicit constructors | ||
reservoir_constructor = RandSparseReservoir(res_size, radius, sparsity) | ||
reservoir_matrix = create_reservoir(reservoir_constructor, res_size) | ||
@test size(reservoir_matrix) == (res_size, res_size) | ||
|
||
reservoir_constructor = RandSparseReservoir(res_size, radius = radius, sparsity = sparsity) | ||
reservoir_matrix = create_reservoir(reservoir_constructor, res_size) | ||
@test size(reservoir_matrix) == (res_size, res_size) | ||
|
||
#testing PseudoSVDReservoir implicit and esplicit constructors | ||
reservoir_constructor = PseudoSVDReservoir(res_size, radius, sparsity) | ||
reservoir_matrix = create_reservoir(reservoir_constructor, res_size) | ||
@test size(reservoir_matrix) == (res_size, res_size) | ||
@test maximum(reservoir_matrix) <= radius | ||
|
||
reservoir_constructor = PseudoSVDReservoir(res_size, max_value = radius, | ||
sparsity = sparsity) | ||
reservoir_matrix = create_reservoir(reservoir_constructor, res_size) | ||
@test size(reservoir_matrix) == (res_size, res_size) | ||
@test maximum(reservoir_matrix) <= radius | ||
|
||
#testing DelayLineReservoir implicit and esplicit constructors | ||
reservoir_constructor = DelayLineReservoir(res_size, weight) | ||
reservoir_matrix = create_reservoir(reservoir_constructor, res_size) | ||
@test size(reservoir_matrix) == (res_size, res_size) | ||
@test maximum(reservoir_matrix) == weight | ||
|
||
reservoir_constructor = DelayLineReservoir(res_size, weight = weight) | ||
reservoir_matrix = create_reservoir(reservoir_constructor, res_size) | ||
@test size(reservoir_matrix) == (res_size, res_size) | ||
@test maximum(reservoir_matrix) == weight | ||
|
||
#testing DelayLineReservoir implicit and esplicit constructors | ||
reservoir_constructor = DelayLineBackwardReservoir(res_size, weight, weight) | ||
reservoir_matrix = create_reservoir(reservoir_constructor, res_size) | ||
@test size(reservoir_matrix) == (res_size, res_size) | ||
@test maximum(reservoir_matrix) == weight | ||
|
||
reservoir_constructor = DelayLineBackwardReservoir(res_size, weight = weight, | ||
fb_weight = weight) | ||
reservoir_matrix = create_reservoir(reservoir_constructor, res_size) | ||
@test size(reservoir_matrix) == (res_size, res_size) | ||
@test maximum(reservoir_matrix) == weight | ||
|
||
#testing SimpleCycleReservoir implicit and esplicit constructors | ||
reservoir_constructor = SimpleCycleReservoir(res_size, weight) | ||
reservoir_matrix = create_reservoir(reservoir_constructor, res_size) | ||
@test size(reservoir_matrix) == (res_size, res_size) | ||
@test maximum(reservoir_matrix) == weight | ||
|
||
reservoir_constructor = SimpleCycleReservoir(res_size, weight = weight) | ||
reservoir_matrix = create_reservoir(reservoir_constructor, res_size) | ||
@test size(reservoir_matrix) == (res_size, res_size) | ||
@test maximum(reservoir_matrix) == weight | ||
|
||
#testing CycleJumpsReservoir implicit and esplicit constructors | ||
reservoir_constructor = CycleJumpsReservoir(res_size, weight, weight, jump_size) | ||
reservoir_matrix = create_reservoir(reservoir_constructor, res_size) | ||
@test size(reservoir_matrix) == (res_size, res_size) | ||
@test maximum(reservoir_matrix) == weight | ||
|
||
reservoir_constructor = CycleJumpsReservoir(res_size, cycle_weight = weight, | ||
jump_weight = weight, jump_size = jump_size) | ||
reservoir_matrix = create_reservoir(reservoir_constructor, res_size) | ||
@test size(reservoir_matrix) == (res_size, res_size) | ||
@test maximum(reservoir_matrix) == weight | ||
|
||
#testing NullReservoir constructors | ||
reservoir_constructor = NullReservoir() | ||
reservoir_matrix = create_reservoir(reservoir_constructor, res_size) | ||
@test size(reservoir_matrix) == (res_size, res_size) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
function check_radius(matrix, target_radius; tolerance=1e-5) | ||
eigenvalues = eigvals(matrix) | ||
spectral_radius = maximum(abs.(eigenvalues)) | ||
return isapprox(spectral_radius, target_radius, atol=tolerance) | ||
end |