Class IBS
- All Implemented Interfaces:
CLOProvider
- Author:
- Christoph Hauert
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumEnumeration of possible events in focal population.static interfaceModules that offer individual based simulation models must implement this interface.static enumTypes of species updates (only relevant for multi-species models): none no migration D diffusive migration (exchange of neighbors) B birth-death migration (fit migrates, random death). d death-birth migration (random death, fit migrates).static enumSchedules for resetting individual payoffs/fitness: onchange Reset when changing trait (only after updating from reference model with a different trait) onupdate Reset when updating from reference individual (not necessarily a change in trait) ephemeral Determine payoffs/fitness calculated only for updatingstatic classThe class managing the settings for statistics mode.Nested classes/interfaces inherited from class Model
Model.HasDE -
Field Summary
FieldsModifier and TypeFieldDescriptionfinal CLOptionCommand line option to set whether player scores from interactions are accumulated or averaged (default).final CLOptionCommand line option to enable consistency checks.final CLOptionCommand line option to set the fraction of links to add.final CLOptionCommand line option to set the competition geometry.final CLOptionCommand line option to set the interaction geometry.final CLOptionCommand line option to set the fraction of links to rewire.final CLOptionCommand line option to set whether players interact with all their neighbours or a random subsample.final CLOptionCommand line option to set the migration types and probabilities of players.final CLOptionCommand line option to set the method for choosing references/models among the neighbours of a player for updating their trait.final CLOptionCommand line option to set method for resetting the scores of individuals.(package private) IBSPopulationPointer to focal species for debugging.protected RNGDistribution.GeometricGeometric (exponential) waiting time distribution for optimizations of homogeneous populations.protected RNGDistributionThe random number generator to display states with ephemeral payoffs.(package private) booleanFlag to indicate whether the population updates are synchronous.private intIndex for turn-based-selection to determine which species to pick next.booleantrueif optimizations for homogeneous populations requested.protected IBSPopulationShort-cut tospecies.get(0).getIBSPopulation()for single species models;nullin multi-species models.protected doubleKeeps track of the elapsed time, taking into account the fitness of the population.Type of species update (multi-species models only).(package private) IBS.StatisticsThe settings for statistics mode.Fields inherited from class Model
cloSamples, cloTimeRelax, cloTimeStep, cloTimeStop, connect, converged, engine, fixData, isMultispecies, isRelaxing, logger, mode, nSamples, nSpecies, nStatisticsFailed, nStatisticsSamples, rng, species, statisticsSampleNew, time, timeRelax, timeStep, timeStop, type -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleancheck()Check consistency of parameters and adjust if necessary (and possible).voidcollectCLO(CLOParser parser) All providers of command line options must implement this method to collect their options.voidPerform single debug step in models that allow it.voidencodeState(StringBuilder plist) Encode the state of the model in aplistinspiredXMLstring.Gets a formatted string summarizing the elapsed time.<T> voidgetFitnessData(int id, T[] colors, ColorMap.Gradient1D<T> colorMap) Translates fitness data into colors using ColorMapcolorMap.voidgetFitnessHistogramData(int id, double[][] bins) Generates a histogram of fitness data and returns the result in the provided arraybins.getFitnessNameAt(int id, int idx) Gets the fitness at locationidxfor species with IDidas a formatted string.(package private) IBSPopulationgetIBSPopulation(int id) Helper routine to retrieve theIBSPopulationassociated with module withid.intgetInteractionsAt(int id, int idx) Gets the number of interactions at locationidxfor species with IDid.doublegetMaxFitness(int id) Calculates and returns the absolute fitness maximum.doublegetMaxScore(int id) Returns the maximum score that individuals of species with IDidcan achieve in this model.booleangetMeanFitness(double[] mean) Gets the mean fitness values for traits in all species.booleangetMeanFitness(int id, double[] mean) Gets the mean fitness values for species with IDid.booleangetMeanTraits(double[] mean) Collect and return mean trait values for all species.booleangetMeanTraits(int id, double[] mean) Return mean trait values for species with IDid.doublegetMinFitness(int id) Calculates and returns the absolute fitness minimum.doublegetMinScore(int id) Returns the minimum score that individuals of species with IDidcan achieve in this model.intgetNMean()Return the number of mean values for this model including all species (for traits or fitness).intgetNMean(int id) Return the number of mean trait values for species with IDid.doubleGets the elapsed time in real time units.getScoreNameAt(int id, int idx) Gets the score at locationidxfor species with IDidas a formatted string.Get species update type.Returns status message from model.getTagNameAt(int id, int idx) Gets formatted tag of individual at locationidxfor species with IDid.<T> voidgetTraitData(int id, T[] colors, ColorMap<T> colorMap) Gets the trait data for species with IDidand translates them into colors using thecolorMap.getTraitNameAt(int id, int idx) Gets the formatted trait names at locationidxfor species with IDid.booleanibsStep(double stepDt) Advances the IBS model by a step of sizestepDt.voidinit()Milestone: Initialize this modelvoidinit(boolean soft) Initializes the IBS model.voidload()Milestone: Load this model and allocate resources (if applicable).booleanmouseHitNode(int id, int hit, boolean alt) Used by GUI to interact with Model.booleannext()Advance model by one step.booleanChecks if debugging single steps is supported.booleanCheck if the current model settings permit sample statistics.booleanCheck if the current model settings permit update statistics.protected IBS.EventpickEvent(IBSPopulation pop) Pick type of next event in focal population.Pick focal population according to the selected scheme.private IBSPopulationpickFocalSpecies(double[] rates, double total) Pick focal species with a probability proportional to the entries inrates.private IBSPopulationpickFocalSpecies(int skip) Pick next focal species.doublerandom01()Random number from interval [0, 1) with 32bit resolution.intrandom0n(int n) random integer number from interval[0, n).voidreset()Milestone: Reset this modelbooleanrestoreState(Plist plist) Restore the state encoded in theplistinspiredmapofkey, value-pairs.voidunload()Milestone: Unload this model and free resources (if applicable).voidupdate()Update this model.Methods inherited from class Model
getFixationData, getLogger, getMeanFitnessAt, getMeanName, getMeanNames, getMeanTraitAt, getMode, getNextHalt, getNSamples, getNSpecies, getNStatisticsFailed, getNStatisticsSamples, getSpecies, getTime, getTimeRelax, getTimeStep, getTimeStop, getType, hasConverged, initStatisticsFailed, initStatisticsSample, isConnected, isContinuous, isDensity, isRelaxing, isTimeReversed, permitsMode, permitsTimeReversal, readStatisticsSample, relax, requestMode, resetStatisticsSample, setMode, setNSamples, setTimeRelax, setTimeReversed, setTimeStep, setTimeStop, useSchedulingMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface CLOProvider
adjustCLO
-
Field Details
-
ephrng
The random number generator to display states with ephemeral payoffs. In order to ensure reproducibility of results this cannot be the same random number generator as for running the simulations.- See Also:
-
distrMutation
Geometric (exponential) waiting time distribution for optimizations of homogeneous populations.- See Also:
-
population
Short-cut tospecies.get(0).getIBSPopulation()for single species models;nullin multi-species models. Convenience field. -
realtime
protected double realtimeKeeps track of the elapsed time, taking into account the fitness of the population. For example, less time passes between reproductive events in populations with high fitness, while more time passes in low fitness populations because there are fewer reproduction events per unit time. If individual scores can be negativerealtimeis set toDouble#POSITIVE_INFINITYto indicate that the measure is meaningless.Note: Requires non-negative individual scores.
-
optimizeHomo
public boolean optimizeHomotrueif optimizations for homogeneous populations requested.Note:
- optimizations can be requested with the command line option
--optimize, seeIBSD.cloOptimize. - currently restricted to discrete traits where homogeneous population
states can be skipped by deterministically introducing new mutant after an
geometrically (exponentially) distributed waiting time (see
IBSD). - requires small mutation rates.
- does not work for variable population sizes.
- optimizations can be requested with the command line option
-
isSynchronous
boolean isSynchronousFlag to indicate whether the population updates are synchronous. In multi-species models this requires that all species are updated synchronously. Helper variable foribsStep(double).- See Also:
-
debugFocalSpecies
IBSPopulation debugFocalSpeciesPointer to focal species for debugging. -
speciesUpdate
Type of species update (multi-species models only). -
nextSpeciesIdx
private int nextSpeciesIdxIndex for turn-based-selection to determine which species to pick next. Simply cycles through species array. -
cloAccumulatedScores
Command line option to set whether player scores from interactions are accumulated or averaged (default).Note: Accumulated scores can be tricky because they are essentially unbounded... On regular structures the two variants merely amount to a rescaling of the selection strength.
- See Also:
-
cloScoringType
Command line option to set method for resetting the scores of individuals.- See Also:
-
cloInteractions
Command line option to set whether players interact with all their neighbours or a random subsample. -
cloReferences
Command line option to set the method for choosing references/models among the neighbours of a player for updating their trait. -
cloMigration
Command line option to set the migration types and probabilities of players. -
cloGeometryInteraction
Command line option to set the interaction geometry. This overrides theModule.cloGeometrysettings.- See Also:
-
cloGeometryCompetition
Command line option to set the competition geometry. This overrides theModule.cloGeometrysettings.- See Also:
-
cloGeometryRewire
Command line option to set the fraction of links to rewire. If graph is undirected it is preserved and if graph is directed, rewiring is done for directed links (where undirected links count as two directed links), which potentially breaks undirected ones. -
cloGeometryAddwire
Command line option to set the fraction of links to add. If graph is undirected only undirected links are added and if graph is directed only directed links are added. -
cloConsistency
Command line option to enable consistency checks. -
statisticsSettings
IBS.Statistics statisticsSettingsThe settings for statistics mode.
-
-
Constructor Details
-
IBS
Creates a population of individuals for IBS simulations.- Parameters:
engine- the pacemaker for running the model
-
-
Method Details
-
permitsSampleStatistics
public boolean permitsSampleStatistics()Description copied from class:ModelCheck if the current model settings permit sample statistics. Fixation probabilities and times are examples of statistics based on samples.- Overrides:
permitsSampleStatisticsin classModel- Returns:
trueif sample statistics are permitted
-
permitsUpdateStatistics
public boolean permitsUpdateStatistics()Description copied from class:ModelCheck if the current model settings permit update statistics. Sojourn times are an example of statistics based on updates.- Overrides:
permitsUpdateStatisticsin classModel- Returns:
trueif update statistics are permitted
-
load
public void load()Milestone: Load this model and allocate resources (if applicable).Loads the IBS model and instantiates the
IBSPopulations representing the different species, if applicable. -
unload
public void unload()Description copied from class:ModelMilestone: Unload this model and free resources (if applicable). -
check
public boolean check()Description copied from class:ModelCheck consistency of parameters and adjust if necessary (and possible). All issues and modifications should be reported throughlogger. Some parameters can be adjusted while the model remains active or even while running, whereas others require a reset. An example of the former category is in general simple adjustments of payoffs, while an example of the latter category is a change of the population structure. -
reset
public void reset()Description copied from class:ModelMilestone: Reset this model -
init
public void init()Description copied from class:ModelMilestone: Initialize this model -
init
public void init(boolean soft) Initializes the IBS model.softinitializations adjust parameters but do not touch the current state of the IBS population(s).Note: Method must be
publicbecause of subclasses inorg.evoludo.simulator.- Parameters:
soft- the flag to indicate whether this should be asoftinitialization.
-
update
public void update()Description copied from class:ModelUpdate this model. For example called after initialization and when parameters changed. -
next
public boolean next()Description copied from class:ModelAdvance model by one step. The details of what happens during one step depends on the modelsTypeas well as itsMode.- Specified by:
nextin classModel- Returns:
trueifnext()can be called again. Typicallyfalseis returned if the model requires attention, such as the following conditions:- the model has converged
- the model turned monomorphic (stops only if requested)
- a statistics sample is available
- a preset time has been reached
- See Also:
-
ibsStep
public boolean ibsStep(double stepDt) Advances the IBS model by a step of sizestepDt. The actual time increment may be shorter, e.g. upon reaching an absorbing state or homogeneous state, if requested.Note: the time increment returned is negative if the IBS converged/absorbed (individual based simulations cannot reverse time).
- Parameters:
stepDt- the time increment requested for advancing the IBS model- Returns:
trueifibsStep(double)can be called again. Typicallyfalseis returned if the simulation requires attention, such as the following conditions:- the population(s) have reached an absorbing state
- the population(s) turned monomorphic (stops only if requested)
- the population(s) went extinct
- See Also:
-
permitsDebugStep
public boolean permitsDebugStep()Description copied from class:ModelChecks if debugging single steps is supported. By default returnsfalse. Only few models support debugging of single update steps.- Overrides:
permitsDebugStepin classModel- Returns:
trueif stepwise debuggin is permissible.
-
debugStep
public void debugStep()Description copied from class:ModelPerform single debug step in models that allow it. -
getIBSPopulation
Helper routine to retrieve theIBSPopulationassociated with module withid.- Parameters:
id- theidof the module- Returns:
- the
IBSPopulation
-
getMinScore
public double getMinScore(int id) Description copied from class:ModelReturns the minimum score that individuals of species with IDidcan achieve in this model. Takes into account potential adjustments due to population structure and payoff accounting.- Specified by:
getMinScorein classModel- Parameters:
id- the id of the population for multi-species models- Returns:
- the minimum score
- See Also:
-
getMaxScore
public double getMaxScore(int id) Description copied from class:ModelReturns the maximum score that individuals of species with IDidcan achieve in this model. Takes into account potential adjustments due to population structure and payoff accounting.- Specified by:
getMaxScorein classModel- Parameters:
id- the id of the population for multi-species models- Returns:
- the maximum score
- See Also:
-
getMinFitness
public double getMinFitness(int id) Description copied from class:ModelCalculates and returns the absolute fitness minimum. This is important to- determine probabilities or rates for adopting the trait of another player,
- optimize fitness based picking of individuals, and
- scaling graphical output.
- Specified by:
getMinFitnessin classModel- Parameters:
id- the id of the population for multi-species models- Returns:
- the minimum fitness
- See Also:
-
getMaxFitness
public double getMaxFitness(int id) Description copied from class:ModelCalculates and returns the absolute fitness maximum. This is important to- determine probabilities or rates for adopting the trait of another player,
- optimize fitness based picking of individuals, and
- scaling graphical output.
- Specified by:
getMaxFitnessin classModel- Parameters:
id- the id of the population for multi-species models- Returns:
- the maximum fitness
- See Also:
-
getStatus
Description copied from class:ModelReturns status message from model. Typically this is a string summarizing the current state of the simulation. For example, models with discrete traits (such as 2x2 games, seeTBT) return the average frequencies of each strategy type in the population(s), seeIBSDPopulation. Similarly, models with continuous strategies (such as continuous snowdrift games, seeCSD) return the mean, minimum and maximum trait value(s) in the population(s), seeIBSMCPopulation. The status message is displayed along the bottom of the GUI.Note: if the model runs into difficulties, problems should be reported through the logging mechanism. Messages with severity
Level.WARNINGor higher are displayed in the status of the GUI and override status messages returned here. -
getCounter
Description copied from class:ModelGets a formatted string summarizing the elapsed time.- Overrides:
getCounterin classModel- Returns:
- elapsed time as string
-
getRealtime
public double getRealtime()Gets the elapsed time in real time units. The real time increments of microscopic updates depends on the fitness of the population. In populations with high fitness many events happen per unit time and hence the increments are smaller. In contrast in populations with low fitness fewer events happen and consequently more time elapses between subsequent events. By default no distinction between real time and generation time is made.- Returns:
- elapsed real time
-
getNMean
public int getNMean()Description copied from class:ModelReturn the number of mean values for this model including all species (for traits or fitness). By default this returns the number of traits in the module. Models that report a different number of mean traits must override this method -
getNMean
public int getNMean(int id) Description copied from class:ModelReturn the number of mean trait values for species with IDid. -
getMeanTraits
public boolean getMeanTraits(double[] mean) Description copied from class:ModelCollect and return mean trait values for all species.NOTE: this is a convenience method for multi-species modules to retrieve states efficiently for further processing or visualization.
- Specified by:
getMeanTraitsin classModel- Parameters:
mean- the array for storing the mean trait values- Returns:
trueif this and previous data point should be connected, i.e. no reset had been requested in the mean time.
-
getMeanTraits
public boolean getMeanTraits(int id, double[] mean) Description copied from class:ModelReturn mean trait values for species with IDid.- Specified by:
getMeanTraitsin classModel- Parameters:
id- the species identifiermean- the array for storing the mean trait values- Returns:
trueif this and the previous data point should be connected, i.e. no reset had been requested in the mean time.
-
getTraitNameAt
Description copied from class:ModelGets the formatted trait names at locationidxfor species with IDid. The formatting may include HTML tags. Used by GUI for example to show trait names in tooltips.Note: optional implementation. Currently makes sense only for IBS models and local dynamics in PDE models.
- Overrides:
getTraitNameAtin classModel- Parameters:
id- the species identifieridx- the index of the location- Returns:
- description of traits at
idx
-
getTraitData
Description copied from class:ModelGets the trait data for species with IDidand translates them into colors using thecolorMap. The result is stored and returned incolors. Used by GUI to visualize the current state of the model.- Specified by:
getTraitDatain classModel- Type Parameters:
T- color data type.ColorforPopGraph2DandPopGraph2Das well asMeshLambertMaterialforPopGraph3D- Parameters:
id- the species identifiercolors- the array for storing the colors for individualscolorMap- the map for translating individual traits into colors
-
getMeanFitness
public boolean getMeanFitness(double[] mean) Description copied from class:ModelGets the mean fitness values for traits in all species. The result is stored and returned inmean. Used by GUI to visualize the current the state of the model.Note: this is a convenience method for multi-species modules to retrieve states efficiently for further processing or visualization.
- Specified by:
getMeanFitnessin classModel- Parameters:
mean- the array for storing the mean fitness values- Returns:
trueif this and the previous data point should be connected, i.e. no reset had been requested in the mean time.
-
getMeanFitness
public boolean getMeanFitness(int id, double[] mean) Description copied from class:ModelGets the mean fitness values for species with IDid. The result is stored and returned inmean. Used by GUI to visualize local dynamics atidx.- Specified by:
getMeanFitnessin classModel- Parameters:
id- the species identifiermean- the array for storing the mean fitness values- Returns:
trueif this and the previous data point should be connected, i.e. no reset had been requested in the mean time.
-
getFitnessNameAt
Description copied from class:ModelGets the fitness at locationidxfor species with IDidas a formatted string. The formatting may include HTML tags. Used by GUI for example to show fitness in tooltips.Note: optional implementation. Currently makes sense only for IBS and PDE models.
- Overrides:
getFitnessNameAtin classModel- Parameters:
id- the species identifieridx- the index of the location- Returns:
- the fitness as a formatted string
-
getScoreNameAt
Description copied from class:ModelGets the score at locationidxfor species with IDidas a formatted string. The formatting may include HTML tags. Used by GUI for example to show scores in tooltips.Note: optional implementation. Currently makes sense only for IBS and PDE models.
- Overrides:
getScoreNameAtin classModel- Parameters:
id- the species identifieridx- the index of the location- Returns:
- the score as a formatted string
-
getFitnessData
Description copied from class:ModelTranslates fitness data into colors using ColorMapcolorMap. Used by GUI to visualize current state of model.- Specified by:
getFitnessDatain classModel- Type Parameters:
T- color data type.ColorforPopGraph2DandPopGraph2Das well asMeshLambertMaterialforPopGraph3D- Parameters:
id- the species identifiercolors- the array for storing color valuescolorMap- the map to use for translating traits to colors
-
getFitnessHistogramData
public void getFitnessHistogramData(int id, double[][] bins) Description copied from class:ModelGenerates a histogram of fitness data and returns the result in the provided arraybins. For Discrete modules a fitness histogram is returned for each trait separately. For Continuous modules there is, in general, only a single fitness dimension.- Specified by:
getFitnessHistogramDatain classModel- Parameters:
id- the species identifierbins- the array for storing histogram. For Discrete modules this is always one dimensional
-
getTagNameAt
Gets formatted tag of individual at locationidxfor species with IDid. The formatting may include HTML tags. Used by GUI for example to show tags in tooltips. Opportunity to track ancestry through tags.Note: optional implementation. Currently makes sense only for IBS models.
- Parameters:
id- the species identifieridx- the index of the location- Returns:
- the formatted tag
-
getInteractionsAt
public int getInteractionsAt(int id, int idx) Gets the number of interactions at locationidxfor species with IDid. Used by GUI for example to show interaction counts in tooltips.Note: optional implementation. Currently makes sense only for IBS models.
- Parameters:
id- the species identifieridx- the index of the location- Returns:
- the interaction count
-
mouseHitNode
public boolean mouseHitNode(int id, int hit, boolean alt) Used by GUI to interact with Model. Called whenever a mouse click/tap was registered by a node.- Parameters:
id- the species identifierhit- the index of the node hit by mousealt-trueifAlt-key pressed- Returns:
falseif no actions taken
-
getSpeciesUpdate
Get species update type.- Returns:
- the species update type
-
pickFocalSpecies
Pick focal population according to the selected scheme.- Returns:
- the focal population
- See Also:
-
pickFocalSpecies
Pick focal species with a probability proportional to the entries inrates.- Parameters:
rates- the rates with which to pick the focal speciestotal- the sum of the rates- Returns:
- the focal population or
nullif all populations extinct
-
pickFocalSpecies
Pick next focal species. For a previous focal species with indexidxthe next focal species is(idx + skip) % nSpecies. Extinct populations are skipped.- Parameters:
skip- the number of species to skip- Returns:
- the focal population or
nullall populations extinct
-
pickEvent
Pick type of next event in focal population.- Parameters:
pop- the focal population- Returns:
- the next event
-
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 classModel- Parameters:
parser- the reference to parser that manages command line options- See Also:
-
encodeState
Description copied from class:ModelEncode the state of the model in aplistinspiredXMLstring. This allows to save the state and restore later with the exact same results as when continuing to run the model. This even allows to switch from JRE to GWT or back and obtain identical results!- Specified by:
encodeStatein classModel- Parameters:
plist- theStringBuilderto write the encoded state to- See Also:
-
restoreState
Description copied from class:ModelRestore the state encoded in theplistinspiredmapofkey, value-pairs.- Specified by:
restoreStatein classModel- Parameters:
plist- the map ofkey, value-pairs- Returns:
trueif successful- See Also:
-
random0n
public int random0n(int n) random integer number from interval[0, n).- Parameters:
n- the upper limit of interval (exclusive)- Returns:
- the random integer number in
[0, n).
-
random01
public double random01()Random number from interval [0, 1) with 32bit resolution. This is the default.- Returns:
- the random number in
[0, 1).
-