Class Continuous
- All Implemented Interfaces:
Runnable
,MilestoneListener
,Features
,CLOProvider
- Author:
- Christoph Hauert
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enum
Selected benefit functions to translate continuous traits into payoffs.static enum
Selected cost functions to translate continuous traits into payoffs.class
Translate continuous traits into payoffs based on configurable cost and benefit functions.Nested classes/interfaces inherited from interface Features
Features.Groups, Features.Pairs, Features.Static
-
Field Summary
FieldsModifier and TypeFieldDescriptionfinal CLOption
Command line option to set the benefit function(s) for continuous traits.final CLOption
Command line option to set the cost function(s) for continuous traits.final CLOption
Command line option to set the minimum value of each trait.protected double
The maximum score in a monomorphic population.protected double
The absolute maximum score.protected double
The minimum score in a monomorphic population.protected double
The absolute minimum score.protected boolean
The flag that indicates whether maximal and minimal scores have already been calculated.(package private) static final int
The number of iterations for the hill climbing process.(package private) static final int
The linear grid size to sample payoffs in the (possibly multi-dimensional) trait space.protected Mutation.Continuous
The mutation operator for continuous traits.(package private) Continuous
Shortcut for species.get(0) as long as continuous modules are restricted to a single species.(package private) ArrayList
<Continuous> The listspecies
contains references to each species in this module.protected double[]
The trait maxima.protected double[]
The trait minima.protected Continuous.Traits2Payoff
The map to translate traits of interacting individuals into payoffs.Fields inherited from class Module
active, cloDeathRate, cloGeometry, cloNGroup, cloNPopulation, cloPhase2DAxis, cloSpeciesUpdateRate, cloTraitColors, cloTraitDisable, cloTraitNames, competition, deathRate, defaultColor, engine, ibs, ID, interaction, logger, map2fitness, markers, model, nActive, name, nGroup, nPopulation, nTraits, opponent, playerUpdate, speciesUpdateRate, structure, traitColor, traitName, trajectoryColor, VACANT
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
Continuous
(EvoLudo engine) Create new module with continuous traits.protected
Continuous
(EvoLudo engine, Continuous partner) Create a new module with continuous traits for pacemakerengine
and interactions with modulepartner
.protected
Continuous
(Continuous partner) Create another module with continuous traits. -
Method Summary
Modifier and TypeMethodDescriptionboolean
add
(Continuous cpop) Addcpop
to list of species.boolean
check()
Check all parameters.void
collectCLO
(CLOParser parser) All providers of command line options must implement this method to collect their options.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.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.private double
findExtremalMonoScore
(boolean maximum) Helper method to find the minimum or maximum payoff for monomorphic populations.private double
findExtremalScore
(boolean maximum) Helper method to determine the minimum or maximum payoff.double
Calculates and returns the maximum payoff/score of an individual.double
Calculates and returns the maximum payoff/score of individuals in monomorphic populations.double
Calculates and returns the minimum payoff/score of an individual.double
Calculates and returns the minimum payoff/score of individuals in monomorphic populations.Gets the mutation type.double[]
Get the maxima for all traits.double[]
Get the minima for all traits.void
load()
Load new module and perform basic initializations.protected void
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.void
setTraitRange
(double min, double max, int trait) Set the trait minimum and maximum for traittrait
.void
unload()
Unload module and free all resources.Methods inherited from class Module
createGeometry, createIBSPop, getActiveTraits, getAuthors, getCompetitionGeometry, getDeathRate, getDependent, getGeometry, getIBSPopulation, getID, getInteractionGeometry, getKey, getMapToFitness, getMarkers, getMeanColors, getModelTypes, getNActive, getName, getNGroup, getNPopulation, getNRoles, getNSpecies, getNTraits, getOpponent, getPlayerUpdate, getSpecies, getSpecies, getSpeciesUpdateRate, getTitle, getTraitColor, getTraitColors, getTraitName, getTraitNames, getTrajectoryColor, getVacant, init, isNeutral, processColorMap, reset, run, setActiveTraits, setDeathRate, setGeometries, setIBSPopulation, setModel, setName, setNGroup, setNPopulation, setNTraits, setOpponent, setSpeciesUpdateRate, setTraitColors, setTraitNames, setTrajectoryColor
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface CLOProvider
adjustCLO
Methods inherited from interface Features
isPairwise, isStatic
Methods inherited from interface MilestoneListener
modelDidInit, modelDidReset, modelLoaded, modelRelaxed, modelRunning, modelSettings, modelStopped, modelUnloaded, moduleLoaded, moduleRestored, moduleUnloaded
-
Field Details
-
species
ArrayList<Continuous> speciesThe listspecies
contains references to each species in this module. It deliberately shadowsModule.species
to simplify bookkeeping. During instantiationModule.species
andspecies
are 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]\).
traitMin
andtraitMax
are used to transform traits appropriately for results. -
traitMax
protected double[] traitMaxThe trait maxima.Note: internally traits are always in \([0,1]\).
traitMin
andtraitMax
are 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 pacemakerengine
and interactions with modulepartner
. Ifpartner == null
this is a single species module and interactions within species (opponent == this
holds).- Parameters:
engine
- the pacemaker for running the modelpartner
- the partner species
-
-
Method Details
-
getMutation
Description copied from class:Module
Gets the mutation type.- Specified by:
getMutation
in classModule
- Returns:
- the mutation type
-
add
Addcpop
to 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:
true
ifdpop
successfully added;false
adding failed or already included in list.
-
load
public void load()Description copied from class:Module
Load new module and perform basic initializations. -
unload
public void unload()Description copied from class:Module
Unload module and free all resources. -
check
public boolean check()Description copied from class:Module
Check 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.
-
getMinGameScore
public double getMinGameScore()Calculates and returns the minimum payoff/score of an individual. This value is important for converting payoffs/scores into probabilities, for scaling graphical output and some optimizations.- Specified by:
getMinGameScore
in classModule
- Returns:
- the minimum payoff/score
- See Also:
-
getMaxGameScore
public double getMaxGameScore()Calculates and returns the maximum payoff/score of an individual. This value is important for converting payoffs/scores into probabilities, for scaling graphical output and some optimizations.- Specified by:
getMaxGameScore
in classModule
- Returns:
- the maximum payoff/score
- See Also:
-
getMinMonoGameScore
public double getMinMonoGameScore()Calculates and returns the minimum payoff/score of individuals in monomorphic populations.- Specified by:
getMinMonoGameScore
in classModule
- Returns:
- the minimum payoff/score in monomorphic populations
- See Also:
-
getMaxMonoGameScore
public double getMaxMonoGameScore()Calculates and returns the maximum payoff/score of individuals in monomorphic populations.- Specified by:
getMaxMonoGameScore
in classModule
- Returns:
- the maximum payoff/score in monomorphic populations
- See Also:
-
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:CLOProvider
All 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, theparser
issues 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:
collectCLO
in interfaceCLOProvider
- Overrides:
collectCLO
in 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_ITER
iterations.- Parameters:
maximum
- iftrue
the 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_STEPS
intervals. 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 arraysresMax
andmutMax
for 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.0
to calculate maximum and-1.0
to 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
- iftrue
the 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.0
to calculate maximum and-1.0
to calculate minimum- Returns:
- the minimum or maximum monomorphic score
-