Skip to content

Commit

Permalink
fix #31; genetic fitness mutations always > -1
Browse files Browse the repository at this point in the history
  • Loading branch information
TheoPannetier committed Jul 12, 2024
1 parent f91fca7 commit cead5dc
Showing 1 changed file with 71 additions and 30 deletions.
101 changes: 71 additions & 30 deletions unit_tests/testIndividual.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -571,42 +571,83 @@ void testGenetics() {

// Genetic fitness mutations are constrained between -1 or 1
{
// Most likely (~96%) to sample a mutation > 1
const float gammaMutShapeParam = 5.0;
const float gammaMutScaleParam = 1.0;
{
// Most likely (~96%) to sample a mutation > 1
const float gammaMutShapeParam = 5.0;
const float gammaMutScaleParam = 1.0;

const int genomeSz = 5;
const bool isDiploid{ false };
const int genomeSz = 5;
const bool isDiploid{ false };

// Create species trait
const map<GenParamType, float> mutationParams{
// all alleles initialised at a single value
pair<GenParamType, float>{GenParamType::SHAPE, gammaMutShapeParam},
pair<GenParamType, float>{GenParamType::SCALE, gammaMutScaleParam}
};
const map<GenParamType, float> placeholderParams = mutationParams;
// Create species trait
const map<GenParamType, float> mutationParams{
// all alleles initialised at a single value
pair<GenParamType, float>{GenParamType::SHAPE, gammaMutShapeParam},
pair<GenParamType, float>{GenParamType::SCALE, gammaMutScaleParam}
};
const map<GenParamType, float> placeholderParams = mutationParams;

SpeciesTrait* spTr = new SpeciesTrait(
TraitType::GENETIC_LOAD1,
sex_t::NA,
createTestGenePositions(genomeSz),
ExpressionType::MULTIPLICATIVE,
DistributionType::NONE, placeholderParams, // not used for genetic load
DistributionType::GAMMA, placeholderParams, // doesn't matter for this test
true,
1.0, // every site mutates
DistributionType::GAMMA, mutationParams,
isDiploid ? 2 : 1
);

// Create individual trait object
GeneticFitnessTrait traitInd(spTr); // initialisation constructor
traitInd.mutate();
for (int i = 0; i < genomeSz; i++) {
float valAllele = traitInd.getAlleleValueAtLocus(0, i);
assert(valAllele <= 1.0);
}
}

SpeciesTrait* spTr = new SpeciesTrait(
TraitType::GENETIC_LOAD1,
sex_t::NA,
createTestGenePositions(genomeSz),
ExpressionType::MULTIPLICATIVE,
DistributionType::NONE, placeholderParams, // not used for genetic load
DistributionType::GAMMA, placeholderParams, // doesn't matter for this test
true,
1.0, // every site mutates
DistributionType::GAMMA, mutationParams,
isDiploid ? 2 : 1
);
{
// 1/2 chance to sample a mutation < -1
const float normalMutMeanParam = 0;
const float normalMutSdParam = 1.0;

// Create individual trait object
GeneticFitnessTrait traitInd(spTr); // initialisation constructor
traitInd.mutate();
for (int i = 0; i < genomeSz; i++) {
float valAllele = traitInd.getAlleleValueAtLocus(0, i);
assert(valAllele <= 1.0);
const int genomeSz = 10;
const bool isDiploid{ false };

// Create species trait
const map<GenParamType, float> mutationParams{
// all alleles initialised at a single value
pair<GenParamType, float>{GenParamType::MEAN, normalMutMeanParam},
pair<GenParamType, float>{GenParamType::SD, normalMutSdParam}
};
const map<GenParamType, float> placeholderParams = mutationParams;

SpeciesTrait* spTr = new SpeciesTrait(
TraitType::GENETIC_LOAD1,
sex_t::NA,
createTestGenePositions(genomeSz),
ExpressionType::MULTIPLICATIVE,
DistributionType::NONE, placeholderParams, // not used for genetic load
DistributionType::NORMAL, placeholderParams, // doesn't matter for this test
true,
1.0, // every site mutates
DistributionType::NORMAL, mutationParams,
isDiploid ? 2 : 1
);

// Create individual trait object
GeneticFitnessTrait traitInd(spTr); // initialisation constructor
traitInd.mutate();
for (int i = 0; i < genomeSz; i++) {
float valAllele = traitInd.getAlleleValueAtLocus(0, i);
assert(valAllele > -1.0);
}
}
}

}

bool haveSameEmigD0Allele(const Individual& indA, const Individual& indB, const int& position, short whichHaplo = 0) {
Expand Down

0 comments on commit cead5dc

Please sign in to comment.