Class Continuous
- All Implemented Interfaces:
Runnable,MilestoneListener,Features,CLOProvider
- Author:
- Christoph Hauert
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumSelected benefit functions to translate continuous traits into payoffs.static enumSelected cost functions to translate continuous traits into payoffs.classTranslate continuous traits into payoffs based on configurable cost and benefit functions.Nested classes/interfaces inherited from interface Features
Features.Groups, Features.Multispecies, Features.Pairs, Features.Payoffs, Features.Static -
Field Summary
FieldsModifier and TypeFieldDescriptionfinal CLOptionCommand line option to set the benefit function(s) for continuous traits.final CLOptionCommand line option to set the cost function(s) for continuous traits.final CLOptionCommand line option to set the minimum value of each trait.protected doubleThe maximum score in a monomorphic population.protected doubleThe absolute maximum score.protected doubleThe minimum score in a monomorphic population.protected doubleThe absolute minimum score.protected booleanThe flag that indicates whether maximal and minimal scores have already been calculated.(package private) static final intThe number of iterations for the hill climbing process.(package private) static final intThe linear grid size to sample payoffs in the (possibly multi-dimensional) trait space.protected Mutation.ContinuousThe mutation operator for continuous traits.(package private) ContinuousShortcut for species.get(0) as long as continuous modules are restricted to a single species.(package private) ArrayList<Continuous> The listspeciescontains references to each species in this module.protected double[]The trait maxima.protected double[]The trait minima.protected Continuous.Traits2PayoffThe map to translate traits of interacting individuals into payoffs.Fields inherited from class Module
active, cloDeathRate, cloGeometry, cloNGroup, cloNPopulation, cloPhase2DAxes, cloTraitColors, cloTraitDisable, cloTraitNames, competition, deathRate, defaultColor, engine, ibs, ID, interaction, logger, map2fitness, markers, model, nActive, name, nGroup, nPopulation, nTraits, opponent, playerUpdate, structure, traitColor, traitName, trajectoryColor, VACANT -
Constructor Summary
ConstructorsModifierConstructorDescriptionContinuous(EvoLudo engine) Create new module with continuous traits.protectedContinuous(EvoLudo engine, Continuous partner) Create a new module with continuous traits for pacemakerengineand interactions with modulepartner.Continuous(Continuous partner) Create another module with continuous traits. -
Method Summary
Modifier and TypeMethodDescriptionbooleanadd(Continuous cpop) Addcpopto list of species.booleancheck()Check all parameters.voidcollectCLO(CLOParser parser) All providers of command line options must implement this method to collect their options.private doublefindExtrema(double[] resTrait, double[] mutTrait, int[] resIdx, int[] mutIdx, double[][] resInterval, double[][] mutInterval, double[] resScale, double[] mutScale, int[] resMax, int[] mutMax, double scoreMax, int trait, double minmax) Helper method to find the minimum or maximum payoff.private doublefindExtrema(double[] resTrait, int[] resIdx, double[][] resInterval, double[] resScale, int[] resMax, double scoreMax, int trait, double minmax) Helper method to find the minimum or maximum payoff for monomorphic populations.private doublefindExtremalMonoScore(boolean maximum) Helper method to find the minimum or maximum payoff for monomorphic populations.private doublefindExtremalScore(boolean maximum) Helper method to determine the minimum or maximum payoff.doubleDefault implementation ofFeatures.Payoffs.getMaxMonoPayoff().doubleDefault implementation ofFeatures.Payoffs.getMaxPayoff().doubleDefault implementation ofFeatures.Payoffs.getMinMonoPayoff().doubleDefault implementation ofFeatures.Payoffs.getMinPayoff().Gets the mutation type.double[]Get the maxima for all traits.double[]Get the minima for all traits.voidload()Load new module and perform basic initializations.protected voidHelper method to numerically determine the minimum and maximum scores in the game through a brute force hill climbing algorithm for two competing traits as well as monomorphic populations.voidsetTraitRange(double min, double max, int trait) Set the trait minimum and maximum for traittrait.voidunload()Unload module and free all resources.Methods inherited from class Module
createGeometry, createIBSPop, createModel, getActiveTraits, getAuthors, getCompetitionGeometry, getDeathRate, getGeometry, getIBSPopulation, getID, getInteractionGeometry, getKey, getMap2Fitness, getMarkers, getMeanColors, getModelTypes, getNActive, getName, getNGroup, getNPopulation, getNRoles, getNSpecies, getNTraits, getOpponent, getPlayerUpdate, getSpecies, getSpecies, getTraitColor, getTraitColors, getTraitName, getTraitNames, getTrajectoryColor, getVacant, init, processColorMap, reset, run, setActiveTraits, setDeathRate, setGeometries, setIBSPopulation, setModel, setName, setNGroup, setNPopulation, setNTraits, setOpponent, setTraitColors, setTraitNames, setTrajectoryColorMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface CLOProvider
adjustCLOMethods inherited from interface Features
getTitle, isMultispecies, isPairwise, isStaticMethods inherited from interface MilestoneListener
modelDidInit, modelDidReset, modelLoaded, modelRelaxed, modelRunning, modelSettings, modelStopped, modelUnloaded, moduleLoaded, moduleRestored, moduleUnloaded
-
Field Details
-
species
ArrayList<Continuous> speciesThe listspeciescontains references to each species in this module. It deliberately shadowsModule.speciesto simplify bookkeeping. During instantiationModule.speciesandspeciesare linked to represent one and the same list.IMPORTANT: currently continuous models support only a single species.
- See Also:
-
population
Continuous populationShortcut for species.get(0) as long as continuous modules are restricted to a single species. -
extremalScoresSet
protected boolean extremalScoresSetThe flag that indicates whether maximal and minimal scores have already been calculated.- See Also:
-
traitMin
protected double[] traitMinThe trait minima.Note: internally traits are always in \([0,1]\).
traitMinandtraitMaxare used to transform traits appropriately for results. -
traitMax
protected double[] traitMaxThe trait maxima.Note: internally traits are always in \([0,1]\).
traitMinandtraitMaxare used to transform traits appropriately for results. -
mutation
The mutation operator for continuous traits. -
traits2payoff
The map to translate traits of interacting individuals into payoffs. -
cloTraitRange
Command line option to set the minimum value of each trait. -
cloCosts
Command line option to set the cost function(s) for continuous traits.- See Also:
-
cloBenefits
Command line option to set the benefit function(s) for continuous traits.- See Also:
-
cxMinScore
protected double cxMinScoreThe absolute minimum score. -
cxMaxScore
protected double cxMaxScoreThe absolute maximum score. -
cxMinMonoScore
protected double cxMinMonoScoreThe minimum score in a monomorphic population. -
cxMaxMonoScore
protected double cxMaxMonoScoreThe maximum score in a monomorphic population. -
MINMAX_STEPS
static final int MINMAX_STEPSThe linear grid size to sample payoffs in the (possibly multi-dimensional) trait space.- See Also:
-
MINMAX_ITER
static final int MINMAX_ITERThe number of iterations for the hill climbing process.- See Also:
-
-
Constructor Details
-
Continuous
Create new module with continuous traits.- Parameters:
engine- the pacemaker for running the model
-
Continuous
Create another module with continuous traits. The additional module represents another species in multi-species modules that interact with speciespartner.- Parameters:
partner- the partner species
-
Continuous
Create a new module with continuous traits for pacemakerengineand interactions with modulepartner. Ifpartner == nullthis is a single species module and interactions within species (opponent == thisholds).- Parameters:
engine- the pacemaker for running the modelpartner- the partner species
-
-
Method Details
-
getMutation
Description copied from class:ModuleGets the mutation type.- Specified by:
getMutationin classModule- Returns:
- the mutation type
-
add
Addcpopto list of species. Duplicate entries are ignored. Allocate new list if necessary. Assign generic name to species if none provided.- Parameters:
cpop- the module to add to species list.- Returns:
trueifdpopsuccessfully added;falseadding failed or already included in list.
-
load
public void load()Description copied from class:ModuleLoad new module and perform basic initializations. -
unload
public void unload()Description copied from class:ModuleUnload module and free all resources. -
check
public boolean check()Description copied from class:ModuleCheck all parameters. After this call all parameters must be consistent. If parameter adjustments require a reset then this method must returntrue.Note: All parameter changes that don't require a reset can be made on the fly, in particular also while a model is running.
-
getMinPayoff
public double getMinPayoff()Default implementation ofFeatures.Payoffs.getMinPayoff(). Only available to modules that implement theFeatures.Payoffsinterface.- Returns:
- the minimum payoff in monomorphic populations
- See Also:
-
getMaxPayoff
public double getMaxPayoff()Default implementation ofFeatures.Payoffs.getMaxPayoff(). Only available to modules that implement theFeatures.Payoffsinterface.- Returns:
- the minimum payoff in monomorphic populations
- See Also:
-
getMinMonoPayoff
public double getMinMonoPayoff()Default implementation ofFeatures.Payoffs.getMinMonoPayoff(). Only available to modules that implement theFeatures.Payoffsinterface.- Returns:
- the minimum payoff in monomorphic populations
-
getMaxMonoPayoff
public double getMaxMonoPayoff()Default implementation ofFeatures.Payoffs.getMaxMonoPayoff(). Only available to modules that implement theFeatures.Payoffsinterface.- Returns:
- the maximum payoff in monomorphic populations
-
getTraitMin
public double[] getTraitMin()Get the minima for all traits.- Returns:
- the array with the trait minima
-
getTraitMax
public double[] getTraitMax()Get the maxima for all traits.- Returns:
- the array with the trait maxima
-
setTraitRange
public void setTraitRange(double min, double max, int trait) Set the trait minimum and maximum for traittrait.- Parameters:
min- the trait minimummax- the trait maximumtrait- the index of the trait
-
collectCLO
Description copied from interface:CLOProviderAll providers of command line options must implement this method to collect their options.Each command line option is (uniquely) identified by it's name (see
CLOption.getName()), which corresponds to the long version of the option. If an attempt is made to add an option with a name that already exists, theparserissues a warning and ignores the option. Thus, in general, implementing subclasses should first register their options and callsuper.collectCLO(CLOParser)at the end such that subclasses are able to override command line options specified in a parental class.Override this method in subclasses to add further command line options. Subclasses must make sure that they include a call to super.
- Specified by:
collectCLOin interfaceCLOProvider- Overrides:
collectCLOin classModule- Parameters:
parser- the reference to parser that manages command line options- See Also:
-
setExtremalScores
protected void setExtremalScores()Helper method to numerically determine the minimum and maximum scores in the game through a brute force hill climbing algorithm for two competing traits as well as monomorphic populations. -
findExtremalScore
private double findExtremalScore(boolean maximum) Helper method to determine the minimum or maximum payoff.Implementation notes:
Repeatedly callsfindExtrema(double[], double[], int[], int[], double[][], double[][], double[], double[], int[], int[], double, int, double)with the most promising interval in each trait for residents and mutants, respectively. The hill climbing process stops after#MINMAX_ITERiterations.- Parameters:
maximum- iftruethe maximum is returned and the minimum otherwise- Returns:
- the minimum or maximum payoff
-
findExtrema
private double findExtrema(double[] resTrait, double[] mutTrait, int[] resIdx, int[] mutIdx, double[][] resInterval, double[][] mutInterval, double[] resScale, double[] mutScale, int[] resMax, int[] mutMax, double scoreMax, int trait, double minmax) Helper method to find the minimum or maximum payoff.Implementation notes:
The function returns the maximum payoff after discretizing each trait of both the resident and the mutant intoMINMAX_STEPSintervals. The function is recursively called for each trait. The indices of the cell (discretized trait interval) that yields the maximum payoff are returned in the arraysresMaxandmutMaxfor residents and mutants respectively. This provides the starting point for the next iteration of the hill climber process.- Parameters:
resTrait- the array of resident traits (helper variable for recursive calculations)mutTrait- the array of mutant traits (helper variable for recursive calculations)resIdx- the index of the resident trait (helper variable for recursive calculations)mutIdx- the index of the mutant trait (helper variable for recursive calculations)resInterval- the resident trait intervals for discretizationmutInterval- the mutant trait intervals for discretizationresScale- the scaling of the width of the resident trait intervalmutScale- the scaling of the width of the mutant trait intervalresMax- the indices of the discretized cell for the resident that yielded the highest payoffmutMax- the indices of the discretized cell for the mutant that yielded the highest payoffscoreMax- the maximum payofftrait- the current trait for the recursion (helper variable for recursive calculations)minmax-1.0to calculate maximum and-1.0to calculate minimum- Returns:
- the minimum or maximum score
-
findExtremalMonoScore
private double findExtremalMonoScore(boolean maximum) Helper method to find the minimum or maximum payoff for monomorphic populations.Implementation notes:
This is essentially the same but simplified hill climber process infindExtremalScore(boolean)under the constraint that the population is monomorphic, i.e. that the resident and mutant traits are identical.- Parameters:
maximum- iftruethe maximum is returned and the minimum otherwise- Returns:
- the minimum or maximum monomorphic score
-
findExtrema
private double findExtrema(double[] resTrait, int[] resIdx, double[][] resInterval, double[] resScale, int[] resMax, double scoreMax, int trait, double minmax) Helper method to find the minimum or maximum payoff for monomorphic populations.Implementation notes:
This is essentially the same but simplified hill climber process infindExtrema(double[], double[], int[], int[], double[][], double[][], double[], double[], int[], int[], double, int, double)under the constraint that the population is monomorphic, i.e. that the resident and mutant traits are identical.- Parameters:
resTrait- the array of resident traits (helper variable for recursive calculations)resIdx- the index of the resident trait (helper variable for recursive calculations)resInterval- the resident trait intervals for discretizationresScale- the scaling of the width of the resident trait intervalresMax- the indices of the discretized cell for the resident that yielded the highest payoffscoreMax- the maximum payofftrait- the current trait for the recursion (helper variable for recursive calculations)minmax-1.0to calculate maximum and-1.0to calculate minimum- Returns:
- the minimum or maximum monomorphic score
-