X-Git-Url: https://git.auder.net/?p=morpheus.git;a=blobdiff_plain;f=pkg%2Ftests%2Ftestthat%2Ftest-Moments_M2.R;fp=pkg%2Ftests%2Ftestthat%2Ftest-Moments_M2.R;h=0000000000000000000000000000000000000000;hp=0395d4e2de9aa00d261d02921b7255c771c0a292;hb=2b3a6af5c55ac121405e3a8da721626ddf46b28b;hpb=2989133a738da99b78594cb00afdd3d87916b8bd diff --git a/pkg/tests/testthat/test-Moments_M2.R b/pkg/tests/testthat/test-Moments_M2.R deleted file mode 100644 index 0395d4e..0000000 --- a/pkg/tests/testthat/test-Moments_M2.R +++ /dev/null @@ -1,43 +0,0 @@ -context("Moments_M2") - -# (Slower, but trusted) R version of Moments_M2 -.Moments_M2_R = function(X,Y) -{ - library(tensor) - n = nrow(X) - d = ncol(X) - v = rep(0,d) - e = diag(rep(1,d)) - - M21 = M2_1 = tensor(v,v) - for (i in 1:n) - M21 = M21 + Y[i] * tensor(X[i,],X[i,]) - M21 = (1/n) * M21 - - for (j in 1:d) - { - L = tensor(v,v) - for (i in 1:n) - L = L + Y[i]*tensor(e[,j],e[,j]) - L = (1/n) * L - M2_1 = M2_1 + L - } - - M2 = M21 - M2_1 - return (M2) -} - -test_that("both versions of Moments_M2 agree on various inputs", -{ - for (n in c(20,200)) - { - for (d in c(2,10,20)) - { - X = matrix( runif(n*d,min=-1,max=1), nrow=n ) - Y = runif(n,min=-1,max=1) - M2 = .Moments_M2(X,Y) - M2_R = .Moments_M2_R(X,Y) - expect_equal(max(abs(M2 - M2_R)), 0) - } - } -})