Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update tests #21

Merged
merged 8 commits into from
Jan 25, 2022
Merged
Show file tree
Hide file tree
Changes from 7 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
*.jl.cov
*.jl.mem
Manifest.toml
.vscode
Binary file modified test/data/center.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/data/eigenanalysis-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/data/eigenanalysis-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/data/scale.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/data/zscore.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
117 changes: 62 additions & 55 deletions test/transforms.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
@testset "Transforms" begin
# using MersenneTwister for compatibility between Julia versions
rng = MersenneTwister(42)
@testset "Select" begin
a = rand(4000)
b = rand(4000)
Expand Down Expand Up @@ -196,9 +198,9 @@
end

@testset "Center" begin
Random.seed!(42) # to reproduce the results
x = rand(Normal(2,1), 4000)
y = rand(Normal(5,1), 4000)
# using rng for reproducible results
x = rand(rng, Normal(2, 1), 4000)
y = rand(rng, Normal(5, 1), 4000)
t = Table(; x, y)
T = Center()
n, c = apply(T, t)
Expand All @@ -214,7 +216,8 @@
p₂ = scatter(n.x, n.y, label="Center")
p = plot(p₁, p₂, layout=(1,2))

@test_reference joinpath(datadir, "center.png") p
@test_reference joinpath(datadir, "center.png") p
# savefig(p, joinpath(datadir, "center.png"))
eliascarv marked this conversation as resolved.
Show resolved Hide resolved
end
end

Expand All @@ -228,18 +231,18 @@
@test n.x == x
@test n.y != y
tₒ = revert(T, n, c)
@test tₒ == t
@test Tables.matrix(t) ≈ Tables.matrix(tₒ)

Random.seed!(42) # to reproduce the results
x = rand(Normal(4,3), 4000)
y = rand(Normal(7,5), 4000)
# using rng for reproducible results
x = rand(rng, Normal(4, 3), 4000)
y = rand(rng, Normal(7, 5), 4000)
t = Table(; x, y)
T = Scale(low=0, high=1)
n, c = apply(T, t)
@test all(x -> x <= 1, n.x)
@test all(x -> x >= 0, n.x)
@test all(y -> y <= 1, n.y)
@test all(y -> y >= 0, n.y)
@test all(≤(1), n.x)
@test all(≥(0), n.x)
@test all(≤(1), n.y)
@test all(≥(0), n.y)
eliascarv marked this conversation as resolved.
Show resolved Hide resolved
tₒ = revert(T, n, c)
@test Tables.matrix(t) ≈ Tables.matrix(tₒ)

Expand All @@ -249,14 +252,15 @@
p₂ = scatter(n.x, n.y, label="Scale")
p = plot(p₁, p₂, layout=(1,2))

@test_reference joinpath(datadir,"scale.png") p
@test_reference joinpath(datadir, "scale.png") p
# savefig(p, joinpath(datadir, "scale.png"))
eliascarv marked this conversation as resolved.
Show resolved Hide resolved
end
end

@testset "ZScore" begin
Random.seed!(42) # to reproduce the results
x = rand(Normal(7,10), 4000)
y = rand(Normal(15,2), 4000)
# using rng for reproducible results
x = rand(rng, Normal(7, 10), 4000)
y = rand(rng, Normal(15, 2), 4000)
t = Table(; x, y)
T = ZScore()
n, c = apply(T, t)
Expand All @@ -275,7 +279,8 @@
p₂ = scatter(n.x, n.y, label="ZScore")
p = plot(p₁, p₂, layout=(1,2))

@test_reference joinpath(datadir,"zscore.png") p
@test_reference joinpath(datadir, "zscore.png") p
# savefig(p, joinpath(datadir, "zscore.png"))
juliohm marked this conversation as resolved.
Show resolved Hide resolved
end
end

