|
1 | | -#include "gtest/gtest.h" |
2 | 1 | #include "error_correlations.h" |
| 2 | + |
3 | 3 | #include <vector> |
4 | 4 |
|
| 5 | +#include "gtest/gtest.h" |
| 6 | + |
5 | 7 | using namespace tesseract; |
6 | 8 |
|
7 | 9 | TEST(TwoPassCorrelationsTest, JointProbabilities) { |
8 | | - stim::DetectorErrorModel dem(R"DEM( |
| 10 | + stim::DetectorErrorModel dem(R"DEM( |
9 | 11 | error(0.1) D0 ^ D1 |
10 | 12 | error(0.2) D0 |
11 | 13 | )DEM"); |
12 | 14 |
|
13 | | - auto joint = get_hyperedge_joint_probabilities(dem); |
14 | | - |
15 | | - Hyperedge h0 = {0}; |
16 | | - Hyperedge h1 = {1}; |
17 | | - |
18 | | - // P(D0) = 0.1 XOR 0.2 = 0.1*(1-0.2) + 0.2*(1-0.1) = 0.08 + 0.18 = 0.26 |
19 | | - EXPECT_NEAR(joint[h0][h0], 0.26, 1e-6); |
20 | | - // P(D1) = 0.1 |
21 | | - EXPECT_NEAR(joint[h1][h1], 0.1, 1e-6); |
22 | | - // P(D0 and D1) = 0.1 |
23 | | - EXPECT_NEAR(joint[h0][h1], 0.1, 1e-6); |
24 | | - EXPECT_NEAR(joint[h1][h0], 0.1, 1e-6); |
| 15 | + std::vector<int> global_det_to_comp_id = {0, 1}; |
| 16 | + auto joint = get_hyperedge_joint_probabilities(dem, global_det_to_comp_id); |
| 17 | + |
| 18 | + Hyperedge h0 = {0}; |
| 19 | + Hyperedge h1 = {1}; |
| 20 | + |
| 21 | + // P(D0) = 0.1 XOR 0.2 = 0.1*(1-0.2) + 0.2*(1-0.1) = 0.08 + 0.18 = 0.26 |
| 22 | + EXPECT_NEAR(joint[h0][h0], 0.26, 1e-6); |
| 23 | + // P(D1) = 0.1 |
| 24 | + EXPECT_NEAR(joint[h1][h1], 0.1, 1e-6); |
| 25 | + // P(D0 and D1) = 0.1 |
| 26 | + EXPECT_NEAR(joint[h0][h1], 0.1, 1e-6); |
| 27 | + EXPECT_NEAR(joint[h1][h0], 0.1, 1e-6); |
25 | 28 | } |
26 | 29 |
|
27 | 30 | TEST(TwoPassCorrelationsTest, ImpliedProbabilities) { |
28 | | - JointProbsMap joint; |
29 | | - Hyperedge h0 = {0}; |
30 | | - Hyperedge h1 = {1}; |
31 | | - |
32 | | - joint[h0][h0] = 0.2; |
33 | | - joint[h1][h1] = 0.1; |
34 | | - joint[h0][h1] = 0.05; |
35 | | - joint[h1][h0] = 0.05; |
36 | | - |
37 | | - auto implied = get_implied_hyperedge_probabilities(joint); |
38 | | - |
39 | | - // P(D1 | D0) = 0.05 / 0.2 = 0.25 |
40 | | - bool found = false; |
41 | | - for (const auto& imp : implied[h0]) { |
42 | | - if (imp.affected_hyperedge == h1) { |
43 | | - EXPECT_NEAR(imp.probability, 0.25, 1e-6); |
44 | | - found = true; |
45 | | - } |
| 31 | + JointProbsMap joint; |
| 32 | + Hyperedge h0 = {0}; |
| 33 | + Hyperedge h1 = {1}; |
| 34 | + |
| 35 | + joint[h0][h0] = 0.2; |
| 36 | + joint[h1][h1] = 0.1; |
| 37 | + joint[h0][h1] = 0.05; |
| 38 | + joint[h1][h0] = 0.05; |
| 39 | + |
| 40 | + auto implied = get_implied_hyperedge_probabilities(joint); |
| 41 | + |
| 42 | + // P(D1 | D0) = 0.05 / 0.2 = 0.25 |
| 43 | + bool found = false; |
| 44 | + for (const auto& imp : implied[h0]) { |
| 45 | + if (imp.affected_hyperedge == h1) { |
| 46 | + EXPECT_NEAR(imp.probability, 0.25, 1e-6); |
| 47 | + found = true; |
46 | 48 | } |
47 | | - EXPECT_TRUE(found); |
48 | | - |
49 | | - // P(D0 | D1) = 0.05 / 0.1 = 0.5 |
50 | | - found = false; |
51 | | - for (const auto& imp : implied[h1]) { |
52 | | - if (imp.affected_hyperedge == h0) { |
53 | | - EXPECT_NEAR(imp.probability, 0.5, 1e-6); |
54 | | - found = true; |
55 | | - } |
| 49 | + } |
| 50 | + EXPECT_TRUE(found); |
| 51 | + |
| 52 | + // P(D0 | D1) = 0.05 / 0.1 = 0.5 |
| 53 | + found = false; |
| 54 | + for (const auto& imp : implied[h1]) { |
| 55 | + if (imp.affected_hyperedge == h0) { |
| 56 | + EXPECT_NEAR(imp.probability, 0.5, 1e-6); |
| 57 | + found = true; |
56 | 58 | } |
57 | | - EXPECT_TRUE(found); |
| 59 | + } |
| 60 | + EXPECT_TRUE(found); |
58 | 61 | } |
0 commit comments