diff --git a/R/computeDiffInCounts.R b/R/computeDiffInCounts.R index af53f61..7de71f5 100644 --- a/R/computeDiffInCounts.R +++ b/R/computeDiffInCounts.R @@ -6,7 +6,7 @@ computeDiffInCounts <- function(rows, max_noalle, nloci, data) { diffInCounts <- zeros(max_noalle, nloci) for (i in rows) { row <- data[i, ] - notEmpty <- find(row>=0) + notEmpty <- as.matrix(find(row>=0)) if (length(notEmpty) > 0) { diffInCounts[row(notEmpty) + (notEmpty - 1) * max_noalle] <- diff --git a/R/computePopulationLogml.R b/R/computePopulationLogml.R index a6cf71c..b2675d7 100644 --- a/R/computePopulationLogml.R +++ b/R/computePopulationLogml.R @@ -1,18 +1,26 @@ -computePopulationLogml <- function(pops, adjprior, priorTerm) { +computePopulationLogml <- function(pops, adjprior, priorTerm = 0) { # Palauttaa length(pops)*1 taulukon, jossa on laskettu korikohtaiset + # ======================================================== # + # Limiting COUNTS size # + # ======================================================== # + COUNTS <- COUNTS[seq_len(nrow(adjprior)), seq_len(ncol(adjprior)), pops, drop=FALSE] + x <- size(COUNTS, 1) y <- size(COUNTS, 2) z <- length(pops) - popLogml <- squeeze( + # ======================================================== # + # Computation # + # ======================================================== # + term1 <- squeeze( # FIXME: assumes COUNTS has 3 dims. Where does this come from? sum( sum( reshape( lgamma( repmat(adjprior, c(1, 1, length(pops))) + - COUNTS[, , pops] + COUNTS[seq_len(nrow(adjprior)), seq_len(ncol(adjprior)), pops, drop=FALSE] ), c(x, y, z) ), @@ -20,6 +28,7 @@ computePopulationLogml <- function(pops, adjprior, priorTerm) { ), 2 ) - ) - sum(lgamma(1 + SUMCOUNTS[pops, ]), 2) - priorTerm + ) + popLogml <- term1 - sum(lgamma(1 + SUMCOUNTS[pops, ]), 2) - priorTerm return(popLogml) } \ No newline at end of file diff --git a/R/indMix.R b/R/indMix.R index 4f1d65c..ac65114 100644 --- a/R/indMix.R +++ b/R/indMix.R @@ -137,11 +137,11 @@ indMix <- function(c, npops, dispText) { round <- roundTypes[n] kivaluku <- 0 - if (kokeiltu(round) == 1) { #Askelta kokeiltu viime muutoksen j�lkeen + if (kokeiltu[round] == 1) { #Askelta kokeiltu viime muutoksen j�lkeen } else if (round == 0 | round == 1) { #Yksil�n siirt�minen toiseen populaatioon. inds <- 1:ninds - aputaulu <- c(t(inds), rand(ninds, 1)) + aputaulu <- cbind(inds, rand(ninds, 1)) aputaulu <- sortrows(aputaulu, 2) inds <- t(aputaulu[, 1]) muutosNyt <- 0