Add dataset tests to Ld models

This commit is contained in:
2025-07-08 16:07:16 +02:00
parent ed380b1494
commit e5227c5f4b
3 changed files with 18 additions and 4 deletions

View File

@@ -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<std::string>());
}
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]")
{

View File

@@ -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();