From e5227c5f4bd4b46b839447d6fa513075568dec5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Monta=C3=B1ana=20G=C3=B3mez?= Date: Tue, 8 Jul 2025 16:07:16 +0200 Subject: [PATCH] Add dataset tests to Ld models --- README.md | 2 +- tests/TestBayesModels.cc | 17 +++++++++++++++-- tests/TestBayesNode.cc | 3 ++- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 1226f6d..dfb8103 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ [![Reliability Rating](https://sonarcloud.io/api/project_badges/measure?project=rmontanana_BayesNet&metric=reliability_rating)](https://sonarcloud.io/summary/new_code?id=rmontanana_BayesNet) [![Ask DeepWiki](https://deepwiki.com/badge.svg)](https://deepwiki.com/Doctorado-ML/BayesNet) ![Gitea Last Commit](https://img.shields.io/gitea/last-commit/rmontanana/bayesnet?gitea_url=https://gitea.rmontanana.es&logo=gitea) -[![Coverage Badge](https://img.shields.io/badge/Coverage-98,5%25-green)](https://gitea.rmontanana.es/rmontanana/BayesNet) +[![Coverage Badge](https://img.shields.io/badge/Coverage-99,1%25-green)](https://gitea.rmontanana.es/rmontanana/BayesNet) [![DOI](https://zenodo.org/badge/667782806.svg)](https://doi.org/10.5281/zenodo.14210344) Bayesian Network Classifiers library diff --git a/tests/TestBayesModels.cc b/tests/TestBayesModels.cc index 9bf98b4..26cd773 100644 --- a/tests/TestBayesModels.cc +++ b/tests/TestBayesModels.cc @@ -301,17 +301,30 @@ TEST_CASE("AODE voting-proba", "[Models]") REQUIRE(pred_proba[67][0] == Catch::Approx(0.702184).epsilon(raw.epsilon)); REQUIRE(clf.topological_order() == std::vector()); } -TEST_CASE("SPODELd dataset", "[Models]") +TEST_CASE("Ld models with dataset", "[Models]") { auto raw = RawDatasets("iris", false); auto clf = bayesnet::SPODELd(0); - // raw.dataset.to(torch::kFloat32); clf.fit(raw.dataset, raw.features, raw.className, raw.states, raw.smoothing); auto score = clf.score(raw.Xt, raw.yt); clf.fit(raw.Xt, raw.yt, raw.features, raw.className, raw.states, raw.smoothing); auto scoret = clf.score(raw.Xt, raw.yt); REQUIRE(score == Catch::Approx(0.97333f).epsilon(raw.epsilon)); REQUIRE(scoret == Catch::Approx(0.97333f).epsilon(raw.epsilon)); + auto clf2 = bayesnet::TANLd(); + clf2.fit(raw.dataset, raw.features, raw.className, raw.states, raw.smoothing); + auto score2 = clf2.score(raw.Xt, raw.yt); + clf2.fit(raw.Xt, raw.yt, raw.features, raw.className, raw.states, raw.smoothing); + auto score2t = clf2.score(raw.Xt, raw.yt); + REQUIRE(score2 == Catch::Approx(0.97333f).epsilon(raw.epsilon)); + REQUIRE(score2t == Catch::Approx(0.97333f).epsilon(raw.epsilon)); + auto clf3 = bayesnet::KDBLd(2); + clf3.fit(raw.dataset, raw.features, raw.className, raw.states, raw.smoothing); + auto score3 = clf3.score(raw.Xt, raw.yt); + clf3.fit(raw.Xt, raw.yt, raw.features, raw.className, raw.states, raw.smoothing); + auto score3t = clf3.score(raw.Xt, raw.yt); + REQUIRE(score3 == Catch::Approx(0.97333f).epsilon(raw.epsilon)); + REQUIRE(score3t == Catch::Approx(0.97333f).epsilon(raw.epsilon)); } TEST_CASE("KDB with hyperparameters", "[Models]") { diff --git a/tests/TestBayesNode.cc b/tests/TestBayesNode.cc index a1fd04f..1ed7133 100644 --- a/tests/TestBayesNode.cc +++ b/tests/TestBayesNode.cc @@ -188,7 +188,8 @@ TEST_CASE("Test operator =", "[Node]") REQUIRE(dimensions[0] == 2); // Number of states of the node REQUIRE(dimensions[1] == 3); // Number of states of the first parent // Create a copy of the node - auto node_copy = node; + bayesnet::Node node_copy("XX"); + node_copy = node; // Check that the copy has not any parents or children auto parents = node_copy.getParents(); auto children = node_copy.getChildren();