Skip to content

Commit

Permalink
plot for genome complexity variance
Browse files Browse the repository at this point in the history
  • Loading branch information
chrxh committed Sep 18, 2024
1 parent 908a54d commit fa6ffc8
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 3 deletions.
17 changes: 17 additions & 0 deletions source/EngineGpuKernels/SimulationStatistics.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ public:

__inline__ __device__ void incNumCells(int color) { atomicAdd(&(_data->timeline.timestep.numCells[color]), 1); }
__inline__ __device__ void incNumReplicator(int color) { atomicAdd(&_data->timeline.timestep.numSelfReplicators[color], 1); }
__inline__ __device__ int getNumReplicators()
{
auto result = 0;
for (int i = 0; i < MAX_COLORS; ++i) {
result += _data->timeline.timestep.numSelfReplicators[i];
}
return result;
}
__inline__ __device__ void incNumViruses(int color) { atomicAdd(&_data->timeline.timestep.numViruses[color], 1); }
__inline__ __device__ void incNumConnections(int color, int numConnections) { atomicAdd(&_data->timeline.timestep.numConnections[color], numConnections); }
__inline__ __device__ void incNumParticles(int color) { atomicAdd(&_data->timeline.timestep.numParticles[color], 1); }
Expand All @@ -52,6 +60,15 @@ public:
alienAtomicAdd64(&_data->timeline.timestep.numGenomeCells[color], valueToAdd);
}
__inline__ __device__ void addGenomeComplexity(int color, float valueToAdd) { atomicAdd(&_data->timeline.timestep.genomeComplexity[color], valueToAdd); }
__inline__ __device__ void addToGenomeComplexityVariance(int color, float valueToAdd, int numReplicators)
{
auto numReplicatorsAsDouble = toDouble(numReplicators);
auto averageGenomeComplexity = toDouble(_data->timeline.timestep.genomeComplexity[color]) / numReplicatorsAsDouble;
auto variance = toDouble(valueToAdd - averageGenomeComplexity);
variance = variance * variance / numReplicatorsAsDouble;

atomicAdd(&_data->timeline.timestep.genomeComplexityVariance[color], variance);
}
__inline__ __device__ void incMutant(int color, uint32_t mutationId, float genomeComplexity)
{
atomicAdd(&_mutantToMutantStatisticsMap[mutationId % MutantToColorCountMapSize].count, 1);
Expand Down
13 changes: 13 additions & 0 deletions source/EngineGpuKernels/StatisticsKernels.cu
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,19 @@ __global__ void cudaUpdateTimestepStatistics_substep3(SimulationData data, Simul
statistics.halveNumConnections();
}
statistics.calcStatisticsForColonies();

{
auto& cells = data.objects.cellPointers;
auto const partition = calcAllThreadsPartition(cells.getNumEntries());

auto numReplicator = statistics.getNumReplicators();
for (int index = partition.startIndex; index <= partition.endIndex; ++index) {
auto& cell = cells.at(index);
if (cell->cellFunction == CellFunction_Constructor && GenomeDecoder::containsSelfReplication(cell->cellFunctionData.constructor)) {
statistics.addToGenomeComplexityVariance(cell->color, cell->genomeComplexity, numReplicator);
}
}
}
}

