-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading status checks…
Merge branch 'issue-24' into develop
* issue-24: Increment version number to 0.0.0.9026 Added (commented) test for BAPS data (#24) Renamed global environment, fixed assignments (#24) Fixes to `laskeMuutokset()` (#24) Syntax fix to `indMix()` (#24) Retranslated `computeDiffInCounts()` (#24) Changed default `npops` to 3 (#24) `laskeMuutokset()` reads `npop` from parent functions (#24) Using a dedicated environment for globals (#24) Retranslated `computePopulationLogml()` (#24) Added/renamed BAPS example data (#24)
- Loading branch information
Showing
30 changed files
with
194 additions
and
183 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
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
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 |
---|---|---|
@@ -1,43 +1,21 @@ | ||
computePopulationLogml <- function(pops, adjprior, priorTerm) { | ||
# Palauttaa length(pops)*1 taulukon, jossa on laskettu korikohtaiset | ||
|
||
# ======================================================== # | ||
# Limiting COUNTS size # | ||
# ======================================================== # | ||
if (!is.null(adjprior)) { | ||
nr <- seq_len(nrow(adjprior)) | ||
nc <- seq_len(ncol(adjprior)) | ||
COUNTS <- COUNTS[nr, nc, pops, drop = FALSE] | ||
} else { | ||
COUNTS <- NA | ||
} | ||
nr <- seq_len(nrow(adjprior)) | ||
nc <- seq_len(ncol(adjprior)) | ||
|
||
x <- size(COUNTS, 1) | ||
y <- size(COUNTS, 2) | ||
x <- size(globals$COUNTS, 1) | ||
y <- size(globals$COUNTS, 2) | ||
z <- length(pops) | ||
|
||
# ======================================================== # | ||
# Computation # | ||
# ======================================================== # | ||
term1 <- NULL | ||
if (!is.null(adjprior)) { | ||
isarray <- length(dim(repmat(adjprior, c(1, 1, length(pops))))) > 2 | ||
term1 <- squeeze( | ||
sum( | ||
sum( | ||
reshape( | ||
lgamma( | ||
repmat(adjprior, c(1, 1, length(pops))) + COUNTS[nr, nc, pops, drop = !isarray] | ||
), | ||
c(x, y, z) | ||
), | ||
1 | ||
), | ||
2 | ||
) | ||
) | ||
} | ||
if (is.null(priorTerm)) priorTerm <- 0 | ||
popLogml <- term1 - sum(lgamma(1 + SUMCOUNTS[pops, ]), 2) - priorTerm | ||
return(popLogml) | ||
rep_adj <- repmat(adjprior, c(1, 1, z)) | ||
gamma_rep_counts <- matlab2r::gammaln(rep_adj + globals$COUNTS[, , pops]) | ||
gamma_sum_counts <- rowSums(matlab2r::gammaln(1 + globals$SUMCOUNTS[pops, , drop = FALSE])) | ||
gamma_rep_counts_sum <- colSums(colSums(reshape(gamma_rep_counts, c(x, y, z)))) | ||
gamma_rep_counts_reshaped <- squeeze(gamma_rep_counts_sum) | ||
popLogml <- gamma_rep_counts_reshaped - gamma_sum_counts - priorTerm | ||
return(popLogml[, , drop = FALSE]) | ||
} |
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
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 |
---|---|---|
@@ -1,11 +1,13 @@ | ||
COUNTS <- array(0, dim = c(100, 100, 100)) | ||
SUMCOUNTS <- array(0, dim = c(100, 100)) | ||
PARTITION <- array(1, dim = 100) | ||
POP_LOGML <- array(1, dim = 100) | ||
LOGDIFF <- array(1, dim = c(100, 100)) | ||
# If handling globas break, try other ideas from | ||
# https://stackoverflow.com/a/65252740/1169233 | ||
globals <- new.env(parent = emptyenv()) | ||
|
||
utils::globalVariables( | ||
c("PARTITION", "COUNTS", "SUMCOUNTS", "LOGDIFF", "POP_LOGML", "GAMMA_LN") | ||
) | ||
assign("COUNTS", array(0, dim = c(0, 0, 0)), envir = globals) | ||
assign("SUMCOUNTS", array(0, dim = c(0, 0)), envir = globals) | ||
assign("PARTITION", array(1, dim = 0), envir = globals) | ||
assign("POP_LOGML", array(1, dim = 0), envir = globals) | ||
assign("LOGDIFF", array(1, dim = c(0, 0)), envir = globals) | ||
assign("CLOQCOUNTS", array(0, dim = c(0, 0)), envir = globals) | ||
assign("SEPCOUNTS", array(0, dim = c(0, 0)), envir = globals) | ||
assign("GAMMA_LN", array(0, dim = c(0, 0)), envir = globals) | ||
# If handling globas break, try other ideas from | ||
# https://stackoverflow.com/a/65252740/1169233 and | ||
# https://stackoverflow.com/questions/12598242/ |
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
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
Oops, something went wrong.