From 64cc95d478cc021be481feda01edc00ee8293087 Mon Sep 17 00:00:00 2001 From: Francois Bonneau Date: Tue, 26 May 2026 16:11:43 +0200 Subject: [PATCH 01/16] feat(StraussTest): reactivate Strauss and Poisson Tests. --- .../stochastic/inference/statistics_tools.hpp | 2 +- .../models/energy_terms/pairwise_term.hpp | 20 +- .../sampling/mcmc/simulation_runner.hpp | 2 +- .../energy_terms/energy_term_builder.cpp | 4 +- tests/stochastic/CMakeLists.txt | 14 +- .../sampling/mcmc/test-mh-poisson.cpp | 47 +--- .../sampling/mcmc/test-mh-strauss.cpp | 263 +++++++++--------- 7 files changed, 163 insertions(+), 189 deletions(-) diff --git a/include/geode/stochastic/inference/statistics_tools.hpp b/include/geode/stochastic/inference/statistics_tools.hpp index ae0abf2..990e7e2 100644 --- a/include/geode/stochastic/inference/statistics_tools.hpp +++ b/include/geode/stochastic/inference/statistics_tools.hpp @@ -49,7 +49,7 @@ namespace geode OpenGeodeStochasticStochasticException::check_exception( rel_error < targets.tolerance( term_uuid ), nullptr, OpenGeodeException::TYPE::result, - "[StatisticsValidator] Failure for term ", + "[StatisticsValidator] Failure \n --> term ", model.term_name( term_uuid ), "\n mean = ", mean, "\n target = ", target, "\n error = ", rel_error, "\n tol = ", targets.tolerance( term_uuid ) ); diff --git a/include/geode/stochastic/models/energy_terms/pairwise_term.hpp b/include/geode/stochastic/models/energy_terms/pairwise_term.hpp index 747ab99..75fc792 100644 --- a/include/geode/stochastic/models/energy_terms/pairwise_term.hpp +++ b/include/geode/stochastic/models/energy_terms/pairwise_term.hpp @@ -119,10 +119,16 @@ namespace geode std::optional< ObjectId > exclude_id, const ObjectSets< ObjectType >& state ) const { - double sum = 0.0; + const auto impacted_set_it = + objectset_adjacency_map_.find( object_ref.set_id ); + if( impacted_set_it == objectset_adjacency_map_.end() ) + { + return 0.; + } const auto neighbors = state.neighbors( object_ref.object, - objectset_adjacency_map_.at( object_ref.set_id ), + impacted_set_it->second, interaction_->neighborhood_searching_distance(), exclude_id ); + double sum = 0.0; for( const auto& neigh_id : neighbors ) { ObjectRef< ObjectType > neigh_object{ @@ -147,11 +153,17 @@ namespace geode { return 0.; } - double sum = 0.0; + const auto impacted_set_it = + objectset_adjacency_map_.find( object_id.set_id ); + if( impacted_set_it == objectset_adjacency_map_.end() ) + { + return 0.; + } const auto neighbors = state.neighbors( cur_obj, - objectset_adjacency_map_.at( object_id.set_id ), + impacted_set_it->second, interaction_->neighborhood_searching_distance(), object_id ); ObjectRef< ObjectType > object_ref{ cur_obj, object_id.set_id }; + double sum = 0.0; for( const auto& neigh_id : neighbors ) { const auto& neigh_obj = state.get_object( neigh_id ); diff --git a/include/geode/stochastic/sampling/mcmc/simulation_runner.hpp b/include/geode/stochastic/sampling/mcmc/simulation_runner.hpp index 74eb77a..bc6aaac 100644 --- a/include/geode/stochastic/sampling/mcmc/simulation_runner.hpp +++ b/include/geode/stochastic/sampling/mcmc/simulation_runner.hpp @@ -66,7 +66,7 @@ namespace geode { public: SimulationRunner( const SpatialDomain< ObjectType::dim >& domain ) - : domain_( domain ) {}; + : domain_( domain ){}; virtual ~SimulationRunner() = default; virtual void initialize() = 0; diff --git a/src/geode/stochastic/models/energy_terms/energy_term_builder.cpp b/src/geode/stochastic/models/energy_terms/energy_term_builder.cpp index ba865cd..52ff4a0 100644 --- a/src/geode/stochastic/models/energy_terms/energy_term_builder.cpp +++ b/src/geode/stochastic/models/energy_terms/energy_term_builder.cpp @@ -63,12 +63,12 @@ namespace namespace geode { - std::pair< std::vector< geode::uuid >, + std::pair< std::vector< uuid >, absl::flat_hash_map< uuid, std::vector< uuid > > > pairwise_builder_initialize_interactions_helper( const std::vector< std::pair< uuid, uuid > >& interacting_sets ) { - std::vector< geode::uuid > interacting_set_ids; + std::vector< uuid > interacting_set_ids; absl::flat_hash_map< uuid, std::vector< uuid > > objectset_adjacency_map; diff --git a/tests/stochastic/CMakeLists.txt b/tests/stochastic/CMakeLists.txt index b18c043..10cbb1e 100644 --- a/tests/stochastic/CMakeLists.txt +++ b/tests/stochastic/CMakeLists.txt @@ -176,13 +176,13 @@ add_geode_test( ${PROJECT_NAME}::stochastic ) -#add_geode_test( -# SOURCE "sampling/mcmc/test-mh-strauss.cpp" -# DEPENDENCIES -# OpenGeode::basic -# OpenGeode::geometry -# ${PROJECT_NAME}::stochastic -#) +add_geode_test( + SOURCE "sampling/mcmc/test-mh-strauss.cpp" + DEPENDENCIES + OpenGeode::basic + OpenGeode::geometry + ${PROJECT_NAME}::stochastic +) add_geode_test( diff --git a/tests/stochastic/sampling/mcmc/test-mh-poisson.cpp b/tests/stochastic/sampling/mcmc/test-mh-poisson.cpp index eabfe37..9e2affc 100644 --- a/tests/stochastic/sampling/mcmc/test-mh-poisson.cpp +++ b/tests/stochastic/sampling/mcmc/test-mh-poisson.cpp @@ -49,7 +49,7 @@ namespace { public: PoissonSimulationRunner( const geode::SpatialDomain< 2 >& domain ) - : geode::SimulationRunner< geode::Point2D >( domain ) {}; + : geode::SimulationRunner< geode::Point2D >( domain ){}; void add_set_descriptor( const SetDescription& descriptor ) { @@ -122,52 +122,7 @@ namespace create_target_statistics(); } - void check_statistics( const geode::StatisticsTracker< geode::Point2D >& - statistic_monitoring ) const - { - // const auto& computed_means = - // statistic_monitoring.means(); const auto& - // computed_variances = statistic_monitoring.variances(); - // - // for( const auto stat_id : - // geode::Range{ - // this->energy_terms_collection_.size() } ) - // { - // const auto& term = energy_terms_collection_.get( - // ordered_energy_terms_[stat_id] ); - // - // const auto expected_means = - // this->ordered_target_statistics_[stat_id]; - // - // const auto target_vs_mean_error = - // std::fabs( computed_means[stat_id] - - // expected_means ) / expected_means; - // - // geode::OpenGeodeStochasticStochasticException::test( - // target_vs_mean_error < 0.05, "[MH test] - // statistic value ", computed_means[stat_id], " - // for energy term: ", term.name().value_or( - // term.id().string() ), " not close enough to - // expected value ", expected_means, " --> error - // : ", target_vs_mean_error ); - // - // const auto target_vs_variance_error = - // std::fabs( computed_variances[stat_id] - - // expected_means ) / expected_means; - // - // geode::OpenGeodeStochasticStochasticException::test( - // target_vs_variance_error < 0.15, - // "[MH test] variance of statistic ", - // computed_variances[stat_id], " for energy - // term: ", term.name().value_or( - // term.id().string() ), " not close enough to - // expected value ", expected_means, " --> error - // : ", target_vs_variance_error ); - // } - } - private: - geode::BoundingBox2D box_; std::vector< SetDescription > set_descriptors_; std::vector< PoissonDensityDescription > density_descriptors_; std::vector< geode::TargetStatisticConfig > diff --git a/tests/stochastic/sampling/mcmc/test-mh-strauss.cpp b/tests/stochastic/sampling/mcmc/test-mh-strauss.cpp index 61cc11d..bfc3830 100644 --- a/tests/stochastic/sampling/mcmc/test-mh-strauss.cpp +++ b/tests/stochastic/sampling/mcmc/test-mh-strauss.cpp @@ -21,15 +21,16 @@ * */ #include -#include -#include +#include +#include #include -#include -#include -#include #include +#include +#include +#include #include -#include +// #include +#include namespace { @@ -41,21 +42,8 @@ namespace double change_ratio{ 1.0 }; }; - struct PoissonDensityDescription - { - std::string name; - double density; - double target_count; - }; - - struct PairwiseInteractionDescription - { - std::vector< std::string > names; - double strength; - double distance_threshold; - // geode::PairwiseInteraction::SCOPE interaction_scope; - double target_interaction_count; - }; + using PoissonDensityDescription = geode::SingleObjectTermConfig; + using PairwiseInteractionDescription = geode::PairwiseTermConfig; class StraussSimulationRunner : public geode::SimulationRunner< geode::Point2D > @@ -83,113 +71,75 @@ namespace interaction_descriptors_.push_back( descriptor ); } - void initialize() override + void add_target_statistics( + const geode::TargetStatisticConfig& statistic_descriptor ) + { + targeted_statistics_descriptors_.push_back( statistic_descriptor ); + } + std::unique_ptr< geode::ProposalKernel< geode::Point2D > > + create_sets_and_set_samplers() { auto proposal_kernel = std::make_unique< geode::ProposalKernel< geode::Point2D > >(); - // Mapping set names -> UUID - std::unordered_map< std::string, geode::uuid > name_to_uuid; - - // Step 1: create object sets and samplers for( const auto& set_desc : set_descriptors_ ) { const auto set_id = this->object_sets_.add_set( set_desc.name ); - name_to_uuid[set_desc.name] = set_id; - this->set_samplers_.push_back( std::make_unique< geode::UniformPointSetSampler< 2 > >( - this->domain_ ) ); + domain_ ) ); geode::add_birth_death_change_moves( this->set_samplers_.back(), *proposal_kernel, set_id, set_desc.birth_ratio, set_desc.death_ratio, set_desc.change_ratio ); } + return proposal_kernel; + } - // Step 2: create density energy terms - for( const auto& density_desc : density_descriptors_ ) + void create_model() + { + geode::ModelConfig config; + for( const auto& energy_desc : density_descriptors_ ) { - const auto set_id = name_to_uuid.at( density_desc.name ); - this->ordered_energy_terms_.push_back( - this->energy_terms_collection_.add_energy_term( - std::make_unique< - geode::DensityTerm< geode::Point2D > >( - absl::StrCat( density_desc.name, "_density" ), - density_desc.density, - std::vector< geode::uuid >{ set_id }, - this->domain_ ) ) ); - - this->ordered_target_statistics_.push_back( - density_desc.target_count ); + config.terms.push_back( energy_desc ); } - - // Step 3: create pairwise interaction terms for( const auto& interaction_desc : interaction_descriptors_ ) { - std::vector< geode::uuid > set_ids; - for( const auto& name : interaction_desc.names ) - { - set_ids.emplace_back( name_to_uuid.at( name ) ); - } - - auto interaction = std::make_unique< - geode::MinimalDistanceCutoff< geode::Point2D > >( - interaction_desc.distance_threshold - /*,interaction_desc.interaction_scope*/ ); - - this->ordered_energy_terms_.push_back( - this->energy_terms_collection_.add_energy_term( - std::make_unique< - geode::PairwiseTerm< geode::Point2D > >( - absl::StrCat( - absl::StrJoin( interaction_desc.names, "_" ), - "_interaction" ), - interaction_desc.strength, set_ids, - std::move( interaction ), this->domain_ ) ) ); - - this->ordered_target_statistics_.push_back( - interaction_desc.target_interaction_count ); + config.terms.push_back( interaction_desc ); } - this->mh_sampler_ = - std::make_unique< geode::MetropolisHastings< geode::Point2D > >( - this->energy_terms_collection_, - std::move( proposal_kernel ) ); + model_ = std::move( geode::build_model< geode::Point2D >( + config, object_sets_, domain_ ) ); + create_target_statistics(); } - void check_statistics( - const geode::StatisticsTracker& statistic_monitoring ) const + void create_target_statistics() { - const auto& computed_means = statistic_monitoring.means(); - - for( const auto stat_id : - geode::Range{ this->energy_terms_collection_.size() } ) + target_statistics_.emplace( *model_ ); + for( const auto& target_stat : targeted_statistics_descriptors_ ) { - const auto& term = energy_terms_collection_.get( - ordered_energy_terms_[stat_id] ); - - const auto expected_mean = - this->ordered_target_statistics_[stat_id]; - auto target_vs_mean_error = - std::fabs( computed_means[stat_id] - expected_mean ); - if( expected_mean > 0 ) - { - target_vs_mean_error /= expected_mean; - } - - geode::OpenGeodeStochasticStochasticException::test( - target_vs_mean_error < 0.1, "[MH test] Statistic value ", - computed_means[stat_id], " for energy term: ", - term.name().value_or( term.id().string() ), - " not close enough to expected value ", expected_mean, - " --> error: ", target_vs_mean_error ); + target_statistics_->set_target( target_stat ); } } + void initialize() override + { + auto proposal_kernel = create_sets_and_set_samplers(); + create_model(); + + this->mh_sampler_ = + std::make_unique< geode::MetropolisHastings< geode::Point2D > >( + *model_, std::move( proposal_kernel ) ); + create_target_statistics(); + } + private: std::vector< SetDescription > set_descriptors_; std::vector< PoissonDensityDescription > density_descriptors_; std::vector< PairwiseInteractionDescription > interaction_descriptors_; + + std::vector< geode::TargetStatisticConfig > + targeted_statistics_descriptors_; }; void test_single_type_strauss() @@ -203,12 +153,11 @@ namespace geode::BoundingBox2D box; box.add_point( geode::Point2D{ { 0.0, 0.0 } } ); box.add_point( geode::Point2D{ { 10.0, 10.0 } } ); - // todo change!! geode::SpatialDomain domain( box, 1. ); std::array< double, 5 > gamma_values{ 0, 0.3, 0.5, 0.7, 1.0 }; std::array< double, 5 > nb_points{ 19.5, 24.4, 31.3, 36.1, 50. }; - std::array< double, 5 > nb_interactions{ 0, 4, 8, 15, 43 }; + std::array< double, 5 > nb_interactions{ 0, 4.7, 9.8, 18.7, 50.3 }; for( const auto config : geode::Range{ gamma_values.size() } ) { @@ -219,26 +168,35 @@ namespace setA.death_ratio = 1.0; setA.change_ratio = 1.0; - // --- Density term + // --- Energy term description PoissonDensityDescription densityA; - densityA.name = "A"; - densityA.density = 0.5; - densityA.target_count = nb_points[config]; + densityA.term_name = "densityA"; + densityA.object_set_names = { "A" }; + densityA.lambda = 0.5; + densityA.object_feature = geode::ObjectInDomainFeatureConfig{}; + + geode::TargetStatisticConfig statA{ "densityA", nb_points[config], + 0.1 }; // --- Intra-set pairwise interaction (Strauss process) PairwiseInteractionDescription intraA; - intraA.names = { "A" }; // same set - intraA.strength = gamma_values[config]; - intraA.distance_threshold = 1; - // intraA.interaction_scope = - // geode::PairwiseInteraction::SCOPE::INTRA; - intraA.target_interaction_count = nb_interactions[config]; + intraA.term_name = "interactionA"; + intraA.object_set_names_interactions = { { "A", "A" } }; + intraA.gamma = gamma_values[config]; + + intraA.interaction_config = geode::MinimalDistanceCutoffConfig{ + 1. + }; /// ici cela devrait etre un paramètre utilisateur + + geode::TargetStatisticConfig stat_intra_A{ "interactionA", + nb_interactions[config], 0.1 }; StraussSimulationRunner runner( domain ); runner.add_set_descriptor( setA ); runner.add_density_descriptor( densityA ); runner.add_interaction_descriptor( intraA ); - + runner.add_target_statistics( statA ); + runner.add_target_statistics( stat_intra_A ); runner.initialize(); // run simulation @@ -253,8 +211,9 @@ namespace sim_config.burn_in_steps = 1000; sim_config.printer = printer_config; - auto statistic_monitoring = runner.run( engine, sim_config ); - runner.check_statistics( statistic_monitoring ); + auto statistic_tracker = runner.run( engine, sim_config ); + geode::statistics::validate( + statistic_tracker, runner.target_statistics() ); } geode::Logger::info( "--> SUCCESS!" ); @@ -271,15 +230,14 @@ namespace geode::BoundingBox2D box; box.add_point( geode::Point2D{ { 0.0, 0.0 } } ); box.add_point( geode::Point2D{ { 10.0, 10.0 } } ); - // todo change!! - geode::SpatialDomain domain( box, 0. ); + geode::SpatialDomain domain( box, 2. ); std::array< double, 3 > gamma_values{ 0, 0.5, 1.0 }; - std::array< double, 3 > nb_points01{ 3.5, 5, 10.0 }; - std::array< double, 3 > nb_points02{ 14, 21, 40.0 }; - std::array< double, 3 > nb_points03{ 11, 16, 30. }; - std::array< double, 3 > nb_interactions01{ 0, 15, 95 }; - std::array< double, 3 > nb_interactions02{ 8, 20, 85 }; + std::array< double, 3 > nb_points01{ 6.7, 8, 10.0 }; + std::array< double, 3 > nb_points02{ 17.5, 24.6, 40.0 }; + std::array< double, 3 > nb_points03{ 14.6, 19.4, 30. }; + std::array< double, 3 > nb_interactions01{ 0, 15, 59.8 }; + std::array< double, 3 > nb_interactions02{ 37.2, 70, 174 }; for( const auto config : geode::Range{ gamma_values.size() } ) { @@ -289,17 +247,59 @@ namespace SetDescription set03{ "set03", 4.0, 1.0, 1.0 }; // --- Density terms - PoissonDensityDescription d01{ "set01", 0.1, nb_points01[config] }; - PoissonDensityDescription d02{ "set02", 0.4, nb_points02[config] }; - PoissonDensityDescription d03{ "set03", 0.3, nb_points03[config] }; + PoissonDensityDescription d01; + d01.term_name = "density_set01"; + d01.object_set_names = { "set01" }; + d01.lambda = 0.1; + d01.object_feature = geode::ObjectInDomainFeatureConfig{}; + + geode::TargetStatisticConfig stat01{ "density_set01", + nb_points01[config], 0.1 }; + + PoissonDensityDescription d02; + d02.term_name = "density_set02"; + d02.object_set_names = { "set02" }; + d02.lambda = 0.4; + d02.object_feature = geode::ObjectInDomainFeatureConfig{}; + + geode::TargetStatisticConfig stat02{ "density_set02", + nb_points02[config], 0.1 }; + + PoissonDensityDescription d03; + d03.term_name = "density_set03"; + d03.object_set_names = { "set03" }; + d03.lambda = 0.3; + d03.object_feature = geode::ObjectInDomainFeatureConfig{}; + + geode::TargetStatisticConfig stat03{ "density_set03", + nb_points03[config], 0.1 }; // --- Pairwise interactions // 1. Intra-type (repulsion within same set) - PairwiseInteractionDescription intra01{ { "set01", "set02", - "set03" }, - gamma_values[config], 1., nb_interactions01[config] }; - PairwiseInteractionDescription intra02{ { "set02" }, 1., 2., - nb_interactions02[config] }; + PairwiseInteractionDescription intra01; + intra01.term_name = "interaction01"; + intra01.object_set_names_interactions = { { "set01", "set01" }, + { "set02", "set02" }, { "set03", "set03" } }; + intra01.gamma = gamma_values[config]; + + intra01.interaction_config = geode::MinimalDistanceCutoffConfig{ + 1. + }; /// ici cela devrait etre un paramètre utilisateur + + geode::TargetStatisticConfig stat_intra_01{ "interaction01", + nb_interactions01[config], 0.1 }; + + PairwiseInteractionDescription intra02; + intra02.term_name = "interaction02"; + intra02.object_set_names_interactions = { { "set02", "set02" } }; + intra02.gamma = 1.; // gamma_values[config]; + + intra02.interaction_config = geode::MinimalDistanceCutoffConfig{ + 2. + }; /// ici cela devrait etre un paramètre utilisateur + + geode::TargetStatisticConfig stat_intra_02{ "interaction02", + nb_interactions02[config], 0.1 }; StraussSimulationRunner runner( domain ); runner.add_set_descriptor( set01 ); @@ -313,6 +313,12 @@ namespace runner.add_interaction_descriptor( intra01 ); runner.add_interaction_descriptor( intra02 ); + runner.add_target_statistics( stat01 ); + runner.add_target_statistics( stat02 ); + runner.add_target_statistics( stat03 ); + runner.add_target_statistics( stat_intra_01 ); + runner.add_target_statistics( stat_intra_02 ); + runner.initialize(); // run simulation @@ -327,8 +333,9 @@ namespace sim_config.burn_in_steps = 1000; sim_config.printer = printer_config; - auto statistic_monitoring = runner.run( engine, sim_config ); - runner.check_statistics( statistic_monitoring ); + auto statistic_tracker = runner.run( engine, sim_config ); + geode::statistics::validate( + statistic_tracker, runner.target_statistics() ); } geode::Logger::info( "--> SUCCESS!" ); From 07bdc97600d65110e823355c73fe167971ce1bc3 Mon Sep 17 00:00:00 2001 From: francoisbonneau <24669995+francoisbonneau@users.noreply.github.com> Date: Tue, 26 May 2026 14:13:10 +0000 Subject: [PATCH 02/16] Apply prepare changes --- include/geode/stochastic/sampling/mcmc/simulation_runner.hpp | 2 +- tests/stochastic/sampling/mcmc/test-mh-poisson.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/geode/stochastic/sampling/mcmc/simulation_runner.hpp b/include/geode/stochastic/sampling/mcmc/simulation_runner.hpp index bc6aaac..74eb77a 100644 --- a/include/geode/stochastic/sampling/mcmc/simulation_runner.hpp +++ b/include/geode/stochastic/sampling/mcmc/simulation_runner.hpp @@ -66,7 +66,7 @@ namespace geode { public: SimulationRunner( const SpatialDomain< ObjectType::dim >& domain ) - : domain_( domain ){}; + : domain_( domain ) {}; virtual ~SimulationRunner() = default; virtual void initialize() = 0; diff --git a/tests/stochastic/sampling/mcmc/test-mh-poisson.cpp b/tests/stochastic/sampling/mcmc/test-mh-poisson.cpp index 9e2affc..9ce9be5 100644 --- a/tests/stochastic/sampling/mcmc/test-mh-poisson.cpp +++ b/tests/stochastic/sampling/mcmc/test-mh-poisson.cpp @@ -49,7 +49,7 @@ namespace { public: PoissonSimulationRunner( const geode::SpatialDomain< 2 >& domain ) - : geode::SimulationRunner< geode::Point2D >( domain ){}; + : geode::SimulationRunner< geode::Point2D >( domain ) {}; void add_set_descriptor( const SetDescription& descriptor ) { From cf5d65873edfcc21ca772deab82575d34a435673 Mon Sep 17 00:00:00 2001 From: Francois Bonneau Date: Tue, 26 May 2026 18:11:31 +0200 Subject: [PATCH 03/16] tidy 00 --- .../stochastic/inference/statistics_tools.hpp | 71 +++++++++---------- .../energy_terms/energy_term_builder.cpp | 1 - .../sampling/mcmc/test-mh-poisson.cpp | 38 +++++----- .../sampling/mcmc/test-mh-strauss.cpp | 58 +++++++-------- 4 files changed, 85 insertions(+), 83 deletions(-) diff --git a/include/geode/stochastic/inference/statistics_tools.hpp b/include/geode/stochastic/inference/statistics_tools.hpp index 990e7e2..4a426be 100644 --- a/include/geode/stochastic/inference/statistics_tools.hpp +++ b/include/geode/stochastic/inference/statistics_tools.hpp @@ -27,50 +27,47 @@ #include #include -namespace geode +namespace geode::statistics { - namespace statistics + template < typename ObjectType > + void validate( const StatisticsTracker< ObjectType >& tracker, + const TargetStatistics< ObjectType >& targets ) { - template < typename ObjectType > - void validate( const StatisticsTracker< ObjectType >& tracker, - const TargetStatistics< ObjectType >& targets ) - { - const auto& model = targets.model(); + const auto& model = targets.model(); - for( const auto& term_uuid : targets.active_terms() ) - { - const auto mean = tracker.mean( term_uuid ); - const auto target = targets.target( term_uuid ); + for( const auto& term_uuid : targets.active_terms() ) + { + const auto mean = tracker.mean( term_uuid ); + const auto target = targets.target( term_uuid ); - const auto rel_error = - std::fabs( mean - target ) - / ( std::fabs( target ) + geode::GLOBAL_EPSILON ); + const auto rel_error = + std::fabs( mean - target ) + / ( std::fabs( target ) + geode::GLOBAL_EPSILON ); - OpenGeodeStochasticStochasticException::check_exception( - rel_error < targets.tolerance( term_uuid ), nullptr, - OpenGeodeException::TYPE::result, - "[StatisticsValidator] Failure \n --> term ", - model.term_name( term_uuid ), "\n mean = ", mean, - "\n target = ", target, "\n error = ", rel_error, - "\n tol = ", targets.tolerance( term_uuid ) ); - } + OpenGeodeStochasticStochasticException::check_exception( + rel_error < targets.tolerance( term_uuid ), nullptr, + OpenGeodeException::TYPE::result, + "[StatisticsValidator] Failure \n --> term ", + model.term_name( term_uuid ), "\n mean = ", mean, + "\n target = ", target, "\n error = ", rel_error, + "\n tol = ", targets.tolerance( term_uuid ) ); } + } - template < typename ObjectType > - double quadratic_loss( const StatisticsTracker< ObjectType >& tracker, - const TargetStatistics< ObjectType >& targets ) - { - double loss = 0.0; - - for( const auto& term_uuid : targets.active_terms() ) - { - const auto diff = - tracker.mean( term_uuid ) - targets.value( term_uuid ); + template < typename ObjectType > + double quadratic_loss( const StatisticsTracker< ObjectType >& tracker, + const TargetStatistics< ObjectType >& targets ) + { + double loss = 0.0; - loss += diff * diff; - } + for( const auto& term_uuid : targets.active_terms() ) + { + const auto diff = + tracker.mean( term_uuid ) - targets.value( term_uuid ); - return loss; + loss += diff * diff; } - } // namespace statistics -} // namespace geode \ No newline at end of file + + return loss; + } +} // namespace geode::statistics diff --git a/src/geode/stochastic/models/energy_terms/energy_term_builder.cpp b/src/geode/stochastic/models/energy_terms/energy_term_builder.cpp index 52ff4a0..4f9e157 100644 --- a/src/geode/stochastic/models/energy_terms/energy_term_builder.cpp +++ b/src/geode/stochastic/models/energy_terms/energy_term_builder.cpp @@ -20,7 +20,6 @@ * SOFTWARE. * */ -#pragma once #include diff --git a/tests/stochastic/sampling/mcmc/test-mh-poisson.cpp b/tests/stochastic/sampling/mcmc/test-mh-poisson.cpp index 9ce9be5..127c7b4 100644 --- a/tests/stochastic/sampling/mcmc/test-mh-poisson.cpp +++ b/tests/stochastic/sampling/mcmc/test-mh-poisson.cpp @@ -34,6 +34,8 @@ #include namespace { + // NOLINTBEGIN(readability-magic-numbers) + struct SetDescription { std::string name; @@ -48,8 +50,9 @@ namespace : public geode::SimulationRunner< geode::Point2D > { public: - PoissonSimulationRunner( const geode::SpatialDomain< 2 >& domain ) - : geode::SimulationRunner< geode::Point2D >( domain ) {}; + explicit PoissonSimulationRunner( + const geode::SpatialDomain< 2 >& domain ) + : geode::SimulationRunner< geode::Point2D >( domain ){}; void add_set_descriptor( const SetDescription& descriptor ) { @@ -94,7 +97,7 @@ namespace geode::ModelConfig config; for( const auto& energy_desc : density_descriptors_ ) { - config.terms.push_back( energy_desc ); + config.terms.emplace_back( energy_desc ); } model_ = std::move( geode::build_model< geode::Point2D >( @@ -147,25 +150,25 @@ namespace for( const auto config : geode::Range{ birth_ratio.size() } ) { // --- Set description - SetDescription setA; - setA.name = "A"; - setA.birth_ratio = birth_ratio[config]; - setA.death_ratio = 1.0; - setA.change_ratio = change_ratio[config]; + SetDescription set_a; + set_a.name = "A"; + set_a.birth_ratio = birth_ratio[config]; + set_a.death_ratio = 1.0; + set_a.change_ratio = change_ratio[config]; // --- Energy term description - PoissonDensityDescription densityA; - densityA.term_name = "density"; - densityA.object_set_names = { "A" }; - densityA.lambda = 0.3; - densityA.object_feature = geode::ObjectInDomainFeatureConfig{}; + PoissonDensityDescription density_a; + density_a.term_name = "density"; + density_a.object_set_names = { "A" }; + density_a.lambda = 0.3; + density_a.object_feature = geode::ObjectInDomainFeatureConfig{}; - geode::TargetStatisticConfig statA{ "density", 30.0, 0.15 }; + geode::TargetStatisticConfig stat_a{ "density", 30.0, 0.15 }; PoissonSimulationRunner runner( domain ); - runner.add_set_descriptor( setA ); - runner.add_density_descriptor( densityA ); - runner.add_target_statistics( statA ); + runner.add_set_descriptor( set_a ); + runner.add_density_descriptor( density_a ); + runner.add_target_statistics( stat_a ); runner.initialize(); // run simulation @@ -278,4 +281,5 @@ int main() { return geode::geode_lippincott(); } + // NOLINTEND(readability-magic-numbers) } \ No newline at end of file diff --git a/tests/stochastic/sampling/mcmc/test-mh-strauss.cpp b/tests/stochastic/sampling/mcmc/test-mh-strauss.cpp index bfc3830..8ffe106 100644 --- a/tests/stochastic/sampling/mcmc/test-mh-strauss.cpp +++ b/tests/stochastic/sampling/mcmc/test-mh-strauss.cpp @@ -34,6 +34,8 @@ namespace { + // NOLINTBEGIN(readability-magic-numbers) + struct SetDescription { std::string name; @@ -101,11 +103,11 @@ namespace geode::ModelConfig config; for( const auto& energy_desc : density_descriptors_ ) { - config.terms.push_back( energy_desc ); + config.terms.emplace_back( energy_desc ); } for( const auto& interaction_desc : interaction_descriptors_ ) { - config.terms.push_back( interaction_desc ); + config.terms.emplace_back( interaction_desc ); } model_ = std::move( geode::build_model< geode::Point2D >( @@ -149,7 +151,6 @@ namespace geode::RandomEngine engine; engine.set_seed( "@mh-test-single-STRAUSS@" ); - geode::BoundingBox2D box; box.add_point( geode::Point2D{ { 0.0, 0.0 } } ); box.add_point( geode::Point2D{ { 10.0, 10.0 } } ); @@ -158,45 +159,45 @@ namespace std::array< double, 5 > gamma_values{ 0, 0.3, 0.5, 0.7, 1.0 }; std::array< double, 5 > nb_points{ 19.5, 24.4, 31.3, 36.1, 50. }; std::array< double, 5 > nb_interactions{ 0, 4.7, 9.8, 18.7, 50.3 }; - for( const auto config : geode::Range{ gamma_values.size() } ) { // --- Object set - SetDescription setA; - setA.name = "A"; - setA.birth_ratio = 1.0; - setA.death_ratio = 1.0; - setA.change_ratio = 1.0; + SetDescription set_a; + set_a.name = "A"; + set_a.birth_ratio = 1.0; + set_a.death_ratio = 1.0; + set_a.change_ratio = 1.0; // --- Energy term description - PoissonDensityDescription densityA; - densityA.term_name = "densityA"; - densityA.object_set_names = { "A" }; - densityA.lambda = 0.5; - densityA.object_feature = geode::ObjectInDomainFeatureConfig{}; + PoissonDensityDescription density_a; + density_a.term_name = "density_a"; + density_a.object_set_names = { "A" }; + density_a.lambda = 0.5; + density_a.object_feature = geode::ObjectInDomainFeatureConfig{}; - geode::TargetStatisticConfig statA{ "densityA", nb_points[config], + geode::TargetStatisticConfig stat_a{ "density_a", nb_points[config], 0.1 }; // --- Intra-set pairwise interaction (Strauss process) - PairwiseInteractionDescription intraA; - intraA.term_name = "interactionA"; - intraA.object_set_names_interactions = { { "A", "A" } }; - intraA.gamma = gamma_values[config]; + PairwiseInteractionDescription interaction_a; + interaction_a.term_name = "interactionA"; + interaction_a.object_set_names_interactions = { { "A", "A" } }; + interaction_a.gamma = gamma_values[config]; - intraA.interaction_config = geode::MinimalDistanceCutoffConfig{ - 1. - }; /// ici cela devrait etre un paramètre utilisateur + interaction_a.interaction_config = + geode::MinimalDistanceCutoffConfig{ + 1. + }; /// ici cela devrait etre un paramètre utilisateur - geode::TargetStatisticConfig stat_intra_A{ "interactionA", + geode::TargetStatisticConfig stat_intra_a{ "interactionA", nb_interactions[config], 0.1 }; StraussSimulationRunner runner( domain ); - runner.add_set_descriptor( setA ); - runner.add_density_descriptor( densityA ); - runner.add_interaction_descriptor( intraA ); - runner.add_target_statistics( statA ); - runner.add_target_statistics( stat_intra_A ); + runner.add_set_descriptor( set_a ); + runner.add_density_descriptor( density_a ); + runner.add_interaction_descriptor( interaction_a ); + runner.add_target_statistics( stat_a ); + runner.add_target_statistics( stat_intra_a ); runner.initialize(); // run simulation @@ -356,4 +357,5 @@ int main() { return geode::geode_lippincott(); } + // NOLINTEND(readability-magic-numbers) } \ No newline at end of file From 8a30a3f64db6a511ff32c50e8bf561ca4b585dab Mon Sep 17 00:00:00 2001 From: francoisbonneau <24669995+francoisbonneau@users.noreply.github.com> Date: Tue, 26 May 2026 16:12:12 +0000 Subject: [PATCH 04/16] Apply prepare changes --- tests/stochastic/sampling/mcmc/test-mh-poisson.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/stochastic/sampling/mcmc/test-mh-poisson.cpp b/tests/stochastic/sampling/mcmc/test-mh-poisson.cpp index 127c7b4..2ce08d7 100644 --- a/tests/stochastic/sampling/mcmc/test-mh-poisson.cpp +++ b/tests/stochastic/sampling/mcmc/test-mh-poisson.cpp @@ -52,7 +52,7 @@ namespace public: explicit PoissonSimulationRunner( const geode::SpatialDomain< 2 >& domain ) - : geode::SimulationRunner< geode::Point2D >( domain ){}; + : geode::SimulationRunner< geode::Point2D >( domain ) {}; void add_set_descriptor( const SetDescription& descriptor ) { From ddab9524014e5652339b54d7f51a01dba3383f93 Mon Sep 17 00:00:00 2001 From: Francois Bonneau Date: Tue, 26 May 2026 18:23:11 +0200 Subject: [PATCH 05/16] tidy01 --- tests/stochastic/sampling/mcmc/test-mh-poisson.cpp | 7 +++---- tests/stochastic/sampling/mcmc/test-mh-strauss.cpp | 5 ++--- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/tests/stochastic/sampling/mcmc/test-mh-poisson.cpp b/tests/stochastic/sampling/mcmc/test-mh-poisson.cpp index 2ce08d7..2662683 100644 --- a/tests/stochastic/sampling/mcmc/test-mh-poisson.cpp +++ b/tests/stochastic/sampling/mcmc/test-mh-poisson.cpp @@ -34,8 +34,7 @@ #include namespace { - // NOLINTBEGIN(readability-magic-numbers) - + // NOLINT(*-magic-numbers) struct SetDescription { std::string name; @@ -52,7 +51,7 @@ namespace public: explicit PoissonSimulationRunner( const geode::SpatialDomain< 2 >& domain ) - : geode::SimulationRunner< geode::Point2D >( domain ) {}; + : geode::SimulationRunner< geode::Point2D >( domain ){}; void add_set_descriptor( const SetDescription& descriptor ) { @@ -281,5 +280,5 @@ int main() { return geode::geode_lippincott(); } - // NOLINTEND(readability-magic-numbers) + // NOLINTEND(*-magic-numbers) } \ No newline at end of file diff --git a/tests/stochastic/sampling/mcmc/test-mh-strauss.cpp b/tests/stochastic/sampling/mcmc/test-mh-strauss.cpp index 8ffe106..17791d5 100644 --- a/tests/stochastic/sampling/mcmc/test-mh-strauss.cpp +++ b/tests/stochastic/sampling/mcmc/test-mh-strauss.cpp @@ -34,8 +34,7 @@ namespace { - // NOLINTBEGIN(readability-magic-numbers) - + // NOLINT(*-magic-numbers) struct SetDescription { std::string name; @@ -357,5 +356,5 @@ int main() { return geode::geode_lippincott(); } - // NOLINTEND(readability-magic-numbers) + // NOLINTEND(*-magic-numbers) } \ No newline at end of file From 2e072ddc9ba38c55ca4201827a81efa323d828ca Mon Sep 17 00:00:00 2001 From: francoisbonneau <24669995+francoisbonneau@users.noreply.github.com> Date: Tue, 26 May 2026 16:23:46 +0000 Subject: [PATCH 06/16] Apply prepare changes --- tests/stochastic/sampling/mcmc/test-mh-poisson.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/stochastic/sampling/mcmc/test-mh-poisson.cpp b/tests/stochastic/sampling/mcmc/test-mh-poisson.cpp index 2662683..5de527e 100644 --- a/tests/stochastic/sampling/mcmc/test-mh-poisson.cpp +++ b/tests/stochastic/sampling/mcmc/test-mh-poisson.cpp @@ -51,7 +51,7 @@ namespace public: explicit PoissonSimulationRunner( const geode::SpatialDomain< 2 >& domain ) - : geode::SimulationRunner< geode::Point2D >( domain ){}; + : geode::SimulationRunner< geode::Point2D >( domain ) {}; void add_set_descriptor( const SetDescription& descriptor ) { From c9128a979338e78c4e85d7a4d65b89407fa350b1 Mon Sep 17 00:00:00 2001 From: Francois Bonneau Date: Tue, 26 May 2026 19:07:24 +0200 Subject: [PATCH 07/16] tidy02 --- tests/stochastic/sampling/mcmc/test-mh-poisson.cpp | 10 +++++++--- tests/stochastic/sampling/mcmc/test-mh-strauss.cpp | 12 ++++++++---- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/tests/stochastic/sampling/mcmc/test-mh-poisson.cpp b/tests/stochastic/sampling/mcmc/test-mh-poisson.cpp index 5de527e..1f69604 100644 --- a/tests/stochastic/sampling/mcmc/test-mh-poisson.cpp +++ b/tests/stochastic/sampling/mcmc/test-mh-poisson.cpp @@ -34,7 +34,6 @@ #include namespace { - // NOLINT(*-magic-numbers) struct SetDescription { std::string name; @@ -138,6 +137,7 @@ namespace geode::RandomEngine engine; engine.set_seed( "@mh-test-single-POISSON@" ); + // NOLINT(*-magic-numbers) geode::BoundingBox2D box; box.add_point( geode::Point2D{ { 0.0, 0.0 } } ); box.add_point( geode::Point2D{ { 10.0, 10.0 } } ); @@ -145,9 +145,11 @@ namespace std::array< double, 4 > birth_ratio{ 0.1, 0.5, 2., 4. }; std::array< double, 4 > change_ratio{ 0., 1., 1., 0. }; - + // NOLINTEND(*-magic-numbers) for( const auto config : geode::Range{ birth_ratio.size() } ) { + // NOLINT(*-magic-numbers) + // --- Set description SetDescription set_a; set_a.name = "A"; @@ -181,6 +183,7 @@ namespace sim_config.metropolis_hasting_steps = 1000; sim_config.burn_in_steps = 1000; sim_config.printer = printer_config; + // NOLINTEND(*-magic-numbers) auto statistic_tracker = runner.run( engine, sim_config ); geode::statistics::validate( @@ -196,6 +199,7 @@ namespace geode::RandomEngine engine; engine.set_seed( "@mh-test-POISSON-multi@" ); + // NOLINT(*-magic-numbers) geode::BoundingBox2D box; box.add_point( geode::Point2D{ { 0.0, 0.0 } } ); @@ -257,6 +261,7 @@ namespace sim_config.metropolis_hasting_steps = 1000; sim_config.burn_in_steps = 3000; sim_config.printer = printer_config; + // NOLINTEND(*-magic-numbers) auto statistic_tracker = runner.run( engine, sim_config ); geode::statistics::validate( @@ -280,5 +285,4 @@ int main() { return geode::geode_lippincott(); } - // NOLINTEND(*-magic-numbers) } \ No newline at end of file diff --git a/tests/stochastic/sampling/mcmc/test-mh-strauss.cpp b/tests/stochastic/sampling/mcmc/test-mh-strauss.cpp index 17791d5..57499bb 100644 --- a/tests/stochastic/sampling/mcmc/test-mh-strauss.cpp +++ b/tests/stochastic/sampling/mcmc/test-mh-strauss.cpp @@ -34,7 +34,6 @@ namespace { - // NOLINT(*-magic-numbers) struct SetDescription { std::string name; @@ -150,6 +149,7 @@ namespace geode::RandomEngine engine; engine.set_seed( "@mh-test-single-STRAUSS@" ); + // NOLINT(*-magic-numbers) geode::BoundingBox2D box; box.add_point( geode::Point2D{ { 0.0, 0.0 } } ); box.add_point( geode::Point2D{ { 10.0, 10.0 } } ); @@ -158,8 +158,10 @@ namespace std::array< double, 5 > gamma_values{ 0, 0.3, 0.5, 0.7, 1.0 }; std::array< double, 5 > nb_points{ 19.5, 24.4, 31.3, 36.1, 50. }; std::array< double, 5 > nb_interactions{ 0, 4.7, 9.8, 18.7, 50.3 }; + // NOLINTEND(*-magic-numbers) for( const auto config : geode::Range{ gamma_values.size() } ) { + // NOLINT(*-magic-numbers) // --- Object set SetDescription set_a; set_a.name = "A"; @@ -210,6 +212,7 @@ namespace sim_config.metropolis_hasting_steps = 1000; sim_config.burn_in_steps = 1000; sim_config.printer = printer_config; + // NOLINTEND(*-magic-numbers) auto statistic_tracker = runner.run( engine, sim_config ); geode::statistics::validate( @@ -226,7 +229,7 @@ namespace geode::RandomEngine engine; engine.set_seed( "@mh-test-multi-STRAUSS@" ); - + // NOLINT(*-magic-numbers) geode::BoundingBox2D box; box.add_point( geode::Point2D{ { 0.0, 0.0 } } ); box.add_point( geode::Point2D{ { 10.0, 10.0 } } ); @@ -238,9 +241,10 @@ namespace std::array< double, 3 > nb_points03{ 14.6, 19.4, 30. }; std::array< double, 3 > nb_interactions01{ 0, 15, 59.8 }; std::array< double, 3 > nb_interactions02{ 37.2, 70, 174 }; - + // NOLINTEND(*-magic-numbers) for( const auto config : geode::Range{ gamma_values.size() } ) { + // NOLINT(*-magic-numbers) // --- Sets SetDescription set01{ "set01", 1.0, 3.0, 1.0 }; SetDescription set02{ "set02", 3.0, 0.5, 1.0 }; @@ -332,6 +336,7 @@ namespace sim_config.metropolis_hasting_steps = 1000; sim_config.burn_in_steps = 1000; sim_config.printer = printer_config; + // NOLINTEND(*-magic-numbers) auto statistic_tracker = runner.run( engine, sim_config ); geode::statistics::validate( @@ -356,5 +361,4 @@ int main() { return geode::geode_lippincott(); } - // NOLINTEND(*-magic-numbers) } \ No newline at end of file From 405e0e49fb82cdfd5e4cae7b9a13a01441e2f0c0 Mon Sep 17 00:00:00 2001 From: Francois Bonneau Date: Tue, 26 May 2026 19:40:10 +0200 Subject: [PATCH 08/16] tidy 04 --- tests/stochastic/sampling/mcmc/test-mh-poisson.cpp | 11 ++++------- tests/stochastic/sampling/mcmc/test-mh-strauss.cpp | 13 ++++--------- 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/tests/stochastic/sampling/mcmc/test-mh-poisson.cpp b/tests/stochastic/sampling/mcmc/test-mh-poisson.cpp index 1f69604..973fb16 100644 --- a/tests/stochastic/sampling/mcmc/test-mh-poisson.cpp +++ b/tests/stochastic/sampling/mcmc/test-mh-poisson.cpp @@ -50,7 +50,7 @@ namespace public: explicit PoissonSimulationRunner( const geode::SpatialDomain< 2 >& domain ) - : geode::SimulationRunner< geode::Point2D >( domain ) {}; + : geode::SimulationRunner< geode::Point2D >( domain ){}; void add_set_descriptor( const SetDescription& descriptor ) { @@ -137,7 +137,7 @@ namespace geode::RandomEngine engine; engine.set_seed( "@mh-test-single-POISSON@" ); - // NOLINT(*-magic-numbers) + // NOLINTBEGIN(*-magic-numbers) geode::BoundingBox2D box; box.add_point( geode::Point2D{ { 0.0, 0.0 } } ); box.add_point( geode::Point2D{ { 10.0, 10.0 } } ); @@ -145,11 +145,8 @@ namespace std::array< double, 4 > birth_ratio{ 0.1, 0.5, 2., 4. }; std::array< double, 4 > change_ratio{ 0., 1., 1., 0. }; - // NOLINTEND(*-magic-numbers) for( const auto config : geode::Range{ birth_ratio.size() } ) { - // NOLINT(*-magic-numbers) - // --- Set description SetDescription set_a; set_a.name = "A"; @@ -183,12 +180,12 @@ namespace sim_config.metropolis_hasting_steps = 1000; sim_config.burn_in_steps = 1000; sim_config.printer = printer_config; - // NOLINTEND(*-magic-numbers) auto statistic_tracker = runner.run( engine, sim_config ); geode::statistics::validate( statistic_tracker, runner.target_statistics() ); } + // NOLINTEND(*-magic-numbers) geode::Logger::info( "--> SUCCESS!" ); } @@ -199,7 +196,7 @@ namespace geode::RandomEngine engine; engine.set_seed( "@mh-test-POISSON-multi@" ); - // NOLINT(*-magic-numbers) + // NOLINTBEGIN(*-magic-numbers) geode::BoundingBox2D box; box.add_point( geode::Point2D{ { 0.0, 0.0 } } ); diff --git a/tests/stochastic/sampling/mcmc/test-mh-strauss.cpp b/tests/stochastic/sampling/mcmc/test-mh-strauss.cpp index 57499bb..06d0702 100644 --- a/tests/stochastic/sampling/mcmc/test-mh-strauss.cpp +++ b/tests/stochastic/sampling/mcmc/test-mh-strauss.cpp @@ -149,7 +149,7 @@ namespace geode::RandomEngine engine; engine.set_seed( "@mh-test-single-STRAUSS@" ); - // NOLINT(*-magic-numbers) + // NOLINTBEGIN(*-magic-numbers) geode::BoundingBox2D box; box.add_point( geode::Point2D{ { 0.0, 0.0 } } ); box.add_point( geode::Point2D{ { 10.0, 10.0 } } ); @@ -158,10 +158,8 @@ namespace std::array< double, 5 > gamma_values{ 0, 0.3, 0.5, 0.7, 1.0 }; std::array< double, 5 > nb_points{ 19.5, 24.4, 31.3, 36.1, 50. }; std::array< double, 5 > nb_interactions{ 0, 4.7, 9.8, 18.7, 50.3 }; - // NOLINTEND(*-magic-numbers) for( const auto config : geode::Range{ gamma_values.size() } ) { - // NOLINT(*-magic-numbers) // --- Object set SetDescription set_a; set_a.name = "A"; @@ -212,13 +210,12 @@ namespace sim_config.metropolis_hasting_steps = 1000; sim_config.burn_in_steps = 1000; sim_config.printer = printer_config; - // NOLINTEND(*-magic-numbers) auto statistic_tracker = runner.run( engine, sim_config ); geode::statistics::validate( statistic_tracker, runner.target_statistics() ); } - + // NOLINTEND(*-magic-numbers) geode::Logger::info( "--> SUCCESS!" ); } @@ -229,7 +226,7 @@ namespace geode::RandomEngine engine; engine.set_seed( "@mh-test-multi-STRAUSS@" ); - // NOLINT(*-magic-numbers) + // NOLINTBEGIN(*-magic-numbers) geode::BoundingBox2D box; box.add_point( geode::Point2D{ { 0.0, 0.0 } } ); box.add_point( geode::Point2D{ { 10.0, 10.0 } } ); @@ -241,10 +238,8 @@ namespace std::array< double, 3 > nb_points03{ 14.6, 19.4, 30. }; std::array< double, 3 > nb_interactions01{ 0, 15, 59.8 }; std::array< double, 3 > nb_interactions02{ 37.2, 70, 174 }; - // NOLINTEND(*-magic-numbers) for( const auto config : geode::Range{ gamma_values.size() } ) { - // NOLINT(*-magic-numbers) // --- Sets SetDescription set01{ "set01", 1.0, 3.0, 1.0 }; SetDescription set02{ "set02", 3.0, 0.5, 1.0 }; @@ -336,12 +331,12 @@ namespace sim_config.metropolis_hasting_steps = 1000; sim_config.burn_in_steps = 1000; sim_config.printer = printer_config; - // NOLINTEND(*-magic-numbers) auto statistic_tracker = runner.run( engine, sim_config ); geode::statistics::validate( statistic_tracker, runner.target_statistics() ); } + // NOLINTEND(*-magic-numbers) geode::Logger::info( "--> SUCCESS!" ); } From d43652002e6c742954e54be74c2f85863785bfac Mon Sep 17 00:00:00 2001 From: francoisbonneau <24669995+francoisbonneau@users.noreply.github.com> Date: Tue, 26 May 2026 17:40:44 +0000 Subject: [PATCH 09/16] Apply prepare changes --- tests/stochastic/sampling/mcmc/test-mh-poisson.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/stochastic/sampling/mcmc/test-mh-poisson.cpp b/tests/stochastic/sampling/mcmc/test-mh-poisson.cpp index 973fb16..bdd5932 100644 --- a/tests/stochastic/sampling/mcmc/test-mh-poisson.cpp +++ b/tests/stochastic/sampling/mcmc/test-mh-poisson.cpp @@ -50,7 +50,7 @@ namespace public: explicit PoissonSimulationRunner( const geode::SpatialDomain< 2 >& domain ) - : geode::SimulationRunner< geode::Point2D >( domain ){}; + : geode::SimulationRunner< geode::Point2D >( domain ) {}; void add_set_descriptor( const SetDescription& descriptor ) { From 0a326988a5dc76ac2f403d322a26e0750d33b66b Mon Sep 17 00:00:00 2001 From: Francois Bonneau Date: Tue, 26 May 2026 19:57:38 +0200 Subject: [PATCH 10/16] tidy05 --- tests/stochastic/sampling/mcmc/test-mh-strauss.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/stochastic/sampling/mcmc/test-mh-strauss.cpp b/tests/stochastic/sampling/mcmc/test-mh-strauss.cpp index 06d0702..d41664e 100644 --- a/tests/stochastic/sampling/mcmc/test-mh-strauss.cpp +++ b/tests/stochastic/sampling/mcmc/test-mh-strauss.cpp @@ -49,7 +49,8 @@ namespace : public geode::SimulationRunner< geode::Point2D > { public: - StraussSimulationRunner( const geode::SpatialDomain< 2 >& domain ) + explicit StraussSimulationRunner( + const geode::SpatialDomain< 2 >& domain ) : geode::SimulationRunner< geode::Point2D >( domain ) { } From a813370efbcd95e9b073e5ef54c6d5e354a49d84 Mon Sep 17 00:00:00 2001 From: Francois Bonneau Date: Tue, 26 May 2026 19:58:30 +0200 Subject: [PATCH 11/16] reduce nb iteration --- tests/stochastic/sampling/mcmc/test-mh-strauss.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/stochastic/sampling/mcmc/test-mh-strauss.cpp b/tests/stochastic/sampling/mcmc/test-mh-strauss.cpp index d41664e..8f53855 100644 --- a/tests/stochastic/sampling/mcmc/test-mh-strauss.cpp +++ b/tests/stochastic/sampling/mcmc/test-mh-strauss.cpp @@ -328,7 +328,7 @@ namespace "/sim_point_multitype_strauss_test" ); geode::SimulationConfigurator sim_config; - sim_config.realizations = 750; + sim_config.realizations = 500; sim_config.metropolis_hasting_steps = 1000; sim_config.burn_in_steps = 1000; sim_config.printer = printer_config; From 4c2ec7624d43e3b6e132357f184dfe546d10a3aa Mon Sep 17 00:00:00 2001 From: Francois Bonneau Date: Tue, 26 May 2026 20:14:43 +0200 Subject: [PATCH 12/16] modif param --- tests/stochastic/sampling/mcmc/test-mh-strauss.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/stochastic/sampling/mcmc/test-mh-strauss.cpp b/tests/stochastic/sampling/mcmc/test-mh-strauss.cpp index 8f53855..5f09044 100644 --- a/tests/stochastic/sampling/mcmc/test-mh-strauss.cpp +++ b/tests/stochastic/sampling/mcmc/test-mh-strauss.cpp @@ -328,9 +328,9 @@ namespace "/sim_point_multitype_strauss_test" ); geode::SimulationConfigurator sim_config; - sim_config.realizations = 500; - sim_config.metropolis_hasting_steps = 1000; - sim_config.burn_in_steps = 1000; + sim_config.realizations = 600; + sim_config.metropolis_hasting_steps = 750; + sim_config.burn_in_steps = 5000; sim_config.printer = printer_config; auto statistic_tracker = runner.run( engine, sim_config ); From 683ebbaf6593c209e2aff30ff905d8e705b031cb Mon Sep 17 00:00:00 2001 From: Francois Bonneau Date: Wed, 27 May 2026 10:20:54 +0200 Subject: [PATCH 13/16] avoid generic capture in lambdas --- .../stochastic/models/energy_terms/energy_term_builder.hpp | 2 +- .../stochastic/models/energy_terms/single_object_term.hpp | 6 +++--- .../pairwise_interactions/pairwise_interactions_builder.hpp | 2 +- .../single_object_feature_builder.hpp | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/include/geode/stochastic/models/energy_terms/energy_term_builder.hpp b/include/geode/stochastic/models/energy_terms/energy_term_builder.hpp index c3b1503..86aac82 100644 --- a/include/geode/stochastic/models/energy_terms/energy_term_builder.hpp +++ b/include/geode/stochastic/models/energy_terms/energy_term_builder.hpp @@ -135,7 +135,7 @@ namespace geode const SpatialDomain< ObjectType::dim >& domain ) { return std::visit( - [&]( const auto& term_cfg ) + [&object_sets, &domain]( const auto& term_cfg ) -> std::unique_ptr< EnergyTerm< ObjectType > > { return build_energy_term_impl< ObjectType >( term_cfg, object_sets, domain ); diff --git a/include/geode/stochastic/models/energy_terms/single_object_term.hpp b/include/geode/stochastic/models/energy_terms/single_object_term.hpp index ae00091..fab3286 100644 --- a/include/geode/stochastic/models/energy_terms/single_object_term.hpp +++ b/include/geode/stochastic/models/energy_terms/single_object_term.hpp @@ -95,10 +95,10 @@ namespace geode const ObjectSets< ObjectType >& state ) const override { double sum = 0.0; - this->for_each_object_in_sets( - state, this->impacted_set_ids(), [&]( const ObjectId& obj_id ) { + this->for_each_object_in_sets( state, this->impacted_set_ids(), + [&state, &sum, this]( const ObjectId& obj_id ) { const auto& obj = state.get_object( obj_id ); - sum += feature_->evaluate( obj, this->domain() ); + sum += this->feature_->evaluate( obj, this->domain() ); } ); return sum; } diff --git a/include/geode/stochastic/spatial/pairwise_interactions/pairwise_interactions_builder.hpp b/include/geode/stochastic/spatial/pairwise_interactions/pairwise_interactions_builder.hpp index 04a6fbf..d0e497e 100644 --- a/include/geode/stochastic/spatial/pairwise_interactions/pairwise_interactions_builder.hpp +++ b/include/geode/stochastic/spatial/pairwise_interactions/pairwise_interactions_builder.hpp @@ -68,7 +68,7 @@ namespace geode build_pairwise_interaction( const PairwiseInteractionConfig& cfg ) { return std::visit( - [&]( auto&& interaction_cfg ) + []( auto&& interaction_cfg ) -> std::unique_ptr< PairwiseInteraction< ObjectType > > { return build_pairwise_interaction_impl< ObjectType >( interaction_cfg ); diff --git a/include/geode/stochastic/spatial/single_object_features/single_object_feature_builder.hpp b/include/geode/stochastic/spatial/single_object_features/single_object_feature_builder.hpp index edd3c88..683fa3b 100644 --- a/include/geode/stochastic/spatial/single_object_features/single_object_feature_builder.hpp +++ b/include/geode/stochastic/spatial/single_object_features/single_object_feature_builder.hpp @@ -80,7 +80,7 @@ namespace geode build_single_object_feature( const SingleObjectFeatureConfig& cfg ) { return std::visit( - [&]( auto&& interaction_cfg ) + []( auto&& interaction_cfg ) -> std::unique_ptr< SingleObjectFeature< ObjectType > > { return build_single_object_feature_impl< ObjectType >( interaction_cfg ); From 60b8dca045919990406440da5951ef3646b6de3b Mon Sep 17 00:00:00 2001 From: Francois Bonneau Date: Wed, 27 May 2026 11:07:10 +0200 Subject: [PATCH 14/16] tidy 05 --- .../models/energy_terms/energy_term_builder.hpp | 12 ++++++------ .../models/energy_terms/pairwise_term.hpp | 2 +- .../pairwise_interactions_builder.hpp | 6 ++++-- .../single_object_feature_builder.hpp | 13 +++++++++---- 4 files changed, 20 insertions(+), 13 deletions(-) diff --git a/include/geode/stochastic/models/energy_terms/energy_term_builder.hpp b/include/geode/stochastic/models/energy_terms/energy_term_builder.hpp index 86aac82..7026f3f 100644 --- a/include/geode/stochastic/models/energy_terms/energy_term_builder.hpp +++ b/include/geode/stochastic/models/energy_terms/energy_term_builder.hpp @@ -108,9 +108,9 @@ namespace geode template < typename ObjectType, typename NewEnergyTypeConfig > std::unique_ptr< EnergyTerm< ObjectType > > build_energy_term_impl( - const NewEnergyTypeConfig&, - const ObjectSets< ObjectType >&, - const SpatialDomain< ObjectType::dim >& ) + const NewEnergyTypeConfig& /*unused*/, + const ObjectSets< ObjectType >& /*unused*/, + const SpatialDomain< ObjectType::dim >& /*unused*/ ) { static_assert( sizeof( NewEnergyTypeConfig ) == 0, "Unsupported EnergyTermConfig type" ); @@ -119,9 +119,9 @@ namespace geode template < typename ObjectType > std::unique_ptr< EnergyTerm< ObjectType > > build_energy_term_impl( - const std::monostate&, - const ObjectSets< ObjectType >&, - const SpatialDomain< ObjectType::dim >& ) + const std::monostate& /*unused*/, + const ObjectSets< ObjectType >& /*unused*/, + const SpatialDomain< ObjectType::dim >& /*unused*/ ) { throw OpenGeodeStochasticStochasticException{ nullptr, OpenGeodeException::TYPE::data, diff --git a/include/geode/stochastic/models/energy_terms/pairwise_term.hpp b/include/geode/stochastic/models/energy_terms/pairwise_term.hpp index 75fc792..4d3bf8c 100644 --- a/include/geode/stochastic/models/energy_terms/pairwise_term.hpp +++ b/include/geode/stochastic/models/energy_terms/pairwise_term.hpp @@ -106,7 +106,7 @@ namespace geode { double sum = 0.0; this->for_each_object_in_sets( state, this->impacted_set_ids(), - [&]( const ObjectId& cur_obj_id ) { + [&state]( const ObjectId& cur_obj_id ) { sum += accumulate_interactions_with_neighbors( cur_obj_id, state ); } ); diff --git a/include/geode/stochastic/spatial/pairwise_interactions/pairwise_interactions_builder.hpp b/include/geode/stochastic/spatial/pairwise_interactions/pairwise_interactions_builder.hpp index d0e497e..fc0ec2f 100644 --- a/include/geode/stochastic/spatial/pairwise_interactions/pairwise_interactions_builder.hpp +++ b/include/geode/stochastic/spatial/pairwise_interactions/pairwise_interactions_builder.hpp @@ -21,6 +21,7 @@ * */ +#include #include #include @@ -47,7 +48,8 @@ namespace geode template < typename ObjectType, typename NewInteractionConfig > std::unique_ptr< PairwiseInteraction< ObjectType > > - build_pairwise_interaction_impl( const NewInteractionConfig& ) + build_pairwise_interaction_impl( + const NewInteractionConfig& /*unused*/ ) { static_assert( sizeof( NewInteractionConfig ) == 0, "Unsupported PairwiseInteractionConfig type" ); @@ -56,7 +58,7 @@ namespace geode template < typename ObjectType > std::unique_ptr< PairwiseInteraction< ObjectType > > - build_pairwise_interaction_impl( const std::monostate& ) + build_pairwise_interaction_impl( const std::monostate& /*unused*/ ) { throw OpenGeodeStochasticStochasticException{ nullptr, OpenGeodeException::TYPE::data, diff --git a/include/geode/stochastic/spatial/single_object_features/single_object_feature_builder.hpp b/include/geode/stochastic/spatial/single_object_features/single_object_feature_builder.hpp index 683fa3b..54cb1bb 100644 --- a/include/geode/stochastic/spatial/single_object_features/single_object_feature_builder.hpp +++ b/include/geode/stochastic/spatial/single_object_features/single_object_feature_builder.hpp @@ -24,6 +24,8 @@ #include +#include + #include #include @@ -52,22 +54,25 @@ namespace geode { throw OpenGeodeStochasticStochasticException{ nullptr, OpenGeodeException::TYPE::data, - "SegmentLengthInsideBoxFeature not valid for this ObjectType" }; + "[SingleObjectFeatureBuilder] SegmentLengthInsideBoxFeature " + "not valid for this ObjectType" }; } } template < typename ObjectType, typename NewObjectFeatureConfig > std::unique_ptr< SingleObjectFeature< ObjectType > > - build_single_object_feature_impl( const NewObjectFeatureConfig& ) + build_single_object_feature_impl( + const NewObjectFeatureConfig& /*unused*/ ) { static_assert( sizeof( NewObjectFeatureConfig ) == 0, - "Unsupported SingleObjectFeatureConfig type" ); + "[SingleObjectFeatureBuilder] Unsupported " + "SingleObjectFeatureConfig type" ); return nullptr; } template < typename ObjectType > std::unique_ptr< SingleObjectFeature< ObjectType > > - build_single_object_feature_impl( const std::monostate& ) + build_single_object_feature_impl( const std::monostate& /*unused*/ ) { throw OpenGeodeStochasticStochasticException{ nullptr, OpenGeodeException::TYPE::data, From 40339c3693689d76f6d4064d0f01667b8d977761 Mon Sep 17 00:00:00 2001 From: Francois Bonneau Date: Wed, 27 May 2026 11:22:38 +0200 Subject: [PATCH 15/16] tidy06 --- .../stochastic/models/energy_terms/energy_term_builder.hpp | 2 ++ include/geode/stochastic/models/energy_terms/pairwise_term.hpp | 2 +- .../pairwise_interactions/pairwise_interactions_builder.hpp | 3 ++- .../single_object_features/single_object_feature_builder.hpp | 2 +- 4 files changed, 6 insertions(+), 3 deletions(-) diff --git a/include/geode/stochastic/models/energy_terms/energy_term_builder.hpp b/include/geode/stochastic/models/energy_terms/energy_term_builder.hpp index 7026f3f..119f01c 100644 --- a/include/geode/stochastic/models/energy_terms/energy_term_builder.hpp +++ b/include/geode/stochastic/models/energy_terms/energy_term_builder.hpp @@ -30,6 +30,8 @@ #include #include +#include + #include #include #include diff --git a/include/geode/stochastic/models/energy_terms/pairwise_term.hpp b/include/geode/stochastic/models/energy_terms/pairwise_term.hpp index 4d3bf8c..ce0658f 100644 --- a/include/geode/stochastic/models/energy_terms/pairwise_term.hpp +++ b/include/geode/stochastic/models/energy_terms/pairwise_term.hpp @@ -106,7 +106,7 @@ namespace geode { double sum = 0.0; this->for_each_object_in_sets( state, this->impacted_set_ids(), - [&state]( const ObjectId& cur_obj_id ) { + [&sum, &state]( const ObjectId& cur_obj_id ) { sum += accumulate_interactions_with_neighbors( cur_obj_id, state ); } ); diff --git a/include/geode/stochastic/spatial/pairwise_interactions/pairwise_interactions_builder.hpp b/include/geode/stochastic/spatial/pairwise_interactions/pairwise_interactions_builder.hpp index fc0ec2f..4421e0f 100644 --- a/include/geode/stochastic/spatial/pairwise_interactions/pairwise_interactions_builder.hpp +++ b/include/geode/stochastic/spatial/pairwise_interactions/pairwise_interactions_builder.hpp @@ -21,7 +21,8 @@ * */ -#include +#include + #include #include diff --git a/include/geode/stochastic/spatial/single_object_features/single_object_feature_builder.hpp b/include/geode/stochastic/spatial/single_object_features/single_object_feature_builder.hpp index 54cb1bb..97c954d 100644 --- a/include/geode/stochastic/spatial/single_object_features/single_object_feature_builder.hpp +++ b/include/geode/stochastic/spatial/single_object_features/single_object_feature_builder.hpp @@ -24,7 +24,7 @@ #include -#include +#include #include #include From 94c997a7e81e9526f36677df90817adfa6595784 Mon Sep 17 00:00:00 2001 From: Francois Bonneau Date: Wed, 27 May 2026 11:37:05 +0200 Subject: [PATCH 16/16] tidy07 --- .../geode/stochastic/models/energy_terms/pairwise_term.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/geode/stochastic/models/energy_terms/pairwise_term.hpp b/include/geode/stochastic/models/energy_terms/pairwise_term.hpp index ce0658f..c4feabb 100644 --- a/include/geode/stochastic/models/energy_terms/pairwise_term.hpp +++ b/include/geode/stochastic/models/energy_terms/pairwise_term.hpp @@ -106,8 +106,8 @@ namespace geode { double sum = 0.0; this->for_each_object_in_sets( state, this->impacted_set_ids(), - [&sum, &state]( const ObjectId& cur_obj_id ) { - sum += accumulate_interactions_with_neighbors( + [&sum, &state, this]( const ObjectId& cur_obj_id ) { + sum += this->accumulate_interactions_with_neighbors( cur_obj_id, state ); } ); return sum;