From 3915d9b469a53f7ca7bfdac0b9ac9731a26b12ce Mon Sep 17 00:00:00 2001 From: Christian Heinemann Date: Sat, 21 Sep 2024 17:42:47 +0200 Subject: [PATCH] + variance -> deviation + avoid using std::format due to GCC 12 compatibility --- .../CellFunctionProcessor.cuh | 2 +- .../EngineGpuKernels/ConstructorProcessor.cuh | 10 ++++--- .../EngineGpuKernels/SimulationStatistics.cuh | 4 +-- source/EngineGpuKernels/StatisticsKernels.cu | 5 ++-- .../EngineInterface/DataPointCollection.cpp | 4 +-- source/EngineInterface/DataPointCollection.h | 2 +- source/EngineInterface/RawStatisticsData.h | 2 +- source/EngineInterface/SerializerService.cpp | 4 +-- .../StatisticsConverterService.cpp | 2 +- source/Gui/StatisticsWindow.cpp | 27 ++++++++++++++----- 10 files changed, 39 insertions(+), 23 deletions(-) diff --git a/source/EngineGpuKernels/CellFunctionProcessor.cuh b/source/EngineGpuKernels/CellFunctionProcessor.cuh index cd52d9c98..c1097f6a1 100644 --- a/source/EngineGpuKernels/CellFunctionProcessor.cuh +++ b/source/EngineGpuKernels/CellFunctionProcessor.cuh @@ -142,7 +142,7 @@ __inline__ __device__ Activity CellFunctionProcessor::calcInputActivity(Cell* ce if (connectedCell->executionOrderNumber == cell->inputExecutionOrderNumber) { for (int i = 0; i < MAX_CHANNELS; ++i) { result.channels[i] += connectedCell->activity.channels[i]; - result.channels[i] = max(-1000000.0f, min(1000000.0f, result.channels[i])); //truncate value to avoid overflow + result.channels[i] = max(-10.0f, min(10.0f, result.channels[i])); //truncate value to avoid overflow } if (connectedCell->activity.origin == ActivityOrigin_Sensor) { result.origin = ActivityOrigin_Sensor; diff --git a/source/EngineGpuKernels/ConstructorProcessor.cuh b/source/EngineGpuKernels/ConstructorProcessor.cuh index dd88b3563..37bbf494b 100644 --- a/source/EngineGpuKernels/ConstructorProcessor.cuh +++ b/source/EngineGpuKernels/ConstructorProcessor.cuh @@ -40,6 +40,7 @@ private: //construction data Cell* lastConstructionCell; + bool containsSelfReplication; }; __inline__ __device__ static void completenessCheck(SimulationData& data, SimulationStatistics& statistics, Cell* cell); @@ -156,7 +157,9 @@ __inline__ __device__ void ConstructorProcessor::processCell(SimulationData& dat if (isConstructionTriggered(data, cell, activity)) { if (tryConstructCell(data, statistics, cell, constructionData)) { cellBuilt = true; - cell->cellFunctionUsed = CellFunctionUsed_Yes; + if (!constructionData.containsSelfReplication) { + cell->cellFunctionUsed = CellFunctionUsed_Yes; + } } } @@ -190,6 +193,7 @@ __inline__ __device__ ConstructorProcessor::ConstructionData ConstructorProcesso ConstructionData result; result.genomeHeader = GenomeDecoder::readGenomeHeader(constructor); result.hasInfiniteRepetitions = GenomeDecoder::hasInfiniteRepetitions(constructor); + result.containsSelfReplication = isSelfReplicator(cell); auto genomeNodesPerRepetition = GenomeDecoder::getNumNodes(constructor.genome, constructor.genomeSize); if (!GenomeDecoder::hasInfiniteRepetitions(constructor) && constructor.genomeCurrentNodeIndex == 0 && constructor.genomeCurrentRepetition == 0) { result.lastConstructionCell = nullptr; @@ -359,7 +363,7 @@ ConstructorProcessor::startNewConstruction(SimulationData& data, SimulationStati return nullptr; } - if (GenomeDecoder::containsSelfReplication(constructor)) { + if (constructionData.containsSelfReplication) { constructor.offspringCreatureId = 1 + data.numberGen1.random(65535); hostCell->genomeComplexity = calcGenomeComplexity(hostCell->color, constructor.genome, constructor.genomeSize); @@ -646,7 +650,7 @@ ConstructorProcessor::constructCellIntern( result->inputExecutionOrderNumber = constructionData.inputExecutionOrderNumber; result->outputBlocked = constructionData.outputBlocked; - result->activationTime = GenomeDecoder::containsSelfReplication(constructor) ? constructor.constructionActivationTime : 0; + result->activationTime = constructionData.containsSelfReplication ? constructor.constructionActivationTime : 0; result->genomeComplexity = hostCell->genomeComplexity; auto genomeCurrentBytePosition = constructionData.genomeCurrentBytePosition; diff --git a/source/EngineGpuKernels/SimulationStatistics.cuh b/source/EngineGpuKernels/SimulationStatistics.cuh index 65c886372..dcb092ad1 100644 --- a/source/EngineGpuKernels/SimulationStatistics.cuh +++ b/source/EngineGpuKernels/SimulationStatistics.cuh @@ -68,9 +68,9 @@ public: } return result; } - __inline__ __device__ void addToGenomeComplexityVariance(int color, double valueToAdd) + __inline__ __device__ void addToGenomeComplexityDeviation(int color, double valueToAdd) { - atomicAdd(&_data->timeline.timestep.genomeComplexityVariance[color], valueToAdd); + atomicAdd(&_data->timeline.timestep.genomeComplexityDeviation[color], valueToAdd); } __inline__ __device__ void incMutant(int color, uint32_t mutationId, float genomeComplexity) { diff --git a/source/EngineGpuKernels/StatisticsKernels.cu b/source/EngineGpuKernels/StatisticsKernels.cu index eda3cb983..197b9d7ae 100644 --- a/source/EngineGpuKernels/StatisticsKernels.cu +++ b/source/EngineGpuKernels/StatisticsKernels.cu @@ -59,9 +59,8 @@ __global__ void cudaUpdateTimestepStatistics_substep3(SimulationData data, Simul for (int index = partition.startIndex; index <= partition.endIndex; ++index) { auto& cell = cells.at(index); if (cell->cellFunction == CellFunction_Constructor && GenomeDecoder::containsSelfReplication(cell->cellFunctionData.constructor)) { - auto variance = toDouble(cell->genomeComplexity) - averageGenomeComplexity; - variance = variance * variance / numReplicators; - statistics.addToGenomeComplexityVariance(cell->color, variance); + auto deviation = abs(toDouble(cell->genomeComplexity) - averageGenomeComplexity) / numReplicators; + statistics.addToGenomeComplexityDeviation(cell->color, deviation); } } } diff --git a/source/EngineInterface/DataPointCollection.cpp b/source/EngineInterface/DataPointCollection.cpp index afd080ff7..578647f89 100644 --- a/source/EngineInterface/DataPointCollection.cpp +++ b/source/EngineInterface/DataPointCollection.cpp @@ -33,7 +33,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.deviationGenomeComplexity = deviationGenomeComplexity + other.deviationGenomeComplexity; result.maxGenomeComplexityOfColonies = maxGenomeComplexityOfColonies + other.maxGenomeComplexityOfColonies; result.totalEnergy = totalEnergy + other.totalEnergy; result.numCreatedCells = numCreatedCells + other.numCreatedCells; @@ -66,7 +66,7 @@ DataPointCollection DataPointCollection::operator/(double divisor) const result.numParticles = numParticles / divisor; result.averageGenomeCells = averageGenomeCells / divisor; result.averageGenomeComplexity = averageGenomeComplexity / divisor; - result.varianceGenomeComplexity = varianceGenomeComplexity / divisor; + result.deviationGenomeComplexity = deviationGenomeComplexity / divisor; result.maxGenomeComplexityOfColonies = maxGenomeComplexityOfColonies / divisor; result.totalEnergy = totalEnergy / divisor; result.numCreatedCells = numCreatedCells / divisor; diff --git a/source/EngineInterface/DataPointCollection.h b/source/EngineInterface/DataPointCollection.h index b2bf9689d..754f969fe 100644 --- a/source/EngineInterface/DataPointCollection.h +++ b/source/EngineInterface/DataPointCollection.h @@ -24,7 +24,7 @@ struct DataPointCollection DataPoint numParticles; DataPoint averageGenomeCells; DataPoint averageGenomeComplexity; - DataPoint varianceGenomeComplexity; + DataPoint deviationGenomeComplexity; DataPoint maxGenomeComplexityOfColonies; DataPoint totalEnergy; diff --git a/source/EngineInterface/RawStatisticsData.h b/source/EngineInterface/RawStatisticsData.h index 8ad71a424..a48dcade6 100644 --- a/source/EngineInterface/RawStatisticsData.h +++ b/source/EngineInterface/RawStatisticsData.h @@ -15,7 +15,7 @@ struct TimestepStatistics ColorVector numGenomeCells = {0, 0, 0, 0, 0, 0, 0}; ColorVector genomeComplexity = {0, 0, 0, 0, 0, 0, 0}; ColorVector maxGenomeComplexityOfColonies = {0, 0, 0, 0, 0, 0, 0}; - ColorVector genomeComplexityVariance = {0, 0, 0, 0, 0, 0, 0}; + ColorVector genomeComplexityDeviation = {0, 0, 0, 0, 0, 0, 0}; ColorVector totalEnergy = {0, 0, 0, 0, 0, 0, 0}; }; diff --git a/source/EngineInterface/SerializerService.cpp b/source/EngineInterface/SerializerService.cpp index 176304359..80e81d129 100644 --- a/source/EngineInterface/SerializerService.cpp +++ b/source/EngineInterface/SerializerService.cpp @@ -1255,7 +1255,7 @@ namespace loadSave(task, serializedData, 1 + 21 * 8, dataPoints.numColonies); loadSave(task, serializedData, 1 + 22 * 8, dataPoints.averageGenomeComplexity); loadSave(task, serializedData, 1 + 23 * 8, dataPoints.maxGenomeComplexityOfColonies); - loadSave(task, serializedData, 1 + 24 * 8, dataPoints.varianceGenomeComplexity); + loadSave(task, serializedData, 1 + 24 * 8, dataPoints.deviationGenomeComplexity); loadSave(task, serializedData, 1 + 25 * 8, dataPoints.systemClock); } } @@ -1294,7 +1294,7 @@ void SerializerService::serializeStatistics(StatisticsHistoryData const& statist writeLabelAllColors("Colonies"); writeLabelAllColors("Genome complexity average"); writeLabelAllColors("Genome complexity Maximum"); - writeLabelAllColors("Genome complexity variance"); + writeLabelAllColors("Genome complexity deviation"); writeLabelAllColors("System clock"); stream << std::endl; diff --git a/source/EngineInterface/StatisticsConverterService.cpp b/source/EngineInterface/StatisticsConverterService.cpp index 77a6b4d44..6560005a4 100644 --- a/source/EngineInterface/StatisticsConverterService.cpp +++ b/source/EngineInterface/StatisticsConverterService.cpp @@ -95,7 +95,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.deviationGenomeComplexity = getDataPointBySummation(data.timestep.genomeComplexityDeviation); result.maxGenomeComplexityOfColonies = getDataPointByMaximation(data.timestep.maxGenomeComplexityOfColonies); result.totalEnergy = getDataPointBySummation(data.timestep.totalEnergy); diff --git a/source/Gui/StatisticsWindow.cpp b/source/Gui/StatisticsWindow.cpp index df5339854..92bb8fa54 100644 --- a/source/Gui/StatisticsWindow.cpp +++ b/source/Gui/StatisticsWindow.cpp @@ -1,7 +1,6 @@ #include "StatisticsWindow.h" #include -#include #include @@ -339,9 +338,9 @@ void _StatisticsWindow::processTimelineStatistics() ImGui::TableNextRow(); ImGui::TableSetColumnIndex(0); - processPlot(row++, &DataPointCollection::varianceGenomeComplexity, 2); + processPlot(row++, &DataPointCollection::deviationGenomeComplexity, 2); ImGui::TableSetColumnIndex(1); - AlienImGui::Text("Genome complexity\nvariance"); + AlienImGui::Text("Genome complexity\ndeviation"); ImGui::TableNextRow(); ImGui::TableSetColumnIndex(0); @@ -681,6 +680,20 @@ void _StatisticsWindow::plotForColorIntern( ImGui::PopID(); } +namespace +{ + std::string convertSystemClockToString(double systemClock) + { + auto time_t = static_cast(systemClock); + std::tm* tm = std::localtime(&time_t); + + char buffer[100]; + std::strftime(buffer, sizeof(buffer), "%Y-%m-%d %H:%M:%S", tm); + return std::string(buffer); + + } +} + void _StatisticsWindow::drawValuesAtMouseCursor( double const* dataPoints, double const* timePoints, @@ -708,17 +721,17 @@ void _StatisticsWindow::drawValuesAtMouseCursor( } return std::string(); } - auto systemClockPoint = systemClock[0]; + auto systemClockEntry = systemClock[0]; for (int i = 1; i < count; ++i) { if (timePoints[i * stride] > mousePos.x) { mousePos.y = dataPoints[i * stride]; - systemClockPoint = systemClock[i * stride]; + systemClockEntry = systemClock[i * stride]; break; } } mousePos.y = std::max(0.0, std::min(upperBound, mousePos.y)); - auto timePoint = std::chrono::floor(std::chrono::system_clock::from_time_t(static_cast(systemClockPoint))); - return systemClockPoint != 0 ? std::format("{:%Y-%m-%d %H:%M:%S}", timePoint) : std::string("-"); + + return systemClockEntry != 0 ? convertSystemClockToString(systemClockEntry) : std::string("-"); }(); ImPlot::PushStyleColor(ImPlotCol_InlayText, ImColor::HSV(0.0f, 0.0f, 1.0f).Value);