Class ATBT
- All Implemented Interfaces:
Runnable,IBS.HasIBS,IBS.HasIBS.DPairs,MilestoneListener,Model.HasDE,Model.HasDE.DPairs,Model.HasDE.EM,Model.HasDE.ODE,Model.HasDE.PDE,Model.HasDE.PDEADV,Model.HasDE.PDERD,Model.HasDE.RK5,Model.HasDE.SDE,Features,Features.Pairs,Features.Payoffs,HasHistogram,HasHistogram.Degree,HasHistogram.Fitness,HasHistogram.StatisticsProbability,HasHistogram.StatisticsStationary,HasHistogram.StatisticsTime,HasMean,HasMean.Fitness,HasMean.Traits,HasPhase2D,HasPop2D,HasPop2D.Fitness,HasPop2D.Traits,HasPop3D,HasPop3D.Fitness,HasPop3D.Traits,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 trait but not the patch quality, whereas in the latter both
the trait and type are are transmitted to the offspring.- Author:
- Christoph Hauert
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclassThe class that defines the mapping of asymmetric2×2games onto a 2D phase plane: fraction of cooperators alongx-axis and fraction of rich patches alongy-axis.classExtends TBT.TBTPop to take advantage of kaleidoscope initializations.classProvide ODE implementation for asymmetric2×2games with environmental feedback.Nested classes/interfaces inherited from class TBT
TBT.IBSPopNested classes/interfaces inherited from interface Features
Features.Groups, Features.Multispecies, Features.Pairs, Features.Payoffs, Features.StaticNested classes/interfaces inherited from interface HasHistogram
HasHistogram.Degree, HasHistogram.Fitness, HasHistogram.StatisticsProbability, HasHistogram.StatisticsStationary, HasHistogram.StatisticsTime, HasHistogram.StrategyNested classes/interfaces inherited from interface HasMean
HasMean.Fitness, HasMean.TraitsNested classes/interfaces inherited from interface HasPhase2D
HasPhase2D.Data2PhaseNested classes/interfaces inherited from interface HasPop2D
HasPop2D.Fitness, HasPop2D.TraitsNested classes/interfaces inherited from interface HasPop3D
HasPop3D.Fitness, HasPop3D.TraitsNested classes/interfaces inherited from interface IBS.HasIBS
IBS.HasIBS.CGroups, IBS.HasIBS.CPairs, IBS.HasIBS.DGroups, IBS.HasIBS.DPairs, IBS.HasIBS.MCGroups, IBS.HasIBS.MCPairsNested classes/interfaces inherited from interface Model.HasDE
Model.HasDE.DGroups, Model.HasDE.DPairs, Model.HasDE.DualDynamics, Model.HasDE.EM, Model.HasDE.PDE, Model.HasDE.PDEADV, Model.HasDE.PDERD, Model.HasDE.RK5, Model.HasDE.SDE -
Field Summary
FieldsModifier and TypeFieldDescriptionfinal CLOptionCommand line option to set the origin of asymmetries to differences in genotype or in the environment.final CLOptionCommand line option to set the environmental values of the two different patch types.final CLOptionCommand line option to set the feedback between traits and patch quality.final CLOptionCommand line option to set the2×2payoff matrix for interactions between cooperators and defectors or the (generic)4×4payoff matrix for arbitrary interactions between four traits.static final intThe trait (and index) value of poor cooperators.static final intThe trait (and index) value of rich cooperators.static final intThe trait (and index) value of poor defectors.static final intThe trait (and index) value of rich defectors.(package private) double[]The array of environmental values for rich and poor sites.(package private) booleanThe flag indicating the type of environmental asymmetry.(package private) double[]The array with environmental feedback rates.(package private) double[][]The2×2payoff matrix for interactions between cooperators and defectors.private booleanThe flag to indicate whether a generic4×4was provided to for the interactions among the four traits.(package private) ATBT.ATBTMapThe map for projecting the four dimensional dynamical system onto a 2D phase plane.static final intThe identifier of poor sites:(int) (trait / 2).static final intThe identifier of rich sites:(int) (trait / 2).Fields inherited from class TBT
cloPayoffs, COOPERATE, DEFECT, payoffsFields inherited from class Discrete
cloMonoStop, monoStop, mutation, speciesFields 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, VACANTFields inherited from interface HasS3
CORNER_LEFT, CORNER_RIGHT, CORNER_TOP, EDGE_BOTTOM, EDGE_LEFT, EDGE_RIGHT -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidProviders of command line options may want to remove certain options that other providers provided by overriding this method.voidavgScores(double[] density, double[] avgscores) Calculate the average payoff for the frequency of traits specified in the arraystatefor pairwise interactions.booleancheck()Check all parameters.voidcollectCLO(CLOParser parser) All providers of command line options must implement this method to collect their options.Opportunity to supply custom individual based simulations.createModel(Type type) Creates a model of typetypeformodule.Returns a string with information about the authors of the module.intFor replicator dynamics the frequencies of all traits must sum up to one.double[]Get the environmental values or patch qualities for rich and poor sites.booleanCheck 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.voidload()Load new module and perform basic initializations.voidmixedScores(int[] count, double[] traitScores) Calculate the average payoff/score in a finite population with the number of each trait provided incountfor pairwise interactions.doublepairScores(int me, int[] traitCount, double[] traitScore) Calculate and return total (accumulated) payoff/score for pairwise interactions of the focal individual with traitmeagainst opponents with different traits.booleansetEnvironment(double[] environment) Set the (array of) environmental values or patch qualities for rich and poor sites.voidsetEnvironmentalAsymmetry(boolean asym) Set the flag whether asymmetries are due to environmental differences, i.e.booleansetFeedback(double[] feedback) Set the feedback between traits and patch qualities: cooperators restoring poor sites defectors degrading rich sites cooperators degrading rich sites defectors restoring poor sites The arrayfeedbackcan 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.voidsetPayoffs(double[][] payoffs) Set the payoff matrix topayoffs, which can be a2×2or4×4matrix.voidunload()Unload module and free all resources.Methods inherited from class TBT
getMaxPayoff, getMeanColors, getMinPayoff, getMonoPayoff, getPayoff, getPayoffs, getTraitName, setPayoffMethods inherited from class Discrete
add, getMaxMonoPayoff, getMinMonoPayoff, getMonoStop, getMutation, setMonoStopMethods inherited from class Module
createGeometry, getActiveTraits, getCompetitionGeometry, getDeathRate, getGeometry, getIBSPopulation, getID, getInteractionGeometry, getMap2Fitness, getMarkers, getModelTypes, getNActive, getName, getNGroup, getNPopulation, getNRoles, getNSpecies, getNTraits, getOpponent, getPlayerUpdate, getSpecies, getSpecies, getTraitColor, getTraitColors, 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 Features
isMultispecies, isStaticMethods inherited from interface Features.Pairs
isPairwiseMethods inherited from interface Features.Payoffs
getMap2Fitness, getMaxMonoPayoff, getMinMonoPayoff, isNeutralMethods inherited from interface HasHistogram
getCustomLevels, getNTraits, getTraitColorsMethods inherited from interface HasPhase2D
setPhase2DMapMethods inherited from interface IBS.HasIBS
createIBSMethods inherited from interface MilestoneListener
modelDidInit, modelDidReset, modelLoaded, modelRelaxed, modelRunning, modelSettings, modelStopped, modelUnloaded, moduleLoaded, moduleRestored, moduleUnloaded
-
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×2payoff 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. Iftrueasymmetries are due to environmental differences (non-heritable) and iffalseasymmetries have a genetic origin (heritable). -
init4x4
private boolean init4x4The flag to indicate whether a generic4×4was provided to for the interactions among the four traits. -
map
ATBT.ATBTMap mapThe map for projecting the four dimensional dynamical system onto a 2D phase plane. -
cloPayoffs4x4
Command line option to set the2×2payoff matrix for interactions between cooperators and defectors or the (generic)4×4payoff matrix for arbitrary interactions between four traits. -
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 traits and patch quality.
-
-
Constructor Details
-
ATBT
Create a new instance of the module for asymmetric2×2games.- Parameters:
engine- the manager of modules and pacemaker for running the model
-
-
Method Details
-
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. -
getKey
Description copied from class:ModuleReturns identifier of the active module. For example, 2x2 games inTBTreturn "2x2". This corresponds to the argument for the--moduleoption to load a particular module. The default is to use the class name. -
getAuthors
Description copied from class:ModuleReturns a string with information about the authors of the module.- Overrides:
getAuthorsin classTBT- Returns:
- the names of the authors
-
getTitle
Description copied from interface:FeaturesReturns title of active module, e.g. 2x2 games inTBTreturns "2x2 Games". -
getDependent
public int getDependent()Description copied from interface:Model.HasDEFor replicator dynamics the frequencies of all traits must sum up to one. Hence, fornTraitstraits there are onlynTraits-1degrees of freedom. The index returned bygetDependent()marks the one rate of change that is derived from all the others.Notes:
- Dependent traits are used by models where the frequencies of all types must sum up to one.
- Density modules do not have dependent traits and
getDependent()should return-1. - Currently differential equations implementations are only provided for Discrete modules.
- Specified by:
getDependentin interfaceModel.HasDE- Overrides:
getDependentin classTBT- Returns:
- the index of the dependent trait (or
-1if there is none)
-
pairScores
public double pairScores(int me, int[] traitCount, double[] traitScore) Description copied from interface:IBS.HasIBS.DPairsCalculate and return total (accumulated) payoff/score for pairwise interactions of the focal individual with traitmeagainst opponents with different traits. The respective numbers of each of thenTraitsopponent traits are provided in the arraytCount. The payoffs/scores for each of thenTraitsopponent traits 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:
pairScoresin interfaceIBS.HasIBS.DPairs- Overrides:
pairScoresin classTBT- Parameters:
me- the trait index of the focal individualtraitCount- number of opponents with each traittraitScore- array for returning the scores of each opponent trait- Returns:
- score of focal individual
meaccumulated over all interactions
-
avgScores
public void avgScores(double[] density, double[] avgscores) Description copied from interface:Model.HasDE.DPairsCalculate the average payoff for the frequency of traits specified in the arraystatefor pairwise interactions. The average payoffs for each of thenTraitstraits must be stored and returned in the arrayscores.- Specified by:
avgScoresin interfaceModel.HasDE.DPairs- Overrides:
avgScoresin classTBT- Parameters:
density- the frequency/density of each traitavgscores- the array for storing the average payoffs/scores of each trait
-
mixedScores
public void mixedScores(int[] count, double[] traitScores) Description copied from interface:IBS.HasIBS.DPairsCalculate the average payoff/score in a finite population with the number of each trait provided incountfor pairwise interactions. The payoffs/scores for each of thenTraitstraits 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()(seeCXPopulationfor an example).- Specified by:
mixedScoresin interfaceIBS.HasIBS.DPairs- Overrides:
mixedScoresin classTBT- Parameters:
count- number of individuals for each traittraitScores- array for returning the payoffs/scores of each trait
-
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.
-
setPayoffs
public void setPayoffs(double[][] payoffs) Set the payoff matrix topayoffs, which can be a2×2or4×4matrix. For2×2matrices, it specifies the payoffs for interactions between cooperators and defectors, while for4×4matrices any generic payoff matrix for interactions among four traits is possible.- Overrides:
setPayoffsin 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-trueif 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:
trueif asymmetries are of environmental origin
-
setFeedback
public boolean setFeedback(double[] feedback) Set the feedback between traits and patch qualities:- cooperators restoring poor sites
- defectors degrading rich sites
- cooperators degrading rich sites
- defectors restoring poor sites
feedbackcan 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:
trueif 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:
trueif 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:HasPhase2DGet the map that transforms the data of the module to a 2D phase plane (projection).- Specified by:
getPhase2DMapin interfaceHasPhase2D- Returns:
- the map
-
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 classTBT- Parameters:
parser- the reference to parser that manages command line options- See Also:
-
adjustCLO
Description copied from interface:CLOProviderProviders 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:
adjustCLOin interfaceCLOProvider- Overrides:
adjustCLOin classTBT- Parameters:
parser- the reference to parser that manages command line options- See Also:
-
createIBSPop
Description copied from class:ModuleOpportunity to supply custom individual based simulations.- Overrides:
createIBSPopin classTBT- Returns:
- the custom IBSPopulation or
nullto use default.
-
createModel
Description copied from class:ModuleCreates a model of typetypeformodule.Note: Override to provide custom model implementations.
Important: any custom model implementations that involve random numbers, must use the shared random number generator for reproducibility
- Overrides:
createModelin classModule- Parameters:
type- the type ofModelto create- Returns:
- the model for
moduleornullif the module does not support the requested model type - See Also:
-