__global__ void cudaUpdateHistogramData_substep1(SimulationData data, SimulationStatistics statistics)
Expand Down
2 changes: 2 additions & 0 deletions source/EngineInterface/DataPointCollection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ DataPointCollection DataPointCollection::operator+(DataPointCollection const& ot
result.numParticles = numParticles + other.numParticles;
result.averageGenomeCells = averageGenomeCells + other.averageGenomeCells;
result.averageGenomeComplexity = averageGenomeComplexity + other.averageGenomeComplexity;
result.varianceGenomeComplexity = varianceGenomeComplexity + other.varianceGenomeComplexity;
result.maxGenomeComplexityOfColonies = maxGenomeComplexityOfColonies + other.maxGenomeComplexityOfColonies;
result.totalEnergy = totalEnergy + other.totalEnergy;
result.numCreatedCells = numCreatedCells + other.numCreatedCells;
Expand Down Expand Up @@ -63,6 +64,7 @@ DataPointCollection DataPointCollection::operator/(double divisor) const
result.numParticles = numParticles / divisor;
result.averageGenomeCells = averageGenomeCells / divisor;
result.averageGenomeComplexity = averageGenomeComplexity / divisor;
result.varianceGenomeComplexity = varianceGenomeComplexity / divisor;
result.maxGenomeComplexityOfColonies = maxGenomeComplexityOfColonies / divisor;
result.totalEnergy = totalEnergy / divisor;
result.numCreatedCells = numCreatedCells / divisor;
Expand Down
1 change: 1 addition & 0 deletions source/EngineInterface/DataPointCollection.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ struct DataPointCollection
DataPoint numParticles;
DataPoint averageGenomeCells;
DataPoint averageGenomeComplexity;
DataPoint varianceGenomeComplexity;
DataPoint maxGenomeComplexityOfColonies;
DataPoint totalEnergy;

Expand Down
1 change: 1 addition & 0 deletions source/EngineInterface/RawStatisticsData.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ struct TimestepStatistics
ColorVector<uint64_t> numGenomeCells = {0, 0, 0, 0, 0, 0, 0};
ColorVector<float> genomeComplexity = {0, 0, 0, 0, 0, 0, 0};
ColorVector<float> maxGenomeComplexityOfColonies = {0, 0, 0, 0, 0, 0, 0};
ColorVector<double> genomeComplexityVariance = {0, 0, 0, 0, 0, 0, 0};
ColorVector<float> totalEnergy = {0, 0, 0, 0, 0, 0, 0};
};

Expand Down
1 change: 1 addition & 0 deletions source/EngineInterface/StatisticsConverterService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ DataPointCollection StatisticsConverterService::convert(
result.numParticles = getDataPointBySummation(data.timestep.numParticles);
result.averageGenomeCells = getDataPointByAveraging(data.timestep.numGenomeCells, data.timestep.numSelfReplicators);
result.averageGenomeComplexity = getDataPointByAveraging(data.timestep.genomeComplexity, data.timestep.numSelfReplicators);
result.varianceGenomeComplexity = getDataPointBySummation(data.timestep.genomeComplexityVariance);
result.maxGenomeComplexityOfColonies = getDataPointByMaximation(data.timestep.maxGenomeComplexityOfColonies);
result.totalEnergy = getDataPointBySummation(data.timestep.totalEnergy);

Expand Down
12 changes: 9 additions & 3 deletions source/Gui/StatisticsWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -326,21 +326,27 @@ void _StatisticsWindow::processTimelineStatistics()
ImGui::TableSetColumnIndex(0);
processPlot(row++, &DataPointCollection::averageGenomeCells, 2);
ImGui::TableSetColumnIndex(1);
AlienImGui::Text("Average genotype\ncells");
AlienImGui::Text("Num genotype\ncells average");
ImGui::SameLine();
AlienImGui::HelpMarker("The average number of encoded cells in the genomes is displayed.");

ImGui::TableNextRow();
ImGui::TableSetColumnIndex(0);
processPlot(row++, &DataPointCollection::averageGenomeComplexity, 2);
ImGui::TableSetColumnIndex(1);
AlienImGui::Text("Average genome\ncomplexity");
AlienImGui::Text("Genome complexity\naverage");

ImGui::TableNextRow();
ImGui::TableSetColumnIndex(0);
processPlot(row++, &DataPointCollection::varianceGenomeComplexity, 5);
ImGui::TableSetColumnIndex(1);
AlienImGui::Text("Genome complexity\nvariance");

ImGui::TableNextRow();
ImGui::TableSetColumnIndex(0);
processPlot(row++, &DataPointCollection::maxGenomeComplexityOfColonies, 2);
ImGui::TableSetColumnIndex(1);
AlienImGui::Text("Max genome\ncomplexity");
AlienImGui::Text("Genome complexity\nmaximum");

ImGui::TableNextRow();
ImGui::TableSetColumnIndex(0);
Expand Down

0 comments on commit fa6ffc8

Please sign in to comment.