Skip to content

Commit

Permalink
Remove one of old ALS tests, add another 5-way test
Browse files Browse the repository at this point in the history
  • Loading branch information
alexmul1114 committed Mar 20, 2024
1 parent c07b942 commit c3e9252
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions test/items/gcp-opt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -69,23 +69,31 @@ end
end

# 5 way tensor to exercise else case in FastALS
@testset "size(X)=$sz, rank(X)=$r" for sz in [(10, 15, 20, 25, 30)], r in [2]
r=2
@testset "size(X)=$sz, rank(X)=$r" for sz in [(10, 15, 20, 25, 30), (30, 25, 5, 5, 5)], r in [2]
r = 2
Random.seed!(0)
M = CPD(ones(r), rand.(sz, r))
X = [M[I] for I in CartesianIndices(size(M))]
Mh = gcp(X, r; loss = GCPLosses.LeastSquaresLoss())
@test maximum(I -> abs(Mh[I] - X[I]), CartesianIndices(X)) <= 1e-5

Xm = convert(Array{Union{Missing,eltype(X)}}, X)
Xm[1, 1, 1, 1] = missing
Xm[1, 1, 1, 1, 1] = missing
Mm = gcp(Xm, r; loss = GCPLosses.LeastSquaresLoss())
@test maximum(I -> abs(Mm[I] - X[I]), CartesianIndices(X)) <= 1e-5

Mh = gcp(X, r) # test default (least-squares) loss
@test maximum(I -> abs(Mh[I] - X[I]), CartesianIndices(X)) <= 1e-5
end

# Test old ALS method
@testset "size(X)=$sz, rank(X)=$r" for sz in [(15, 20, 25)], r in [2]
Random.seed!(0)
M = CPD(ones(r), rand.(sz, r))
X = [M[I] for I in CartesianIndices(size(M))]
Mh = gcp(X, r; loss = GCPLosses.LeastSquaresLoss(), algorithm = GCPAlgorithms.ALS())
@test maximum(I -> abs(Mh[I] - X[I]), CartesianIndices(X)) <= 1e-5
end
end

@testitem "NonnegativeLeastSquaresLoss" begin
Expand Down

0 comments on commit c3e9252

Please sign in to comment.