Expand Down Expand Up @@ -304,8 +309,8 @@
t = Table(; x, y)
T = Functional(cos)
n, c = apply(T, t)
@test all(x -> -1 <= x <= 1, n.x)
@test all(y -> -1 <= y <= 1, n.y)
@test all(x -> -1 x 1, n.x)
@test all(y -> -1 y 1, n.y)
juliohm marked this conversation as resolved.
Show resolved Hide resolved
tₒ = revert(T, n, c)
@test Tables.matrix(t) ≈ Tables.matrix(tₒ)

Expand All @@ -314,8 +319,8 @@
t = Table(; x, y)
T = Functional(acos)
n, c = apply(T, t)
@test all(x -> 0 <= x <= π, n.x)
@test all(y -> 0 <= y <= π, n.y)
@test all(x -> 0 x π, n.x)
@test all(y -> 0 y π, n.y)
tₒ = revert(T, n, c)
@test Tables.matrix(t) ≈ Tables.matrix(tₒ)

Expand All @@ -324,8 +329,8 @@
t = Table(; x, y)
T = Functional(sin)
n, c = apply(T, t)
@test all(x -> -1 <= x <= 1, n.x)
@test all(y -> -1 <= y <= 1, n.y)
@test all(x -> -1 x 1, n.x)
@test all(y -> -1 y 1, n.y)
tₒ = revert(T, n, c)
@test Tables.matrix(t) ≈ Tables.matrix(tₒ)

Expand All @@ -334,8 +339,8 @@
t = Table(; x, y)
T = Functional(asin)
n, c = apply(T, t)
@test all(x -> -π/2 <= x <= π/2, n.x)
@test all(y -> -π/2 <= y <= π/2, n.y)
@test all(x -> -π/2 x π/2, n.x)
@test all(y -> -π/2 y π/2, n.y)
tₒ = revert(T, n, c)
@test Tables.matrix(t) ≈ Tables.matrix(tₒ)

Expand All @@ -344,8 +349,8 @@
t = Table(; x, y)
T = Functional(exp)
n, c = apply(T, t)
@test all(x -> x > 0, n.x)
@test all(y -> y > 0, n.y)
@test all(>(0), n.x)
@test all(>(0), n.y)
tₒ = revert(T, n, c)
@test Tables.matrix(t) ≈ Tables.matrix(tₒ)

Expand All @@ -360,8 +365,8 @@

@testset "EigenAnalysis" begin
# PCA test
x = rand(Normal(0,10), 1500)
y = x + rand(Normal(0,2), 1500)
x = rand(Normal(0, 10), 1500)
y = x + rand(Normal(0, 2), 1500)
t = Table(; x, y)
T = EigenAnalysis(:V)
n, c = apply(T, t)
Expand All @@ -374,8 +379,8 @@
@test Tables.matrix(t) ≈ Tables.matrix(tₒ)

# DRS test
x = rand(Normal(0,10), 1500)
y = x + rand(Normal(0,2), 1500)
x = rand(Normal(0, 10), 1500)
y = x + rand(Normal(0, 2), 1500)
t = Table(; x, y)
T = EigenAnalysis(:VD)
n, c = apply(T, t)
Expand All @@ -388,8 +393,8 @@
@test Tables.matrix(t) ≈ Tables.matrix(tₒ)

# SDS test
x = rand(Normal(0,10), 1500)
y = x + rand(Normal(0,2), 1500)
x = rand(Normal(0, 10), 1500)
y = x + rand(Normal(0, 2), 1500)
t = Table(; x, y)
T = EigenAnalysis(:VDV)
n, c = apply(T, t)
Expand All @@ -401,9 +406,9 @@
tₒ = revert(T, n, c)
@test Tables.matrix(t) ≈ Tables.matrix(tₒ)

Random.seed!(42) # to reproduce the results
x = rand(Normal(0,10), 4000)
y = x + rand(Normal(0,2), 4000)
# using rng for reproducible results
x = rand(rng, Normal(0, 10), 4000)
y = x + rand(rng, Normal(0, 2), 4000)
t₁ = Table(; x, y)
t₂, c₂ = apply(EigenAnalysis(:V), t₁)
t₃, c₃ = apply(EigenAnalysis(:VD), t₁)
Expand All @@ -424,24 +429,26 @@
p = plot(p₁, p₂, p₃, p₄, layout=(2,2))
q = plot(p₂, p₃, p₄, p₅, p₆, p₇, layout=(2,3))

