diff --git a/.clang-format b/.clang-format index 465b025..659a859 100644 --- a/.clang-format +++ b/.clang-format @@ -21,17 +21,17 @@ AlwaysBreakTemplateDeclarations: true BinPackArguments: true BinPackParameters: false BraceWrapping: - AfterClass: true - AfterControlStatement: true - AfterEnum: true - AfterFunction: true - AfterNamespace: true - AfterObjCDeclaration: true - AfterStruct: true - AfterUnion: true - BeforeCatch: true - BeforeElse: true - IndentBraces: false + AfterClass: true + AfterControlStatement: true + AfterEnum: true + AfterFunction: true + AfterNamespace: true + AfterObjCDeclaration: true + AfterStruct: true + AfterUnion: true + BeforeCatch: true + BeforeElse: true + IndentBraces: false BreakBeforeBinaryOperators: NonAssignment BreakBeforeBraces: Custom BreakBeforeTernaryOperators: true @@ -39,7 +39,7 @@ BreakConstructorInitializers: BeforeColon BreakInheritanceList: BeforeColon #BreakStringLiterals ColumnLimit: 80 -CommentPragmas: '' +CommentPragmas: "" CompactNamespaces: false ConstructorInitializerAllOnOneLineOrOnePerLine: true ConstructorInitializerIndentWidth: 4 diff --git a/.clang-tidy b/.clang-tidy index c5d55af..b039849 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -5,29 +5,36 @@ Checks: > *, -altera*, + -boost*, -fuchsia*, -llvmlibc*, -llvm-header-guard, + -llvm-prefer-static-over-anonymous-namespace, + -google-readability-todo, -misc-no-recursion, + -misc-include-cleaner, + -misc-const-correctness, -modernize-use-trailing-return-type, + -portability-avoid-pragma-once, + -readability-use-anyofallof, -readability-redundant-access-specifiers, -readability-convert-member-functions-to-static, -cppcoreguidelines-avoid-const-or-ref-data-members CheckOptions: - - key: misc-non-private-member-variables-in-classes.IgnoreClassesWithAllMemberVariablesBeingPublic - value: '1' + - key: misc-non-private-member-variables-in-classes.IgnoreClassesWithAllMemberVariablesBeingPublic + value: "1" - key: readability-identifier-length.MinimumLoopCounterNameLength value: 1 - key: readability-identifier-length.IgnoredVariableNames - value: '^[defijkptuvw]$' + value: "^[_defijkptuvwxyz]$" # More options here: https://clang.llvm.org/extra/clang-tidy/checks/readability/identifier-naming.html - key: readability-identifier-naming.NamespaceCase value: lower_case - key: readability-identifier-naming.ClassCase - value: CamelCase + value: CamelCase - key: readability-identifier-naming.StructCase - value: CamelCase + value: CamelCase - key: readability-identifier-naming.FunctionCase value: lower_case - key: readability-identifier-naming.VariableCase @@ -51,14 +58,10 @@ CheckOptions: - key: readability-identifier-naming.GlobalFunctionCase value: lower_case - key: readability-identifier-naming.MemberConstantCase - value: CamelCase + value: CamelCase - key: readability-identifier-naming.StaticConstantCase - value: lower_case + value: lower_case - key: readability-function-cognitive-complexity.Threshold value: 10 - key: readability-function-size.ParameterThreshold value: 4 - - key: misc-include-cleaner.IgnoreHeaders - value: utility;cstddef;geode/.*_export\.h;geode/.*/common\.h;geode/basic/types\.h;geode/basic/assert\.h; - - diff --git a/bindings/python/src/common.hpp b/bindings/python/src/common.hpp new file mode 100644 index 0000000..71d75fb --- /dev/null +++ b/bindings/python/src/common.hpp @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2019 - 2026 Geode-solutions + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + */ + +#include +#include +#include + +#include +#include +#include +#include + +namespace pybind11 +{ + namespace detail + { + template < typename Type > + struct type_caster< absl::FixedArray< Type > > + : list_caster< absl::FixedArray< Type >, Type > + { + }; + + template < typename Type, size_t dimension > + struct type_caster< absl::InlinedVector< Type, dimension > > + : list_caster< absl::InlinedVector< Type, dimension >, Type > + { + }; + + template < typename Type > + struct type_caster< absl::Span< Type > > + : list_caster< absl::Span< Type >, Type > + { + using value_conv = make_caster< Type >; + + bool load( handle src, bool convert ) + { + cpp_.clear(); + auto s = reinterpret_borrow< sequence >( src ); + cpp_.reserve( s.size() ); + for( auto it : s ) + { + value_conv conv; + if( !conv.load( it, convert ) ) + return false; + cpp_.push_back( cast_op< Type&& >( std::move( conv ) ) ); + } + this->value = absl::MakeConstSpan( cpp_ ); + return true; + } + + std::vector< typename std::remove_const< Type >::type > cpp_; + }; + + template < typename Key, typename Value > + struct type_caster< absl::flat_hash_map< Key, Value > > + : map_caster< absl::flat_hash_map< Key, Value >, Key, Value > + { + }; + } // namespace detail +} // namespace pybind11 diff --git a/bindings/python/src/stochastic/CMakeLists.txt b/bindings/python/src/stochastic/CMakeLists.txt index a7a96a6..48bd7a0 100644 --- a/bindings/python/src/stochastic/CMakeLists.txt +++ b/bindings/python/src/stochastic/CMakeLists.txt @@ -24,7 +24,7 @@ add_geode_python_binding( "sampling/mcmc/helpers/fracture_simulation_runner.hpp" "sampling/mcmc/helpers/simulation_monitor.hpp" "sampling/mcmc/helpers/simulation_printer.hpp" - "sampling/mcmc/helpers/simulation_runner.hpp" + "sampling/mcmc/simulation_runner.hpp" "sampling/direct/double_sampler.hpp" "sampling/random_engine.hpp" "sampling/distributions.hpp" diff --git a/bindings/python/src/stochastic/sampling/mcmc/helpers/simulation_runner.hpp b/bindings/python/src/stochastic/sampling/mcmc/simulation_runner.hpp similarity index 96% rename from bindings/python/src/stochastic/sampling/mcmc/helpers/simulation_runner.hpp rename to bindings/python/src/stochastic/sampling/mcmc/simulation_runner.hpp index ddecda2..9745da9 100644 --- a/bindings/python/src/stochastic/sampling/mcmc/helpers/simulation_runner.hpp +++ b/bindings/python/src/stochastic/sampling/mcmc/simulation_runner.hpp @@ -20,9 +20,10 @@ * SOFTWARE. * */ +#include "../../../common.hpp" #include -#include +#include namespace geode { diff --git a/bindings/python/src/stochastic/stochastic.cpp b/bindings/python/src/stochastic/stochastic.cpp index c36db5d..27e9f2f 100644 --- a/bindings/python/src/stochastic/stochastic.cpp +++ b/bindings/python/src/stochastic/stochastic.cpp @@ -29,7 +29,7 @@ #include "sampling/mcmc/helpers/fracture_simulation_runner.hpp" #include "sampling/mcmc/helpers/simulation_monitor.hpp" #include "sampling/mcmc/helpers/simulation_printer.hpp" -#include "sampling/mcmc/helpers/simulation_runner.hpp" +#include "sampling/mcmc/simulation_runner.hpp" #include "sampling/distributions.hpp" #include "sampling/random_engine.hpp" diff --git a/include/geode/stochastic/common.hpp b/include/geode/stochastic/common.hpp index d83b668..60115dc 100644 --- a/include/geode/stochastic/common.hpp +++ b/include/geode/stochastic/common.hpp @@ -26,6 +26,7 @@ #include #include #include + #include namespace geode diff --git a/include/geode/stochastic/inference/abc_shadow.hpp b/include/geode/stochastic/inference/abc_shadow.hpp new file mode 100644 index 0000000..1daba84 --- /dev/null +++ b/include/geode/stochastic/inference/abc_shadow.hpp @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2019 - 2026 Geode-solutions + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + */ \ No newline at end of file diff --git a/include/geode/stochastic/models/spatial_model.hpp b/include/geode/stochastic/models/spatial_model.hpp new file mode 100644 index 0000000..1daba84 --- /dev/null +++ b/include/geode/stochastic/models/spatial_model.hpp @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2019 - 2026 Geode-solutions + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + */ \ No newline at end of file diff --git a/include/geode/stochastic/sampling/direct/bounding_box_sampler.hpp b/include/geode/stochastic/sampling/direct/bounding_box_sampler.hpp index fdfda71..ae644e9 100644 --- a/include/geode/stochastic/sampling/direct/bounding_box_sampler.hpp +++ b/include/geode/stochastic/sampling/direct/bounding_box_sampler.hpp @@ -37,7 +37,7 @@ namespace geode namespace geode { - template < index_t dimension > + template < local_index_t dimension > class BoundingBoxSampler { public: diff --git a/include/geode/stochastic/sampling/direct/point_uniform_sampler.hpp b/include/geode/stochastic/sampling/direct/point_uniform_sampler.hpp index 968f519..b1f3349 100644 --- a/include/geode/stochastic/sampling/direct/point_uniform_sampler.hpp +++ b/include/geode/stochastic/sampling/direct/point_uniform_sampler.hpp @@ -26,6 +26,8 @@ #include +#include + namespace geode { FORWARD_DECLARATION_DIMENSION_CLASS( BoundingBox ); diff --git a/include/geode/stochastic/sampling/mcmc/models/components/density_term.hpp b/include/geode/stochastic/sampling/mcmc/energy_terms/density_term.hpp similarity index 87% rename from include/geode/stochastic/sampling/mcmc/models/components/density_term.hpp rename to include/geode/stochastic/sampling/mcmc/energy_terms/density_term.hpp index 1a37a8e..91e3858 100644 --- a/include/geode/stochastic/sampling/mcmc/models/components/density_term.hpp +++ b/include/geode/stochastic/sampling/mcmc/energy_terms/density_term.hpp @@ -24,7 +24,7 @@ #include -#include +#include namespace geode { @@ -46,10 +46,9 @@ namespace geode std::move( targeted_set_ids ), 1.0, // scale by domain area to get density per unit []( const ObjectType& obj, - const SpatialDomain< ObjectType::dim >& domain ) { - if( SpatialDomainChecker< - ObjectType >::is_anchored_in_domain( domain, - obj ) ) + const SpatialDomain< ObjectType::dim >& spatial_domain ) { + if( SpatialDomainChecker< ObjectType >:: + is_anchored_in_domain( spatial_domain, obj ) ) { return 1.0; } diff --git a/include/geode/stochastic/sampling/mcmc/models/components/energy_term.hpp b/include/geode/stochastic/sampling/mcmc/energy_terms/energy_term.hpp similarity index 67% rename from include/geode/stochastic/sampling/mcmc/models/components/energy_term.hpp rename to include/geode/stochastic/sampling/mcmc/energy_terms/energy_term.hpp index 335ccbc..8463bb6 100644 --- a/include/geode/stochastic/sampling/mcmc/models/components/energy_term.hpp +++ b/include/geode/stochastic/sampling/mcmc/energy_terms/energy_term.hpp @@ -34,59 +34,58 @@ #include -namespace geode +namespace geode::detail { - namespace detail + struct EnergyScale { - struct EnergyScale + explicit EnergyScale( double param ) { - explicit EnergyScale( double param ) - { - OPENGEODE_EXCEPTION( param >= 0., - "[Gibbs energy term] - The model parameter " - "cannot be negative." ); + OPENGEODE_EXCEPTION( param >= 0., + "[Gibbs energy term] - The model parameter " + "cannot be negative." ); - if( param >= geode::GLOBAL_EPSILON ) - { - value = -std::log( param ); // store log-space parameter - } - // else value = std::nullopt → special case: param == 0 + if( param >= geode::GLOBAL_EPSILON ) + { + value_ = -std::log( param ); // store log-space parameter } + // else value = std::nullopt → special case: param == 0 + } - /// Compute energy contribution for a given statistic multiplier - double contribution( double multiplier ) const + /// Compute energy contribution for a given statistic multiplier + [[nodiscard]] double contribution( double multiplier ) const + { + if( value_ ) { - if( value ) - { - return value.value() * multiplier; - } - // Hard constraint: param == 0 - return ( multiplier > 0 ) - ? std::numeric_limits< double >::infinity() - : 0.0; + return value_.value() * multiplier; } + // Hard constraint: param == 0 + return ( multiplier > 0 ) + ? std::numeric_limits< double >::infinity() + : 0.0; + } - /// Return original parameter (gamma) - double parameter() const + /// Return original parameter (gamma) + [[nodiscard]] double parameter() const + { + if( value_ ) { - if( value ) - { - return std::exp( -value.value() ); - } - return 0.; + return std::exp( -value_.value() ); } + return 0.; + } - private: - std::optional< double > value; // empty if param == 0 (hardcore) - }; - } // namespace detail -} // namespace geode + private: + std::optional< double > value_; // empty if param == 0 (hardcore) + }; +} // namespace geode::detail namespace geode { template < typename ObjectType > class EnergyTerm : public Identifier { + OPENGEODE_DISABLE_COPY_AND_MOVE( EnergyTerm ); + public: explicit EnergyTerm( std::string_view name, double param, @@ -103,39 +102,42 @@ namespace geode virtual ~EnergyTerm() = default; - double parameter() const + [[nodiscard]] double parameter() const { return energy_scale_.parameter(); } - const std::vector< uuid >& targeted_set_ids() const + [[nodiscard]] const std::vector< uuid >& targeted_set_ids() const { return targeted_set_ids_; } /// Energy contribution for a given statistic multiplier - double contribution( double multiplier ) const + [[nodiscard]] double contribution( double multiplier ) const { return energy_scale_.contribution( multiplier ); } - virtual double total_log( + [[nodiscard]] virtual double total_log( const ObjectSets< ObjectType >& state ) const = 0; - virtual double delta_log_add( const ObjectSets< ObjectType >& state, + [[nodiscard]] virtual double delta_log_add( + const ObjectSets< ObjectType >& state, const ObjectRef< ObjectType >& new_object ) const = 0; - virtual double delta_log_remove( const ObjectSets< ObjectType >& state, + [[nodiscard]] virtual double delta_log_remove( + const ObjectSets< ObjectType >& state, const ObjectId& object_id ) const = 0; - virtual double delta_log_change( const ObjectSets< ObjectType >& state, + [[nodiscard]] virtual double delta_log_change( + const ObjectSets< ObjectType >& state, const ObjectId& old_object_id, const ObjectRef< ObjectType >& new_object ) const = 0; - virtual double statistic( + [[nodiscard]] virtual double statistic( const ObjectSets< ObjectType >& state ) const = 0; - std::string string() const + [[nodiscard]] std::string string() const { auto message = absl::StrCat( "Term : ", name().value_or( id().string() ), @@ -151,13 +153,13 @@ namespace geode } protected: - bool is_targeted_set( const uuid& set_id ) const + [[nodiscard]] bool is_targeted_set( const uuid& set_id ) const { return std::binary_search( targeted_set_ids_.begin(), targeted_set_ids_.end(), set_id ); } - const SpatialDomain< ObjectType::dim >& domain() const + [[nodiscard]] const SpatialDomain< ObjectType::dim >& domain() const { return domain_; } @@ -175,10 +177,10 @@ namespace geode { for( const auto& targeted_set_id : targeted_set_ids_ ) { - for( const auto id : + for( const auto set_id : state.get_objects_in_set( targeted_set_id ) ) { - do_apply( id ); + std::forward< Func >( do_apply )( set_id ); } } } diff --git a/include/geode/stochastic/sampling/mcmc/models/energy_term_collection.hpp b/include/geode/stochastic/sampling/mcmc/energy_terms/energy_term_collection.hpp similarity index 72% rename from include/geode/stochastic/sampling/mcmc/models/energy_term_collection.hpp rename to include/geode/stochastic/sampling/mcmc/energy_terms/energy_term_collection.hpp index f8ce986..5826df9 100644 --- a/include/geode/stochastic/sampling/mcmc/models/energy_term_collection.hpp +++ b/include/geode/stochastic/sampling/mcmc/energy_terms/energy_term_collection.hpp @@ -1,7 +1,7 @@ #pragma once #include -#include +#include namespace geode { @@ -13,42 +13,52 @@ namespace geode public: EnergyTermCollection() = default; EnergyTermCollection( EnergyTermCollection&& ) noexcept = default; + ~EnergyTermCollection() = default; - uuid add_energy_term( std::shared_ptr< EnergyTerm< ObjectType > > term ) + EnergyTermCollection& operator=( EnergyTermCollection&& ) = default; + + [[nodiscard]] uuid add_energy_term( + std::shared_ptr< EnergyTerm< ObjectType > > term ) { - const uuid id = term->id(); - energy_terms_.emplace( id, term ); + const uuid term_id = term->id(); + energy_terms_.emplace( term_id, term ); for( const uuid& set_id : term->targeted_set_ids() ) { set_to_terms_[set_id].push_back( term ); } - return id; + return term_id; } - bool remove_energy_term( const uuid& id ) + [[nodiscard]] bool remove_energy_term( const uuid& term_id ) { - auto it = energy_terms_.find( id ); - if( it == energy_terms_.end() ) + auto term_it = energy_terms_.find( term_id ); + if( term_it == energy_terms_.end() ) + { return false; + } - auto term = it->second; + auto term = term_it->second; for( const uuid& set_id : term->targeted_set_ids() ) { auto vec_it = set_to_terms_.find( set_id ); if( vec_it == set_to_terms_.end() ) + { continue; + } auto& vec = vec_it->second; vec.erase( std::remove( vec.begin(), vec.end(), term ), vec.end() ); if( vec.empty() ) + { set_to_terms_.erase( vec_it ); + } } - energy_terms_.erase( it ); + energy_terms_.erase( term_it ); return true; } @@ -64,13 +74,13 @@ namespace geode } [[nodiscard]] const EnergyTerm< ObjectType >& get( - const uuid& id ) const + const uuid& term_id ) const { - auto it = energy_terms_.find( id ); - OPENGEODE_EXCEPTION( it != energy_terms_.end(), + auto term_it = energy_terms_.find( term_id ); + OPENGEODE_EXCEPTION( term_it != energy_terms_.end(), absl::StrCat( "[EnergyTermCollection] Unknown energy term: ", - id.string() ) ); - return *it->second; + term_id.string() ) ); + return *term_it->second; } [[nodiscard]] const absl::flat_hash_map< uuid, @@ -91,7 +101,7 @@ namespace geode return it->second; } - std::string string() const + [[nodiscard]] std::string string() const { auto message = absl::StrCat( "EnergyTermCollection: ", energy_terms_.size(), " terms:" ); diff --git a/include/geode/stochastic/sampling/mcmc/models/gibbs_energy.hpp b/include/geode/stochastic/sampling/mcmc/energy_terms/gibbs_energy.hpp similarity index 79% rename from include/geode/stochastic/sampling/mcmc/models/gibbs_energy.hpp rename to include/geode/stochastic/sampling/mcmc/energy_terms/gibbs_energy.hpp index fdadd1e..2718107 100644 --- a/include/geode/stochastic/sampling/mcmc/models/gibbs_energy.hpp +++ b/include/geode/stochastic/sampling/mcmc/energy_terms/gibbs_energy.hpp @@ -22,7 +22,7 @@ */ #pragma once -#include +#include #include namespace geode @@ -37,18 +37,20 @@ namespace geode { } - double total_log_energy( const ObjectSets< ObjectType >& state ) const + [[nodiscard]] double total_log_energy( + const ObjectSets< ObjectType >& state ) const { double log_energy = 0.0; const auto& energy_terms = energy_terms_collection_.all_terms(); - for( auto& [id, term] : energy_terms ) + for( auto& [term_id, term] : energy_terms ) { + geode_unused( term_id ); log_energy += term->total_log( state ); } return log_energy; } - double total_log_energy_for_set( + [[nodiscard]] double total_log_energy_for_set( const ObjectSets< ObjectType >& state, const uuid& set_id ) const { double log_energy = 0.0; @@ -60,7 +62,8 @@ namespace geode return log_energy; } - double delta_log_add( const ObjectSets< ObjectType >& state, + [[nodiscard]] double delta_log_add( + const ObjectSets< ObjectType >& state, const ObjectRef< ObjectType >& new_object ) const { double log_energy = 0.0; @@ -72,19 +75,21 @@ namespace geode return log_energy; } - double delta_log_remove( - const ObjectSets< ObjectType >& state, const ObjectId& id ) const + [[nodiscard]] double delta_log_remove( + const ObjectSets< ObjectType >& state, + const ObjectId& object_id ) const { double log_energy = 0.0; for( const auto& term : - energy_terms_collection_.terms_for_set( id.set_id ) ) + energy_terms_collection_.terms_for_set( object_id.set_id ) ) { - log_energy += term->delta_log_remove( state, id ); + log_energy += term->delta_log_remove( state, object_id ); } return log_energy; } - double delta_log_change( const ObjectSets< ObjectType >& state, + [[nodiscard]] double delta_log_change( + const ObjectSets< ObjectType >& state, const ObjectId& old_id, const ObjectRef< ObjectType >& new_object ) const { diff --git a/include/geode/stochastic/sampling/mcmc/energy_terms/intensity_term.hpp b/include/geode/stochastic/sampling/mcmc/energy_terms/intensity_term.hpp new file mode 100644 index 0000000..7cd9dc1 --- /dev/null +++ b/include/geode/stochastic/sampling/mcmc/energy_terms/intensity_term.hpp @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2019 - 2026 Geode-solutions + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + */ +#pragma once + +#include + +#include + +namespace geode +{ + FORWARD_DECLARATION_DIMENSION_CLASS( OwnerSegment ); + ALIAS_2D( OwnerSegment ); +} // namespace geode + +namespace geode +{ + class opengeode_stochastic_stochastic_api IntensityTerm + : public SingleObjectTerm< OwnerSegment2D, + std::function< double( const OwnerSegment2D&, + const SpatialDomain< OwnerSegment2D::dim >& ) > > + { + public: + explicit IntensityTerm( std::string_view name, + double lambda, + std::vector< uuid > targeted_set_ids, + double caracteristic_length, + const SpatialDomain< OwnerSegment2D::dim >& domain ); + }; +} // namespace geode \ No newline at end of file diff --git a/include/geode/stochastic/sampling/mcmc/models/components/pairwise_term.hpp b/include/geode/stochastic/sampling/mcmc/energy_terms/pairwise_term.hpp similarity index 93% rename from include/geode/stochastic/sampling/mcmc/models/components/pairwise_term.hpp rename to include/geode/stochastic/sampling/mcmc/energy_terms/pairwise_term.hpp index f7ad066..4f12ad1 100644 --- a/include/geode/stochastic/sampling/mcmc/models/components/pairwise_term.hpp +++ b/include/geode/stochastic/sampling/mcmc/energy_terms/pairwise_term.hpp @@ -26,7 +26,7 @@ #include #include -#include +#include namespace geode { @@ -46,13 +46,15 @@ namespace geode { } - double total_log( const ObjectSets< ObjectType >& state ) const final + [[nodiscard]] double total_log( + const ObjectSets< ObjectType >& state ) const final { const auto interaction_weight = statistic( state ); return this->contribution( interaction_weight ); } - double delta_log_add( const ObjectSets< ObjectType >& state, + [[nodiscard]] double delta_log_add( + const ObjectSets< ObjectType >& state, const ObjectRef< ObjectType >& new_object ) const final { if( !this->is_targeted_set( new_object.set_id ) ) @@ -82,7 +84,8 @@ namespace geode return this->contribution( delta ); } - double delta_log_remove( const ObjectSets< ObjectType >& state, + [[nodiscard]] double delta_log_remove( + const ObjectSets< ObjectType >& state, const ObjectId& object_id ) const override { if( !this->is_targeted_set( object_id.set_id ) ) @@ -114,7 +117,8 @@ namespace geode return this->contribution( -delta ); } - double delta_log_change( const ObjectSets< ObjectType >& state, + [[nodiscard]] double delta_log_change( + const ObjectSets< ObjectType >& state, const ObjectId& old_object_id, const ObjectRef< ObjectType >& new_object ) const override { @@ -173,7 +177,8 @@ namespace geode return this->contribution( delta ); } - double statistic( const ObjectSets< ObjectType >& state ) const override + [[nodiscard]] double statistic( + const ObjectSets< ObjectType >& state ) const override { double sum = 0.0; this->for_each_targeted_object( state, [&]( const ObjectId& @@ -205,7 +210,7 @@ namespace geode } private: - bool is_new_pair( const ObjectType& obj, + [[nodiscard]] bool is_new_pair( const ObjectType& obj, const ObjectId& obj_id, const ObjectId& neigh_obj_id ) const { diff --git a/include/geode/stochastic/sampling/mcmc/models/components/single_object_term.hpp b/include/geode/stochastic/sampling/mcmc/energy_terms/single_object_term.hpp similarity index 86% rename from include/geode/stochastic/sampling/mcmc/models/components/single_object_term.hpp rename to include/geode/stochastic/sampling/mcmc/energy_terms/single_object_term.hpp index ec35b16..d98240c 100644 --- a/include/geode/stochastic/sampling/mcmc/models/components/single_object_term.hpp +++ b/include/geode/stochastic/sampling/mcmc/energy_terms/single_object_term.hpp @@ -24,7 +24,7 @@ #include -#include +#include #include namespace geode @@ -46,12 +46,14 @@ namespace geode { } - double total_log( const ObjectSets< ObjectType >& state ) const override + [[nodiscard]] double total_log( + const ObjectSets< ObjectType >& state ) const override { return this->contribution( scale_ * statistic( state ) ); } - double delta_log_add( const ObjectSets< ObjectType >& /*state*/, + [[nodiscard]] double delta_log_add( + const ObjectSets< ObjectType >& /*state*/, const ObjectRef< ObjectType >& new_object ) const override { if( !this->is_targeted_set( new_object.set_id ) ) @@ -63,7 +65,8 @@ namespace geode * contribution_func_( new_object.object, this->domain() ) ); } - double delta_log_remove( const ObjectSets< ObjectType >& state, + [[nodiscard]] double delta_log_remove( + const ObjectSets< ObjectType >& state, const ObjectId& object_id ) const override { if( !this->is_targeted_set( object_id.set_id ) ) @@ -76,7 +79,8 @@ namespace geode state.get_object( object_id ), this->domain() ) ); } - double delta_log_change( const ObjectSets< ObjectType >& state, + [[nodiscard]] double delta_log_change( + const ObjectSets< ObjectType >& state, const ObjectId& old_object_id, const ObjectRef< ObjectType >& new_object ) const override { @@ -87,7 +91,8 @@ namespace geode return this->contribution( scale_ * delta ); } - double statistic( const ObjectSets< ObjectType >& state ) const override + [[nodiscard]] double statistic( + const ObjectSets< ObjectType >& state ) const override { double sum = 0.0; this->for_each_targeted_object( diff --git a/include/geode/stochastic/sampling/mcmc/helpers/fracture_simulation_runner.hpp b/include/geode/stochastic/sampling/mcmc/helpers/fracture_simulation_runner.hpp index 0e2b987..237e741 100644 --- a/include/geode/stochastic/sampling/mcmc/helpers/fracture_simulation_runner.hpp +++ b/include/geode/stochastic/sampling/mcmc/helpers/fracture_simulation_runner.hpp @@ -27,11 +27,11 @@ #include #include #include -#include -#include -#include -#include +#include +#include +#include #include +#include #include #include diff --git a/include/geode/stochastic/sampling/mcmc/metropolis_hasting_sampler.hpp b/include/geode/stochastic/sampling/mcmc/metropolis_hasting_sampler.hpp index 4b4903b..64a80ec 100644 --- a/include/geode/stochastic/sampling/mcmc/metropolis_hasting_sampler.hpp +++ b/include/geode/stochastic/sampling/mcmc/metropolis_hasting_sampler.hpp @@ -24,7 +24,7 @@ #pragma once #include -#include +#include #include namespace geode diff --git a/include/geode/stochastic/sampling/mcmc/models/components/intensity_term.hpp b/include/geode/stochastic/sampling/mcmc/models/components/intensity_term.hpp deleted file mode 100644 index ea49dcd..0000000 --- a/include/geode/stochastic/sampling/mcmc/models/components/intensity_term.hpp +++ /dev/null @@ -1,125 +0,0 @@ -/* - * Copyright (c) 2019 - 2026 Geode-solutions - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - */ -#pragma once - -#include - -#include - -double length_inside_box( const geode::Point2D& segment_start, - const geode::Point2D& segment_end, - const geode::BoundingBox2D& box ) -{ - // Segment direction - const double dir_x = segment_end.value( 0 ) - segment_start.value( 0 ); - const double dir_y = segment_end.value( 1 ) - segment_start.value( 1 ); - - // Parameter interval where the segment is inside the box - double t_enter = 0.0; // start of valid interval - double t_exit = 1.0; // end of valid interval - - // Clips the parametric segment against one axis interval - auto clip_against_axis_interval = [&t_enter, &t_exit]( double direction, - double min_distance, - double max_distance ) -> bool { - // Segment is parallel to this axis - if( std::fabs( direction ) < geode::GLOBAL_EPSILON ) - { - // Outside the interval → no intersection - return min_distance <= 0.0 && 0.0 <= max_distance; - } - - double t0 = min_distance / direction; - double t1 = max_distance / direction; - - if( t0 > t1 ) - { - std::swap( t0, t1 ); - } - - t_enter = std::max( t_enter, t0 ); - t_exit = std::min( t_exit, t1 ); - - return t_enter <= t_exit; - }; - - // Clip against X interval of the box - if( !clip_against_axis_interval( dir_x, - box.min().value( 0 ) - segment_start.value( 0 ), - box.max().value( 0 ) - segment_start.value( 0 ) ) ) - { - return 0.0; - } - - // Clip against Y interval of the box - if( !clip_against_axis_interval( dir_y, - box.min().value( 1 ) - segment_start.value( 1 ), - box.max().value( 1 ) - segment_start.value( 1 ) ) ) - { - return 0.0; - } - - // No portion of the segment is inside the box - if( t_exit <= t_enter ) - { - return 0.0; - } - - // Length of the clipped segment - const double clipped_dx = dir_x * ( t_exit - t_enter ); - const double clipped_dy = dir_y * ( t_exit - t_enter ); - - return std::sqrt( clipped_dx * clipped_dx + clipped_dy * clipped_dy ); -} - -namespace geode -{ - class IntensityTerm - : public SingleObjectTerm< OwnerSegment2D, - std::function< double( const OwnerSegment2D&, - const SpatialDomain< OwnerSegment2D::dim >& ) > > - { - public: - explicit IntensityTerm( std::string_view name, - double lambda, - std::vector< uuid > targeted_set_ids, - double caracteristic_length, - const SpatialDomain< OwnerSegment2D::dim >& domain ) - : SingleObjectTerm< OwnerSegment2D, - std::function< double( const OwnerSegment2D&, - const SpatialDomain< OwnerSegment2D::dim >& ) > >( - name, - lambda, - std::move( targeted_set_ids ), - 1.0 / caracteristic_length, - []( const OwnerSegment2D& segment, - const SpatialDomain< OwnerSegment2D::dim >& domain ) { - auto seg_extremities = segment.vertices(); - return length_inside_box( seg_extremities[0], - seg_extremities[1], domain.box() ); - }, - domain ) - { - } - }; -} // namespace geode \ No newline at end of file diff --git a/include/geode/stochastic/sampling/mcmc/helpers/simulation_runner.hpp b/include/geode/stochastic/sampling/mcmc/simulation_runner.hpp similarity index 98% rename from include/geode/stochastic/sampling/mcmc/helpers/simulation_runner.hpp rename to include/geode/stochastic/sampling/mcmc/simulation_runner.hpp index 52e142d..dd432db 100644 --- a/include/geode/stochastic/sampling/mcmc/helpers/simulation_runner.hpp +++ b/include/geode/stochastic/sampling/mcmc/simulation_runner.hpp @@ -23,10 +23,10 @@ #pragma once #include +#include #include #include #include -#include #include #include diff --git a/src/geode/stochastic/CMakeLists.txt b/src/geode/stochastic/CMakeLists.txt index 68a0b91..0394ccc 100644 --- a/src/geode/stochastic/CMakeLists.txt +++ b/src/geode/stochastic/CMakeLists.txt @@ -33,8 +33,11 @@ add_geode_library( "sampling/direct/segment_uniform_sampler.cpp" "sampling/distributions.cpp" "sampling/random_engine.cpp" + "sampling/mcmc/energy_terms/intensity_term.cpp" "common.cpp" PUBLIC_HEADERS + "inference/abc_shadow.hpp" + "models/spatial_model.hpp" "spatial/object_set.hpp" "spatial/object_sets.hpp" "spatial/object_neighborhood.hpp" @@ -51,20 +54,20 @@ add_geode_library( "sampling/direct/point_uniform_sampler.hpp" "sampling/direct/segment_uniform_sampler.hpp" "sampling/mcmc/helpers/fracture_simulation_runner.hpp" - "sampling/mcmc/helpers/simulation_runner.hpp" "sampling/mcmc/helpers/simulation_printer.hpp" "sampling/mcmc/helpers/simulation_monitor.hpp" - "sampling/mcmc/models/components/density_term.hpp" - "sampling/mcmc/models/components/energy_term.hpp" - "sampling/mcmc/models/components/intensity_term.hpp" - "sampling/mcmc/models/components/pairwise_term.hpp" - "sampling/mcmc/models/components/single_object_term.hpp" - "sampling/mcmc/models/energy_term_collection.hpp" - "sampling/mcmc/models/gibbs_energy.hpp" + "sampling/mcmc/energy_terms/density_term.hpp" + "sampling/mcmc/energy_terms/energy_term.hpp" + "sampling/mcmc/energy_terms/intensity_term.hpp" + "sampling/mcmc/energy_terms/pairwise_term.hpp" + "sampling/mcmc/energy_terms/single_object_term.hpp" + "sampling/mcmc/energy_terms/energy_term_collection.hpp" + "sampling/mcmc/energy_terms/gibbs_energy.hpp" "sampling/mcmc/proposal/classical_proposals.hpp" "sampling/mcmc/proposal/moves.hpp" "sampling/mcmc/proposal/proposal_kernel.hpp" "sampling/mcmc/metropolis_hasting_sampler.hpp" + "sampling/mcmc/simulation_runner.hpp" "sampling/distributions.hpp" "sampling/random_engine.hpp" "common.hpp" diff --git a/src/geode/stochastic/sampling/direct/bounding_box_sampler.cpp b/src/geode/stochastic/sampling/direct/bounding_box_sampler.cpp index 723616a..5e7de9d 100644 --- a/src/geode/stochastic/sampling/direct/bounding_box_sampler.cpp +++ b/src/geode/stochastic/sampling/direct/bounding_box_sampler.cpp @@ -32,7 +32,7 @@ namespace geode { - template < index_t dimension > + template < local_index_t dimension > class BoundingBoxSampler< dimension >::Impl { public: @@ -40,8 +40,8 @@ namespace geode { for( const auto dim : LRange( dimension ) ) { - dist_coordinates[dim].min_value = box.min().value( dim ); - dist_coordinates[dim].max_value = box.max().value( dim ); + dist_coordinates_[dim].min_value = box.min().value( dim ); + dist_coordinates_[dim].max_value = box.max().value( dim ); } } Point< dimension > sample_uniform( RandomEngine& engine ) @@ -50,26 +50,26 @@ namespace geode for( const auto dim : geode::Range( dimension ) ) { point.set_value( - dim, engine.sample_uniform( dist_coordinates[dim] ) ); + dim, engine.sample_uniform( dist_coordinates_[dim] ) ); } return point; } private: - std::array< UniformClosed< double >, dimension > dist_coordinates; + std::array< UniformClosed< double >, dimension > dist_coordinates_; }; - template < index_t dimension > + template < local_index_t dimension > BoundingBoxSampler< dimension >::BoundingBoxSampler( const BoundingBox< dimension >& box ) : impl_{ box } { } - template < index_t dimension > + template < local_index_t dimension > BoundingBoxSampler< dimension >::~BoundingBoxSampler() = default; - template < index_t dimension > + template < local_index_t dimension > Point< dimension > BoundingBoxSampler< dimension >::sample_uniform( RandomEngine& engine ) { diff --git a/src/geode/stochastic/sampling/mcmc/energy_terms/intensity_term.cpp b/src/geode/stochastic/sampling/mcmc/energy_terms/intensity_term.cpp new file mode 100644 index 0000000..a207110 --- /dev/null +++ b/src/geode/stochastic/sampling/mcmc/energy_terms/intensity_term.cpp @@ -0,0 +1,121 @@ +/* + * Copyright (c) 2019 - 2026 Geode-solutions + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to permit + * persons to whom the Software is furnished to do so, subject to the + * following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN + * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE + * USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ + +#include + +#include + +namespace +{ + double length_inside_box( const geode::Point2D& segment_start, + const geode::Point2D& segment_end, + const geode::BoundingBox2D& box ) + { + // Segment direction + const double dir_x = segment_end.value( 0 ) - segment_start.value( 0 ); + const double dir_y = segment_end.value( 1 ) - segment_start.value( 1 ); + + // Parameter interval where the segment is inside the box + double t_enter = 0.0; // start of valid interval + double t_exit = 1.0; // end of valid interval + + // Clips the parametric segment against one axis interval + auto clip_against_axis_interval = [&t_enter, &t_exit]( double direction, + double min_distance, + double max_distance ) -> bool { + // Segment is parallel to this axis + if( std::fabs( direction ) < geode::GLOBAL_EPSILON ) + { + // Outside the interval → no intersection + return min_distance <= 0.0 && 0.0 <= max_distance; + } + + double axis_min_t = min_distance / direction; + double axis_max_t = max_distance / direction; + + if( axis_min_t > axis_max_t ) + { + std::swap( axis_min_t, axis_max_t ); + } + + t_enter = std::max( t_enter, axis_min_t ); + t_exit = std::min( t_exit, axis_max_t ); + + return t_enter <= t_exit; + }; + + // Clip against X interval of the box + if( !clip_against_axis_interval( dir_x, + box.min().value( 0 ) - segment_start.value( 0 ), + box.max().value( 0 ) - segment_start.value( 0 ) ) ) + { + return 0.0; + } + + // Clip against Y interval of the box + if( !clip_against_axis_interval( dir_y, + box.min().value( 1 ) - segment_start.value( 1 ), + box.max().value( 1 ) - segment_start.value( 1 ) ) ) + { + return 0.0; + } + + // No portion of the segment is inside the box + if( t_exit <= t_enter ) + { + return 0.0; + } + + // Length of the clipped segment + const double clipped_dx = dir_x * ( t_exit - t_enter ); + const double clipped_dy = dir_y * ( t_exit - t_enter ); + + return std::sqrt( + ( clipped_dx * clipped_dx ) + ( clipped_dy * clipped_dy ) ); + } +} // namespace +namespace geode +{ + IntensityTerm::IntensityTerm( std::string_view name, + double lambda, + std::vector< uuid > targeted_set_ids, + double caracteristic_length, + const SpatialDomain< OwnerSegment2D::dim >& domain ) + : SingleObjectTerm< OwnerSegment2D, + std::function< double( const OwnerSegment2D&, + const SpatialDomain< OwnerSegment2D::dim >& ) > >( + name, + lambda, + std::move( targeted_set_ids ), + 1.0 / caracteristic_length, + []( const OwnerSegment2D& segment, + const SpatialDomain< OwnerSegment2D::dim >& spatial_domain ) { + auto seg_extremities = segment.vertices(); + return length_inside_box( seg_extremities[0], + seg_extremities[1], spatial_domain.box() ); + }, + domain ) + { + } +} // namespace geode \ No newline at end of file diff --git a/src/geode/stochastic/sampling/random_engine.cpp b/src/geode/stochastic/sampling/random_engine.cpp index fabfda3..f904077 100644 --- a/src/geode/stochastic/sampling/random_engine.cpp +++ b/src/geode/stochastic/sampling/random_engine.cpp @@ -25,6 +25,7 @@ #include #include +#include #include #include @@ -35,10 +36,6 @@ #include #include -#define FORWARD_DECLARATION_DIMENSION_CLASS( Class ) \ - template < index_t > \ - class Class - namespace { double normal_cdf( double x ) diff --git a/tests/stochastic/CMakeLists.txt b/tests/stochastic/CMakeLists.txt index 0baa3bb..0239d46 100644 --- a/tests/stochastic/CMakeLists.txt +++ b/tests/stochastic/CMakeLists.txt @@ -106,7 +106,7 @@ add_geode_test( ) add_geode_test( - SOURCE "sampling/mcmc/models/components/test-density-term.cpp" + SOURCE "sampling/mcmc/energy_terms/test-density-term.cpp" DEPENDENCIES OpenGeode::basic OpenGeode::geometry @@ -114,7 +114,7 @@ add_geode_test( ) add_geode_test( - SOURCE "sampling/mcmc/models/components/test-intensity-term.cpp" + SOURCE "sampling/mcmc/energy_terms/test-intensity-term.cpp" DEPENDENCIES OpenGeode::basic OpenGeode::geometry @@ -122,7 +122,7 @@ add_geode_test( ) add_geode_test( - SOURCE "sampling/mcmc/models/components/test-pairwise-term.cpp" + SOURCE "sampling/mcmc/energy_terms/test-pairwise-term.cpp" DEPENDENCIES OpenGeode::basic OpenGeode::geometry @@ -130,7 +130,7 @@ add_geode_test( ) add_geode_test( - SOURCE "sampling/mcmc/models/test-gibbs-energy.cpp" + SOURCE "sampling/mcmc/energy_terms/test-gibbs-energy.cpp" DEPENDENCIES OpenGeode::basic OpenGeode::geometry diff --git a/tests/stochastic/sampling/mcmc/models/components/test-density-term.cpp b/tests/stochastic/sampling/mcmc/energy_terms/test-density-term.cpp similarity index 98% rename from tests/stochastic/sampling/mcmc/models/components/test-density-term.cpp rename to tests/stochastic/sampling/mcmc/energy_terms/test-density-term.cpp index 650dacc..217d430 100644 --- a/tests/stochastic/sampling/mcmc/models/components/test-density-term.cpp +++ b/tests/stochastic/sampling/mcmc/energy_terms/test-density-term.cpp @@ -20,7 +20,7 @@ * SOFTWARE. * */ -#include +#include #include #include diff --git a/tests/stochastic/sampling/mcmc/models/test-gibbs-energy.cpp b/tests/stochastic/sampling/mcmc/energy_terms/test-gibbs-energy.cpp similarity index 89% rename from tests/stochastic/sampling/mcmc/models/test-gibbs-energy.cpp rename to tests/stochastic/sampling/mcmc/energy_terms/test-gibbs-energy.cpp index 1837638..8cdc90a 100644 --- a/tests/stochastic/sampling/mcmc/models/test-gibbs-energy.cpp +++ b/tests/stochastic/sampling/mcmc/energy_terms/test-gibbs-energy.cpp @@ -25,10 +25,10 @@ #include -#include -#include -#include -#include +#include +#include +#include +#include #include void test_gibbs_energy() @@ -48,19 +48,20 @@ void test_gibbs_energy() geode::EnergyTermCollection< geode::Point2D > energy_terms; // Add intensity term - energy_terms.add_energy_term( + const auto term_id = energy_terms.add_energy_term( std::make_unique< geode::DensityTerm< geode::Point2D > >( "intensity", 0.5, std::vector< geode::uuid >{ set_id }, domain ) ); - + geode_unused( term_id ); // Add pairwise term with trivial interaction: always counts 1 for each pair auto interaction = std::make_unique< geode::EuclideanCutoffInteraction< geode::Point2D > >( 1000000 ); - energy_terms.add_energy_term( + const auto pwterm_id = energy_terms.add_energy_term( std::make_unique< geode::PairwiseTerm< geode::Point2D > >( "interaction", 0.8, std::vector< geode::uuid >{ set_id }, std::move( interaction ), domain ) ); + geode_unused( pwterm_id ); OPENGEODE_EXCEPTION( energy_terms.size() == 2, "[test gibbs] Wrong number of components after adding terms." ); diff --git a/tests/stochastic/sampling/mcmc/models/components/test-intensity-term.cpp b/tests/stochastic/sampling/mcmc/energy_terms/test-intensity-term.cpp similarity index 98% rename from tests/stochastic/sampling/mcmc/models/components/test-intensity-term.cpp rename to tests/stochastic/sampling/mcmc/energy_terms/test-intensity-term.cpp index 8baac05..0a3f14f 100644 --- a/tests/stochastic/sampling/mcmc/models/components/test-intensity-term.cpp +++ b/tests/stochastic/sampling/mcmc/energy_terms/test-intensity-term.cpp @@ -20,7 +20,7 @@ * SOFTWARE. * */ -#include +#include #include #include diff --git a/tests/stochastic/sampling/mcmc/models/components/test-pairwise-term.cpp b/tests/stochastic/sampling/mcmc/energy_terms/test-pairwise-term.cpp similarity index 99% rename from tests/stochastic/sampling/mcmc/models/components/test-pairwise-term.cpp rename to tests/stochastic/sampling/mcmc/energy_terms/test-pairwise-term.cpp index 12bc487..a94a04f 100644 --- a/tests/stochastic/sampling/mcmc/models/components/test-pairwise-term.cpp +++ b/tests/stochastic/sampling/mcmc/energy_terms/test-pairwise-term.cpp @@ -22,7 +22,7 @@ */ #include -#include +#include #include #include diff --git a/tests/stochastic/sampling/mcmc/test-metropolis-hasting-sampler.cpp b/tests/stochastic/sampling/mcmc/test-metropolis-hasting-sampler.cpp index 119d97d..4acc3b5 100644 --- a/tests/stochastic/sampling/mcmc/test-metropolis-hasting-sampler.cpp +++ b/tests/stochastic/sampling/mcmc/test-metropolis-hasting-sampler.cpp @@ -22,10 +22,10 @@ */ #include #include +#include +#include +#include #include -#include -#include -#include #include namespace { @@ -175,10 +175,11 @@ int main() geode::EnergyTermCollection< geode::Point2D > energy_terms; // Add intensity term - energy_terms.add_energy_term( + const auto term_id = energy_terms.add_energy_term( std::make_unique< geode::DensityTerm< geode::Point2D > >( "intensity", 0.5, std::vector< geode::uuid >{ set_id }, domain ) ); + geode_unused( term_id ); geode::MetropolisHastings< geode::Point2D > mh( energy_terms, std::move( kernel ) ); diff --git a/tests/stochastic/sampling/mcmc/test-mh-poisson.cpp b/tests/stochastic/sampling/mcmc/test-mh-poisson.cpp index 71b6b4a..4415275 100644 --- a/tests/stochastic/sampling/mcmc/test-mh-poisson.cpp +++ b/tests/stochastic/sampling/mcmc/test-mh-poisson.cpp @@ -22,11 +22,11 @@ */ #include #include -#include +#include +#include #include -#include -#include #include +#include #include namespace { diff --git a/tests/stochastic/sampling/mcmc/test-mh-strauss.cpp b/tests/stochastic/sampling/mcmc/test-mh-strauss.cpp index ce72961..e5e3eb0 100644 --- a/tests/stochastic/sampling/mcmc/test-mh-strauss.cpp +++ b/tests/stochastic/sampling/mcmc/test-mh-strauss.cpp @@ -22,12 +22,12 @@ */ #include #include -#include +#include +#include +#include #include -#include -#include -#include #include +#include #include #include