Package org.evoludo.simulator.models
Class IBSGroup
Object
IBSGroup
Interaction and reference groups in IBS models.
- Author:
- Christoph Hauert
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enum
Types of sampling of groups for interactions or references: none no interactions all interact with all neighbours random interact with n random neighbours -
Field Summary
FieldsModifier and TypeFieldDescription(package private) int
The index of the focal individual.(package private) int[]
Reference to the indices of the members of the group.private static int[]
The empty neighbourhood of a lone individual.private int[]
Storage for selected interaction or reference groups.(package private) int
The effective sample size.(package private) int
The sample size requested.protected RNGDistribution
The shared random number generator to ensure reproducibility of results.(package private) IBSGroup.SamplingType
The current sampling type for the formation of interaction or reference groups.(package private) boolean
The flag indicating whether to include the focal individual when sampling. -
Constructor Summary
ConstructorsConstructorDescriptionIBSGroup
(RNGDistribution rng) Create a new interaction or competition group. -
Method Summary
Modifier and TypeMethodDescriptionint
getFocal()
Gets the index of the focal individual.int[]
getGroup()
Gets the array of indices of the interaction/reference group members.int
Get the number of interactions with random neighbours.int
Get the number of interactions with random neighbours.Gets the type of sampling of interaction/reference groups.boolean
getSelf()
Gets whether random sampling includes the focal individual or not.boolean
Checks whether the type of sampling of interaction/reference groups istype
.int[]
Picks an interaction/reference group for the focal individualfocal
and the population structuregeom
.private void
pickRandom
(int size) Pick group ofnSamples
random individual with indices0 - (size-1)
.void
setGroupAt
(int focal, int[] group, int size) Sets the interaction/reference group togroup
with a sizesize
and the focal indiviualfocal
.void
setNSamples
(int nSamples) Set the number of interactions with random neighbours.void
Sets the type of sampling of interaction/reference groups totype
.void
setSelf
(boolean self) Sets whether random sampling should include the focal individual or not.
-
Field Details
-
loner
private static int[] lonerThe empty neighbourhood of a lone individual. -
mem
private int[] memStorage for selected interaction or reference groups. -
group
int[] groupReference to the indices of the members of the group. -
focal
int focalThe index of the focal individual. -
rng
The shared random number generator to ensure reproducibility of results.- See Also:
-
samplingType
IBSGroup.SamplingType samplingTypeThe current sampling type for the formation of interaction or reference groups. -
nSamples
int nSamplesThe sample size requested. Default is a single sample for RANDOM sampling. -
nSampled
int nSampledThe effective sample size.nSampled < nSamples
may hold depending on the population structure. -
self
boolean selfThe flag indicating whether to include the focal individual when sampling.Notes
In the original Moran process the offspring can replace the parent. Hence, for reference groups in well-mixed populations it makes sense to include the focal individual. In contrast, self-interactions may simplify some analytical considerations but in IBS never make sense.
-
-
Constructor Details
-
IBSGroup
Create a new interaction or competition group. The global, shared random number generatorrng
must be passed here to ensure reproducibility of the simulation results.Note: The default (empty) constructor does not need to be declared private in order to prevent instantiation. The compiler does not generate a default constructor if another one exists.
- Parameters:
rng
- the random number generator for picking interaction or reference groups
-
-
Method Details
-
setSampling
Sets the type of sampling of interaction/reference groups totype
.- Parameters:
type
- the type of sampling
-
getSampling
Gets the type of sampling of interaction/reference groups.- Returns:
- the type of sampling
-
getNSamples
public int getNSamples()Get the number of interactions with random neighbours.- Returns:
- the number of interactions
-
setNSamples
public void setNSamples(int nSamples) Set the number of interactions with random neighbours.- Parameters:
nSamples
- the number of interactions
-
isSampling
Checks whether the type of sampling of interaction/reference groups istype
.- Parameters:
type
- the sampling type to check- Returns:
true
if the type of sampling istype
-
getNSampled
public int getNSampled()Get the number of interactions with random neighbours.- Returns:
- the number of interactions
-
setSelf
public void setSelf(boolean self) Sets whether random sampling should include the focal individual or not.- Parameters:
self
-true
if sampling includes focal
-
getSelf
public boolean getSelf()Gets whether random sampling includes the focal individual or not.- Returns:
true
if sampling includes focal
-
setGroupAt
public void setGroupAt(int focal, int[] group, int size) Sets the interaction/reference group togroup
with a sizesize
and the focal indiviualfocal
.- Parameters:
focal
- the index of the focal individualgroup
- the array with the indices of the members of the groupsize
- the size of the group
-
getGroup
public int[] getGroup()Gets the array of indices of the interaction/reference group members.- Returns:
- the interaction/reference group
-
getFocal
public int getFocal()Gets the index of the focal individual.- Returns:
- the index of the focal individual
-
pickAt
Picks an interaction/reference group for the focal individualfocal
and the population structuregeom
. If the flagout == true
then the group is sampled from the outgoing neighbours (downstream) of thefocal
and from the incoming neighbours (upstream) otherwise.Important: For efficiency the sampled group may be a direct reference to the population structure. For example,
group = out[focal]
to reference all neighbours of the focal individual. As a consequence the array group is untouchable and must never be manipulated because this would result in permanent changes of the population structure.- Parameters:
me
- the index of the focal individualgeom
- the geometry of the populationout
- the flag indicating whether to sample the group from the outgoing or incoming neighbours- Returns:
- the interaction/reference group (same as
group
) - See Also:
-
pickRandom
private void pickRandom(int size) Pick group ofnSamples
random individual with indices0 - (size-1)
. The focal individual is included ifself==true
.- Parameters:
size
- the maximum index to pick
-