Class ATBT
- All Implemented Interfaces:
Runnable
,IBS.HasIBS
,IBS.HasIBS.DPairs
,MilestoneListener
,ODE.HasDE
,ODE.HasODE
,PDE.HasPDE
,SDE.HasSDE
,Features
,Features.Pairs
,HasHistogram
,HasHistogram.Degree
,HasHistogram.Fitness
,HasHistogram.StatisticsProbability
,HasHistogram.StatisticsStationary
,HasHistogram.StatisticsTime
,HasMean
,HasMean.Fitness
,HasMean.Strategy
,HasPhase2D
,HasPop2D
,HasPop2D.Fitness
,HasPop2D.Strategy
,HasPop3D
,HasPop3D.Fitness
,HasPop3D.Strategy
,HasS3
,CLOProvider
2×2
games. The origin of asymmetries can either be due to
environmental differences where individuals occupy rich or poor sites or due
to genetic differences, e.g. with weak and strong types. The key distinction
between the two scenarios is that in the former case, the offspring only
inherits the strategy but not the patch quality, whereas in the latter both
the strategy and type are are transmitted to the offspring.- Author:
- Christoph Hauert
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclass
The class that defines the mapping of asymmetric2×2
games onto a 2D phase plane: fraction of cooperators alongx
-axis and fraction of rich patches alongy
-axis.class
Extends TBT.TBTPop to take advantage of kaleidoscope initializations.class
Provide ODE implementation for asymmetric2×2
games with environmental feedback.Nested classes/interfaces inherited from class TBT
TBT.IBSPop
Nested classes/interfaces inherited from interface Features
Features.Groups, Features.Pairs, Features.Static
Nested classes/interfaces inherited from interface HasHistogram
HasHistogram.Degree, HasHistogram.Fitness, HasHistogram.StatisticsProbability, HasHistogram.StatisticsStationary, HasHistogram.StatisticsTime, HasHistogram.Strategy
Nested classes/interfaces inherited from interface HasMean
HasMean.Fitness, HasMean.Strategy
Nested classes/interfaces inherited from interface HasPhase2D
HasPhase2D.Data2Phase
Nested classes/interfaces inherited from interface HasPop2D
HasPop2D.Fitness, HasPop2D.Strategy
Nested classes/interfaces inherited from interface HasPop3D
HasPop3D.Fitness, HasPop3D.Strategy
Nested classes/interfaces inherited from interface IBS.HasIBS
IBS.HasIBS.CGroups, IBS.HasIBS.CPairs, IBS.HasIBS.DGroups, IBS.HasIBS.DPairs, IBS.HasIBS.MCGroups, IBS.HasIBS.MCPairs
-
Field Summary
FieldsModifier and TypeFieldDescriptionfinal CLOption
Command line option to set the origin of asymmetries to differences in genotype or in the environment.final CLOption
Command line option to set the environmental values of the two different patch types.final CLOption
Command line option to set the feedback between strategic types and patch quality.final CLOption
Command line option to set the2×2
payoff matrix for interactions between cooperators and defectors or the (generic)4×4
payoff matrix for arbitrary interactions between four strategic types.static final int
The trait (and index) value of poor cooperators.static final int
The trait (and index) value of rich cooperators.static final int
The trait (and index) value of poor defectors.static final int
The trait (and index) value of rich defectors.(package private) double[]
The array of environmental values for rich and poor sites.(package private) boolean
The flag indicating the type of environmental asymmetry.(package private) double[]
The array with environmental feedback rates.(package private) double[][]
The2×2
payoff matrix for interactions between cooperators and defectors.private boolean
The flag to indicate whether a generic4×4
was provided to for the interactions among the four strategy types.(package private) ATBT.ATBTMap
The map for projecting the four dimensional dynamical system onto a 2D phase plane.static final int
The identifier of poor sites:(int) (trait / 2)
.static final int
The identifier of rich sites:(int) (trait / 2)
.Fields inherited from class TBT
cloPayoffs, COOPERATE, DEFECT, payoffs
Fields inherited from class Discrete
cloMonoStop, monoStop, mutation, species
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
Fields inherited from interface HasS3
CORNER_LEFT, CORNER_RIGHT, CORNER_TOP, EDGE_BOTTOM, EDGE_LEFT, EDGE_RIGHT
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
Providers of command line options may want to remove certain options that other providers provided by overriding this method.void
avgScores
(double[] density, int n, double[] avgscores) Calculate the average payoff/score for the frequency of traits/strategies specified in the arraydensity
for interactions in groups of sizen
.boolean
check()
Check all parameters.void
collectCLO
(CLOParser parser) All providers of command line options must implement this method to collect their options.Opportunity to supply custom individual based simulations.Provides opportunity for model to supply custom ODE implementation.Returns a string with information about the authors of the module.int
Get the index of dependent type or-1
if Module does not have an dependent type.double[]
Get the environmental values or patch qualities for rich and poor sites.boolean
Check whether asymmetries are due to environmental differences, i.e.double[]
Get the array with feedback rates/probabilities.getKey()
Returns identifier of the active module.Get the map that transforms the data of the module to a 2D phase plane (projection).getTitle()
Returns title of active module, e.g.void
load()
Load new module and perform basic initializations.void
mixedScores
(int[] count, double[] traitScores) Calculate the average payoff/score in a finite population with the number of each trait/strategy provided incount
for pairwise interactions.double
pairScores
(int me, int[] traitCount, double[] traitScore) Calculate and return total (accumulated) payoff/score for pairwise interactions of the focal individual with trait/strategyme
against opponents with different traits/strategies.boolean
setEnvironment
(double[] environment) Set the (array of) environmental values or patch qualities for rich and poor sites.void
setEnvironmentalAsymmetry
(boolean asym) Set the flag whether asymmetries are due to environmental differences, i.e.boolean
setFeedback
(double[] feedback) Set the feedback between strategic types and patch qualities: cooperators restoring poor sites defectors degrading rich sites cooperators degrading rich sites defectors restoring poor sites The arrayfeedback
can have one, two or four elements: all four rates/probabilities are the same rates/probabilities for cooperators restoring poor sites and defectors degrading rich sites.void
setPayoffs
(double[][] payoffs) Set the payoff matrix topayoffs
, which can be a2×2
or4×4
matrix.void
unload()
Unload module and free all resources.Methods inherited from class TBT
getMaxGameScore, getMeanColors, getMinGameScore, getMonoGameScore, getPayoff, getPayoffs, getTraitName, setPayoff
Methods inherited from class Discrete
add, getMaxMonoGameScore, getMinMonoGameScore, getMonoStop, getMutation, setMonoStop
Methods inherited from class Module
createGeometry, getActiveTraits, getCompetitionGeometry, getDeathRate, getGeometry, getIBSPopulation, getID, getInteractionGeometry, getMapToFitness, getMarkers, getModelTypes, getNActive, getName, getNGroup, getNPopulation, getNRoles, getNSpecies, getNTraits, getOpponent, getPlayerUpdate, getSpecies, getSpecies, getSpeciesUpdateRate, getTraitColor, getTraitColors, 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 Features.Pairs
isPairwise
Methods inherited from interface HasHistogram
getCustomLevels, getNTraits, getTraitColors
Methods inherited from interface HasPhase2D
setPhase2DMap
Methods inherited from interface IBS.HasIBS
createIBS
Methods inherited from interface MilestoneListener
modelDidInit, modelDidReset, modelLoaded, modelRelaxed, modelRunning, modelSettings, modelStopped, modelUnloaded, moduleLoaded, moduleRestored, moduleUnloaded
Methods inherited from interface PDE.HasPDE
createPDE
Methods inherited from interface SDE.HasSDE
createSDE
-
Field Details
-
RICH
public static final int RICHThe identifier of rich sites:(int) (trait / 2)
.- See Also:
-
POOR
public static final int POORThe identifier of poor sites:(int) (trait / 2)
.- See Also:
-
COOPERATE_RICH
public static final int COOPERATE_RICHThe trait (and index) value of rich cooperators.- See Also:
-
COOPERATE_POOR
public static final int COOPERATE_POORThe trait (and index) value of poor cooperators.- See Also:
-
DEFECT_RICH
public static final int DEFECT_RICHThe trait (and index) value of rich defectors.- See Also:
-
DEFECT_POOR
public static final int DEFECT_POORThe trait (and index) value of poor defectors.- See Also:
-
game
double[][] gameThe2×2
payoff matrix for interactions between cooperators and defectors. -
environment
double[] environmentThe array of environmental values for rich and poor sites. -
feedback
double[] feedbackThe array with environmental feedback rates.- See Also:
-
environmentalAsymmetry
boolean environmentalAsymmetryThe flag indicating the type of environmental asymmetry. Iftrue
asymmetries are due to environmental differences (non-heritable) and iffalse
asymmetries have a genetic origin (heritable). -
init4x4
private boolean init4x4The flag to indicate whether a generic4×4
was provided to for the interactions among the four strategy types. -
map
ATBT.ATBTMap mapThe map for projecting the four dimensional dynamical system onto a 2D phase plane. -
cloPayoffs4x4
Command line option to set the2×2
payoff matrix for interactions between cooperators and defectors or the (generic)4×4
payoff matrix for arbitrary interactions between four strategic types. -
cloEnvironment
Command line option to set the environmental values of the two different patch types. -
cloAsymmetry
Command line option to set the origin of asymmetries to differences in genotype or in the environment. -
cloFeedback
Command line option to set the feedback between strategic types and patch quality.
-
-
Constructor Details
-
ATBT
Create a new instance of the module for asymmetric2×2
games.- Parameters:
engine
- the manager of modules and pacemaker for running the model
-
-
Method Details
-
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. -
getKey
Description copied from class:Module
Returns identifier of the active module. For example, 2x2 games inTBT
return "2x2". This corresponds to the argument for the--module
option to load a particular module. The default is to use the class name. -
getAuthors
Description copied from class:Module
Returns a string with information about the authors of the module.- Overrides:
getAuthors
in classTBT
- Returns:
- the names of the authors
-
getTitle
Description copied from class:Module
Returns title of active module, e.g. 2x2 games inTBT
returns "2x2 Games". -
getDependent
public int getDependent()Description copied from class:Module
Get the index of dependent type or-1
if Module does not have an dependent type.Notes:
- Dependent types are used by replicator type models where the frequencies of all types must sum up to one. Currently only used by Discrete modules.
- Density modules do not have dependent types.
- By default use vacant type as the dependent
- Specified by:
getDependent
in interfaceODE.HasDE
- Overrides:
getDependent
in classTBT
- Returns:
- the index of the vacant type
-
pairScores
public double pairScores(int me, int[] traitCount, double[] traitScore) Description copied from interface:IBS.HasIBS.DPairs
Calculate and return total (accumulated) payoff/score for pairwise interactions of the focal individual with trait/strategyme
against opponents with different traits/strategies. The respective numbers of each of thenTraits
opponent traits/strategies are provided in the arraytCount
. The payoffs/scores for each of thenTraits
opponent traits/strategies must be stored and returned in the arraytScore
.Important: must be overridden and implemented in subclasses that define game interactions between pairs of individuals (
nGroup=2
,pairwise=true
), otherwise seeIBS.HasIBS.DGroups.groupScores(int[], double[])
.- Specified by:
pairScores
in interfaceIBS.HasIBS.DPairs
- Overrides:
pairScores
in classTBT
- Parameters:
me
- the trait index of the focal individualtraitCount
- number of opponents with each trait/strategytraitScore
- array for returning the scores of each opponent trait/strategy- Returns:
- score of focal individual
me
accumulated over all interactions
-
avgScores
public void avgScores(double[] density, int n, double[] avgscores) Description copied from interface:ODE.HasDE
Calculate the average payoff/score for the frequency of traits/strategies specified in the arraydensity
for interactions in groups of sizen
. The average payoffs/scores for each of thenTraits
traits/strategies must be stored and returned in the arrayavgscores
.Note: needs to be thread safe for parallel processing of PDE's.
IMPORTANT: one of
should be implemented in modules that advertise the model typesODE, SDE
orPDE
.Alternatively, the method
ODE.getDerivatives(double, double[], double[], double[])
may be overridden in a subclass ofODE
, which may prevent calls toavgScores(...)
altogether. -
mixedScores
public void mixedScores(int[] count, double[] traitScores) Description copied from interface:IBS.HasIBS.DPairs
Calculate the average payoff/score in a finite population with the number of each trait/strategy provided incount
for pairwise interactions. The payoffs/scores for each of thenTraits
traits/strategies must be stored and returned in the arraytraitScores
.Important: must be overridden and implemented in subclasses that define game interactions in well-mixed populations where individuals interact with everyone else. Computationally it is not feasible to cover this scenario with
IBS.HasIBS.DPairs.pairScores(int, int[], double[])
orIBS.HasIBS.DGroups.groupScores(int[], double[])
, respectively.Note: If explicit calculations of the well-mixed scores are not available, interactions with everyone in well-mixed populations should checked for and excluded with a warning in
IBS.check()
(seeCXPopulation
for an example).- Specified by:
mixedScores
in interfaceIBS.HasIBS.DPairs
- Overrides:
mixedScores
in classTBT
- Parameters:
count
- number of individuals for each trait/strategytraitScores
- array for returning the payoffs/scores of each trait/strategy
-
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.
-
setPayoffs
public void setPayoffs(double[][] payoffs) Set the payoff matrix topayoffs
, which can be a2×2
or4×4
matrix. For2×2
matrices, it specifies the payoffs for interactions between cooperators and defectors, while for4×4
matrices any generic payoff matrix for interactions among four types of strategies is possible.- Overrides:
setPayoffs
in classTBT
- Parameters:
payoffs
- the payoff matrix
-
setEnvironmentalAsymmetry
public void setEnvironmentalAsymmetry(boolean asym) Set the flag whether asymmetries are due to environmental differences, i.e. patch qualities (as opposed to genetic differences).- Parameters:
asym
-true
if asymmetries are of environmental origin
-
getEnvironmentalAsymmetry
public boolean getEnvironmentalAsymmetry()Check whether asymmetries are due to environmental differences, i.e. patch qualities (as opposed to genetic differences).- Returns:
true
if asymmetries are of environmental origin
-
setFeedback
public boolean setFeedback(double[] feedback) Set the feedback between strategic types and patch qualities:- cooperators restoring poor sites
- defectors degrading rich sites
- cooperators degrading rich sites
- defectors restoring poor sites
feedback
can have one, two or four elements:- all four rates/probabilities are the same
- rates/probabilities for cooperators restoring poor sites and defectors degrading rich sites. The other two, cooperators degrading rich sites and defectors restoring poor sites are set to zero.
- all four rates/probabilities are set.
- Parameters:
feedback
- the array with feedback rates/probabilities- Returns:
true
if feedback successfully set
-
getFeedback
public double[] getFeedback()Get the array with feedback rates/probabilities.- Returns:
- the feedback array
- See Also:
-
setEnvironment
public boolean setEnvironment(double[] environment) Set the (array of) environmental values or patch qualities for rich and poor sites.- Parameters:
environment
- the array of patch values- Returns:
true
if environmental values successfully set
-
getEnvironment
public double[] getEnvironment()Get the environmental values or patch qualities for rich and poor sites.- Returns:
- the array of patch values
-
getPhase2DMap
Description copied from interface:HasPhase2D
Get the map that transforms the data of the module to a 2D phase plane (projection).- Specified by:
getPhase2DMap
in interfaceHasPhase2D
- Returns:
- the map
-
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 classTBT
- Parameters:
parser
- the reference to parser that manages command line options- See Also:
-
adjustCLO
Description copied from interface:CLOProvider
Providers of command line options may want to remove certain options that other providers provided by overriding this method. After all command line options are collected, all providers get a chance to adjust the collection. In particular, options should be removed that do not make sense in present context. Overriding methods usually callCLOParser.removeCLO(String[])
or variants thereof.- Specified by:
adjustCLO
in interfaceCLOProvider
- Overrides:
adjustCLO
in classTBT
- Parameters:
parser
- the reference to parser that manages command line options- See Also:
-
createIBSPop
Opportunity to supply custom individual based simulations.Note: Cannot return more specific type due to subclass
invalid reference
CG#createIBSPop()
- Overrides:
createIBSPop
in classTBT
- Returns:
- the custom IBSPopulation or
null
to use default.
-
createODE
Description copied from interface:ODE.HasODE
Provides opportunity for model to supply custom ODE implementation.Important: if the custom ODE implementation involves random numbers, the shared random number generator should be used for reproducibility
- Specified by:
createODE
in interfaceODE.HasODE
- Returns:
- the custom ODE model or
null
to use use default - See Also:
-