Skip to content

Commit b493d48

Browse files
committed
add column simplex NMF test
1 parent ff22b79 commit b493d48

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

test/runtests.jl

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -649,6 +649,42 @@ end
649649
);
650650

651651
@test stats[end, :Iteration] < 1000 # ensure we did not hit the maximum number of iterations
652+
653+
# More interesting run of factorize
654+
I, J = 10, 20
655+
R = 3
656+
657+
A = abs_randn(I, R)
658+
B = abs_randn(R, J)
659+
l1scale_cols!(A)
660+
l1scale_cols!(B)
661+
662+
Ydecomp = Tucker1((B, A))
663+
Y = array(Ydecomp)
664+
665+
options = (
666+
rank=R,
667+
model=Tucker1,
668+
momentum=false,
669+
do_subblock_updates=true,
670+
tolerance=.01,
671+
converged=RelativeError,
672+
maxiter=500,
673+
stats=[
674+
Iteration, ObjectiveValue, GradientNNCone, RelativeError,
675+
],
676+
constraints=[l1scale_cols! nonnegative!, l1scale_cols! nonnegative!],
677+
constrain_init=true,
678+
constrain_output=true,
679+
)
680+
681+
decomposition, stats_data, kwargs = fact(Y; options...);
682+
B_learned, A_learned = factors(decomposition)
683+
684+
@test isapprox(Y, A_learned*B_learned; rtol=0.02) # might be slightly more than 1% after `constrain_output`
685+
@test all(check.(simplex_cols!, (B_learned, A_learned)))
686+
@test stats[end, :Iteration] < 500 # ensure we did not hit the maximum number of iterations
687+
652688
end
653689
@testset "CPFactorization" begin
654690
fact = BlockTensorFactorization.factorize
@@ -710,6 +746,7 @@ end
710746
R = 5
711747
D = 2
712748

749+
# More constrained problem
713750
matrices = [abs_randn(N, R) for _ in 1:D]
714751
l1scale_cols!.(matrices)
715752
Ydecomp = CPDecomposition(Tuple(matrices))#abs_randn

0 commit comments

Comments
 (0)