Description Usage Arguments Author(s) See Also Examples
This mutation function will randomly change 1 to 0 or 0 to 1. The default probability of mutation is 0.1. The mutation function is used in evolve function.
1 | mutation(population, mutation.prob = 0.1)
|
population |
|
mutation.prob |
|
Qi Chen
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | N <- 1000
data <- matrix(sample(c(0, 1), N, replace = TRUE), ncol = 20)
mutation(data)
## The function is currently defined as
function (population, mutation.prob = 0.1)
{
index <- replicate(dim(population)[2], expr = runif(dim(population)[1])) <
mutation.prob
index2 <- population == 1
population[which((index + index2) == 2)] <- 0
index3 <- population == 0
population[which((index + index3) == 2)] <- 1
return(population)
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.