Class NetGames.IBSPop

Enclosing class:
NetGames

public class NetGames.IBSPop extends IBSDPopulation
The extension for IBS simulations implement cooperative actions on dynamical networks.
  • Field Details

    • prevgen

      double prevgen
      The previous generation time.
    • meanPerformance

      double meanPerformance
      The mean fitness of individuals.
    • performance

      double[] performance
      The array with the mean, minimum, and maximum fitness of individuals.
  • Constructor Details

    • IBSPop

      protected IBSPop(EvoLudo engine, NetGames module)
      Create a new instance of the IBS model for cooperative actions on dynamical networks.
      Parameters:
      engine - the pacemaker for running the model
      module - 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 with traitScore?
      Overrides:
      reset in class IBSDPopulation
      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 class IBSDPopulation
      See Also:
    • getStatus

      public String 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 class IBSDPopulation
      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

      1. Review migration. Exclusively used in Demes2x2. Should probably be treated as an independent event, in particular independent of population or player updates
      2. Implement Wright-Fisher update.
      3. How to scale realtime with multiple populations? How to define a generation if population sizes can vary?
      4. IBSPopulation.updatePlayerEcology() returns time increment in realtime units. Everyone else does fine without...
      Overrides:
      step in class IBSPopulation
      Returns:
      the elapsed time in realtime units
    • updatePlayerIndividual

      protected void updatePlayerIndividual(int focal)
      Update the focal individual with index focal by probabilistically
      1. removing links from more successful and less cooperative individuals,
      2. 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 index focal considers acts of cooperation towards the candidate member with index mdl 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 individual
      mdl - the index of the candidate member
      Returns:
      true to establish the direct link from focal to mdl
      See Also:
    • removeCandidate

      protected boolean removeCandidate(int focal, int mdl)
      The focal individual with index focal considers to stop acts of cooperation towards the candidate member with index mdl 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 individual
      mdl - the index of the candidate member
      Returns:
      true to remove the direct link from focal to mdl
    • getFitnessDiff

      protected double getFitnessDiff(int focal, int mdl)
      Calculate the difference in fitness of individual with index focal as compared to the model individual with index mdl. 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 individual
      mdl - 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 index focal as compared to the model individual with index mdl. 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 individual
      mdl - the index of the candidate member
      Returns:
      the normalized difference in cooperativity
    • getProbability

      protected double getProbability(double z)
      Converts the difference z 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 array mean. Used by GUI to visualize the current state of this IBS model.
      Overrides:
      getMeanTraits in class IBSDPopulation
      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 array mean. Used by GUI to visualize the current state of this IBS model. Returns true if data point belongs to the same time series and false if a new series was started through IBSPopulation.init() or IBSPopulation.reset().
      Overrides:
      getMeanFitness in class IBSDPopulation
      Parameters:
      meanscores - the array for storing the mean fitness values
      See Also:
    • getFitnessData

      public <T> void getFitnessData(T[] colors, ColorMap.Gradient1D<T> cMap)
      Description copied from class: IBSPopulation
      Returns the fitness of all individuals in this population coded as colors in the array colors using the map colorMap. 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 or PopGraph3D).
      Overrides:
      getFitnessData in class IBSPopulation
      Type Parameters:
      T - the type of color data (String or MeshLambertMaterial for GWT and Color for JRE).
      Parameters:
      colors - the array where the colors of all nodes are stored
      cMap - the map that converts traits into colors
    • getLeafColor

      private <T> T getLeafColor(T type, ColorMap<T> cMap)
      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 use
      cMap - 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 array bins.

      Notes:

      1. bins is a 2D array because discrete models generate histograms for each trait separately.
      2. By default generate a histogram of the scores in bins[0].
      3. Consider moving to IBSDPopulation and IBSCPopulation with arguments bins[][] and bins[], respectively.
      Overrides:
      getFitnessHistogramData in class IBSDPopulation
      Parameters:
      bins - the 2D array to store the histogram(s)
    • parseGeometry

      public boolean parseGeometry(Geometry geom, String arg)
      Description copied from class: IBSPopulation
      Provide opportunity/hook for subclasses to introduce new geometries.
      Overrides:
      parseGeometry in class IBSPopulation
      Parameters:
      geom - the current empty/uninitialized geometry
      arg - the commandline argument
      Returns:
      true if parsing was successful
      See Also:
    • checkGeometry

      public boolean checkGeometry(Geometry geom)
      Description copied from class: IBSPopulation
      Provide opportunity/hook for subclasses to introduce new geometries.
      Overrides:
      checkGeometry in class IBSPopulation
      Parameters:
      geom - the geometry to check
      Returns:
      true if checks were successful
      See Also:
    • generateGeometry

      public boolean generateGeometry(Geometry geom)
      Description copied from class: IBSPopulation
      Provide opportunity/hook for subclasses to introduce new geometries.
      Overrides:
      generateGeometry in class IBSPopulation
      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 class IBSDPopulation
    • 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 class IBSDPopulation
    • 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 class IBSDPopulation
    • 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 class IBSDPopulation
      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 class IBSDPopulation
      See Also:
    • commitStrategyAt

      public void commitStrategyAt(int index)
      Description copied from class: IBSPopulation
      The change of a strategy of the player at index is stored in a temporary variable and must be committed before proceeding.
      Overrides:
      commitStrategyAt in class IBSDPopulation
      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 index a and index b have the same strategies.
      Overrides:
      haveSameStrategy in class IBSDPopulation
      Parameters:
      a - the index of first individual
      b - 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 index a has switched strategies.

      Note: this test is only meaningful before strategy gets committed.

      Overrides:
      isSameStrategy in class IBSDPopulation
      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 index a and index b.

      Note: the strategies still need to be committed.

      Overrides:
      swapStrategies in class IBSDPopulation
      Parameters:
      a - the index of first individual
      b - the index of second individual
      See Also:
    • playPairGameAt

      public void playPairGameAt(IBSGroup group)
      Description copied from class: IBSPopulation
      Play a pairwise interaction with the individuals in group.
      Overrides:
      playPairGameAt in class IBSDPopulation
      Parameters:
      group - the group of individuals interacting in pairs
    • playGroupGameAt

      public void playGroupGameAt(IBSGroup group)
      Description copied from class: IBSPopulation
      Play a group interaction with the individuals in group.
      Overrides:
      playGroupGameAt in class IBSDPopulation
      Parameters:
      group - the group of interacting individuals
    • playGameSyncAt

      public void playGameSyncAt(int idx)
      Description copied from class: IBSPopulation
      Update the score of individual me.

      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 class IBSPopulation
      Parameters:
      idx - the index of the focal individual
    • yalpGroupGameAt

      public void yalpGroupGameAt(IBSGroup groupd)
      Description copied from class: IBSPopulation
      Counterpart of IBSPopulation.playGroupGameAt(IBSGroup), IBSPopulation.playGameAt(int) and/or IBSPopulation.playGameSyncAt(int). Removes the payoffs of group interactions.
      Overrides:
      yalpGroupGameAt in class IBSDPopulation
      Parameters:
      groupd - the interaction group
    • updatePlayerBestResponse

      public boolean updatePlayerBestResponse(int index, int[] group, int size)
      Description copied from class: IBSDPopulation
      Best-response update.

      Important:

      1. The array group is untouchable because it may refer to the population structure. Any change would also permanently change the structure.
      2. The best-response update must be implemented in subclasses that override this method. By default throws an error.
      3. Instead of overriding the method, subclasses may remove PlayerUpdate.Type.BEST_RESPONSE from PlayerUpdate#clo.

      Note: Takes composition of entire population into account for Geometry.Type#MEANFIELD but only the reference neighborhood in structured populations.

      Overrides:
      updatePlayerBestResponse in class IBSDPopulation
      Parameters:
      index - the index of individual to update
      group - the array with indices of reference group
      size - the size of the reference group
      Returns:
      true if strategy changed (signaling score needs to be reset)
    • 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, strategy 0 preferred over 1 preferred over 2 ... preferred over N-1 preferred over N preferred over 0, 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 class IBSDPopulation
      Parameters:
      me - the index of the focal individual
      best - the index of the best performing individual
      sample - the index of the sample type
      Returns:
      true if sample is preferred over best
    • getTraitNameAt

      public String getTraitNameAt(int index)
      Description copied from class: IBSPopulation
      Gets the formatted name of the trait of the individual at site index.
      Overrides:
      getTraitNameAt in class IBSDPopulation
      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 index idx. Returns -1 if site idx is vacant or fitness is static, i.e. not based on interactions.
      Overrides:
      getInteractionsAt in class IBSPopulation
      Parameters:
      idx - the index of the individual
      Returns:
      the number of interactions
    • getTagNameAt

      public String getTagNameAt(int idx)
      Description copied from class: IBSPopulation
      Gets the formatted tag of the individual with index idx as string.
      Overrides:
      getTagNameAt in class IBSPopulation
      Parameters:
      idx - the index of the individual
      Returns:
      the tag as a string
    • getTraitData

      public <T> void getTraitData(T[] colors, ColorMap<T> cMap)
      Returns the traits of all individuals in this population coded as colors in the array colors using the map colorMap. 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 or PopGraph3D).

      Note: with the help of engine (see EvoLudoGWT and EvoLudoJRE) 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 class IBSDPopulation
      Type Parameters:
      T - the type of color data (String or MeshLambertMaterial for GWT and Color for JRE).
      Parameters:
      colors - the array where the colors of all nodes are stored
      cMap - the map that converts traits into colors