From fe5fead27e07aef1ed5e3da07bca916969bd2887 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Monta=C3=B1ana?= Date: Sat, 7 Oct 2023 01:43:26 +0200 Subject: [PATCH] Begin Fix Test MST --- mac_mst.txt | 33 +++++++++++++++++++++++++++++++++ src/BayesNet/Mst.cc | 1 + tests/TestBayesMetrics.cc | 15 ++++++++++++++- 3 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 mac_mst.txt diff --git a/mac_mst.txt b/mac_mst.txt new file mode 100644 index 0000000..7327f7b --- /dev/null +++ b/mac_mst.txt @@ -0,0 +1,33 @@ +Weights matrix: + 0.0000000, 0.0384968, 0.0795434, 0.1546867, -0.0000000, 0.1788104, 0.2214721, 0.0323837, 0.0366549, + 0.0384968, 0.0000000, 0.0200662, 0.0200937, -0.0000000, 0.0637224, 0.0183005, 0.0127657, 0.0136054, + 0.0795434, 0.0200662, 0.0000000, 0.0605489, -0.0000000, 0.0894469, 0.1689408, 0.0321602, 0.0223184, + 0.1546867, 0.0200937, 0.0605489, 0.0000000, -0.0000000, 0.1150757, 0.1332292, 0.0422865, 0.0191138, +-0.0000000, -0.0000000, -0.0000000, -0.0000000, 0.0000000, 0.0000000, 0.0000000, 0.0000000, 0.0000000, + 0.1788104, 0.0637224, 0.0894469, 0.1150757, 0.0000000, 0.0000000, 0.1407102, 0.0406590, 0.0366986, + 0.2214721, 0.0183005, 0.1689408, 0.1332292, 0.0000000, 0.1407102, 0.0000000, 0.0427515, 0.0349965, + 0.0323837, 0.0127657, 0.0321602, 0.0422865, 0.0000000, 0.0406590, 0.0427515, 0.0000000, 0.0343376, + 0.0366549, 0.0136054, 0.0223184, 0.0191138, 0.0000000, 0.0366986, 0.0349965, 0.0343376, 0.0000000, +Edge : Weight +0 - 6 : 0.2214721 +0 - 5 : 0.1788104 +2 - 6 : 0.1689408 +0 - 3 : 0.1546867 +1 - 5 : 0.0637224 +6 - 7 : 0.0427515 +5 - 8 : 0.0366986 +4 - 5 : 0.0000000 +------------------------------------------------------------------------------- +Metrics Test + Test Maximum Spanning Tree +------------------------------------------------------------------------------- +/Users/rmontanana/Code/BayesNet/tests/TestBayesMetrics.cc:58 +............................................................................... + +/Users/rmontanana/Code/BayesNet/tests/TestBayesMetrics.cc:69: PASSED: + REQUIRE( result == resultsMST.at(file_name) ) +with expansion: + (0, 6) (0, 5) (0, 3) (5, 1) (5, 8) (5, 4) (6, 2) (6, 7) + == + (0, 6) (0, 5) (0, 3) (5, 1) (5, 8) (5, 4) (6, 2) (6, 7) + diff --git a/src/BayesNet/Mst.cc b/src/BayesNet/Mst.cc index 11e4b2b..42a45c9 100644 --- a/src/BayesNet/Mst.cc +++ b/src/BayesNet/Mst.cc @@ -108,6 +108,7 @@ namespace bayesnet { } g.kruskal_algorithm(); auto mst = g.get_mst(); + g.display_mst(); return reorder(mst, root); } diff --git a/tests/TestBayesMetrics.cc b/tests/TestBayesMetrics.cc index 4383762..87b792c 100644 --- a/tests/TestBayesMetrics.cc +++ b/tests/TestBayesMetrics.cc @@ -8,7 +8,13 @@ using namespace std; TEST_CASE("Metrics Test", "[BayesNet]") { - string file_name = GENERATE("glass", "iris", "ecoli", "diabetes"); + // string file_name = GENERATE("glass", "iris", "ecoli", "diabetes"); + string file_name = "glass"; + // + // + // OJO CAMBIAR + // + // map>> resultsKBest = { {"glass", {7, { 0, 1, 7, 6, 3, 5, 2 }}}, {"iris", {3, { 0, 3, 2 }} }, @@ -52,6 +58,13 @@ TEST_CASE("Metrics Test", "[BayesNet]") SECTION("Test Maximum Spanning Tree") { auto weights_matrix = metrics.conditionalEdge(raw.weights); + cout << "Weights matrix: " << endl; + for (int i = 0; i < static_cast(raw.featurest.size()); ++i) { + for (int j = 0; j < static_cast(raw.featurest.size()); ++j) { + cout << setw(10) << setprecision(7) << fixed << weights_matrix[i][j].item() << ", "; + } + cout << endl; + } auto result = metrics.maximumSpanningTree(raw.featurest, weights_matrix, 0); REQUIRE(result == resultsMST.at(file_name)); }