| evolafit | R Documentation |
Using the AlphaSimR machinery it recreates the evolutionary forces applied to a problem where possible solutions replace individuals and combinations of variables to optimize in the problem replace the genes or QTLs. Then evolutionary forces (mutation, selection and drift) are applied to find a close-to-optimal solution. Although multiple traits are enabled it is assumed that same QTLs are behind all the traits, differing only in their average allelic effects.
evolafit(formula, dt,
constraintsUB, constraintsLB, constraintW=NULL,
b, nCrosses=50, nProgeny=20,nGenerations=20,
recombGens=1, nChr=1, mutRateAllele=0, mutRateAlpha=0,
nQtlStart=NULL, D=NULL, lambda=0,
propSelBetween=NULL,propSelWithin=NULL,
fitnessf=NULL, verbose=TRUE, dateWarning=TRUE,
selectTop=TRUE, tolVarG=1e-6,
Ne=50, initPop=NULL, simParam=NULL,
fixNumQtlPerInd=FALSE, traceDelta=TRUE, topN=10,
includeSet=NULL, excludeSet=NULL,
...)
formula |
Formula of the form y~x where |
dt |
A dataset containing the average allelic effects (a) and classifiers/genes/QTLs. |
constraintsUB |
A numeric vector specifying the upper bound constraints for the breeding values
applied at each trait. The length is equal to the number of traits/features in
the formula. If missing is assume an infinite value for all traits. Solutions
(individuals in the population) with higher value than the upper bound are
assigned a -infinite value if the argument |
constraintsLB |
A numeric vector specifying the lower bound constraints for the breeding values
applied at each trait. The length is equal to the number of traits/features
in the formula. If missing is assume a -infinite value for all traits. Solutions
with lower value than the lower bound are assigned a +infinite value if the
argument |
constraintW |
A numeric vector of length equal to the number of generations to specify the weights to be applied to the lower and upper bound constraint values to relax the constraints if needed. If values is NULL a vector of 1s with length equal to the number of generations is created. |
b |
A numeric vector specifying the weights that each trait has in the fitness function (i.e., a selection index). The length should be equal to the number of traits/features. If missing is assumed equal weight (1) for all traits. |
nCrosses |
A numeric value indicating how many crosses should occur in the population of solutions at every generation. |
nProgeny |
A numeric value indicating how many progeny (solutions) each cross should generate in the population of solutions at every generation. |
nGenerations |
The number of generations that the evolutionary process should run for. |
recombGens |
The number of recombination generations that should occur before selection is applied. This is in case the user wants to allow for more recombination before selection operates. The default is 1. |
nChr |
The number of chromosomes where features/genes should be allocated to. The default value is 1 but this number can be increased to mimic more recombination events at every generation and avoid linkage disequilibrium. |
mutRateAllele |
A value between 0 and 1 to indicate the proportion of random QTL dosage that should mutate in each individual. For example, a value of 0.1 means that a random 10% of the QTLs will mutate in each individual randomly taking values of 0 or 1. Is important to notice that this implies that the stopping criteria based in variance will never be reached because we keep introducing variance through random mutation. |
mutRateAlpha |
A value between 0 and 1 to indicate the proportion of random QTL average allelic effects that should mutate in each individual. For example, a value of 0.1 means that a random 10% of the QTLs will mutate in each individual randomly taking values of 0 or 1. Is important to notice that this implies that the stopping criteria based in variance will never be reached because we keep introducing variance through random mutation. |
nQtlStart |
The number of QTLs/genes (classifier |
D |
A relationship matrix between the QTLs (a kind of linkage disequilibrium) specified
in the right side of the formula (levels of the |
lambda |
A numeric value indicating the weight assigned to the relationship between QTLs in the fitness function. If not specified is assumed to be 0. This can be used or ignored in your customized fitness function. |
propSelBetween |
A numeric value between 0 and 1 indicating the proportion of families/crosses of solutions/individuals that should be selected. The default is 1, meaning all crosses are selected or passed to the next generation. |
propSelWithin |
A numeric value between 0 and 1 indicating the proportion of individuals/solutions within families/crosses that should be selected. The default value is 0.5, meaning that 50% of the top individuals are selected. |
fitnessf |
An alternative fitness function to be applied at the level of individuals or solutions. It could be a linear combination of the trait breeding values. The available variables internally are: Y: matrix of trait breeding values for the individuals/solutions. Of dimensions s x t, s soultions and t traits. b: vector of trait weights, specified in the 'b' argument. Of dimensions t x 1, t traits by 1 Q: matrix with QTLs for the individuals/solutions. Of dimensions s x p, s solutions and p QTL columns. Although multiple traits are enabled it is assumed that same QTLs are behind all the traits, differing only in their average allelic effects. D: matrix of relationship between the QTLs, specified in the 'D' argument. Of dimensions p x p, for p QTL columns lambda: a numeric value indicating the weight assigned to the relationship between QTLs in the fitness function. If not specified is assumed to be 0. This can be used or ignored in your customized fitness function. a: list of vectors with average allelic effects for a given trait. Of dimensions s x 1, s solutions by 1 column If
where If you provide your own fitness function please keep in mind that the variables Y, b, Q, D, a, and lambda are already reserved and these variables should always be added to your function (even if you do not use them) in addition to your new variables so the machinery runs. An additional fitness function for accounting only for the group relationship is
An additional fitness function available for regression problems is |
verbose |
A logical value indicating if we should print logs. |
dateWarning |
A logical value indicating if you should be warned when there is a new version
on |
selectTop |
Selects highest values for the fitness value if |
tolVarG |
A stopping criteria (tolerance for genetic variance) when the variance across
traits is smaller than this value, which is equivalent to assume that all solutions
having the same QTL profile (depleted variance). The default value is |
Ne |
initial number of founders in the population (will be important for long term sustainability of genetic variance). |
initPop |
an object of |
simParam |
an object of |
fixNumQtlPerInd |
A |
traceDelta |
a logical value indicating if we should compute the rate of coancestry Q'DQ at each iteration. This metric is used by the pareto plot but is not needed for the evolutionary process and it can take a considerable amount of time when the number of QTLs is big. |
topN |
an integer value indicating the maximum number of solutions to keep in each generation. |
includeSet |
a numeric vector with 0s and 1s of length equal to the number of QTLs (number of rows in your dataset) to indicate which individuals (1s) should be forced to be activated. |
excludeSet |
a numeric vector with 0s and 1s of length equal to the number of QTLs (number of rows in your dataset) to indicate which individuals (1s) should be forced to be deactivated. |
... |
Further arguments to be passed to the fitness function if required. |
Using the AlphaSimR machinery (runMacs) it recreates the evolutionary
forces applied to a problem where possible solutions replace individuals and
combinations of variables in the problem replace the genes. Then evolutionary
forces are applied to find a close-to-optimal solution. The number of solutions
are controlled with the nCrosses and nProgeny parameters, whereas the number of
initial QTLs activated in a solution is controlled by the nQtlStart parameter.
The number of activated QTLs of course will increase if has a positive effect in
the fitness of the solutions. The drift force can be controlled by the recombGens
parameter. The mutation rate can be controlled with the mutRateAllele parameter. The
recombination rate can be controlled with the nChr argument.
The indivPerformance output slot contains the columns id, fitness,
generation, nQTLs, and deltaC. These mean the following:
In fitness : represents the fitness function value of a solution.
In deltaC : it represents the change in coancestry (e.g., inbreeding), it can be thought as the rate of coancestry. It is calculated as q'Dq where 'q' represents the contribution vector, 'D' is the linkage disequilibrium matrix between QTNs (whatever the QTNs represent for your specific problem). In practice we do QAQ' and extract the diagonal values.
In generation : it represents the generation at which this solution appeared.
In nQTNs : it represent the final number of QTNs that are activated in homozygote state for the positive effect.
During the run the columns printed in the console mean the following:
generation: generation of reproduction
constrainedUB: number of solutions constrained by the upper bound specified
constrainedLB: number of solutions constrained by the lower bound specified
varG: genetic variance present in the population due to the QTNs
propB: proportion of families selected during that iteration
propW: proportion of individuals within a family selected in that iteration
time: the time when the iteration has finished.
the matrix of fitness, deltaC, generation, nQTNs per solution per generation. See details section above.
contains the pedigree of the selected solutions across iterations.
a matrix with scores for different metrics across n generations of evolution.
the matrix of phenotypes of individuals/solutions present in the last generation.
AlphaSimR object used for the evolutionary algorithm at the last iteration.
A matrix with as many rows as solutions and columns as traits to be constrained. 0s indicate that such trait went beyond the bound in that particular solution.
A matrix with as many rows as solutions and columns as traits to be constrained. 0s indicate that such trait went beyond the bound in that particular solution.
a character vector corresponding to the name of the variables used in the fitness function.
Giovanny Covarrubias-Pazaran (2024). evola: a simple evolutionary algorithm for complex problems. To be submitted to Bioinformatics.
Gaynor, R. Chris, Gregor Gorjanc, and John M. Hickey. 2021. AlphaSimR: an R package for breeding program simulations. G3 Gene|Genomes|Genetics 11(2):jkaa017. https://doi.org/10.1093/g3journal/jkaa017.
Chen GK, Marjoram P, Wall JD (2009). Fast and Flexible Simulation of DNA Sequence Data. Genome Research, 19, 136-142. http://genome.cshlp.org/content/19/1/136.
evolafit – the information of the package
set.seed(1)
# Data
Gems <- data.frame(
Color = c("Red", "Blue", "Purple", "Orange",
"Green", "Pink", "White", "Black",
"Yellow"),
Weight = round(runif(9,0.5,5),2),
Value = round(abs(rnorm(9,0,5))+0.5,2),
Times=c(rep(1,8),0)
)
head(Gems)
# Color Weight Value
# 1 Red 4.88 9.95
# 2 Blue 1.43 2.73
# 3 Purple 1.52 2.60
# 4 Orange 3.11 0.61
# 5 Green 2.49 0.77
# 6 Pink 3.53 1.99
# 7 White 0.62 9.64
# 8 Black 2.59 1.14
# 9 Yellow 1.77 10.21
# Task: Gem selection.
# Aim: Get highest combined value.
# Restriction: Max weight of the gem combined = 10.
# simple specification
res00<-evolafit(formula=cbind(Weight,Value)~Color, dt= Gems,
# constraints on traits: if greater than this ignore
constraintsUB = c(10,Inf), nGenerations = 10
)
best = bestSol(res00$pop)[,"fitness"]
Q <- pullQtlGeno(res00$pop, simParam = res00$simParam, trait=1); Q <- Q/2
qa = Q[best,] %*% as.matrix(Gems[,c("Weight","Value")]); qa
# more complete specification
res0<-evolafit(formula=cbind(Weight,Value)~Color, dt= Gems,
# constraints on traits: if greater than this ignore
constraintsUB = c(10,Inf),
# constraints on traits: if smaller than this ignore
constraintsLB= c(-Inf,-Inf),
# weight the traits for the selection (fitness function)
b = c(0,1),
# population parameters
nCrosses = 100, nProgeny = 20,
# genome parameters
recombGens = 1, nChr=1, mutRateAllele=0, nQtlStart = 2,
# coancestry parameters
D=NULL, lambda=0,
# selection parameters
propSelBetween = .9, propSelWithin =0.9,
nGenerations = 50
)
Q <- pullQtlGeno(res0$pop, simParam = res0$simParam, trait=2); Q <- Q/2
best = bestSol(res0$pop)[,"fitness"]
qa = Q[best,] %*% as.matrix(Gems[,c("Weight","Value")]); qa
Q[best,]
# $`Genes`
# Red Blue Purple Orange Green Pink White Black Yellow
# 1 1 0 0 1 0 0 1 0
#
# $Result
# Weight Value
# 8.74 32.10
pmonitor(res0)
pareto(res0)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.