Class EcoPGG
- All Implemented Interfaces:
Runnable
,IBS.HasIBS
,IBS.HasIBS.DGroups
,IBS.HasIBS.DPairs
,MilestoneListener
,Model.HasDE
,Model.HasDE.DGroups
,Model.HasDE.EM
,Model.HasDE.ODE
,Model.HasDE.PDE
,Model.HasDE.PDEADV
,Model.HasDE.PDERD
,Model.HasDE.RK5
,Model.HasDE.SDE
,Features
,Features.Groups
,Features.Pairs
,Features.Payoffs
,HasHistogram
,HasHistogram.Degree
,HasHistogram.Fitness
,HasHistogram.StatisticsStationary
,HasMean
,HasMean.Fitness
,HasMean.Traits
,HasPhase2D
,HasPop2D
,HasPop2D.Fitness
,HasPop2D.Traits
,HasPop3D
,HasPop3D.Fitness
,HasPop3D.Traits
,HasS3
,CLOProvider
- Author:
- Christoph Hauert
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclass
The map for translating the data of the ecological public goods game models into 2D phase plane representation.Nested classes/interfaces inherited from interface Features
Features.Groups, Features.Multispecies, Features.Pairs, Features.Payoffs, 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.Traits
Nested classes/interfaces inherited from interface HasPhase2D
HasPhase2D.Data2Phase
Nested classes/interfaces inherited from interface HasPop2D
HasPop2D.Fitness, HasPop2D.Traits
Nested classes/interfaces inherited from interface HasPop3D
HasPop3D.Fitness, HasPop3D.Traits
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
Nested classes/interfaces inherited from interface Model.HasDE
Model.HasDE.DGroups, Model.HasDE.DPairs, Model.HasDE.DualDynamics, Model.HasDE.EM, Model.HasDE.ODE, Model.HasDE.PDE, Model.HasDE.PDEADV, Model.HasDE.PDERD, Model.HasDE.RK5, Model.HasDE.SDE
-
Field Summary
FieldsModifier and TypeFieldDescriptionfinal CLOption
Command line option to set the cost of cooperation, i.e.final CLOption
Command line option to set the multiplication factor for public good interactions.final CLOption
Command line option to set the payoff to cooperators that failed to find any interaction partners.final CLOption
Command line option to set the payoff to defectors that failed to find any interaction partners.static final int
The trait (and index) value of cooperators.(package private) double
The cost of cooperation or the individual contribution to the public good.static final int
The trait (and index) value of defectors.(package private) double
The multiplication factor of the public good.(package private) EcoPGG.EcoPGGMap
The map for translating the model data into 2D phase plane representation.(package private) double
The payoff to lone cooperators.(package private) double
The payoff to lone defectors.Fields inherited from class Discrete
cloMonoStop, monoStop, mutation, species
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
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
avgScores
(double[] dens, int n, double[] avgscores) Calculate the average payoff for the frequency of traits specified in the arraystate
for interactions in groups of sizen
.void
collectCLO
(CLOParser parser) All providers of command line options must implement this method to collect their options.Returns a string with information about the authors of the module.double
Get the cost of cooperation.int
For replicator dynamics the frequencies of all traits must sum up to one.double
Get the multiplication factor of the linear public goods game.getKey()
Returns identifier of the active module.double
Calculates and returns the maximum payoff/score of an individual.double
Calculates and returns the minimum payoff/score of an individual.double
getMonoPayoff
(int type) Calculate and return the payoff/score of individuals in monomorphic populations with traittype
.double
Get the payoff to lone cooperators.double
Get the payoff to lone defectors.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
groupScores
(int[] traitCount, double[] traitScore) Calculate the payoff/score for interactions in groups consisting of traits with respective numbers given in the arraytraitCount
.void
load()
Load new module and perform basic initializations.void
mixedScores
(int[] traitCount, int n, double[] traitScore) Calculate the average payoff/score in a finite population with the number of each trait provided incount
for interaction groups of sizen
.double
pairScores
(int me, int[] traitCount, double[] traitScore) Calculate and return total (accumulated) payoff/score for pairwise interactions of the focal individual with traitme
against opponents with different traits.void
setCostCoop
(double aValue) Set the cost of cooperation.void
setInterest
(double aValue) Set the multiplication factor of the linear public goods game.void
setPayLoneCoop
(double aValue) Set the payoff to lone cooperators.void
setPayLoneDefect
(double aValue) Set the payoff to lone defectors.Methods inherited from class Discrete
add, getMaxMonoPayoff, getMinMonoPayoff, getMonoStop, getMutation, setMonoStop, unload
Methods inherited from class Module
check, createGeometry, createIBSPop, createModel, getActiveTraits, getCompetitionGeometry, getDeathRate, getGeometry, getIBSPopulation, getID, getInteractionGeometry, 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, 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
isMultispecies, isStatic
Methods inherited from interface Features.Groups
getNGroup, isPairwise
Methods inherited from interface Features.Payoffs
getMap2Fitness, getMaxMonoPayoff, getMinMonoPayoff, isNeutral
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 IBS.HasIBS.DGroups
mixedScores
Methods inherited from interface MilestoneListener
modelDidInit, modelDidReset, modelLoaded, modelRelaxed, modelRunning, modelSettings, modelStopped, modelUnloaded, moduleLoaded, moduleRestored, moduleUnloaded
-
Field Details
-
DEFECT
public static final int DEFECTThe trait (and index) value of defectors.- See Also:
-
COOPERATE
public static final int COOPERATEThe trait (and index) value of cooperators.- See Also:
-
interest
double interestThe multiplication factor of the public good. -
cost
double costThe cost of cooperation or the individual contribution to the public good. -
payLoneCoop
double payLoneCoopThe payoff to lone cooperators. -
payLoneDefect
double payLoneDefectThe payoff to lone defectors. -
map
EcoPGG.EcoPGGMap mapThe map for translating the model data into 2D phase plane representation. -
cloInterest
Command line option to set the multiplication factor for public good interactions. -
cloCost
Command line option to set the cost of cooperation, i.e. contributions to the public good. -
cloLoneCooperator
Command line option to set the payoff to cooperators that failed to find any interaction partners. -
cloLoneDefector
Command line option to set the payoff to defectors that failed to find any interaction partners.
-
-
Constructor Details
-
EcoPGG
Create a new instance of the module for ecological public goods 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. -
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 classModule
- Returns:
- the names of the authors
-
getTitle
Description copied from interface:Features
Returns title of active module, e.g. 2x2 games inTBT
returns "2x2 Games". -
getMinPayoff
public double getMinPayoff()Description copied from interface:Features.Payoffs
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:
getMinPayoff
in interfaceFeatures.Payoffs
- Returns:
- the minimum payoff/score
- See Also:
-
getMaxPayoff
public double getMaxPayoff()Description copied from interface:Features.Payoffs
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:
getMaxPayoff
in interfaceFeatures.Payoffs
- Returns:
- the maximum payoff/score
- See Also:
-
getMonoPayoff
public double getMonoPayoff(int type) Description copied from class:Discrete
Calculate and return the payoff/score of individuals in monomorphic populations with traittype
.Note: Optional implementation. Returns
Double#NaN
if not defined or not implemented.- Overrides:
getMonoPayoff
in classDiscrete
- Parameters:
type
- the index of the trait- Returns:
- payoff/score in monomorphic population with trait
type
-
getDependent
public int getDependent()Description copied from interface:Model.HasDE
For replicator dynamics the frequencies of all traits must sum up to one. Hence, fornTraits
traits there are onlynTraits-1
degrees 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:
getDependent
in interfaceModel.HasDE
- Returns:
- the index of the dependent trait (or
-1
if there is none)
-
mixedScores
public void mixedScores(int[] traitCount, int n, double[] traitScore) Calculate the average payoff/score in a finite population with the number of each trait provided incount
for interaction groups of sizen
. The payoffs/scores for each of thenTraits
traits must be stored and returned in the arraytraitScores
.Notes:
For payoff calculations:- each trait sees one less of its own type in its environment
- the size of the environment is
nPopulation-1
- the fact that the payoff of each trait does not depend on its own type simplifies things
IBS.check()
(seeIBSMCPopulation
for an example).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 withIBS.HasIBS.DPairs.pairScores(int, int[], double[])
orIBS.HasIBS.DGroups.groupScores(int[], double[])
, respectively.Proper sampling in finite populations (c.f. CDL): \begin{align*} f_L =& \sigma\\ f_D =& \frac{\binom z{N-1}}{\binom{M-1}{N-1}}\sigma+r\frac x{M-z-1}\\ & \left(1-\frac 1{N(M-z)} \left( M-(z-N+1)\frac{\binom z{N-1}}{\binom{M-1}{N-1}}\right)\right) c\\ f_C =& f_d-F(z)c\\ F(z) =& 1-\frac rN\frac{M-N}{M-z-1}+\frac{\binom z{N-1}}{\binom{M-1}{N-1}}\\ & \left(\frac rN \frac{z+1}{M-z-1}+r\frac{M-z-2}{M-z-1}-1\right) \end{align*}
- Specified by:
mixedScores
in interfaceIBS.HasIBS.DGroups
- Parameters:
traitCount
- number of individuals for each traitn
- interaction group sizetraitScore
- array for returning the payoffs/scores of each trait
-
avgScores
public void avgScores(double[] dens, int n, double[] avgscores) Description copied from interface:Model.HasDE.DGroups
Calculate the average payoff for the frequency of traits specified in the arraystate
for interactions in groups of sizen
. The average payoffs for each of thenTraits
traits must be stored and returned in the arrayscores
.- Specified by:
avgScores
in interfaceModel.HasDE.DGroups
- Parameters:
dens
- the frequency/density of each traitn
- the size of interaction groupsavgscores
- the array for storing the average payoffs/scores of each trait
-
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 traitme
against opponents with different traits. The respective numbers of each of thenTraits
opponent traits are provided in the arraytCount
. The payoffs/scores for each of thenTraits
opponent 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:
pairScores
in interfaceIBS.HasIBS.DPairs
- 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
me
accumulated over all interactions
-
groupScores
public void groupScores(int[] traitCount, double[] traitScore) Description copied from interface:IBS.HasIBS.DGroups
Calculate the payoff/score for interactions in groups consisting of traits with respective numbers given in the arraytraitCount
. The interaction group size is given by the sum overtraitCount[i]
fori=0,1,...,nTraits
. The payoffs/scores for each of thenTraits
traits must be stored and returned in the arraytraitScore
.Important: must be overridden and implemented in subclasses that define game interactions among groups of individuals (for groups with sizes
nGroup>2
, otherwise seeIBS.HasIBS.DPairs.pairScores(int, int[], double[])
).- Specified by:
groupScores
in interfaceIBS.HasIBS.DGroups
- Parameters:
traitCount
- group composition given by the number of individuals with each traittraitScore
- array for returning the payoffs/scores of each trait
-
setCostCoop
public void setCostCoop(double aValue) Set the cost of cooperation.- Parameters:
aValue
- the cost of cooperation
-
getCostCoop
public double getCostCoop()Get the cost of cooperation.- Returns:
- the cost of cooperation
-
setInterest
public void setInterest(double aValue) Set the multiplication factor of the linear public goods game.- Parameters:
aValue
- the new multiplication factor
-
getInterest
public double getInterest()Get the multiplication factor of the linear public goods game.- Returns:
- the multiplication factor
-
setPayLoneCoop
public void setPayLoneCoop(double aValue) Set the payoff to lone cooperators. Defaults to loner payoff.- Parameters:
aValue
- the payoff to lone cooperators.
-
getPayLoneCoop
public double getPayLoneCoop()Get the payoff to lone cooperators.- Returns:
- the payoff to lone cooperators.
-
setPayLoneDefect
public void setPayLoneDefect(double aValue) Set the payoff to lone defectors. Defaults to loner payoff.- Parameters:
aValue
- the payoff to lone defectors.
-
getPayLoneDefect
public double getPayLoneDefect()Get the payoff to lone defectors.- Returns:
- the payoff to lone defectors.
-
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 classDiscrete
- Parameters:
parser
- the reference to parser that manages command line options- See Also:
-