17template<
typename ValueType,
typename StateType>
22template<
typename ValueType,
typename StateType>
24 this->distribution.reserve(size);
27template<
typename ValueType,
typename StateType>
30 std::set_union(this->distribution.begin(), this->distribution.end(), other.distribution.begin(), other.distribution.end(),
31 std::inserter(newDistribution, newDistribution.begin()));
32 this->distribution = std::move(newDistribution);
35template<
typename ValueType,
typename StateType>
39 if (this->distribution.size() != other.distribution.size()) {
43 auto first1 = this->distribution.begin();
44 auto last1 = this->distribution.end();
45 auto first2 = other.distribution.begin();
47 for (; first1 != last1; ++first1, ++first2) {
48 if (first1->first != first2->first) {
51 if (!comparator.
isEqual(first1->second, first2->second)) {
59template<
typename ValueType,
typename StateType>
61 auto [
iterator, newEntry] = this->distribution.try_emplace(state, probability);
67template<
typename ValueType,
typename StateType>
70 auto it = this->distribution.find(state);
71 STORM_LOG_ASSERT(it != this->distribution.end(),
"Cannot remove probability, because the state is not in the support of the distribution.");
72 it->second -= probability;
73 if (comparator.
isZero(it->second)) {
74 this->distribution.erase(it);
78template<
typename ValueType,
typename StateType>
81 removeProbability(fromState, probability, comparator);
82 addProbability(toState, probability);
85template<
typename ValueType,
typename StateType>
87 return this->distribution.begin();
90template<
typename ValueType,
typename StateType>
92 return this->distribution.begin();
95template<
typename ValueType,
typename StateType>
100template<
typename ValueType,
typename StateType>
102 return this->distribution.end();
105template<
typename ValueType,
typename StateType>
107 return this->distribution.end();
110template<
typename ValueType,
typename StateType>
115template<
typename ValueType,
typename StateType>
117 auto probabilityIterator = this->distribution.find(state);
118 if (probabilityIterator != this->distribution.end()) {
119 ValueType scaleValue = storm::utility::one<ValueType>() / probabilityIterator->second;
120 this->distribution.erase(probabilityIterator);
122 for (
auto& entry : this->distribution) {
123 entry.second *= scaleValue;
128template<
typename ValueType,
typename StateType>
130 return this->distribution.size();
133template<
typename ValueType,
typename StateType>
136 for (
auto const& entry : distribution) {
137 out <<
"[" << entry.second <<
": " << entry.first <<
"], ";
144template<
typename ValueType,
typename StateType>
147 if (this->size() != other.
size()) {
148 return this->size() < other.
size();
150 auto firstIt = this->begin();
151 auto firstIte = this->end();
152 auto secondIt = other.
begin();
153 for (; firstIt != firstIte; ++firstIt, ++secondIt) {
155 if (firstIt->first != secondIt->first) {
156 return firstIt->first < secondIt->first;
160 if (!comparator.
isEqual(firstIt->second, secondIt->second)) {
161 return comparator.
isLess(firstIt->second, secondIt->second);
167template<
typename ValueType,
typename StateType>
169 auto it = this->distribution.find(state);
170 if (it == this->distribution.end()) {
171 return storm::utility::zero<ValueType>();
177template<
typename ValueType,
typename StateType>
179 ValueType sum = storm::utility::zero<ValueType>();
180 for (
auto const& entry : distribution) {
183 for (
auto& entry : distribution) {
188template<
typename ValueType,
typename StateType>
189typename std::enable_if<!std::is_same<ValueType, storm::RationalFunction>::value, StateType>::type
sample(
190 boost::container::flat_map<StateType, ValueType>
const& distr, ValueType
const& quantile) {
191 ValueType sum = storm::utility::zero<ValueType>();
192 for (
auto const& entry : distr) {
194 if (quantile < sum) {
202template<
typename ValueType,
typename StateType>
203typename std::enable_if<std::is_same<ValueType, storm::RationalFunction>::value, StateType>::type
sample(
204 boost::container::flat_map<StateType, storm::RationalFunction>
const& distr,
storm::RationalFunction const& quantile) {
205 STORM_LOG_THROW(
false, storm::exceptions::NotSupportedException,
"We cannot sample from parametric distributions.");
208template<
typename ValueType,
typename StateType>
210 return sample<ValueType, StateType>(this->distribution, quantile);
void shiftProbability(StateType const &fromState, StateType const &toState, ValueType const &probability, storm::utility::ConstantsComparator< ValueType > const &comparator)
Removes the probability mass from one state and adds it to another.
iterator end()
Retrieves an iterator past the elements in this distribution.
void reserve(uint64_t size)
void addProbability(StateType const &state, ValueType const &probability)
Assigns the given state the given probability under this distribution.
boost::container::flat_map< StateType, ValueType > container_type
void removeProbability(StateType const &state, ValueType const &probability, storm::utility::ConstantsComparator< ValueType > const &comparator)
Removes the given probability mass of going to the given state.
const_iterator cend() const
Retrieves an iterator past the elements in this distribution.
bool less(Distribution< ValueType, StateType > const &other, storm::utility::ConstantsComparator< ValueType > const &comparator) const
void normalize()
Normalizes the distribution such that the values sum up to one.
container_type::const_iterator const_iterator
const_iterator cbegin() const
Retrieves an iterator to the elements in this distribution.
std::size_t size() const
Retrieves the size of the distribution, i.e.
bool equals(Distribution< ValueType, StateType > const &other, storm::utility::ConstantsComparator< ValueType > const &comparator) const
Checks whether the two distributions specify the same probabilities to go to the same states.
StateType sampleFromDistribution(ValueType const &quantile) const
Given a value q, find the event in the ordered distribution that corresponds to this prob.
iterator begin()
Retrieves an iterator to the elements in this distribution.
ValueType getProbability(StateType const &state) const
Returns the probability of the given state.
Distribution()
Creates an empty distribution.
container_type::iterator iterator
void add(Distribution const &other)
Adds the given distribution to the current one.
void scale(StateType const &state)
Scales the distribution by multiplying all the probabilities with 1/p where p is the probability of m...
bool isLess(ValueType const &value1, ValueType const &value2) const
bool isZero(ValueType const &value) const
bool isEqual(ValueType const &value1, ValueType const &value2) const
#define STORM_LOG_ASSERT(cond, message)
#define STORM_LOG_THROW(cond, exception, message)
std::enable_if<!std::is_same< ValueType, storm::RationalFunction >::value, StateType >::type sample(boost::container::flat_map< StateType, ValueType > const &distr, ValueType const &quantile)