Removed boost/random usage from linear and discrete directories

release/4.3a0
Frank Dellaert 2019-06-15 17:52:57 -04:00 committed by Frank Dellaert
parent 8b201f07bb
commit 7d86b073e6
4 changed files with 14 additions and 21 deletions

View File

@ -23,13 +23,11 @@
#include <gtsam/base/debug.h> #include <gtsam/base/debug.h>
#include <boost/make_shared.hpp> #include <boost/make_shared.hpp>
#include <boost/random/mersenne_twister.hpp>
#include <boost/random/uniform_real.hpp>
#include <boost/random/variate_generator.hpp>
#include <vector>
#include <algorithm> #include <algorithm>
#include <random>
#include <stdexcept> #include <stdexcept>
#include <vector>
using namespace std; using namespace std;
@ -176,8 +174,7 @@ size_t DiscreteConditional::solve(const Values& parentsValues) const {
/* ******************************************************************************** */ /* ******************************************************************************** */
size_t DiscreteConditional::sample(const Values& parentsValues) const { size_t DiscreteConditional::sample(const Values& parentsValues) const {
using boost::uniform_real; static mt19937 rng(2); // random number generator
static boost::mt19937 gen(2); // random number generator
bool debug = ISDEBUG("DiscreteConditional::sample"); bool debug = ISDEBUG("DiscreteConditional::sample");
@ -209,9 +206,8 @@ size_t DiscreteConditional::sample(const Values& parentsValues) const {
} }
// inspired by http://www.boost.org/doc/libs/1_46_1/doc/html/boost_random/tutorial.html // inspired by http://www.boost.org/doc/libs/1_46_1/doc/html/boost_random/tutorial.html
uniform_real<> dist(0, cdf.back()); uniform_real_distribution<double> dist(0, cdf.back());
boost::variate_generator<boost::mt19937&, uniform_real<> > die(gen, dist); size_t sampled = lower_bound(cdf.begin(), cdf.end(), dist(rng)) - cdf.begin();
size_t sampled = lower_bound(cdf.begin(), cdf.end(), die()) - cdf.begin();
if (debug) if (debug)
cout << "-> " << sampled << endl; cout << "-> " << sampled << endl;

View File

@ -21,15 +21,13 @@
#include <boost/format.hpp> #include <boost/format.hpp>
#include <boost/make_shared.hpp> #include <boost/make_shared.hpp>
#include <boost/random/linear_congruential.hpp>
#include <boost/random/normal_distribution.hpp>
#include <boost/random/variate_generator.hpp>
#include <limits>
#include <iostream>
#include <typeinfo>
#include <stdexcept>
#include <cmath> #include <cmath>
#include <iostream>
#include <limits>
#include <random>
#include <stdexcept>
#include <typeinfo>
using namespace std; using namespace std;

View File

@ -46,10 +46,9 @@ Vector Sampler::sampleDiagonal(const Vector& sigmas) {
if (sigma == 0.0) { if (sigma == 0.0) {
result(i) = 0.0; result(i) = 0.0;
} else { } else {
typedef boost::normal_distribution<double> Normal; typedef std::normal_distribution<double> Normal;
Normal dist(0.0, sigma); Normal dist(0.0, sigma);
boost::variate_generator<boost::mt19937_64&, Normal> norm(generator_, dist); result(i) = dist(generator_);
result(i) = norm();
} }
} }
return result; return result;

View File

@ -20,7 +20,7 @@
#include <gtsam/linear/NoiseModel.h> #include <gtsam/linear/NoiseModel.h>
#include <boost/random.hpp> #include <random>
namespace gtsam { namespace gtsam {
@ -37,7 +37,7 @@ protected:
noiseModel::Diagonal::shared_ptr model_; noiseModel::Diagonal::shared_ptr model_;
/** generator */ /** generator */
boost::mt19937_64 generator_; std::mt19937_64 generator_;
public: public:
typedef boost::shared_ptr<Sampler> shared_ptr; typedef boost::shared_ptr<Sampler> shared_ptr;