Skip to content

Commit

Permalink
added more tests to improve codecov
Browse files Browse the repository at this point in the history
  • Loading branch information
FlyingWorkshop committed Dec 16, 2024
1 parent 8e588ce commit 98b75e2
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/options.jl
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ Returns an instance of `Options` configured for optimization over the positive d
# Specific Settings
- `A_init_value = 1`: Initializes `A` with a positive value.
- `A_upper = 1e-4`: Upper bound for `A` is constrained to a small positive value.
- `A_lower = 1e-4`: Lower bound for `A` is constrained to a small positive value.
- `V_init_value = 1`: Initializes `V` with a positive value.
- `V_lower = 1e-4`: Lower bound for `V` is constrained to a small positive value.
Expand All @@ -117,7 +117,7 @@ function PositiveDomain(
tol = tol,
maxiter = maxiter,
A_init_value = 1.0,
A_upper = 1e-4,
A_lower = 1e-4,
V_init_value = 1.0,
V_lower = 1e-4,
)
Expand Down
5 changes: 0 additions & 5 deletions src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,6 @@ function _invert_legendre(f, options::Options)
return g
end

function is_constant_matrix(A::AbstractMatrix)
flag = length(unique(A)) == 1
return flag
end

function _optimize(
f::F,
lower::Union{Real, Nothing},
Expand Down
6 changes: 3 additions & 3 deletions test/family/test_gamma.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@testset "Gamma" begin
n = 2
indim = 5
outdim = 5
indim = 3
outdim = 3
X = rand(n, indim) * 100

M1 = GammaEPCA(indim, outdim)
Expand All @@ -11,6 +11,6 @@
M1,
A1,
X,
atol=2.5
atol=1.5
)
end
103 changes: 103 additions & 0 deletions test/options_tests.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
@testset "Misc Options Tests" begin
n = 2
indim = 5
outdim = 5
X = (rand(n, indim) .- 0.5) .* 100

ϵ = eps()
G(θ) = θ^2 / 2
g = identity
F = G
f = identity
B(p, q) = Distances.sqeuclidean(p, q) / 2
Bg = B
μ = 1

run_EPCA_tests(
GaussianEPCA,
indim,
outdim,
Bg,
F,
G,
f,
g,
B,
X;
custom_options = Options(A_use_sobol=true, V_use_sobol=true)
)

run_EPCA_tests(
GaussianEPCA,
indim,
outdim,
Bg,
F,
G,
f,
g,
B,
X;
custom_options = Options(metaprogramming=false)
)

M1 = GaussianEPCA(indim, outdim; options=Options(A_lower=-1000., A_upper=1000.))
A1 = fit!(M1, X)
smoke_test(
M1,
A1,
X,
atol=0.5
)
end

@testset "Positive Domain" begin
n = 2
indim = 5
outdim = 5
X = rand(-100:100, n, indim)

M1 = GaussianEPCA(indim, outdim; options=PositiveDomain())
A1 = fit!(M1, X)
Θ = A1 * M1.V
@test all.> 0)
end

@testset "Negative Domain" begin
@testset "Negative Binomial" begin
r = 2
n = 2
indim = 3
outdim = 3
X = rand(1:10, indim, outdim)

M1 = NegativeBinomialEPCA(indim, outdim, r; options=NegativeDomain())
A1 = fit!(M1, X)
Θ = A1 * M1.V
@test all.< 0)
end

@testset "Gamma" begin
n = 2
indim = 5
outdim = 5
X = rand(n, indim) * 100

M1 = GammaEPCA(indim, outdim; options=NegativeDomain())
A1 = fit!(M1, X)
Θ = A1 * M1.V
@test all.< 0)
end

@testset "Weibull" begin
n = 2
indim = 3
outdim = 3
X = rand(indim, outdim) * 2.5

M1 = WeibullEPCA(indim, outdim; options=NegativeDomain())
A1 = fit!(M1, X)
Θ = A1 * M1.V
@test all.< 0)
end
end
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ include("utils.jl")
include("family/test_negative_binomial.jl")
include("family/test_pareto.jl")
include("family/test_weibull.jl")
include("options_tests.jl")
end
10 changes: 8 additions & 2 deletions test/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,15 @@ function run_EPCA_tests(
f::Function,
g::Function,
B::Union{Function, PreMetric},
X::AbstractMatrix
X::AbstractMatrix;
custom_options::Union{Nothing, Options} = nothing
)
M1 = epca_constructor(indim, outdim)
if !isnothing(custom_options)
M1 = epca_constructor(indim, outdim; options=custom_options)
else
M1 = epca_constructor(indim, outdim)
end

A1 = fit!(M1, X)

smoke_test(
Expand Down

0 comments on commit 98b75e2

Please sign in to comment.