From eca6b94c354039194f1c049f4f1a0430ca0a0095 Mon Sep 17 00:00:00 2001 From: Logan Mondal Bhamidipaty <76822456+FlyingWorkshop@users.noreply.github.com> Date: Thu, 9 May 2024 21:39:21 -0700 Subject: [PATCH] added implicit tests --- src/implicit.jl | 2 +- src/utils.jl | 2 +- test/explicit_tests.jl | 4 +++- test/implicit_tests.jl | 21 +++++++++++++++++++++ test/runtests.jl | 1 + 5 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 test/implicit_tests.jl diff --git a/src/implicit.jl b/src/implicit.jl index b0a3996..b6ca7d8 100644 --- a/src/implicit.jl +++ b/src/implicit.jl @@ -18,7 +18,7 @@ end function ImplicitEPCA(G::Function; tol=eps(), μ=1, ϵ=eps()) - # NOTE: μ must be in the range of g, so g_inv(μ) is finite. It is up to the user to enforce this. + # NOTE: μ must be in the range of g, so g⁻¹(μ) is finite. It is up to the user to enforce this. # G induces g, Fg = F(g(θ)), and fg = f(g(θ)) @variables θ D = Differential(θ) diff --git a/src/utils.jl b/src/utils.jl index a4f2923..3327c31 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -56,4 +56,4 @@ function compress(epca::EPCA, X; maxiter=10, verbose=false, steps_per_print=10, end -decompress(epca::EPCA, A) = epca.g(A * epca.V) \ No newline at end of file +decompress(epca::EPCA, A) = epca.g.(A * epca.V) \ No newline at end of file diff --git a/test/explicit_tests.jl b/test/explicit_tests.jl index 19ae1c5..0b12755 100644 --- a/test/explicit_tests.jl +++ b/test/explicit_tests.jl @@ -8,6 +8,8 @@ function test_explicit(model::Function, X, rtol) Z1 = decompress(epca, Y1) Z2 = decompress(epca, Y2) @test isapprox(Z1, Z2, rtol=rtol) + @test isapprox(Z1, X, rtol=rtol) + @test isapprox(Z2, X, rtol=rtol) end end @@ -16,5 +18,5 @@ end d = 5 test_explicit(NormalEPCA, rand(n, d) * 100, 1) test_explicit(PoissonEPCA, rand(0:100, n, d), 1) - test_explicit(BernoulliEPCA, rand(0:1, n, d), 1) + test_explicit(BernoulliEPCA, rand(0:1, n, d), 0.5) end \ No newline at end of file diff --git a/test/implicit_tests.jl b/test/implicit_tests.jl new file mode 100644 index 0000000..d140212 --- /dev/null +++ b/test/implicit_tests.jl @@ -0,0 +1,21 @@ +function test_implicit(name, epca::EPCA, X, rtol) + @testset "$name" begin + _, d = size(X) + Y1 = fit!(epca, X; maxoutdim=d) + Y2 = compress(epca, X) + @test isapprox(Y1, Y2, rtol=rtol) + Z1 = decompress(epca, Y1) + Z2 = decompress(epca, Y2) + @test isapprox(Z1, Z2, rtol=rtol) + @test isapprox(Z1, X, rtol=rtol) + @test isapprox(Z2, X, rtol=rtol) + end +end + +@testset "Implicit Models" begin + n = 10 + d = 5 + test_implicit("Normal", EPCA(x->x^2/2), rand(n, d) * 100, 1) + test_implicit("Poisson", EPCA(x->exp(x)), rand(0:100, n, d), 1) + # test_implicit("Bernoulli", EPCA(@. x->exp(x)/(1 + exp(x))), rand(0:1, n, d), 0.5) +end \ No newline at end of file diff --git a/test/runtests.jl b/test/runtests.jl index 8635585..9ce5f9f 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -7,4 +7,5 @@ Random.seed!(1) @testset "ExpFamilyPCA.jl" begin include("explicit_tests.jl") + include("implicit_tests.jl") end