-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor mergePopulations. now much more efficient
- Loading branch information
1 parent
edf9aea
commit de18099
Showing
2 changed files
with
31 additions
and
19 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Helper for merging populations. | ||
# | ||
# @param ... [\code{list}]\cr | ||
# List of objects of type \code{setOfIndividuals}. | ||
# @return [\code{setOfIndividuals}] | ||
mergePopulations = function(...) { | ||
populations = list(...) | ||
# get n.params | ||
n.params = ncol(populations[[1]]$individuals) | ||
|
||
# summarize over all population sizes | ||
n.pop = sum(sapply(populations, function(x) length(x$fitness))) | ||
|
||
# allocate space | ||
fitness = numeric(n) | ||
individuals = matrix(NA, ncol = m, nrow = n) | ||
|
||
# now iterate over populations and generate merged population | ||
#FIXME: maybe better implement this in C++ | ||
start = 1L | ||
for (i in 1:length(populations)) { | ||
j = nrow(populations[[i]]$individuals) | ||
individuals[start:(start + j - 1), ] = populations[[i]]$individuals | ||
fitness[start:(start + j - 1)] = populations[[i]]$fitness | ||
start = start + j | ||
} | ||
makePopulation( | ||
individuals = individuals, | ||
fitness = fitness | ||
) | ||
} |