Add dataset tests to Ld models
This commit is contained in:
@@ -8,7 +8,7 @@
|
|||||||
[](https://sonarcloud.io/summary/new_code?id=rmontanana_BayesNet)
|
[](https://sonarcloud.io/summary/new_code?id=rmontanana_BayesNet)
|
||||||
[](https://deepwiki.com/Doctorado-ML/BayesNet)
|
[](https://deepwiki.com/Doctorado-ML/BayesNet)
|
||||||

|

|
||||||
[](https://gitea.rmontanana.es/rmontanana/BayesNet)
|
[](https://gitea.rmontanana.es/rmontanana/BayesNet)
|
||||||
[](https://doi.org/10.5281/zenodo.14210344)
|
[](https://doi.org/10.5281/zenodo.14210344)
|
||||||
|
|
||||||
Bayesian Network Classifiers library
|
Bayesian Network Classifiers library
|
||||||
|
@@ -301,17 +301,30 @@ TEST_CASE("AODE voting-proba", "[Models]")
|
|||||||
REQUIRE(pred_proba[67][0] == Catch::Approx(0.702184).epsilon(raw.epsilon));
|
REQUIRE(pred_proba[67][0] == Catch::Approx(0.702184).epsilon(raw.epsilon));
|
||||||
REQUIRE(clf.topological_order() == std::vector<std::string>());
|
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 raw = RawDatasets("iris", false);
|
||||||
auto clf = bayesnet::SPODELd(0);
|
auto clf = bayesnet::SPODELd(0);
|
||||||
// raw.dataset.to(torch::kFloat32);
|
|
||||||
clf.fit(raw.dataset, raw.features, raw.className, raw.states, raw.smoothing);
|
clf.fit(raw.dataset, raw.features, raw.className, raw.states, raw.smoothing);
|
||||||
auto score = clf.score(raw.Xt, raw.yt);
|
auto score = clf.score(raw.Xt, raw.yt);
|
||||||
clf.fit(raw.Xt, raw.yt, raw.features, raw.className, raw.states, raw.smoothing);
|
clf.fit(raw.Xt, raw.yt, raw.features, raw.className, raw.states, raw.smoothing);
|
||||||
auto scoret = clf.score(raw.Xt, raw.yt);
|
auto scoret = clf.score(raw.Xt, raw.yt);
|
||||||
REQUIRE(score == Catch::Approx(0.97333f).epsilon(raw.epsilon));
|
REQUIRE(score == Catch::Approx(0.97333f).epsilon(raw.epsilon));
|
||||||
REQUIRE(scoret == 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]")
|
TEST_CASE("KDB with hyperparameters", "[Models]")
|
||||||
{
|
{
|
||||||
|
@@ -188,7 +188,8 @@ TEST_CASE("Test operator =", "[Node]")
|
|||||||
REQUIRE(dimensions[0] == 2); // Number of states of the node
|
REQUIRE(dimensions[0] == 2); // Number of states of the node
|
||||||
REQUIRE(dimensions[1] == 3); // Number of states of the first parent
|
REQUIRE(dimensions[1] == 3); // Number of states of the first parent
|
||||||
// Create a copy of the node
|
// 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
|
// Check that the copy has not any parents or children
|
||||||
auto parents = node_copy.getParents();
|
auto parents = node_copy.getParents();
|
||||||
auto children = node_copy.getChildren();
|
auto children = node_copy.getChildren();
|
||||||
|
Reference in New Issue
Block a user