16template<
typename ValueType,
typename StateType>
21template<
typename ValueType,
typename StateType>
23 this->distribution.reserve(size);
26template<
typename ValueType,
typename StateType>
29 std::set_union(this->distribution.begin(), this->distribution.end(), other.distribution.begin(), other.distribution.end(),
30 std::inserter(newDistribution, newDistribution.begin()));
31 this->distribution = std::move(newDistribution);
34template<
typename ValueType,
typename StateType>
38 if (this->distribution.size() != other.distribution.size()) {
42 auto first1 = this->distribution.begin();
43 auto last1 = this->distribution.end();
44 auto first2 = other.distribution.begin();
46 for (; first1 != last1; ++first1, ++first2) {
47 if (first1->first != first2->first) {
50 if (!comparator.
isEqual(first1->second, first2->second)) {
58template<
typename ValueType,
typename StateType>
60 this->distribution[state] += probability;
63template<
typename ValueType,
typename StateType>
66 auto it = this->distribution.find(state);
67 STORM_LOG_ASSERT(it != this->distribution.end(),
"Cannot remove probability, because the state is not in the support of the distribution.");
68 it->second -= probability;
69 if (comparator.
isZero(it->second)) {
70 this->distribution.erase(it);
74template<
typename ValueType,
typename StateType>
77 removeProbability(fromState, probability, comparator);
78 addProbability(toState, probability);
81template<
typename ValueType,
typename StateType>
83 return this->distribution.begin();
86template<
typename ValueType,
typename StateType>
88 return this->distribution.begin();
91template<
typename ValueType,
typename StateType>
96template<
typename ValueType,
typename StateType>
98 return this->distribution.end();
101template<
typename ValueType,
typename StateType>
103 return this->distribution.end();
106template<
typename ValueType,
typename StateType>
111template<
typename ValueType,
typename StateType>
113 auto probabilityIterator = this->distribution.find(state);
114 if (probabilityIterator != this->distribution.end()) {
115 ValueType scaleValue = storm::utility::one<ValueType>() / probabilityIterator->second;
116 this->distribution.erase(probabilityIterator);
118 for (
auto& entry : this->distribution) {
119 entry.second *= scaleValue;
124template<
typename ValueType,
typename StateType>
126 return this->distribution.size();
129template<
typename ValueType,
typename StateType>
132 for (
auto const& entry : distribution) {
133 out <<
"[" << entry.second <<
": " << entry.first <<
"], ";
140template<
typename ValueType,
typename StateType>
143 if (this->size() != other.
size()) {
144 return this->size() < other.
size();
146 auto firstIt = this->begin();
147 auto firstIte = this->end();
148 auto secondIt = other.
begin();
149 for (; firstIt != firstIte; ++firstIt, ++secondIt) {
151 if (firstIt->first != secondIt->first) {
152 return firstIt->first < secondIt->first;
156 if (!comparator.
isEqual(firstIt->second, secondIt->second)) {
157 return comparator.
isLess(firstIt->second, secondIt->second);
163template<
typename ValueType,
typename StateType>
165 auto it = this->distribution.find(state);
166 if (it == this->distribution.end()) {
167 return storm::utility::zero<ValueType>();
173template<
typename ValueType,
typename StateType>
175 ValueType sum = storm::utility::zero<ValueType>();
176 for (
auto const& entry : distribution) {
179 for (
auto& entry : distribution) {
184template<
typename ValueType,
typename StateType>
185typename std::enable_if<!std::is_same<ValueType, storm::RationalFunction>::value, StateType>::type
sample(
186 boost::container::flat_map<StateType, ValueType>
const& distr, ValueType
const& quantile) {
187 ValueType sum = storm::utility::zero<ValueType>();
188 for (
auto const& entry : distr) {
190 if (quantile < sum) {
198template<
typename ValueType,
typename StateType>
199typename std::enable_if<std::is_same<ValueType, storm::RationalFunction>::value, StateType>::type
sample(
200 boost::container::flat_map<StateType, storm::RationalFunction>
const& distr,
storm::RationalFunction const& quantile) {
201 STORM_LOG_THROW(
false, storm::exceptions::NotSupportedException,
"We cannot sample from parametric distributions.");
204template<
typename ValueType,
typename StateType>
206 return sample<ValueType, StateType>(this->distribution, quantile);
214#ifdef STORM_HAVE_CARL
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
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 shiftProbability(StateType const &fromState, StateType const &toState, ValueType const &probability, storm::utility::ConstantsComparator< ValueType > const &comparator=storm::utility::ConstantsComparator< ValueType >())
Removes the probability mass from one state and adds it to another.
void normalize()
Normalizes the distribution such that the values sum up to one.
bool equals(Distribution< ValueType, StateType > const &other, storm::utility::ConstantsComparator< ValueType > const &comparator=storm::utility::ConstantsComparator< ValueType >()) const
Checks whether the two distributions specify the same probabilities to go to the same states.
container_type::const_iterator const_iterator
const_iterator cbegin() const
Retrieves an iterator to the elements in this distribution.
void removeProbability(StateType const &state, ValueType const &probability, storm::utility::ConstantsComparator< ValueType > const &comparator=storm::utility::ConstantsComparator< ValueType >())
Removes the given probability mass of going to the given state.
std::size_t size() const
Retrieves the size of the distribution, i.e.
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 isZero(ValueType const &value) const
bool isEqual(ValueType const &value1, ValueType const &value2) const
bool isLess(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)
std::ostream & operator<<(std::ostream &out, ParameterRegion< ParametricType > const ®ion)