Learn R Programming

gor (version 2.0)

mutate_binary_sequence: Binary sequence mutation

Description

Mutation of binary sequences for use in the genetic algorithm

Usage

mutate_binary_sequence(s, p = 0.1)

Value

A mutated binary sequence

Arguments

s

Sequence consisting of 0 and 1

p

Mutation probability. Defaults to 0.1

Author

Cesar Asensio

Details

This routine takes a binary sequence and it flips ("mutates") each bit with a fixed probability. In the genetic algorithm context, this operation randomly explores regions of configuration space which are far away from the starting point, thus trying to avoid local optima. The fitting function values of mutated individuals are generically very poor, and this behavior is to be expected. Thus, mutation is not an optimization procedure per se.

See Also

search_cut_genetic genetic cut-searching algorithm, crossover_sequences crossover operation

Examples

Run this code
set.seed(1)
s <- sample(0:1, 10, replace = TRUE)  # 0 0 1 1 0 1 1 1 1 0
mutate_binary_sequence(s, p = 0.5)    # 1 1 1 0 0 0 1 1 0 0
mutate_binary_sequence(s, p = 1)      # 1 1 0 0 1 0 0 0 0 1

Run the code above in your browser using DataLab