Nothing
test_that("g is produced if any solution is found", {
set.seed(123)
A = array(rnorm(108*2), c(108, 2))
B = array(rnorm(100*2), c(100, 2))
C = array(rnorm(10*2), c(10, 2))
D = array(rnorm(100*2), c(100, 2))
E = array(rnorm(10*2), c(10, 2))
df1 = reinflateTensor(A, B, C)
df2 = reinflateTensor(A, D, E)
datasets = list(df1, df2)
modes = list(c(1,2,3), c(1,4,5))
Z = setupCMTFdata(datasets, modes)
result = initializeCMTF(Z, 1, initialization="random")
expect_no_error(cmtf_gradient(fac_to_vect(result), Z))
})
test_that("the size of g is correct in the two-tensor case", {
set.seed(123)
A = array(rnorm(108*2), c(108, 2))
B = array(rnorm(100*2), c(100, 2))
C = array(rnorm(10*2), c(10, 2))
D = array(rnorm(100*2), c(100, 2))
E = array(rnorm(10*2), c(10, 2))
df1 = reinflateTensor(A, B, C)
df2 = reinflateTensor(A, D, E)
datasets = list(df1, df2)
modes = list(c(1,2,3), c(1,4,5))
Z = setupCMTFdata(datasets, modes)
result = initializeCMTF(Z, 1, initialization="random")
g = cmtf_gradient(fac_to_vect(result), Z)
expect_equal(length(g), 108+100+10+100+10)
})
test_that("the size of g is correct in the tensor-matrix case", {
set.seed(123)
A = array(rnorm(108*2), c(108, 2))
B = array(rnorm(100*2), c(100, 2))
C = array(rnorm(10*2), c(10, 2))
D = array(rnorm(100*2), c(100, 2))
df1 = reinflateTensor(A, B, C)
df2 = reinflateMatrix(A, D)
datasets = list(df1, df2)
modes = list(c(1,2,3), c(1,4))
Z = setupCMTFdata(datasets, modes, normalize=FALSE)
fakeResult = list(A, B, C, D)
g = cmtf_gradient(fac_to_vect(fakeResult), Z)
expect_equal(length(g), 108*2+100*2+10*2+100*2)
})
test_that("g is zero if the perfect solution is found", {
set.seed(123)
A = array(rnorm(108*2), c(108, 2))
B = array(rnorm(100*2), c(100, 2))
C = array(rnorm(10*2), c(10, 2))
D = array(rnorm(100*2), c(100, 2))
E = array(rnorm(10*2), c(10, 2))
df1 = reinflateTensor(A, B, C)
df2 = reinflateTensor(A, D, E)
datasets = list(df1, df2)
modes = list(c(1,2,3), c(1,4,5))
Z = setupCMTFdata(datasets, modes, normalize=FALSE)
fakeResult = list(A, B, C, D, E)
g = cmtf_gradient(fac_to_vect(fakeResult), Z)
expect_equal(g, rep(0, (108+100+10+100+10)*2))
})
test_that("an error is thrown for 4-way or more", {
I = 108
J = 100
K = 10
L = 5
df = array(rnorm(I*J*K*L), c(I,J,K,L))
datasets = list(df, df)
modes = list(c(1,2,3,4), c(1,5,6,7))
Z = setupCMTFdata(datasets, modes)
result = initializeCMTF(Z, 1, initialization="random")
expect_error(cmtf_gradient(fac_to_vect(result), Z))
})
test_that("g is zero also in the tensor-matrix case", {
set.seed(123)
A = array(rnorm(108*2), c(108, 2))
B = array(rnorm(100*2), c(100, 2))
C = array(rnorm(10*2), c(10, 2))
D = array(rnorm(100*2), c(100, 2))
df1 = reinflateTensor(A, B, C)
df2 = reinflateMatrix(A, D)
datasets = list(df1, df2)
modes = list(c(1,2,3), c(1,4))
Z = setupCMTFdata(datasets, modes, normalize=FALSE)
fakeResult = list(A, B, C, D)
g = cmtf_gradient(fac_to_vect(fakeResult), Z)
expect_equal(g, rep(0, (108+100+10+100)*2))
})
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.