-
Notifications
You must be signed in to change notification settings - Fork 0
Mcmc config #39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
francoisbonneau
wants to merge
50
commits into
next
Choose a base branch
from
mcmc_config
base: next
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Mcmc config #39
Changes from all commits
Commits
Show all changes
50 commits
Select commit
Hold shift + click to select a range
d42a8b7
file reoganisation
francoisbonneau b3e9957
feat(ObjectSets): add map registry in ObjectSets.
francoisbonneau 5b95c35
keep refactoring
francoisbonneau 3d7e55c
feat(EnergyTerm): builder for energy terms
francoisbonneau 4e4a5a6
Apply prepare changes
francoisbonneau 14e2055
static monitoring
francoisbonneau 964ff1f
Apply prepare changes
francoisbonneau a1b1ea5
feat(Helpers): create inference helpers.
francoisbonneau b4cfae3
Merge remote-tracking branch 'origin/HEAD' into energy_term_refactoring
francoisbonneau 2c94303
Apply prepare changes
francoisbonneau 1dd751a
update to last OpenGeode Version
francoisbonneau 538826d
fix wind compile
francoisbonneau 79a054d
Merge pull request #36 from Geode-solutions/energy_term_refactoring
francoisbonneau 43b70fb
PA comments
francoisbonneau adfec09
Apply prepare changes
francoisbonneau 8ddb2df
feat(statisticstools): implement validator and quadratic loss.
francoisbonneau fda9aff
feat(StatsticTool): Implement validator
francoisbonneau f534c2c
Apply prepare changes
francoisbonneau 9f30eda
fix clang error
francoisbonneau 866cb84
try linking issue
francoisbonneau 64cc95d
feat(StraussTest): reactivate Strauss and Poisson Tests.
francoisbonneau 07bdc97
Apply prepare changes
francoisbonneau cf5d658
tidy 00
francoisbonneau 8a30a3f
Apply prepare changes
francoisbonneau ddab952
tidy01
francoisbonneau 2e072dd
Apply prepare changes
francoisbonneau c9128a9
tidy02
francoisbonneau 405e0e4
tidy 04
francoisbonneau d436520
Apply prepare changes
francoisbonneau 0a32698
tidy05
francoisbonneau a813370
reduce nb iteration
francoisbonneau 4c2ec76
modif param
francoisbonneau 683ebba
avoid generic capture in lambdas
francoisbonneau 60b8dca
tidy 05
francoisbonneau 40339c3
tidy06
francoisbonneau 94c997a
tidy07
francoisbonneau 3331379
Merge pull request #40 from Geode-solutions/update_test_strauss
francoisbonneau dbf2fdf
feat(SimulationContext): remove inheritance in simulation runner
francoisbonneau 1dd8903
Apply prepare changes
francoisbonneau 449ca08
fix execution
francoisbonneau 3c30a67
tidy
francoisbonneau e0a5a94
Apply prepare changes
francoisbonneau d724578
create simulation context builder
francoisbonneau 68f5d6f
tidy
francoisbonneau 7d1a5be
Apply prepare changes
francoisbonneau fd01ad8
tidy2
francoisbonneau 426a3a2
Update include/geode/stochastic/sampling/mcmc/simulation_runner.hpp
francoisbonneau 3f3192a
Apply prepare changes
francoisbonneau 2ae78a9
more tidy
francoisbonneau 8e86a7b
Merge pull request #41 from Geode-solutions/refacto_simulation_runner
francoisbonneau File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| /* | ||
| * 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 <absl/container/flat_hash_map.h> | ||
|
|
||
| #include <geode/stochastic/inference/statistics_tracker.hpp> | ||
| #include <geode/stochastic/inference/target_statistics.hpp> | ||
|
|
||
| namespace geode::statistics | ||
| { | ||
| template < typename ObjectType > | ||
| void validate( const StatisticsTracker< ObjectType >& tracker, | ||
| const TargetStatistics< ObjectType >& targets ) | ||
| { | ||
| 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 ); | ||
|
|
||
| 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 ) ); | ||
| } | ||
| } | ||
|
|
||
| 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 ); | ||
|
|
||
| loss += diff * diff; | ||
| } | ||
|
|
||
| return loss; | ||
| } | ||
| } // namespace geode::statistics |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| #pragma once | ||
|
|
||
| // #include <absl/container/flat_hash_map.h> | ||
| #include <geode/basic/common.hpp> | ||
| #include <geode/basic/uuid.hpp> | ||
|
|
||
| #include <geode/stochastic/common.hpp> | ||
| #include <geode/stochastic/models/model.hpp> | ||
|
|
||
| namespace geode | ||
| { | ||
| template < typename ObjectType > | ||
| class StatisticsTracker | ||
| { | ||
| public: | ||
| StatisticsTracker( const Model< ObjectType >& model ) : model_{ model } | ||
|
Check warning on line 16 in include/geode/stochastic/inference/statistics_tracker.hpp
|
||
| { | ||
| means_.resize( model.nb_terms(), 0.0 ); | ||
| m2_.resize( model.nb_terms(), 0.0 ); | ||
| } | ||
|
|
||
| [[nodiscard]] index_t statiscal_count() const | ||
| { | ||
| return count_; | ||
| } | ||
|
|
||
| void add_realization( const std::vector< double >& values ) | ||
| { | ||
| ++count_; | ||
| for( const auto value_id : geode::Range{ values.size() } ) | ||
| { | ||
| auto& value = values[value_id]; | ||
| auto& mean = means_[value_id]; | ||
| auto& sum_of_squares = m2_[value_id]; | ||
|
|
||
| const auto delta = value - mean; | ||
| mean += delta / count_; | ||
| const auto delta2 = value - mean; | ||
| sum_of_squares += delta * delta2; | ||
| } | ||
| } | ||
|
|
||
| [[nodiscard]] double mean( const uuid& term_uuid ) const | ||
| { | ||
| return means_[model_.term_index( term_uuid )]; | ||
| } | ||
|
|
||
| [[nodiscard]] const std::vector< double >& means() const | ||
| { | ||
| return means_; | ||
| } | ||
|
|
||
| [[nodiscard]] double variance( const uuid& term_uuid ) const | ||
| { | ||
| return variance( model_.term_index( term_uuid ) ); | ||
| } | ||
|
|
||
| [[nodiscard]] std::vector< double > variances() const | ||
| { | ||
| std::vector< double > variances; | ||
| variances.reserve( model_.nb_terms() ); | ||
| for( const auto variance_id : geode::Range{ model_.nb_terms() } ) | ||
| { | ||
| variances.emplace_back( this->variance( variance_id ) ); | ||
| } | ||
| return variances; | ||
| } | ||
|
|
||
| private: | ||
| [[nodiscard]] double variance( index_t term_index ) const | ||
| { | ||
| if( count_ < 2 ) | ||
| { | ||
| return 0.0; | ||
| } | ||
| return m2_[term_index] / ( count_ - 1 ); | ||
| } | ||
|
|
||
| private: | ||
| const Model< ObjectType >& model_; | ||
|
|
||
| std::vector< double > means_; | ||
| std::vector< double > m2_; | ||
| index_t count_{ 0 }; | ||
| }; | ||
| } // namespace geode | ||
107 changes: 107 additions & 0 deletions
107
include/geode/stochastic/inference/target_statistics.hpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| /* | ||
| * 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 <geode/basic/uuid.hpp> | ||
| #include <geode/stochastic/models/model.hpp> | ||
|
|
||
| namespace geode | ||
| { | ||
| struct TargetStatisticConfig | ||
| { | ||
| std::string term_name; | ||
| double value; | ||
| double tolerance; | ||
| }; | ||
|
|
||
| template < typename ObjectType > | ||
| class TargetStatistics | ||
| { | ||
| public: | ||
| explicit TargetStatistics( const Model< ObjectType >& model, | ||
| const std::vector< TargetStatisticConfig >& statistic_targets ) | ||
| : model_( model ) | ||
| { | ||
| values_.resize( model.nb_terms(), 0.0 ); | ||
| tolerances_.resize( model.nb_terms(), 0.0 ); | ||
| active_.resize( model.nb_terms(), false ); | ||
| for( const auto& target : statistic_targets ) | ||
| { | ||
| set_target( target ); | ||
| } | ||
| } | ||
|
|
||
| [[nodiscard]] const Model< ObjectType >& model() const | ||
| { | ||
| return model_; | ||
| } | ||
|
|
||
| [[nodiscard]] bool has_target( const uuid& term_uuid ) const | ||
| { | ||
| return active_[model_.term_index( term_uuid )]; | ||
| } | ||
|
|
||
| [[nodiscard]] double target( const uuid& term_uuid ) const | ||
| { | ||
| return values_[model_.term_index( term_uuid )]; | ||
| } | ||
|
|
||
| [[nodiscard]] double tolerance( const uuid& term_uuid ) const | ||
| { | ||
| return tolerances_[model_.term_index( term_uuid )]; | ||
| } | ||
|
|
||
| [[nodiscard]] std::vector< uuid > active_terms() const | ||
| { | ||
| std::vector< uuid > active_terms_uuid; | ||
|
|
||
| for( const auto& term : model_.terms().energy_terms() ) | ||
| { | ||
| const auto& term_id = term->id(); | ||
| if( active_[model_.term_index( term_id )] ) | ||
| { | ||
| active_terms_uuid.push_back( term_id ); | ||
| } | ||
| } | ||
| return active_terms_uuid; | ||
| } | ||
|
|
||
| private: | ||
| void set_target( const TargetStatisticConfig& statistic ) | ||
| { | ||
| const auto term_uuid = | ||
| model_.terms().get_term_uuid( statistic.term_name ); | ||
| const auto idx = model_.term_index( term_uuid ); | ||
|
|
||
| values_[idx] = statistic.value; | ||
| tolerances_[idx] = statistic.tolerance; | ||
| active_[idx] = true; | ||
| } | ||
|
|
||
| private: | ||
| const Model< ObjectType >& model_; | ||
|
|
||
| std::vector< double > values_; | ||
| std::vector< double > tolerances_; | ||
| std::vector< bool > active_; | ||
| }; | ||
| } // namespace geode |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.