mutation: Mutates a random allele

Description Usage Arguments Author(s) See Also Examples

View source: R/evolve.R

Description

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.

Usage

1
mutation(population, mutation.prob = 0.1)

Arguments

population

population matrix of dimension n * p

mutation.prob

mutation probability

Author(s)

Qi Chen

See Also

evolve

Examples

 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)
  }

dchen49/GA documentation built on May 3, 2019, 6:43 p.m.