summaryrefslogtreecommitdiff
path: root/utils/mfcr_test.cc
diff options
context:
space:
mode:
authorPatrick Simianer <simianer@cl.uni-heidelberg.de>2012-11-05 15:29:46 +0100
committerPatrick Simianer <simianer@cl.uni-heidelberg.de>2012-11-05 15:29:46 +0100
commit6f29f345dc06c1a1033475eac1d1340781d1d603 (patch)
tree6fa4cdd7aefd7d54c9585c2c6274db61bb8b159a /utils/mfcr_test.cc
parentb510da2e562c695c90d565eb295c749569c59be8 (diff)
parentc615c37501fa8576584a510a9d2bfe2fdd5bace7 (diff)
merge upstream/master
Diffstat (limited to 'utils/mfcr_test.cc')
-rw-r--r--utils/mfcr_test.cc72
1 files changed, 0 insertions, 72 deletions
diff --git a/utils/mfcr_test.cc b/utils/mfcr_test.cc
deleted file mode 100644
index 29a1a2ce..00000000
--- a/utils/mfcr_test.cc
+++ /dev/null
@@ -1,72 +0,0 @@
-#include "mfcr.h"
-
-#include <iostream>
-#include <cassert>
-#include <cmath>
-
-#define BOOST_TEST_MODULE MFCRTest
-#include <boost/test/unit_test.hpp>
-#include <boost/test/floating_point_comparison.hpp>
-
-#include "sampler.h"
-
-using namespace std;
-
-BOOST_AUTO_TEST_CASE(Exchangability) {
- MT19937 r;
- MT19937* rng = &r;
- MFCR<2, int> crp(0.5, 3.0);
- vector<double> lambdas(2);
- vector<double> p0s(2);
- lambdas[0] = 0.2;
- lambdas[1] = 0.8;
- p0s[0] = 1.0;
- p0s[1] = 1.0;
-
- double tot = 0;
- double tot2 = 0;
- double xt = 0;
- int cust = 10;
- vector<int> hist(cust + 1, 0), hist2(cust + 1, 0);
- for (int i = 0; i < cust; ++i) { crp.increment(1, p0s.begin(), lambdas.begin(), rng); }
- const int samples = 100000;
- const bool simulate = true;
- for (int k = 0; k < samples; ++k) {
- if (!simulate) {
- crp.clear();
- for (int i = 0; i < cust; ++i) { crp.increment(1, p0s.begin(), lambdas.begin(), rng); }
- } else {
- int da = rng->next() * cust;
- bool a = rng->next() < 0.45;
- if (a) {
- for (int i = 0; i < da; ++i) { crp.increment(1, p0s.begin(), lambdas.begin(), rng); }
- for (int i = 0; i < da; ++i) { crp.decrement(1, rng); }
- xt += 1.0;
- } else {
- for (int i = 0; i < da; ++i) { crp.decrement(1, rng); }
- for (int i = 0; i < da; ++i) { crp.increment(1, p0s.begin(), lambdas.begin(), rng); }
- }
- }
- int c = crp.num_tables(1);
- ++hist[c];
- tot += c;
- int c2 = crp.num_tables(1,0); // tables on floor 0 with dish 1
- ++hist2[c2];
- tot2 += c2;
- }
- cerr << cust << " = " << crp.num_customers() << endl;
- cerr << "P(a) = " << (xt / samples) << endl;
- cerr << "E[num tables] = " << (tot / samples) << endl;
- double error = fabs((tot / samples) - 6.894);
- cerr << " error = " << error << endl;
- for (int i = 1; i <= cust; ++i)
- cerr << i << ' ' << (hist[i]) << endl;
- cerr << "E[num tables on floor 0] = " << (tot2 / samples) << endl;
- double error2 = fabs((tot2 / samples) - 1.379);
- cerr << " error2 = " << error2 << endl;
- for (int i = 1; i <= cust; ++i)
- cerr << i << ' ' << (hist2[i]) << endl;
- assert(error < 0.05); // these can fail with very low probability
- assert(error2 < 0.05);
-};
-