Browse Source

Support for sampling from exponential distribution

tempestpy_adaptions
Matthias Volk 4 years ago
parent
commit
d6d36ee557
No known key found for this signature in database GPG Key ID: 83A57678F739FCD3
  1. 25
      src/storm/utility/random.cpp
  2. 8
      src/storm/utility/random.h

25
src/storm/utility/random.cpp

@ -4,17 +4,12 @@
namespace storm {
namespace utility {
RandomProbabilityGenerator<double>::RandomProbabilityGenerator()
: distribution(0.0, 1.0)
{
RandomProbabilityGenerator<double>::RandomProbabilityGenerator() : distribution(0.0, 1.0) {
std::random_device rd;
engine = std::mt19937(rd());
}
RandomProbabilityGenerator<double>::RandomProbabilityGenerator(uint64_t seed)
: distribution(0.0, 1.0), engine(seed)
{
RandomProbabilityGenerator<double>::RandomProbabilityGenerator(uint64_t seed) : distribution(0.0, 1.0), engine(seed) {
}
double RandomProbabilityGenerator<double>::random() {
@ -25,22 +20,16 @@ namespace storm {
return std::uniform_int_distribution<uint64_t>(min, max)(engine);
}
RandomProbabilityGenerator<RationalNumber>::RandomProbabilityGenerator()
: distribution(0, std::numeric_limits<uint64_t>::max())
{
RandomProbabilityGenerator<RationalNumber>::RandomProbabilityGenerator() : distribution(0, std::numeric_limits<uint64_t>::max()) {
std::random_device rd;
engine = std::mt19937(rd());
}
RandomProbabilityGenerator<RationalNumber>::RandomProbabilityGenerator(uint64_t seed)
: distribution(0, std::numeric_limits<uint64_t>::max()), engine(seed)
{
RandomProbabilityGenerator<RationalNumber>::RandomProbabilityGenerator(uint64_t seed) : distribution(0, std::numeric_limits<uint64_t>::max()), engine(seed) {
}
RationalNumber RandomProbabilityGenerator<RationalNumber>::random() {
return carl::rationalize<RationalNumber>(distribution(engine)) / carl::rationalize<RationalNumber>(std::numeric_limits<uint64_t>::max());
}
uint64_t RandomProbabilityGenerator<RationalNumber>::random_uint(uint64_t min, uint64_t max) {
@ -48,5 +37,11 @@ namespace storm {
}
ExponentialDistributionGenerator::ExponentialDistributionGenerator(double rate) : distribution(rate) {
}
double ExponentialDistributionGenerator::random(boost::mt19937& engine) {
return distribution(engine);
}
}
}

8
src/storm/utility/random.h

@ -1,4 +1,5 @@
#include <random>
#include <boost/random.hpp>
#include "storm/adapters/RationalNumberAdapter.h"
namespace storm {
@ -41,6 +42,13 @@ namespace storm {
};
class ExponentialDistributionGenerator {
public:
ExponentialDistributionGenerator(double rate);
double random(boost::mt19937& engine);
private:
boost::random::exponential_distribution<> distribution;
};
}
}
Loading…
Cancel
Save