-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c970e58
commit fb93b3a
Showing
31 changed files
with
278 additions
and
379 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,35 @@ | ||
#' Bitplip mutation operator. | ||
#' | ||
#' @param setOfIndividuals [\code{setOfIndividuals}]\cr | ||
#' Set of individuals. | ||
#' @param control [\code{list}]\cr | ||
#' Not used. | ||
#' @return [\code{setOfIndividuals}] | ||
#' Set of individuals. | ||
#' @param mutator.flip.prob [\code{numeric(1)}]\cr | ||
#' Probability to flip a single bit. Default is \code{0.1}. | ||
#' @return [\code{ecr_mutator}] | ||
#' @export | ||
bitflipMutator = function(setOfIndividuals, control) { | ||
n.params = ncol(setOfIndividuals$individuals) | ||
n = nrow(setOfIndividuals$individuals) | ||
|
||
for (i in seq(n)) { | ||
do.mutate = runif(n.params) < control$mutator.flip.prob | ||
setOfIndividuals$individuals[i, do.mutate] = 1 - setOfIndividuals$individuals[i, do.mutate] | ||
makeBitFlipMutator = function(mutator.flip.prob = 0.1) { | ||
mutatorCheck = function(operator.control) { | ||
assertNumber(operator.control$mutator.flip.pro, lower = 0.000001, upper = 0.999999, na.ok = FALSE) | ||
} | ||
return(setOfIndividuals) | ||
} | ||
|
||
attr(bitflipMutator, "name") = "Bitplip mutator" | ||
attr(bitflipMutator, "description") = "Flips each bit of the allele with a specific probability." | ||
attr(bitflipMutator, "supported") = c("binary") | ||
attr(bitflipMutator, "class") = c("ecr_operator", "ecr_mutator") | ||
attr(bitflipMutator, "defaults") = list(mutator.flip.prob = 1 / 10) | ||
force(mutator.flip.prob) | ||
defaults = list(mutator.flip.prob = mutator.flip.prob) | ||
mutatorCheck(defaults) | ||
|
||
bitflipMutatorCheck = function(operator.control) { | ||
assertNumber(operator.control$mutator.flip.pro, lower = 0.000001, upper = 0.999999, na.ok = FALSE) | ||
} | ||
mutator = function(setOfIndividuals, control = defaults) { | ||
n.params = ncol(setOfIndividuals$individuals) | ||
n = nrow(setOfIndividuals$individuals) | ||
|
||
attr(bitflipMutator, "checkFunction") = bitflipMutator | ||
for (i in seq(n)) { | ||
do.mutate = runif(n.params) < control$mutator.flip.prob | ||
setOfIndividuals$individuals[i, do.mutate] = 1 - setOfIndividuals$individuals[i, do.mutate] | ||
} | ||
return(setOfIndividuals) | ||
} | ||
|
||
makeMutator( | ||
mutator = mutator, | ||
name = "Bitplip mutator", | ||
description = "Flips each bit of the allele with a specific probability.", | ||
supported = "binary", | ||
defaults = defaults, | ||
checker = mutatorCheck | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,44 @@ | ||
#' Generator of the Gauss mutation operator. | ||
#' | ||
#' Default Gauss mutation operator known from Evolutionary Algorithms. | ||
#' @param setOfIndividuals [\code{setOfIndividuals}]\cr | ||
#' Set of individuals. | ||
#' @param control [\code{list}]\cr | ||
#' List containing evolutionary operators for fine-tuning the mutation operator. | ||
#' The \code{gaussMutator} function expects the two values: | ||
#' \itemize{ | ||
#' \item{mutator.gauss.prob [\code{numeric(1)}]}{Probability of mutation for the gauss mutation operator.} | ||
#' \item{mutator.gauss.sd [\code{numeric(1)}}{Standard deviance of the Gauss mutation, i. e., the mutation strength.} | ||
#' } | ||
#' @return [\code{setOfIndividuals}] | ||
#' Set of individuals. | ||
#' | ||
#' @param mutator.gauss.prob [\code{numeric(1)}]\cr | ||
#' Probability of mutation for the gauss mutation operator. | ||
#' @param mutator.gauss.sd [\code{numeric(1)}\cr | ||
#' Standard deviance of the Gauss mutation, i. e., the mutation strength. | ||
#' @return [\code{ecr_mutator}] | ||
#' @export | ||
gaussMutator = function(setOfIndividuals, control = list(mutator.gauss.prob = 1, mutator.gauss.sd = 0.05)) { | ||
n.params = ncol(setOfIndividuals$individuals) | ||
n = nrow(setOfIndividuals$individuals) | ||
makeGaussMutator = function(mutator.gauss.prob = 1L, mutator.gauss.sd = 0.05) { | ||
force(mutator.gauss.prob) | ||
force(mutator.gauss.sd) | ||
|
||
mutation.bool = matrix(runif(n * n.params) < control$mutator.gauss.prob, ncol = n.params) | ||
mutation = matrix(0, ncol = n.params, nrow = n) | ||
idx = which(mutation.bool) | ||
mutation[idx] = rnorm(length(idx), mean = 0, sd = control$mutator.gauss.sd) | ||
setOfIndividuals$individuals = setOfIndividuals$individuals + mutation | ||
mutatorCheck = function(operator.control) { | ||
assertNumber(operator.control$mutator.gauss.prob, lower = 0, finite = TRUE, na.ok = FALSE) | ||
assertNumber(operator.control$mutator.gauss.sd, lower = 0, finite = TRUE, na.ok = FALSE) | ||
} | ||
|
||
return(setOfIndividuals) | ||
} | ||
defaults = list(mutator.gauss.prob = mutator.gauss.prob, mutator.gauss.sd = mutator.gauss.sd) | ||
mutatorCheck(defaults) | ||
|
||
attr(gaussMutator, "name") = "Gauss mutator" | ||
attr(gaussMutator, "description") = "Adds gaussian noise to each gene" | ||
attr(gaussMutator, "supported") = c("float") | ||
attr(gaussMutator, "class") = c("ecr_operator", "ecr_mutator") | ||
attr(gaussMutator, "defaults") = list(mutator.gauss.prob = 1, mutator.gauss.sd = 0.05) | ||
mutator = function(setOfIndividuals, control = defaults) { | ||
n.params = ncol(setOfIndividuals$individuals) | ||
n = nrow(setOfIndividuals$individuals) | ||
|
||
gaussMutatorCheck = function(operator.control) { | ||
assertNumber(operator.control$mutator.gauss.prob, lower = 0, finite = TRUE, na.ok = FALSE) | ||
assertNumber(operator.control$mutator.gauss.sd, lower = 0, finite = TRUE, na.ok = FALSE) | ||
} | ||
mutation.bool = matrix(runif(n * n.params) < control$mutator.gauss.prob, ncol = n.params) | ||
mutation = matrix(0, ncol = n.params, nrow = n) | ||
idx = which(mutation.bool) | ||
mutation[idx] = rnorm(length(idx), mean = 0, sd = control$mutator.gauss.sd) | ||
setOfIndividuals$individuals = setOfIndividuals$individuals + mutation | ||
|
||
attr(gaussMutator, "checkFunction") = gaussMutatorCheck | ||
return(setOfIndividuals) | ||
} | ||
|
||
makeMutator( | ||
mutator = mutator, | ||
name = "Gauss mutator", | ||
description = "Adds gaussian noise to each gene", | ||
supported = "float", | ||
defaults = defaults, | ||
checker = mutatorCheck | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,28 @@ | ||
#' Swap mutation operator. | ||
#' | ||
#' @param setOfIndividuals [\code{setOfIndividuals}]\cr | ||
#' Set of individuals. | ||
#' @param control [\code{list}]\cr | ||
#' Not used. | ||
#' @return [\code{setOfIndividuals}] | ||
#' Set of individuals. | ||
#' @return [\code{ecr_mutator}] | ||
#' @export | ||
swapMutator = function(setOfIndividuals, control = list()) { | ||
n.params = ncol(setOfIndividuals$individuals) | ||
n = nrow(setOfIndividuals$individuals) | ||
makeSwapMutator = function() { | ||
mutator = function(setOfIndividuals, control = list()) { | ||
n.params = ncol(setOfIndividuals$individuals) | ||
n = nrow(setOfIndividuals$individuals) | ||
|
||
for (i in seq(n)) { | ||
pos = sample(1:n.params, size = 2) | ||
pos1 = pos[1] | ||
pos2 = pos[2] | ||
#catf("Positions: %i, %i", pos1, pos2) | ||
tmp = setOfIndividuals$individuals[i, pos1] | ||
setOfIndividuals$individuals[i, pos1] = setOfIndividuals$individuals[i, pos2] | ||
setOfIndividuals$individuals[i, pos2] = tmp | ||
for (i in seq(n)) { | ||
pos = sample(1:n.params, size = 2) | ||
pos1 = pos[1] | ||
pos2 = pos[2] | ||
#catf("Positions: %i, %i", pos1, pos2) | ||
tmp = setOfIndividuals$individuals[i, pos1] | ||
setOfIndividuals$individuals[i, pos1] = setOfIndividuals$individuals[i, pos2] | ||
setOfIndividuals$individuals[i, pos2] = tmp | ||
} | ||
return(setOfIndividuals) | ||
} | ||
return(setOfIndividuals) | ||
} | ||
|
||
attr(swapMutator, "name") = "Swap mutator" | ||
attr(swapMutator, "description") = "Swaps two alleles" | ||
attr(swapMutator, "supported") = c("permutation") | ||
attr(swapMutator, "class") = c("ecr_operator", "ecr_mutator") | ||
attr(swapMutator, "defaults") = list() | ||
|
||
swapMutatorCheck = function(operator.control) {} | ||
|
||
attr(swapMutator, "checkFunction") = swapMutatorCheck | ||
makeMutator( | ||
mutator = mutator, | ||
name = "Swap mutator", | ||
description = "Swaps two alleles", | ||
supported = "permutation", | ||
) | ||
} |
Oops, something went wrong.