From 1b0319a88c6f9efe19d77ad5979fb3a11d029c3b Mon Sep 17 00:00:00 2001 From: Waldir Leoncio Date: Tue, 14 Jul 2020 15:47:01 +0200 Subject: [PATCH] Translated initialCounts() --- R/greedyMix.R | 32 -------------------------------- R/initialCounts.R | 25 +++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 32 deletions(-) create mode 100644 R/initialCounts.R diff --git a/R/greedyMix.R b/R/greedyMix.R index 4aa71fc..0841ca5 100644 --- a/R/greedyMix.R +++ b/R/greedyMix.R @@ -877,38 +877,6 @@ greedyMix <- function( # %---------------------------------------------------------------------------------------- - -# function logml = ... -# initialCounts(partition, data, npops, rows, noalle, adjprior) - -# nloci=size(data,2); -# ninds = size(rows, 1); - -# koot = rows(:,1) - rows(:,2) + 1; -# maxSize = max(koot); - -# counts = zeros(max(noalle),nloci,npops); -# sumcounts = zeros(npops,nloci); -# for i=1:npops -# for j=1:nloci -# havainnotLokuksessa = find(partition==i & data(:,j)>=0); -# sumcounts(i,j) = length(havainnotLokuksessa); -# for k=1:noalle(j) -# alleleCode = k; -# N_ijk = length(find(data(havainnotLokuksessa,j)==alleleCode)); -# counts(k,j,i) = N_ijk; -# end -# end -# end - -# %initializeGammaln(ninds, maxSize, max(noalle)); - -# logml = laskeLoggis(counts, sumcounts, adjprior); - - -# %----------------------------------------------------------------------- - - # function logml=computeLogml(counts, sumcounts, noalle, data, rowsFromInd) # nloci = size(counts,2); # npops = size(counts,3); diff --git a/R/initialCounts.R b/R/initialCounts.R new file mode 100644 index 0000000..9638e78 --- /dev/null +++ b/R/initialCounts.R @@ -0,0 +1,25 @@ +initialCounts <- function(partition, data, npops, rows, noalle, adjprior) { + nloci <- size(data, 2) + ninds <- size(rows, 1) + + koot <- rows[, 1] - rows[, 2] + 1 + maxSize <- max(koot) + + counts <- zeros(max(noalle), nloci, npops) + sumcounts <- zeros(npops, nloci) + for (i in 1:npops) { + for (j in 1:nloci) { + havainnotLokuksessa <- find(partition == i & data[, j] >= 0) + sumcounts[i, j] <- length(havainnotLokuksessa) + for (k in 1:noalle[j]) { + alleleCode <- k + N_ijk <- length( + find(data[havainnotLokuksessa, j] == alleleCode) + ) + counts[k, j, i] <- N_ijk + } + } + } + logml <- laskeLoggis(counts, sumcounts, adjprior) + return(logml) +} \ No newline at end of file