Adjusted behavior to benchmark

This commit is contained in:
Waldir Leoncio 2020-01-30 17:52:20 +01:00
parent c9c9b7cb26
commit f6768c67bc
3 changed files with 22 additions and 8 deletions

View file

@ -5,23 +5,27 @@
#' @param COUNTS COUNTS #' @param COUNTS COUNTS
#' @export #' @export
simulateAllFreqs <- function(noalle, COUNTS = matrix(0)) { simulateAllFreqs <- function(noalle, COUNTS = matrix(NA, 0, 0)) {
max_noalle <- size(COUNTS, 1) max_noalle <- size(COUNTS, 1)
nloci <- size(COUNTS, 2) nloci <- size(COUNTS, 2)
npops <- size(COUNTS, 3) npops <- size(COUNTS, 3)
prioriAlleelit <- zeros(max_noalle, nloci) prioriAlleelit <- zeros(max_noalle, nloci)
for (j in 1:nloci) { if (nloci > 0) {
prioriAlleelit[1:noalle[j], j] <- 1 / noalle[j] for (j in 1:nloci) {
prioriAlleelit[1:noalle[j], j] <- 1 / noalle[j]
}
} }
prioriAlleelit <- repmat(prioriAlleelit, matrix(c(1, 1, npops), ncol = 1)) prioriAlleelit <- repmat(prioriAlleelit, matrix(c(1, 1, npops), 1))
counts <- COUNTS + prioriAlleelit counts <- COUNTS + prioriAlleelit
allfreqs <- zeros(size(counts)) allfreqs <- zeros(size(counts))
for (i in 1:npops) { for (i in 1:npops) {
for (j in 1:nloci) { if (nloci > 0) {
simuloidut <- randdir(counts[1:noalle[j], j, i] , noalle[j]) for (j in 1:nloci) {
allfreqs[1:noalle[j], j, i] <- simuloidut simuloidut <- randdir(counts[1:noalle[j], j, i] , noalle[j])
allfreqs[1:noalle[j], j, i] <- simuloidut
}
} }
} }
return(allfreqs) return(allfreqs)

View file

@ -4,7 +4,7 @@
\alias{simulateAllFreqs} \alias{simulateAllFreqs}
\title{Simulate All Frequencies} \title{Simulate All Frequencies}
\usage{ \usage{
simulateAllFreqs(noalle, COUNTS = matrix(0)) simulateAllFreqs(noalle, COUNTS = matrix())
} }
\arguments{ \arguments{
\item{noalle}{noalle} \item{noalle}{noalle}

View file

@ -211,4 +211,14 @@ test_that("simulateIndividuals works like on Matlab", {
object = sum(simulateIndividuals(3, 3, 2, 1, .5) == 1), object = sum(simulateIndividuals(3, 3, 2, 1, .5) == 1),
expected = 6 expected = 6
) )
})
test_that("simulateAllFreqs works as expected", {
empty_mt <- matrix(NA, 0, 0)
expect_equivalent(suppressWarnings(simulateAllFreqs(3)), empty_mt)
expect_equivalent(suppressWarnings(simulateAllFreqs(3:5)), empty_mt)
expect_equivalent(
object = suppressWarnings(simulateAllFreqs(matrix(1:4, 2))),
expected = empty_mt
)
}) })