199 | 199 |
old mode 100644 |
200 | 200 |
new mode 100755 |
... | ... |
@@ -38,6 +38,7 @@ OBJECTS = Cogaps.o \ |
38 | 38 |
cpp_tests/testHybridMatrix.o \ |
39 | 39 |
cpp_tests/testHybridVector.o \ |
40 | 40 |
cpp_tests/testMatrix.o \ |
41 |
+ cpp_tests/testRandom.o \ |
|
41 | 42 |
cpp_tests/testSerialization.o \ |
42 | 43 |
cpp_tests/testSparseGibbsSampler.o \ |
43 | 44 |
cpp_tests/testSparseIterator.o \ |
76 | 77 |
old mode 100644 |
77 | 78 |
new mode 100755 |
... | ... |
@@ -1,9 +1,37 @@ |
1 | 1 |
#include "catch.h" |
2 |
-#include "../math/Algorithms.h" |
|
3 | 2 |
#include "../math/Random.h" |
3 |
+#include "../math/Math.h" |
|
4 | 4 |
|
5 | 5 |
#define TEST_APPROX(x) Approx(x).epsilon(0.001) |
6 | 6 |
|
7 |
+static void requireSmallError(float in, float out, float est, float tol) |
|
8 |
+{ |
|
9 |
+ float denom = gaps::max(std::abs(out), 1.f); |
|
10 |
+ if (std::abs(est - out) / denom >= tol) |
|
11 |
+ { |
|
12 |
+ gaps_printf("input: %f, output: %f, error: %f\n", in, out, |
|
13 |
+ std::abs(est - out)); |
|
14 |
+ } |
|
15 |
+ REQUIRE(std::abs(est - out) / denom < tol); |
|
16 |
+} |
|
17 |
+ |
|
18 |
+TEST_CASE("Test error of q_norm lookup table") |
|
19 |
+{ |
|
20 |
+ GapsRandomState randState(123); |
|
21 |
+ |
|
22 |
+ const unsigned nIterations = 10000; |
|
23 |
+ const float mean = 0.f; |
|
24 |
+ const float sd = 1.f; |
|
25 |
+ const float tolerance = 0.00001f; |
|
26 |
+ for (unsigned i = 1; i < nIterations; ++i) |
|
27 |
+ { |
|
28 |
+ float q = static_cast<float>(i) / static_cast<float>(nIterations); |
|
29 |
+ float lookup_val = randState.q_norm_fast(q, mean, sd); |
|
30 |
+ float actual_val = gaps::q_norm(q, mean, sd); |
|
31 |
+ requireSmallError(q, actual_val, lookup_val, tolerance); |
|
32 |
+ } |
|
33 |
+} |
|
34 |
+ |
|
7 | 35 |
#if 0 |
8 | 36 |
|
9 | 37 |
TEST_CASE("Test Random.h - Random Number Generation") |