From c6ec2355e4409c6c04fcc58bc26921ffe045e0de Mon Sep 17 00:00:00 2001 From: Sebastian Junges Date: Sat, 12 Jun 2021 14:21:32 -0700 Subject: [PATCH] avoid use of constants comparator to avoid skewing the distribution --- src/storm/storage/Distribution.cpp | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/storm/storage/Distribution.cpp b/src/storm/storage/Distribution.cpp index 0d4ceb8eb..cecc08020 100644 --- a/src/storm/storage/Distribution.cpp +++ b/src/storm/storage/Distribution.cpp @@ -10,6 +10,7 @@ #include "storm/settings/SettingsManager.h" #include "storm/adapters/RationalFunctionAdapter.h" +#include "storm/exceptions/NotSupportedException.h" namespace storm { namespace storage { @@ -178,18 +179,27 @@ namespace storm { } template - StateType Distribution::sampleFromDistribution(const ValueType &quantile) const { + typename std::enable_if::value, StateType>::type sample(boost::container::flat_map const& distr, ValueType const& quantile) { ValueType sum = storm::utility::zero(); - storm::utility::ConstantsComparator comp; - for (auto const& entry: distribution) { + for (auto const& entry : distr) { sum += entry.second; - if (comp.isLess(quantile,sum)) { + if (quantile < sum) { return entry.first; } } STORM_LOG_ASSERT(false,"This point should not be reached."); return 0; } + + template + typename std::enable_if::value, StateType>::type sample(boost::container::flat_map const& distr, storm::RationalFunction const& quantile) { + STORM_LOG_THROW(false, storm::exceptions::NotSupportedException, "We cannot sample from parametric distributions."); + } + + template + StateType Distribution::sampleFromDistribution(const ValueType &quantile) const { + return sample(this->distribution, quantile); + } template class Distribution;