@test_reference joinpath(datadir,"eigenanalysis-1.png") p
@test_reference joinpath(datadir,"eigenanalysis-2.png") q
@test_reference joinpath(datadir, "eigenanalysis-1.png") p
@test_reference joinpath(datadir, "eigenanalysis-2.png") q
# savefig(p, joinpath(datadir, "eigenanalysis-1.png"))
# savefig(q, joinpath(datadir, "eigenanalysis-2.png"))
eliascarv marked this conversation as resolved.
Show resolved Hide resolved
end
end

@testset "Sequential" begin
x = rand(Normal(0,10), 1500)
y = x + rand(Normal(0,2), 1500)
z = y + rand(Normal(0,5), 1500)
x = rand(Normal(0, 10), 1500)
y = x + rand(Normal(0, 2), 1500)
z = y + rand(Normal(0, 5), 1500)
t = Table(; x, y, z)
T = Scale(low=0.2, high=0.8) → EigenAnalysis(:VDV)
n, c = apply(T, t)
tₒ = revert(T, n, c)
@test Tables.matrix(t) ≈ Tables.matrix(tₒ)

x = rand(Normal(0,10), 1500)
y = x + rand(Normal(0,2), 1500)
z = y + rand(Normal(0,5), 1500)
x = rand(Normal(0, 10), 1500)
y = x + rand(Normal(0, 2), 1500)
z = y + rand(Normal(0, 5), 1500)
t = Table(; x, y, z)
T = Select(:x, :z) → ZScore() → EigenAnalysis(:V) → Scale(low=0, high=1)
n, c = apply(T, t)
Expand All @@ -457,34 +464,34 @@
end

@testset "Parallel" begin
x = rand(Normal(0,10), 1500)
y = x + rand(Normal(0,2), 1500)
z = y + rand(Normal(0,5), 1500)
x = rand(Normal(0, 10), 1500)
y = x + rand(Normal(0, 2), 1500)
z = y + rand(Normal(0, 5), 1500)
t = Table(; x, y, z)
T = Scale(low=0.3, high=0.6) ⊔ EigenAnalysis(:VDV)
n, c = apply(T, t)
tₒ = revert(T, n, c)
@test Tables.matrix(t) ≈ Tables.matrix(tₒ)

# check cardinality of Parallel
x = rand(Normal(0,10), 1500)
y = x + rand(Normal(0,2), 1500)
z = y + rand(Normal(0,5), 1500)
x = rand(Normal(0, 10), 1500)
y = x + rand(Normal(0, 2), 1500)
z = y + rand(Normal(0, 5), 1500)
t = Table(; x, y, z)
T = ZScore() ⊔ EigenAnalysis(:V)
n = T(t)
@test length(Tables.columnnames(n)) == 6

# distributivity with respect to Sequential
x = rand(Normal(0,10), 1500)
y = x + rand(Normal(0,2), 1500)
z = y + rand(Normal(0,5), 1500)
x = rand(Normal(0, 10), 1500)
y = x + rand(Normal(0, 2), 1500)
z = y + rand(Normal(0, 5), 1500)
t = Table(; x, y, z)
T₁ = Center()
T₂ = Scale(low=0.2, high=0.8)
T₃ = EigenAnalysis(:VD)
P₁ = T₁ → (T₂ ⊔ T₃)
P₂ = (T₁ → T₂) ⊔ (T₁ →T₃)
P₂ = (T₁ → T₂) ⊔ (T₁ → T₃)
n₁ = P₁(t)
n₂ = P₂(t)
@test Tables.matrix(n₁) ≈ Tables.matrix(n₂)
Expand All @@ -508,4 +515,4 @@
@test isapprox(mean(r.x), mean(t.x), atol=1e-8)
@test isapprox(std(r.x), std(t.x), atol=1e-8)
end
end
end