Description Usage Arguments Value See Also Examples
The function randomly mutates an individual's genetic code
1 |
a |
The binary matrix of all individuals |
p |
The mutation rate |
seed |
Set a seed for comparability. Default is |
Returns a binary matrix with mutated genes.
Other Genetic Algorithm Functions:
crossover()
,
fitness()
,
genetic_algorithm()
,
init_population()
,
selection()
,
trimton()
,
windfarmGA()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | ## Create 4 random individuals with binary values
a <- cbind(bin0 = sample(c(0,1), 20, replace=TRUE, prob = c(70,30)),
bin1 = sample(c(0,1), 20, replace=TRUE, prob = c(30,70)),
bin2 = sample(c(0,1), 20, replace=TRUE, prob = c(30,70)),
bin3 = sample(c(0,1), 20, replace=TRUE, prob = c(30,70)))
a
## Mutate the individuals with a low percentage
aMut <- mutation(a, 0.1, NULL)
## Check which values are not like the originals
a == aMut
## Mutate the individuals with a high percentage
aMut <- mutation(a, 0.4, NULL)
## Check which values are not like the originals
a == aMut
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.