Skip to content

Commit

Permalink
adding more refactor tests
Browse files Browse the repository at this point in the history
  • Loading branch information
elior rahmani authored and elior rahmani committed May 20, 2019
1 parent b8ef414 commit cb9403b
Show file tree
Hide file tree
Showing 10 changed files with 870 additions and 454 deletions.
Binary file modified manual.pdf
Binary file not shown.
200 changes: 200 additions & 0 deletions tests/assets/refactor.R_est.adjusted.C.remove.txt

Large diffs are not rendered by default.

200 changes: 200 additions & 0 deletions tests/assets/refactor.R_est.adjusted.txt

Large diffs are not rendered by default.

400 changes: 200 additions & 200 deletions tests/assets/refactor.R_est.txt

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions tests/assets/refactor.ranked_list.adjusted.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
99,62,60,37,54,4,16,22,92,78,7,69,77,5,82,90,50,26,10,38,32,18,52,89,95,11,27,45,24,57,21,93,76,72,39,43,20,88,30,40,87,67,29,79,1,15,12,100,73,98,75,70,65,86,44,48,9,31,3,14,61,66,46,97,91,80,33,68,84,25,51,36,13,59,2,74,94,96,23,28,71,81,55,49,83,42,35,58,63,64,85,53,6,19,34,17,8,56,47,41
2 changes: 1 addition & 1 deletion tests/assets/refactor.ranked_list.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
99,62,60,37,54,4,16,22,92,78,7,69,77,5,82,90,50,26,10,38,32,18,52,89,95,11,27,45,24,57,21,93,76,72,39,43,20,88,30,40,87,67,29,79,1,15,12,100,73,98,75,70,65,86,44,48,9,31,3,14,61,66,46,97,91,80,33,68,84,25,51,36,13,59,2,74,94,96,23,28,71,81,55,49,83,42,35,58,63,64,85,53,6,19,34,17,8,56,47,41
62,37,99,54,16,60,4,69,77,78,92,10,90,45,22,5,95,18,93,38,26,21,50,7,24,32,52,43,88,57,76,79,12,40,82,44,39,89,75,86,100,87,98,72,70,27,11,29,15,31,48,30,73,61,1,46,9,13,66,97,91,36,80,51,65,84,20,28,96,2,74,67,3,68,59,94,14,23,33,49,81,71,25,58,85,55,42,63,83,34,64,53,35,17,19,56,6,8,41,47
69 changes: 42 additions & 27 deletions tests/testthat/test_refactor.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,45 @@ library("TCA")

context("Test ReFACTor")

# test_that("Compare the result of refactor with those of the matlab version of refactor", {
#
# skip_on_cran()
#
# basedir <- "../assets/"
#
# # load data and the matlab results
# X <- as.matrix(read.table(paste(basedir,"X.txt",sep=""), header = FALSE, sep=","))
# rownames(X) <- 1:nrow(X)
# C <- as.matrix(read.table(paste(basedir,"C2.txt",sep=""), header = FALSE, sep=","))
# t <- 50
# k <- 3
# matlab.ref_comp <- as.matrix(read.table(paste(basedir,"refactor.R_est.txt",sep=""), header = FALSE, sep=","))
# matlab.ranked_list <- as.matrix(read.table(paste(basedir,"refactor.ranked_list.txt",sep=""), header = FALSE, sep=","))
#
# # run refactor
# ref <- refactor(t(X), k, sparsity = t, C = C, sd_threshold = 0, num_comp = ncol(matlab.ref_comp), debug = TRUE, log_file = NULL)
#
# # evaluating the feature ranking
# expect_equal(sum(as.numeric(substring(ref[["ranked_list"]], 2)) == matlab.ranked_list), ncol(X))
#
# # evaluate correlation of the refactor components
# for (h in 1:2){
# expect_equal(abs(cor(matlab.ref_comp[,h],ref[["scores"]][,h])) > 0.99, TRUE)
# }
#
# })
test_that("Compare the result of refactor with those of the matlab version of refactor", {

skip_on_cran()

basedir <- "../assets/"

# load data and the matlab results
X <- as.matrix(read.table(paste(basedir,"X.txt",sep=""), header = FALSE, sep=","))
rownames(X) <- 1:nrow(X)
C <- as.matrix(read.table(paste(basedir,"C2.txt",sep=""), header = FALSE, sep=","))
# add intercept
C <- cbind(matrix(1,nrow(X),1),C)
t <- 50
k <- 3
matlab.ref_comp <- as.matrix(read.table(paste(basedir,"refactor.R_est.txt",sep=""), header = FALSE, sep=","))
matlab.ranked_list <- as.matrix(read.table(paste(basedir,"refactor.ranked_list.txt",sep=""), header = FALSE, sep=","))
matlab.ref_comp.adj <- as.matrix(read.table(paste(basedir,"refactor.R_est.adjusted.txt",sep=""), header = FALSE, sep=","))
matlab.ref_comp.adj.C.remove <- as.matrix(read.table(paste(basedir,"refactor.R_est.adjusted.C.remove.txt",sep=""), header = FALSE, sep=","))
matlab.ranked_list.adj <- as.matrix(read.table(paste(basedir,"refactor.ranked_list.adjusted.txt",sep=""), header = FALSE, sep=","))

# run refactor
ref1 <- refactor(t(X), k, sparsity = t, C = NULL, sd_threshold = 0, num_comp = ncol(matlab.ref_comp), debug = TRUE, log_file = NULL)
ref2 <- refactor(t(X), k, sparsity = t, C = C, C.remove = FALSE, sd_threshold = 0, num_comp = ncol(matlab.ref_comp), debug = TRUE, log_file = NULL)
ref3 <- refactor(t(X), k, sparsity = t, C = C, C.remove = TRUE, sd_threshold = 0, num_comp = ncol(matlab.ref_comp), debug = TRUE, log_file = NULL)

# evaluating the feature ranking
expect_equal(sum(as.numeric(substring(ref1[["ranked_list"]], 2)) == matlab.ranked_list), ncol(X))
expect_equal(sum(as.numeric(substring(ref2[["ranked_list"]], 2)) == matlab.ranked_list.adj), ncol(X))
expect_equal(sum(as.numeric(substring(ref3[["ranked_list"]], 2)) == matlab.ranked_list.adj), ncol(X))

# evaluate correlation of the refactor components
for (h in 1:ncol(matlab.ref_comp)){
expect_equal(abs(cor(matlab.ref_comp[,h],ref1[["scores"]][,h])) > 0.99, TRUE)

expect_equal(abs(cor(matlab.ref_comp.adj.C.remove[,h],ref3[["scores"]][,h])) > 0.99, TRUE)
}
# the version with C.remove=TRUE has more differences compared with the matlab version - evaluate the the first two components only.
for (h in 1:2){
expect_equal(abs(cor(matlab.ref_comp.adj[,h],ref2[["scores"]][,h])) > 0.99, TRUE)
}

})
Loading

0 comments on commit cb9403b

Please sign in to comment.