R/operator.EARecombinatorIntermediate.R

Defines functions EARecombinatorIntermediate

#' @title
#' Indermediate recombinator.
#'
#' @description
#' Intermediate recombination computes the component-wise mean value of the
#' \code{k} given parents. It is applicable only for float representation.
#'
#' @param inds [\code{list}]\cr
#'   Parents, i.e., list of exactly two numeric vectors of equal length.
#' @return [\code{numeric}] Single offspring.
#' @family recombinators
#' @export
EARecombinatorIntermediate = function() {
  EARecombinator$new(
    name = "Intermediate recombination",
    representations = "real",
    params = list(),
    n.parents = 2L,
    n.children = 1L,
    fun = function(inds) {
      # FIXME: actually we can use more than two paretns
      #checkmate::assertList(inds, len = 2L, any.missing = FALSE, all.missing = FALSE)
      n = length(inds[[1L]])
      # FIXME: make this more efficient
      # Reduce(inds, "+") or so
      child = rep(0, n)
      for (i in 1:length(inds)) {
        child = child + inds[[i]]
      }
      return(child / length(inds))
    }
  )
} # EARecombinatorIntermediate
jakobbossek/ecr3 documentation built on Nov. 14, 2019, 7:47 p.m.