Translated computeDiffInCliqCounts() (#3)
This commit is contained in:
parent
eef819a9c3
commit
84e0eb61d8
2 changed files with 25 additions and 5 deletions
15
R/computeDiffInCliqCounts.R
Normal file
15
R/computeDiffInCliqCounts.R
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
computeDiffInCliqCounts <- function(cliques, inds) {
|
||||||
|
# Laskee muutoksen CLIQCOUNTS:ssa (tai SEPCOUNTS:ssa, jos syצtteen?
|
||||||
|
# separators) kun yksilצt inds siirretההn. diffInCliqcounts on ncliq*1 taulu,
|
||||||
|
# joka on CLIQCOUNTS:n sarakkeesta josta yksilצt inds siirretההn ja
|
||||||
|
# lisהttהv?sarakkeeseen, johon yksilצt siirretההn.
|
||||||
|
ncliq <- size(cliques, 1)
|
||||||
|
diffInCliqCounts <- zeros(ncliq, 1)
|
||||||
|
ninds <- length(inds)
|
||||||
|
for (i in 1:ninds) {
|
||||||
|
ind <- inds[i]
|
||||||
|
rivit <- rowSums(cliques == ind)
|
||||||
|
diffInCliqCounts <- diffInCliqCounts + rivit
|
||||||
|
}
|
||||||
|
return(diffInCliqCounts)
|
||||||
|
}
|
||||||
|
|
@ -1,9 +1,14 @@
|
||||||
context("Spatial mixture")
|
context("Spatial mixture")
|
||||||
|
|
||||||
test_that("functions work with basic input", {
|
test_that("functions work with basic input", {
|
||||||
x <- c(1, 3, 0, 2)
|
q <- c(1, 3, 0, 2)
|
||||||
y <- array(c(1, 3, 2, 4, 5, 7, 6, 8), c(2, 2, 2))
|
w <- array(c(1, 3, 2, 4, 5, 7, 6, 8), c(2, 2, 2))
|
||||||
z <- computeCounts(x, 4, 5, y)
|
e <- computeCounts(q, 4, 5, w)
|
||||||
expect_equal(z$cliqcounts, t(c(1, 1, 1, 0, 0)))
|
r <- matrix(c(5, 3, 3, 6, 4, 4, 7, 9, 1), 3)
|
||||||
expect_equal(z$sepcounts, t(c(0, 0, 0, 1, 0)))
|
expect_equal(e$cliqcounts, t(c(1, 1, 1, 0, 0)))
|
||||||
|
expect_equal(e$sepcounts, t(c(0, 0, 0, 1, 0)))
|
||||||
|
expect_equal(computeDiffInCliqCounts(r, 4), matrix(c(0, 1, 1)))
|
||||||
|
expect_equal(computeDiffInCliqCounts(r, 3), matrix(c(0, 1, 1)))
|
||||||
|
expect_equal(computeDiffInCliqCounts(r, 5), matrix(c(1, 0, 0)))
|
||||||
|
expect_equal(computeDiffInCliqCounts(r, 0), matrix(c(0, 0, 0)))
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue