-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Option in scDissim method to not use the step function.
- Loading branch information
Showing
10 changed files
with
269 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
library(testthat) | ||
library(cidr) | ||
|
||
test_check("cidr") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
context("cpp_dist - C++ function to create dissimilarity matrix") | ||
|
||
test_that("distance calculation works", { | ||
N <- 2 | ||
|
||
# Both dropout candidates | ||
dist <- array(0, dim=c(N, N)) | ||
dropouts <- array(1, dim=c(1, N)) | ||
data <- array(c(1.2, 0.9), dim=c(1,N)) | ||
threshold <- 5.0 | ||
cpp_dist(dist, dropouts, data, N, threshold) | ||
expect_equal(dist, array(c(c(0, 0), c(0, 0)), dim=c(2,2))) | ||
|
||
# Neither dropouts, same counts | ||
dist <- array(0, dim=c(N, N)) | ||
dropouts <- array(0, dim=c(1, N)) | ||
data <- array(c(3.5, 3.5), dim=c(1,N)) | ||
threshold <- 5.0 | ||
cpp_dist(dist, dropouts, data, N, threshold) | ||
expect_equal(dist, array(c(c(0, 0), c(0, 0)), dim=c(2,2))) | ||
|
||
# Neither dropouts, different counts | ||
dist <- array(0, dim=c(N, N)) | ||
dropouts <- array(0, dim=c(1, N)) | ||
data <- array(c(3.5, 3.6), dim=c(1,N)) | ||
threshold <- 5.0 | ||
cpp_dist(dist, dropouts, data, N, threshold) | ||
expect_equal(dist, array(c(c(0, 0), c(0.01, 0)), dim=c(2,2))) | ||
|
||
# #1 is dropout, #2 below threshold (imputation occurs) | ||
dist <- array(0, dim=c(N, N)) | ||
dropouts <- array(c(1, 0), dim=c(1, N)) | ||
data <- array(c(1.2, 4.5), dim=c(1,N)) | ||
threshold <- 5.0 | ||
cpp_dist(dist, dropouts, data, N, threshold) | ||
expect_equal(dist, array(c(c(0, 0), c(0, 0)), dim=c(2,2))) | ||
|
||
# #1 is dropout, #2 above threshold | ||
dist <- array(0, dim=c(N, N)) | ||
dropouts <- array(c(1, 0), dim=c(1, N)) | ||
data <- array(c(1.2, 5.2), dim=c(1,N)) | ||
threshold <- 5.0 | ||
cpp_dist(dist, dropouts, data, N, threshold) | ||
expect_equal(dist, array(c(c(0, 0), c(16, 0)), dim=c(2,2))) | ||
|
||
# 3 features | ||
dist <- array(0, dim=c(N, N)) | ||
dropouts <- array(c(c(0, 0, 0), | ||
c(1, 1, 0)), dim=c(3, N)) | ||
data <- array(c(c(4.2, 5.7, 4.5), | ||
c(1.2, 0.7, 2.5)), dim=c(3,N)) | ||
threshold <- 5.0 | ||
cpp_dist(dist, dropouts, data, N, threshold) | ||
expect_equal(dist, array(c(c(0, 0), c(29, 0)), dim=c(2,2))) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
context("cpp_dist_weighted - dissimilarity matrix using weighted imputation") | ||
|
||
test_that("distance calculation works", { | ||
N <- 2 | ||
a <- 1.5 | ||
b <- 5.0 | ||
|
||
# Both dropout candidates | ||
dist <- array(0, dim=c(N, N)) | ||
dropouts <- array(1, dim=c(1, N)) | ||
data <- array(c(1.2, 0.9), dim=c(1,N)) | ||
cpp_dist_weighted(dist, dropouts, data, N, a, b) | ||
expect_equal(dist, array(c(c(0, 0), c(0, 0)), dim=c(2,2))) | ||
|
||
# Neither dropouts, same counts | ||
dist <- array(0, dim=c(N, N)) | ||
dropouts <- array(0, dim=c(1, N)) | ||
data <- array(c(3.5, 3.5), dim=c(1,N)) | ||
cpp_dist_weighted(dist, dropouts, data, N, a, b) | ||
expect_equal(dist, array(c(c(0, 0), c(0, 0)), dim=c(2,2))) | ||
|
||
# Neither dropouts, different counts | ||
dist <- array(0, dim=c(N, N)) | ||
dropouts <- array(0, dim=c(1, N)) | ||
data <- array(c(3.5, 3.6), dim=c(1,N)) | ||
cpp_dist_weighted(dist, dropouts, data, N, a, b) | ||
expect_equal(dist, array(c(c(0, 0), c(0.01, 0)), dim=c(2,2))) | ||
|
||
# #1 dropout, #2 not dropout (imputation occurs) | ||
dist <- array(0, dim=c(N, N)) | ||
dropouts <- array(c(1, 0), dim=c(1, N)) | ||
data <- array(c(0.5, 5.0), dim=c(1,N)) | ||
# P(5.0) = 0.5, imputed value = 2.75 | ||
cpp_dist_weighted(dist, dropouts, data, N, a, b) | ||
expect_equal(dist, array(c(c(0, 0), c(5.0625, 0)), dim=c(2,2))) | ||
|
||
# #1 not dropout, #2 dropout (imputation occurs) | ||
dist <- array(0, dim=c(N, N)) | ||
dropouts <- array(c(0, 1), dim=c(1, N)) | ||
data <- array(c(3.5, 0.5), dim=c(1,N)) | ||
# P(3.5) = 0.9046505351, imputed value = 3.2139516053 | ||
cpp_dist_weighted(dist, dropouts, data, N, a, b) | ||
expect_equal(dist, array(c(c(0, 0), c(0.081823684110447, 0)), dim=c(2,2))) | ||
|
||
# 3 features | ||
dist <- array(0, dim=c(N, N)) | ||
dropouts <- array(c(c(0, 0, 0), | ||
c(1, 1, 0)), dim=c(3, N)) | ||
data <- array(c(c(5.0, 5.0, 4.5), | ||
c(0.5, 1.0, 2.5)), dim=c(3,N)) | ||
cpp_dist_weighted(dist, dropouts, data, N, a, b) | ||
expect_equal(dist, array(c(c(0, 0), c(13.0625, 0)), dim=c(2,2))) | ||
}) |