From 50e5219b2bd961eaa6756a6c235aa2f750929a11 Mon Sep 17 00:00:00 2001 From: MartinuzziFrancesco Date: Mon, 11 Mar 2024 12:08:27 +0100 Subject: [PATCH] more fixes --- Project.toml | 3 +- src/ReservoirComputing.jl | 1 - test/esn/test_inits.jl | 89 --------------------------------------- test/runtests.jl | 1 - 4 files changed, 2 insertions(+), 92 deletions(-) delete mode 100644 test/esn/test_inits.jl diff --git a/Project.toml b/Project.toml index e1145a11..aec307ca 100644 --- a/Project.toml +++ b/Project.toml @@ -35,6 +35,7 @@ MLJLinearModels = "0.9.2" NNlib = "0.8.4, 0.9" Optim = "1" Random = "1.10" +Reexport = "1.2.2" SafeTestsets = "0.1" Statistics = "1.10" Test = "1" @@ -49,4 +50,4 @@ SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" [targets] -test = ["Aqua", "Test", "SafeTestsets", "Random", "DifferentialEquations"] +test = ["Aqua", "Test", "SafeTestsets", "Random", "DifferentialEquations", "MLJLinearModels", "LIBSVM"] diff --git a/src/ReservoirComputing.jl b/src/ReservoirComputing.jl index c58da583..320f32d1 100644 --- a/src/ReservoirComputing.jl +++ b/src/ReservoirComputing.jl @@ -6,7 +6,6 @@ using Distances using LinearAlgebra using NNlib using Optim -using PartialFunctions using Random using Reexport using Statistics diff --git a/test/esn/test_inits.jl b/test/esn/test_inits.jl deleted file mode 100644 index 96ecf4b5..00000000 --- a/test/esn/test_inits.jl +++ /dev/null @@ -1,89 +0,0 @@ -using ReservoirComputing -using LinearAlgebra -using Random - -const res_size = 30 -const in_size = 3 -const radius = 1.0 -const sparsity = 0.1 -const weight = 0.2 -const jump_size = 3 -const rng = Random.default_rng() - -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 - -ft = [Float16, Float32, Float64] -reservoir_inits = [ - rand_sparse, - delay_line, - delay_line_backward, - cycle_jumps, - simple_cycle, - pseudo_svd -] -input_inits = [ - scaled_rand, - weighted_init, - minimal_init, - minimal_init(; sampling_type = :irrational) -] - -@testset "Reservoir Initializers" begin - @testset "Sizes and types: $init $T" for init in reservoir_inits, T in ft - #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(T, res_size, res_size)) == T - @test eltype(init(rng, T, res_size, res_size)) == T - #closure - cl = init(rng) - @test eltype(cl(T, res_size, res_size)) == T - end - - @testset "Check spectral radius" begin - sp = rand_sparse(res_size, res_size) - @test check_radius(sp, radius) - end - - @testset "Minimum complexity: $init" for init in [ - delay_line, - delay_line_backward, - cycle_jumps, - simple_cycle - ] - dl = init(res_size, res_size) - if init === delay_line_backward - @test unique(dl) == Float32.([0.0, 0.1, 0.2]) - else - @test unique(dl) == Float32.([0.0, 0.1]) - end - end -end - -# TODO: @MartinuzziFrancesco Missing tests for informed_init -@testset "Input Initializers" begin - @testset "Sizes and types: $init $T" for init in input_inits, T in ft - #sizes - @test size(init(res_size, in_size)) == (res_size, in_size) - @test size(init(rng, res_size, in_size)) == (res_size, in_size) - #types - @test eltype(init(T, res_size, in_size)) == T - @test eltype(init(rng, T, res_size, in_size)) == T - #closure - cl = init(rng) - @test eltype(cl(T, res_size, in_size)) == T - end - - @testset "Minimum complexity: $init" for init in [ - minimal_init, - minimal_init(; sampling_type = :irrational) - ] - dl = init(res_size, in_size) - @test sort(unique(dl)) == Float32.([-0.1, 0.1]) - end -end diff --git a/test/runtests.jl b/test/runtests.jl index 27a8ed2c..1f57d7cc 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -7,7 +7,6 @@ using Test end @testset "Echo State Networks" begin - @safetestset "ESN Input Layers" include("esn/test_inits.jl") @safetestset "ESN Train and Predict" include("esn/test_train.jl") @safetestset "ESN Drivers" include("esn/test_drivers.jl") @safetestset "Hybrid ESN" include("esn/test_hybrid.jl")