Class NetGames.IBSPop
- Enclosing class:
NetGames
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) doubleThe mean fitness of individuals.(package private) double[]The array with the mean, minimum, and maximum fitness of individuals.(package private) doubleThe previous generation time.Fields inherited from class IBSDPopulation
accuTypeScores, active, groupmodule, init, initCount, module, mutation, opponent, optimizeMoran, pairmodule, traitsCount, traitsNextFields 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 booleanaddCandidate(int focal, int mdl) The focal individual with indexfocalconsiders acts of cooperation towards the candidate member with indexmdlthrough a probabilistic comparison of their differences in fitness as well as in levels of cooperativity.booleancheckGeometry(Geometry geom) Provide opportunity/hook for subclasses to introduce new geometries.voidcommitTraitAt(int index) The change of a trait of the player atindexis stored in a temporary variable and must be committed before proceeding.voidAfter a synchronous update step the new state must be copied back to become the current state.booleangenerateGeometry(Geometry geom) Provide opportunity/hook for subclasses to introduce new geometries.protected doublegetCooperativityDiff(int focal, int mdl) Calculate the difference in cooperativity of individual indexfocalas compared to the model individual with indexmdl.<T> voidgetFitnessData(T[] colors, ColorMap.Gradient1D<T> cMap) Returns the fitness of all individuals in this population coded as colors in the arraycolorsusing the mapcolorMap.protected doublegetFitnessDiff(int focal, int mdl) Calculate the difference in fitness of individual with indexfocalas compared to the model individual with indexmdl.voidgetFitnessHistogramData(double[][] bins) Generates a histogram of the fitness distribution in this population.intgetInteractionsAt(int idx) Gets the number of interactions of the individual with indexidx.private <T> TgetLeafColor(T type, ColorMap<T> cMap) Utility method to determine the color of leaves in the network.voidgetMeanFitness(double[] meanscores) Returns the mean fitness of this population in the arraymean.voidgetMeanTraits(double[] mean) Returns the mean trait(s) of this population in the arraymean.protected doublegetProbability(double z) Converts the differencezinto 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 indexidxas string.<T> voidgetTraitData(T[] colors, ColorMap<T> cMap) Returns the traits of all individuals in this population coded as colors in the arraycolorsusing the mapcolorMap.getTraitNameAt(int index) Gets the formatted name of the trait of the individual at siteindex.booleanhaveSameTrait(int a, int b) Check if individuals with indexaand indexbhave the same traits.voidinit()Initialize the model.booleanisSameTrait(int a) Check if individual with indexahas switched traits.booleanparseGeometry(Geometry geom, String arg) Provide opportunity/hook for subclasses to introduce new geometries.voidplayGameSyncAt(int idx) Update the score of individualme.voidplayGroupGameAt(IBSGroup group) Play a group interaction with the individuals ingroup.voidplayPairGameAt(IBSGroup group) Play a pairwise interaction with the individuals ingroup.booleanpreferredPlayerBest(int me, int best, int sample) For deterministic updating with multiple traits (more than two), it must be specified which trait is the preferred one.voidPrior to a synchronous update step the current state must be duplicated in preparation for processing the next step.protected booleanremoveCandidate(int focal, int mdl) The focal individual with indexfocalconsiders to stop acts of cooperation towards the candidate member with indexmdlthrough a probabilistic comparison of their differences in fitness as well as in levels of cooperativity.voidreset()Reset the model.voidReset scores and fitness of all individuals to zero.voidReset all traits in preparation of the next update step.intstep()Perform a single IBS step, i.e.voidswapTraits(int a, int b) Swap traits of individuals with indexaand indexb.voidUpdate the mean, minimum, and maximum fitness of individuals.booleanupdatePlayerBestResponse(int index, int[] group, int size) Best-response update.protected voidupdatePlayerIndividual(int focal) Update the focal individual with indexfocalby probabilistically removing links from more successful and less cooperative individuals, adding links to more successful and more cooperative individuals.voidUpdate the scores of all individuals in the population.voidyalpGroupGameAt(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, encodeTraits, getFitnessAt, getInit, getInitialTraits, getMonoScore, getPopulationSize, getScoreAt, getTraitAt, getTraits, getTraitsCount, initFrequency, initKaleidoscope, initMono, initMono, initMono, initMutant, initStripes, initTemperature, initUniform, isConsistent, isMonomorphic, isVacantAt, maybeMutateAt, maybeMutateMoran, mouseHitNode, mutateAt, resetScoreAt, restoreFitness, restoreTraits, setInit, setInitialTraits, setNextTraitAt, setOpponentPop, setScoreAt, setTraitAt, stripGroupVacancies, stripVacancies, updateFromModelAt, updateMixedMeanScores, updatePlayerEcologyAt, updatePlayerMoranBirthDeath, updatePlayerMoranDeathBirth, updatePlayerMoranDeathBirth, updatePlayerMoranImitate, updateScoreAt, updateTraitCountMethods 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, getSpeciesUpdateRate, 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, 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:IBSDPopulationReset 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 trait and call super.Allocates memory for optimized Moran process.
Discussions/extensions
groupScoresunused in IBSDPopulation. Merge withtraitScore?- Overrides:
resetin classIBSDPopulation- See Also:
-
init
public void init()Description copied from class:IBSPopulationInitialize the model. All parameters must be consistent. Subclasses must override this method to generate the initial trait configuration and call super.Note: Initialization leaves the interaction and competition structures untouched
- Overrides:
initin classIBSDPopulation- See Also:
-
getStatus
Description copied from class:IBSPopulationGets the status of the as a formatted string. This is typically used in the GUI to summarize the progress of the model.- Overrides:
getStatusin classIBSDPopulation- Returns:
- the status of the population
-
step
public int step()Description copied from class:IBSPopulationPerform 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:
stepin classIBSPopulation- Returns:
- the number of elapsed realtime units
-
updatePlayerIndividual
protected void updatePlayerIndividual(int focal) Update the focal individual with indexfocalby 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 indexfocalconsiders acts of cooperation towards the candidate member with indexmdlthrough 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:
trueto establish the direct link fromfocaltomdl- See Also:
-
removeCandidate
protected boolean removeCandidate(int focal, int mdl) The focal individual with indexfocalconsiders to stop acts of cooperation towards the candidate member with indexmdlthrough 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:
trueto remove the direct link fromfocaltomdl
-
getFitnessDiff
protected double getFitnessDiff(int focal, int mdl) Calculate the difference in fitness of individual with indexfocalas 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 indexfocalas 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 differencezinto 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:IBSPopulationReturns the mean trait(s) of this population in the arraymean. Used by GUI to visualize the current state of this IBS model.- Overrides:
getMeanTraitsin classIBSDPopulation- Parameters:
mean- the array for returning the trait values- See Also:
-
getMeanFitness
public void getMeanFitness(double[] meanscores) Description copied from class:IBSPopulationReturns the mean fitness of this population in the arraymean. Used by GUI to visualize the current state of this IBS model. Returnstrueif data point belongs to the same time series andfalseif a new series was started throughIBSPopulation.init()orIBSPopulation.reset().- Overrides:
getMeanFitnessin classIBSDPopulation- Parameters:
meanscores- the array for storing the mean fitness values- See Also:
-
getFitnessData
Description copied from class:IBSPopulationReturns the fitness of all individuals in this population coded as colors in the arraycolorsusing 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.PopGraph2DorPopGraph3D).- Overrides:
getFitnessDatain classIBSPopulation- Type Parameters:
T- the type of color data (StringorMeshLambertMaterialfor GWT andColorfor 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:IBSPopulationGenerates a histogram of the fitness distribution in this population. The result is returned in the arraybins.Notes:
binsis 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
IBSDPopulationandIBSCPopulationwith argumentsbins[][]andbins[], respectively.
- Overrides:
getFitnessHistogramDatain classIBSDPopulation- Parameters:
bins- the 2D array to store the histogram(s)
-
parseGeometry
Description copied from class:IBSPopulationProvide opportunity/hook for subclasses to introduce new geometries.- Overrides:
parseGeometryin classIBSPopulation- Parameters:
geom- the current empty/uninitialized geometryarg- the commandline argument- Returns:
trueif parsing was successful- See Also:
-
checkGeometry
Description copied from class:IBSPopulationProvide opportunity/hook for subclasses to introduce new geometries.- Overrides:
checkGeometryin classIBSPopulation- Parameters:
geom- the geometry to check- Returns:
trueif checks were successful- See Also:
-
generateGeometry
Description copied from class:IBSPopulationProvide opportunity/hook for subclasses to introduce new geometries.- Overrides:
generateGeometryin classIBSPopulation- Parameters:
geom- the geometry to initialize- Returns:
trueif generation of structure was successful- See Also:
-
resetScores
public void resetScores()Description copied from class:IBSPopulationReset scores and fitness of all individuals to zero.- Overrides:
resetScoresin classIBSDPopulation
-
updateScores
public void updateScores()Description copied from class:IBSDPopulationUpdate the scores of all individuals in the population.Note: Overridden to set scores in well-mixed populations more efficiently.
- Overrides:
updateScoresin classIBSDPopulation
-
resetTraits
public void resetTraits()Description copied from class:IBSDPopulationReset all traits in preparation of the next update step. Simply an opportunity for customizations in subclasses.Reset the colors of recently changed trait.
- Overrides:
resetTraitsin classIBSDPopulation
-
prepareTraits
public void prepareTraits()Description copied from class:IBSPopulationPrior to a synchronous update step the current state must be duplicated in preparation for processing the next step.- Overrides:
prepareTraitsin classIBSDPopulation- See Also:
-
commitTraits
public void commitTraits()Description copied from class:IBSDPopulationAfter a synchronous update step the new state must be copied back to become the current state.For discrete modules, update the trait count of each type and check if population reached a homogeneous state.
- Overrides:
commitTraitsin classIBSDPopulation- See Also:
-
commitTraitAt
public void commitTraitAt(int index) Description copied from class:IBSPopulationThe change of a trait of the player atindexis stored in a temporary variable and must be committed before proceeding.- Overrides:
commitTraitAtin classIBSDPopulation- Parameters:
index- the index of the player that needs to have its new trait committed
-
haveSameTrait
public boolean haveSameTrait(int a, int b) Description copied from class:IBSPopulationCheck if individuals with indexaand indexbhave the same traits.- Overrides:
haveSameTraitin classIBSDPopulation- Parameters:
a- the index of first individualb- the index of second individual- Returns:
trueif the two individuals have the same traits
-
isSameTrait
public boolean isSameTrait(int a) Description copied from class:IBSPopulationCheck if individual with indexahas switched traits.Note: this test is only meaningful before trait are committed.
- Overrides:
isSameTraitin classIBSDPopulation- Parameters:
a- index of individual- Returns:
trueif trait remained unchanged- See Also:
-
swapTraits
public void swapTraits(int a, int b) Description copied from class:IBSPopulationSwap traits of individuals with indexaand indexb.Note: the traits still need to be committed.
- Overrides:
swapTraitsin classIBSDPopulation- Parameters:
a- the index of first individualb- the index of second individual- See Also:
-
playPairGameAt
Description copied from class:IBSPopulationPlay a pairwise interaction with the individuals ingroup.- Overrides:
playPairGameAtin classIBSDPopulation- Parameters:
group- the group of individuals interacting in pairs
-
playGroupGameAt
Description copied from class:IBSPopulationPlay a group interaction with the individuals ingroup.- Overrides:
playGroupGameAtin classIBSDPopulation- Parameters:
group- the group of interacting individuals
-
playGameSyncAt
public void playGameSyncAt(int idx) Description copied from class:IBSPopulationUpdate 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:
playGameSyncAtin classIBSPopulation- Parameters:
idx- the index of the focal individual
-
yalpGroupGameAt
Description copied from class:IBSPopulationCounterpart ofIBSPopulation.playGroupGameAt(IBSGroup),IBSPopulation.playGameAt(int)and/orIBSPopulation.playGameSyncAt(int). Removes the payoffs of group interactions.- Overrides:
yalpGroupGameAtin classIBSDPopulation- Parameters:
groupd- the interaction group
-
updatePlayerBestResponse
public boolean updatePlayerBestResponse(int index, int[] group, int size) Description copied from class:IBSDPopulationBest-response update.Important:
- The array
groupis 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_RESPONSEfromPlayerUpdate#clo.
Note: Takes composition of entire population into account for
Geometry.Type#MEANFIELDbut only the reference neighborhood in structured populations.- Overrides:
updatePlayerBestResponsein classIBSDPopulation- Parameters:
index- the index of individual to updategroup- the array with indices of reference groupsize- the size of the reference group- Returns:
trueif trait changed (signaling score needs to be reset)
- The array
-
preferredPlayerBest
public boolean preferredPlayerBest(int me, int best, int sample) Description copied from class:IBSDPopulationFor deterministic updating with multiple traits (more than two), it must be specified which trait is the preferred one.Summary: does 'me' prefer 'sample' over 'best'?
Here we introduce the convention of a cyclic preference where traits with lower indices are always preferred. For example, with
Ntraits, trait0is preferred over1preferred over2... preferred overN-1preferred overNpreferred over0, etc. This convention is arbitrary but makes sense for systems with cyclic dominance of traits 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:
preferredPlayerBestin classIBSDPopulation- Parameters:
me- the index of the focal individualbest- the index of the best performing individualsample- the index of the sample type- Returns:
trueifsampleis preferred overbest
-
getTraitNameAt
Description copied from class:IBSPopulationGets the formatted name of the trait of the individual at siteindex.- Overrides:
getTraitNameAtin classIBSDPopulation- Parameters:
index- the index of the- Returns:
- the string describing the trait
-
getInteractionsAt
public int getInteractionsAt(int idx) Description copied from class:IBSPopulationGets the number of interactions of the individual with indexidx. Returns-1if siteidxis vacant or fitness is static, i.e. not based on interactions.- Overrides:
getInteractionsAtin classIBSPopulation- Parameters:
idx- the index of the individual- Returns:
- the number of interactions
-
getTagNameAt
Description copied from class:IBSPopulationGets the formatted tag of the individual with indexidxas string.- Overrides:
getTagNameAtin 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 arraycolorsusing 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.PopGraph2DorPopGraph3D).Note: with the help of
engine(seeEvoLudoGWTandEvoLudoJRE) 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:
getTraitDatain classIBSDPopulation- Type Parameters:
T- the type of color data (StringorMeshLambertMaterialfor GWT andColorfor JRE).- Parameters:
colors- the array where the colors of all nodes are storedcMap- the map that converts traits into colors
-