Class NetGames.IBSPop
- Enclosing class:
NetGames
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) double
The mean fitness of individuals.(package private) double[]
The array with the mean, minimum, and maximum fitness of individuals.(package private) double
The previous generation time.Fields inherited from class IBSDPopulation
accuTypeScores, groupmodule, init, initTypeCount, module, mutation, optimizeMoran, pairmodule, strategies, strategiesScratch, strategiesTypeCount
Fields inherited from class IBSPopulation
adjustScores, competition, compGroup, debugFocal, debugModel, debugModels, debugNModels, debugSame, distrMigrants, engine, fitness, groupScores, hasLookupTable, interaction, interactions, interGroup, isMultispecies, isNeutral, logger, map2fit, maxEffScoreIdx, maxFitness, maxScore, migrationType, minFitness, minScore, nMixedInter, nPopulation, nTraits, pAddwire, playerScoreAveraged, playerScoring, pMigration, pRewire, rng, scores, smallScores, staticmodule, sumFitness, tags, typeFitness, typeScores, VACANT
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected boolean
addCandidate
(int focal, int mdl) The focal individual with indexfocal
considers acts of cooperation towards the candidate member with indexmdl
through a probabilistic comparison of their differences in fitness as well as in levels of cooperativity.boolean
checkGeometry
(Geometry geom) Provide opportunity/hook for subclasses to introduce new geometries.void
After a synchronous update step the new state must be copied back to become the current state.void
commitStrategyAt
(int index) The change of a strategy of the player atindex
is stored in a temporary variable and must be committed before proceeding.boolean
generateGeometry
(Geometry geom) Provide opportunity/hook for subclasses to introduce new geometries.protected double
getCooperativityDiff
(int focal, int mdl) Calculate the difference in cooperativity of individual indexfocal
as compared to the model individual with indexmdl
.<T> void
getFitnessData
(T[] colors, ColorMap.Gradient1D<T> cMap) Returns the fitness of all individuals in this population coded as colors in the arraycolors
using the mapcolorMap
.protected double
getFitnessDiff
(int focal, int mdl) Calculate the difference in fitness of individual with indexfocal
as compared to the model individual with indexmdl
.void
getFitnessHistogramData
(double[][] bins) Generates a histogram of the fitness distribution in this population.int
getInteractionsAt
(int idx) Gets the number of interactions of the individual with indexidx
.private <T> T
getLeafColor
(T type, ColorMap<T> cMap) Utility method to determine the color of leaves in the network.void
getMeanFitness
(double[] meanscores) Returns the mean fitness of this population in the arraymean
.void
getMeanTraits
(double[] mean) Returns the mean trait(s) of this population in the arraymean
.protected double
getProbability
(double z) Converts the differencez
into a probability following the Fermi function \[p = 1/(1+\exp(-w z)),\] where \(w\) denotes the selection strength.Gets the status of the as a formatted string.getTagNameAt
(int idx) Gets the formatted tag of the individual with indexidx
as string.<T> void
getTraitData
(T[] colors, ColorMap<T> cMap) Returns the traits of all individuals in this population coded as colors in the arraycolors
using the mapcolorMap
.getTraitNameAt
(int index) Gets the formatted name of the trait of the individual at siteindex
.boolean
haveSameStrategy
(int a, int b) Check if individuals with indexa
and indexb
have the same strategies.void
init()
Initialize the model.boolean
isSameStrategy
(int a) Check if individual with indexa
has switched strategies.boolean
parseGeometry
(Geometry geom, String arg) Provide opportunity/hook for subclasses to introduce new geometries.void
playGameSyncAt
(int idx) Update the score of individualme
.void
playGroupGameAt
(IBSGroup group) Play a group interaction with the individuals ingroup
.void
playPairGameAt
(IBSGroup group) Play a pairwise interaction with the individuals ingroup
.boolean
preferredPlayerBest
(int me, int best, int sample) For deterministic updating with multiple strategies (more than two), it must be specified which strategy is the preferred one.void
Prior to a synchronous update step the current state must be duplicated in preparation for processing the next step.protected boolean
removeCandidate
(int focal, int mdl) The focal individual with indexfocal
considers to stop acts of cooperation towards the candidate member with indexmdl
through a probabilistic comparison of their differences in fitness as well as in levels of cooperativity.void
reset()
Reset the model.void
Reset scores and fitness of all individuals to zero.void
Reset all strategies in preparation of the next update step.double
step()
Perform a single IBS step, i.e.void
swapStrategies
(int a, int b) Swap strategies of individuals with indexa
and indexb
.void
Update the mean, minimum, and maximum fitness of individuals.boolean
updatePlayerBestResponse
(int index, int[] group, int size) Best-response update.protected void
updatePlayerIndividual
(int focal) Update the focal individual with indexfocal
by probabilistically removing links from more successful and less cooperative individuals, adding links to more successful and more cooperative individuals.void
Update the scores of all individuals in the population.void
yalpGroupGameAt
(IBSGroup groupd) Counterpart ofIBSPopulation.playGroupGameAt(IBSGroup)
,IBSPopulation.playGameAt(int)
and/orIBSPopulation.playGameSyncAt(int)
.Methods inherited from class IBSDPopulation
adjustGameScoresAt, adjustPairGameScoresAt, adjustScoreAt, adjustScoreAt, becomesVacantAt, check, checkConvergence, countTraits, debugMarkChange, doAdjustScores, encodeStrategies, getFitnessAt, getInit, getInitialTraits, getMonoScore, getPopulationSize, getScoreAt, getStrategiesTypeCount, getTraits, initFrequency, initKaleidoscope, initMono, initMutant, initStripes, initTemperature, initUniform, isConsistent, isMonomorphic, isVacantAt, maybeMutateAt, maybeMutateMoran, mouseHitNode, mutateAt, resetScoreAt, restoreFitness, restoreStrategies, setInit, setInitialTraits, setOpponentPop, setScoreAt, stripGroupVacancies, stripVacancies, updateFromModelAt, updateMixedMeanScores, updatePlayerEcologyAt, updatePlayerMoranBirthDeath, updatePlayerMoranDeathBirth, updatePlayerMoranDeathBirth, updatePlayerMoranImitate, updateScoreAt, updateStrategiesTypeCount
Methods inherited from class IBSPopulation
createCompetitionGeometry, createInteractionGeometry, debugScores, debugUpdatePopulationAt, doBirthDeathMigration, doDeathBirthMigration, doDiffusionMigration, doMigration, doSyncMigration, encodeFitness, encodeGeometry, encodeInteractions, getCompetitionGeometry, getCompGroup, getFitness, getFitnessNameAt, getFitnessNameAt, getInteractionGeometry, getInterGroup, getMaxScore, getMigrationProb, getMigrationType, getMinScore, getModule, getNMean, getPlayerScoreAveraged, getPlayerScoring, getPopulationUpdate, getScoreNameAt, getScores, getSyncFraction, getTagAt, getTagData, getTags, getTotalFitness, migrateMoran, mouseHitNode, mutate, nextBinomial, pickFitFocalIndividual, pickFitFocalIndividual, pickFitNeighborAt, pickFitNeighborAt, pickFocalIndividual, pickFocalIndividual, pickFocalSite, pickFocalSite, pickNeighborSiteAt, playGameAt, processScore, random01, random01d, random0n, random0N, randomGaussian, removeScoreAt, removeScoreAt, restoreGeometry, restoreInteractions, setAddwire, setConsistencyCheck, setMaxEffScoreIdx, setMigrationProb, setMigrationType, setPlayerScoreAveraged, setPlayerScoring, setPopulationUpdate, setRewire, setSyncFraction, setTagAt, srandom, swapScoresAt, updateEffScoreRange, updateFitnessAt, updateMinMaxScores, updatePlayerAsync, updatePlayerAsyncAt, updatePlayerAt, updatePlayerBest, updatePlayerBestHalf, updatePlayerEcology, updatePlayerMoranBirthDeathAt, updatePlayerMoranDeathBirthAt, updatePlayerMoranImitateAt, updatePlayerSwap, updateProportionalAbs, updateReplicatorHalf, updateReplicatorPlus, updateScoreAt, updateScoreAt, updateThermal
-
Field Details
-
prevgen
double prevgenThe previous generation time. -
meanPerformance
double meanPerformanceThe mean fitness of individuals. -
performance
double[] performanceThe array with the mean, minimum, and maximum fitness of individuals.
-
-
Constructor Details
-
IBSPop
Create a new instance of the IBS model for cooperative actions on dynamical networks.- Parameters:
engine
- the pacemaker for running the modelmodule
- the module that defines the game
-
-
Method Details
-
reset
public void reset()Description copied from class:IBSDPopulation
Reset the model. All parameters must be consistent at this point. Allocate memory and initialize the interaction and competition structures. If structures include random elements, e.g. random regular graphs, a new structure is generated. Generate initial configuration. Subclasses must override this method to allocate memory for the strategies and call super.Allocates memory for optimized Moran process.
Discussions/extensions
groupScores
unused in IBSDPopulation. Merge withtraitScore
?- Overrides:
reset
in classIBSDPopulation
- See Also:
-
init
public void init()Description copied from class:IBSPopulation
Initialize the model. All parameters must be consistent. Subclasses must override this method to generate the initial strategy configuration and call super.Note: Initialization leaves the interaction and competition structures untouched
- Overrides:
init
in classIBSDPopulation
- See Also:
-
getStatus
Description copied from class:IBSPopulation
Gets the status of the as a formatted string. This is typically used in the GUI to summarize the progress of the model.- Overrides:
getStatus
in classIBSDPopulation
- Returns:
- the status of the population
-
step
public double step()Description copied from class:IBSPopulation
Perform a single IBS step, i.e. update one individual for asynchronous updates or once the entire population for synchronous updates.Discussions/extensions
- Review migration. Exclusively used in Demes2x2. Should probably be treated as an independent event, in particular independent of population or player updates
- Implement Wright-Fisher update.
- How to scale realtime with multiple populations? How to define a generation if population sizes can vary?
IBSPopulation.updatePlayerEcology()
returns time increment in realtime units. Everyone else does fine without...
- Overrides:
step
in classIBSPopulation
- Returns:
- the elapsed time in realtime units
-
updatePlayerIndividual
protected void updatePlayerIndividual(int focal) Update the focal individual with indexfocal
by probabilistically- removing links from more successful and less cooperative individuals,
- adding links to more successful and more cooperative individuals.
- Parameters:
focal
- the index of the individual to be updated- See Also:
-
addCandidate
protected boolean addCandidate(int focal, int mdl) The focal individual with indexfocal
considers acts of cooperation towards the candidate member with indexmdl
through a probabilistic comparison of their differences in fitness as well as in levels of cooperativity. Links are more likely established to more successful and more cooperative individuals.- Parameters:
focal
- the index of the focal individualmdl
- the index of the candidate member- Returns:
true
to establish the direct link fromfocal
tomdl
- See Also:
-
removeCandidate
protected boolean removeCandidate(int focal, int mdl) The focal individual with indexfocal
considers to stop acts of cooperation towards the candidate member with indexmdl
through a probabilistic comparison of their differences in fitness as well as in levels of cooperativity. Links to more successful and less cooperative individuals are more likely removed.- Parameters:
focal
- the index of the focal individualmdl
- the index of the candidate member- Returns:
true
to remove the direct link fromfocal
tomdl
-
getFitnessDiff
protected double getFitnessDiff(int focal, int mdl) Calculate the difference in fitness of individual with indexfocal
as compared to the model individual with indexmdl
. The fitness difference is normalized to[-1,1]
where negative differences refer to models that do worse and positive ones to models that perform better.- Parameters:
focal
- the index of the focal individualmdl
- the index of the candidate member- Returns:
- the normalized difference in fitness
-
getCooperativityDiff
protected double getCooperativityDiff(int focal, int mdl) Calculate the difference in cooperativity of individual indexfocal
as compared to the model individual with indexmdl
. The cooperativity difference is normalized to[-1,1]
where negative differences refer to models that are less cooperative and positive ones to models that are more cooperative.- Parameters:
focal
- the index of the focal individualmdl
- the index of the candidate member- Returns:
- the normalized difference in cooperativity
-
getProbability
protected double getProbability(double z) Converts the differencez
into a probability following the Fermi function \[p = 1/(1+\exp(-w z)),\] where \(w\) denotes the selection strength.- Parameters:
z
- the difference to convert into a probability- Returns:
- the probability
-
updateFitnessMean
public void updateFitnessMean()Update the mean, minimum, and maximum fitness of individuals. -
getMeanTraits
public void getMeanTraits(double[] mean) Description copied from class:IBSPopulation
Returns the mean trait(s) of this population in the arraymean
. Used by GUI to visualize the current state of this IBS model.- Overrides:
getMeanTraits
in classIBSDPopulation
- Parameters:
mean
- the array for returning the trait values- See Also:
-
getMeanFitness
public void getMeanFitness(double[] meanscores) Description copied from class:IBSPopulation
Returns the mean fitness of this population in the arraymean
. Used by GUI to visualize the current state of this IBS model. Returnstrue
if data point belongs to the same time series andfalse
if a new series was started throughIBSPopulation.init()
orIBSPopulation.reset()
.- Overrides:
getMeanFitness
in classIBSDPopulation
- Parameters:
meanscores
- the array for storing the mean fitness values- See Also:
-
getFitnessData
Description copied from class:IBSPopulation
Returns the fitness of all individuals in this population coded as colors in the arraycolors
using the mapcolorMap
. Used by GUI to visualize the current state of this IBS model. Colors are coded in different data types<T>
depending on the runtime environment (GWT or JRE) as well as the graph (e.g.PopGraph2D
orPopGraph3D
).- Overrides:
getFitnessData
in classIBSPopulation
- Type Parameters:
T
- the type of color data (String
orMeshLambertMaterial
for GWT andColor
for JRE).- Parameters:
colors
- the array where the colors of all nodes are storedcMap
- the map that converts traits into colors
-
getLeafColor
Utility method to determine the color of leaves in the network.- Type Parameters:
T
- the type parameter of the color- Parameters:
type
- the type of color to usecMap
- the color map to use- Returns:
- the color of the leaf with type
T
-
getFitnessHistogramData
public void getFitnessHistogramData(double[][] bins) Description copied from class:IBSPopulation
Generates a histogram of the fitness distribution in this population. The result is returned in the arraybins
.Notes:
bins
is a 2D array because discrete models generate histograms for each trait separately.- By default generate a histogram of the scores in
bins[0]
. - Consider moving to
IBSDPopulation
andIBSCPopulation
with argumentsbins[][]
andbins[]
, respectively.
- Overrides:
getFitnessHistogramData
in classIBSDPopulation
- Parameters:
bins
- the 2D array to store the histogram(s)
-
parseGeometry
Description copied from class:IBSPopulation
Provide opportunity/hook for subclasses to introduce new geometries.- Overrides:
parseGeometry
in classIBSPopulation
- Parameters:
geom
- the current empty/uninitialized geometryarg
- the commandline argument- Returns:
true
if parsing was successful- See Also:
-
checkGeometry
Description copied from class:IBSPopulation
Provide opportunity/hook for subclasses to introduce new geometries.- Overrides:
checkGeometry
in classIBSPopulation
- Parameters:
geom
- the geometry to check- Returns:
true
if checks were successful- See Also:
-
generateGeometry
Description copied from class:IBSPopulation
Provide opportunity/hook for subclasses to introduce new geometries.- Overrides:
generateGeometry
in classIBSPopulation
- Parameters:
geom
- the geometry to initialize- Returns:
true
if generation of structure was successful- See Also:
-
resetScores
public void resetScores()Description copied from class:IBSPopulation
Reset scores and fitness of all individuals to zero.- Overrides:
resetScores
in classIBSDPopulation
-
updateScores
public void updateScores()Description copied from class:IBSDPopulation
Update the scores of all individuals in the population.Note: Overridden to set scores in well-mixed populations more efficiently.
- Overrides:
updateScores
in classIBSDPopulation
-
resetStrategies
public void resetStrategies()Description copied from class:IBSDPopulation
Reset all strategies in preparation of the next update step. Simply an opportunity for customizations in subclasses.Reset the colors of recently changed strategies.
- Overrides:
resetStrategies
in classIBSDPopulation
-
prepareStrategies
public void prepareStrategies()Description copied from class:IBSPopulation
Prior to a synchronous update step the current state must be duplicated in preparation for processing the next step.- Overrides:
prepareStrategies
in classIBSDPopulation
- See Also:
-
commitStrategies
public void commitStrategies()Description copied from class:IBSDPopulation
After a synchronous update step the new state must be copied back to become the current state.For discrete modules, update the strategy count of each type and check if population reached a homogeneous state.
- Overrides:
commitStrategies
in classIBSDPopulation
- See Also:
-
commitStrategyAt
public void commitStrategyAt(int index) Description copied from class:IBSPopulation
The change of a strategy of the player atindex
is stored in a temporary variable and must be committed before proceeding.- Overrides:
commitStrategyAt
in classIBSDPopulation
- Parameters:
index
- the index of the player that needs to have its new strategy committed
-
haveSameStrategy
public boolean haveSameStrategy(int a, int b) Description copied from class:IBSPopulation
Check if individuals with indexa
and indexb
have the same strategies.- Overrides:
haveSameStrategy
in classIBSDPopulation
- Parameters:
a
- the index of first individualb
- the index of second individual- Returns:
true
if the two individuals have the same strategies
-
isSameStrategy
public boolean isSameStrategy(int a) Description copied from class:IBSPopulation
Check if individual with indexa
has switched strategies.Note: this test is only meaningful before strategy gets committed.
- Overrides:
isSameStrategy
in classIBSDPopulation
- Parameters:
a
- index of individual- Returns:
true
if strategy remained the same- See Also:
-
swapStrategies
public void swapStrategies(int a, int b) Description copied from class:IBSPopulation
Swap strategies of individuals with indexa
and indexb
.Note: the strategies still need to be committed.
- Overrides:
swapStrategies
in classIBSDPopulation
- Parameters:
a
- the index of first individualb
- the index of second individual- See Also:
-
playPairGameAt
Description copied from class:IBSPopulation
Play a pairwise interaction with the individuals ingroup
.- Overrides:
playPairGameAt
in classIBSDPopulation
- Parameters:
group
- the group of individuals interacting in pairs
-
playGroupGameAt
Description copied from class:IBSPopulation
Play a group interaction with the individuals ingroup
.- Overrides:
playGroupGameAt
in classIBSDPopulation
- Parameters:
group
- the group of interacting individuals
-
playGameSyncAt
public void playGameSyncAt(int idx) Description copied from class:IBSPopulation
Update the score of individualme
.After initialization and for synchronized population updating this method is invoked (rather than
IBSPopulation.playGameAt(int)
). The synchronous flag simply indicates that all players are going to be updated. For directed graphs this implies that incoming and outgoing links do not need to be treated separately because every outgoing link corresponds to an incoming link of another node.- Overrides:
playGameSyncAt
in classIBSPopulation
- Parameters:
idx
- the index of the focal individual
-
yalpGroupGameAt
Description copied from class:IBSPopulation
Counterpart ofIBSPopulation.playGroupGameAt(IBSGroup)
,IBSPopulation.playGameAt(int)
and/orIBSPopulation.playGameSyncAt(int)
. Removes the payoffs of group interactions.- Overrides:
yalpGroupGameAt
in classIBSDPopulation
- Parameters:
groupd
- the interaction group
-
updatePlayerBestResponse
public boolean updatePlayerBestResponse(int index, int[] group, int size) Description copied from class:IBSDPopulation
Best-response update.Important:
- The array
group
is untouchable because it may refer to the population structure. Any change would also permanently change the structure. - The best-response update must be implemented in subclasses that override this method. By default throws an error.
- Instead of overriding the method, subclasses may remove
PlayerUpdate.Type.BEST_RESPONSE
fromPlayerUpdate#clo
.
Note: Takes composition of entire population into account for
Geometry.Type#MEANFIELD
but only the reference neighborhood in structured populations.- Overrides:
updatePlayerBestResponse
in classIBSDPopulation
- Parameters:
index
- the index of individual to updategroup
- the array with indices of reference groupsize
- the size of the reference group- Returns:
true
if strategy changed (signaling score needs to be reset)
- The array
-
preferredPlayerBest
public boolean preferredPlayerBest(int me, int best, int sample) Description copied from class:IBSDPopulation
For deterministic updating with multiple strategies (more than two), it must be specified which strategy is the preferred one.Summary: does 'me' prefer 'sample' over 'best'?
Here we introduce the convention of a cyclic preference where strategies with lower indices are always preferred. For example, with
N
strategic types, strategy0
preferred over1
preferred over2
... preferred overN-1
preferred overN
preferred over0
, etc. This convention is arbitrary but seems to make sense for systems with cyclic dominance of strategies and such systems are most likely to produce evolutionary kaleidoscopes and only for those is this deterministic updating of crucial importance. For anything else, these are irrelevant quibbles.- Overrides:
preferredPlayerBest
in classIBSDPopulation
- Parameters:
me
- the index of the focal individualbest
- the index of the best performing individualsample
- the index of the sample type- Returns:
true
ifsample
is preferred overbest
-
getTraitNameAt
Description copied from class:IBSPopulation
Gets the formatted name of the trait of the individual at siteindex
.- Overrides:
getTraitNameAt
in classIBSDPopulation
- Parameters:
index
- the index of the- Returns:
- the string describing the trait
-
getInteractionsAt
public int getInteractionsAt(int idx) Description copied from class:IBSPopulation
Gets the number of interactions of the individual with indexidx
. Returns-1
if siteidx
is vacant or fitness is static, i.e. not based on interactions.- Overrides:
getInteractionsAt
in classIBSPopulation
- Parameters:
idx
- the index of the individual- Returns:
- the number of interactions
-
getTagNameAt
Description copied from class:IBSPopulation
Gets the formatted tag of the individual with indexidx
as string.- Overrides:
getTagNameAt
in classIBSPopulation
- Parameters:
idx
- the index of the individual- Returns:
- the tag as a string
-
getTraitData
Returns the traits of all individuals in this population coded as colors in the arraycolors
using the mapcolorMap
. Used by GUI to visualize the current state of this IBS model. Colors are coded in different data types<T>
depending on the runtime environment (GWT or JRE) as well as the graph (e.g.PopGraph2D
orPopGraph3D
).Note: with the help of
engine
(seeEvoLudoGWT
andEvoLudoJRE
) the color specifics of GWT and JRE are shielded from interfering with shared code. Some careful checks and casts are needed to ensure the correct color map is used while preventing re-allocation of the custom color gradients.- Overrides:
getTraitData
in classIBSDPopulation
- Type Parameters:
T
- the type of color data (String
orMeshLambertMaterial
for GWT andColor
for JRE).- Parameters:
colors
- the array where the colors of all nodes are storedcMap
- the map that converts traits into colors
-