Skip to content

Commit

Permalink
Tweak in xover for edge case
Browse files Browse the repository at this point in the history
Apparently, recomb_point() is somehow able to return a value greater than the end of the chromosome.  This fix just returns that to just before the end of the chromosome.
  • Loading branch information
eriqande committed Dec 19, 2023
1 parent cc5b664 commit dde96ee
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions R/xover.R
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,15 @@ xover <- function(V1, V2, R) {
return(list(V1 = V1, V2 = V2))
}

# there are some weird edge cases, somehow, where an element of R
# is greater than V1 or V2. We just whack those back as need be, in the loop below
mV1 = max(V1)
mV2 = max(V2)

for(r in R) {
if (r >= mV1) {r <- mV1 - 1 + runif(1, min = 0, max = 0.001)}
if (r >= mV2) {r <- mV2 - 1 + runif(1, min = 0, max = 0.001)}

i1 <- as.integer(cut(r, V1))
i2 <- as.integer(cut(r, V2))

Expand Down

0 comments on commit dde96ee

Please sign in to comment.