rao_genetic_max: rao_genetic_max

View source: R/RcppExports.R

rao_genetic_maxR Documentation

rao_genetic_max

Description

Uses a genetic algorithm to find the optimum permutation of p to maximize Rao(p,D).

Usage

rao_genetic_max(
  p, 
  D,
  swap_freq,
  term_cycles=10, 
  maxiters=400,
  popsize_perm=150,
  popsize_swap=150,
  keep=25, 
  cross=0,
  prc=0.001
)

Arguments

p

numeric vector of length n. A species weights vector.

D

numeric vector of length n(n-1)/2. i.e. a dist object representing the lower triangle of an nxn matrix.

swap_freq

integer vector - distribution of swaps per generation. For a constant swap rate, set to a constant value (recommend 1). If set to c(1,1,2,3), for example, one swap per generation will occur about half the time, and two swaps per generation will occur one quarter of the time, etc.

term_cycles

integer, number of cycles with no improvement to trigger termination (default: 10).

maxiters

integer, maximum number of iterations to run algorithm (default: 400).

popsize_perm

integer, population size for genetic algorithm that is initialized using random permutations of p. Total population size is equal to popsize_perm+popsize_swap+1, and all mutation post initialization is performed using swaps (default: 150).

popsize_swap

integer, population size for genetic algorithm that is initialized using random swaps of p. The numbers of swaps are drawn from swap_freq (default: 150).

keep

integer, number of individuals to keep during each iteration (default: 25).

cross

integer, number of items in pop mutated via PMX instead of by swap each generation (default: 0).

prc

double, precision for calculating termination with term_cycles (default: 0.001).

Value

List object containing results of genetic algorithm:

best_rao:

Maximum Rao value found.

iter_raos:

Max Rao value for each iteration. If termination condition was met, rest of values after final iteration are NA.

iterations:

Iteration numbers, corresponding to iter_raos.

best_p:

The best permutation of p found (corresponds to best_rao).

Author(s)

John L. Darcy

Examples

  # library(specificity)
  # set.seed(12345)
  # p <- runif(100)
  # D <- dist(sample(p))
  # a <- rao_genetic_max(p,D,c(1,1,2,3))
  # plot(a$iter_raos ~ a$iterations)

darcyj/specificity documentation built on Aug. 1, 2023, 8 a.m.