Add getNumberOfNodes & getNumberOfEdges to Models
Add some more tests
This commit is contained in:
@@ -21,7 +21,7 @@ TEST_CASE("Test Bayesian Classifiers score", "[BayesNet]")
|
||||
};
|
||||
|
||||
string file_name = GENERATE("glass", "iris", "ecoli", "diabetes");
|
||||
auto[Xd, y, features, className, states] = loadFile(file_name);
|
||||
auto [Xd, y, features, className, states] = loadFile(file_name);
|
||||
|
||||
SECTION("Test TAN classifier (" + file_name + ")")
|
||||
{
|
||||
@@ -59,4 +59,30 @@ TEST_CASE("Test Bayesian Classifiers score", "[BayesNet]")
|
||||
// for (auto scores : scores) {
|
||||
// cout << "{{\"" << scores.first.first << "\", \"" << scores.first.second << "\"}, " << scores.second << "}, ";
|
||||
// }
|
||||
}
|
||||
TEST_CASE("Models features")
|
||||
{
|
||||
auto graph = vector<string>({ "digraph BayesNet {\nlabel=<BayesNet Test>\nfontsize=30\nfontcolor=blue\nlabelloc=t\nlayout=circo\n",
|
||||
"class [shape=circle, fontcolor=red, fillcolor=lightblue, style=filled ] \n",
|
||||
"class -> sepallength", "class -> sepalwidth", "class -> petallength", "class -> petalwidth", "petallength [shape=circle] \n",
|
||||
"petallength -> sepallength", "petalwidth [shape=circle] \n", "sepallength [shape=circle] \n",
|
||||
"sepallength -> sepalwidth", "sepalwidth [shape=circle] \n", "sepalwidth -> petalwidth", "}\n"
|
||||
}
|
||||
);
|
||||
|
||||
auto clf = bayesnet::TAN();
|
||||
auto [Xd, y, features, className, states] = loadFile("iris");
|
||||
clf.fit(Xd, y, features, className, states);
|
||||
REQUIRE(clf.getNumberOfNodes() == 5);
|
||||
REQUIRE(clf.getNumberOfEdges() == 7);
|
||||
REQUIRE(clf.show() == vector<string>{"class -> sepallength, sepalwidth, petallength, petalwidth, ", "petallength -> sepallength, ", "petalwidth -> ", "sepallength -> sepalwidth, ", "sepalwidth -> petalwidth, "});
|
||||
REQUIRE(clf.graph("Test") == graph);
|
||||
}
|
||||
TEST_CASE("Get num features & num edges")
|
||||
{
|
||||
auto [Xd, y, features, className, states] = loadFile("iris");
|
||||
auto clf = bayesnet::KDB(2);
|
||||
clf.fit(Xd, y, features, className, states);
|
||||
REQUIRE(clf.getNumberOfNodes() == 5);
|
||||
REQUIRE(clf.getNumberOfEdges() == 8);
|
||||
}
|
@@ -7,7 +7,7 @@
|
||||
|
||||
TEST_CASE("Test Bayesian Network")
|
||||
{
|
||||
auto[Xd, y, features, className, states] = loadFile("iris");
|
||||
auto [Xd, y, features, className, states] = loadFile("iris");
|
||||
|
||||
SECTION("Test Update Nodes")
|
||||
{
|
||||
@@ -26,4 +26,16 @@ TEST_CASE("Test Bayesian Network")
|
||||
net.addNode("C", 2);
|
||||
REQUIRE(net.getFeatures() == vector<string>{"A", "B", "C"});
|
||||
}
|
||||
SECTION("Test get edges")
|
||||
{
|
||||
auto net = bayesnet::Network();
|
||||
net.addNode("A", 3);
|
||||
net.addNode("B", 5);
|
||||
net.addNode("C", 2);
|
||||
net.addEdge("A", "B");
|
||||
net.addEdge("B", "C");
|
||||
REQUIRE(net.getEdges() == vector<pair<string, string>>{ {"A", "B"}, { "B", "C" } });
|
||||
net.addEdge("A", "C");
|
||||
REQUIRE(net.getEdges() == vector<pair<string, string>>{ {"A", "B"}, { "A", "C" }, { "B", "C" } });
|
||||
}
|
||||
}
|
||||
|
@@ -1,8 +1,8 @@
|
||||
if(ENABLE_TESTING)
|
||||
set(TEST_MAIN "unit_tests")
|
||||
set(TEST_SOURCES main.cc ../sample/ArffFiles.cc ../sample/CPPFImdlp.cpp ../sample/Metrics.cpp
|
||||
set(TEST_SOURCES BayesModels.cc BayesNetwork.cc ../sample/ArffFiles.cc ../sample/CPPFImdlp.cpp ../sample/Metrics.cpp
|
||||
../src/utils.cc ../src/Network.cc ../src/Node.cc ../src/Metrics.cc ../src/BaseClassifier.cc ../src/KDB.cc
|
||||
../src/TAN.cc ../src/SPODE.cc ../src/Ensemble.cc ../src/AODE.cc ../src/Mst.cc BayesNetwork.cc utils.cc utils.h)
|
||||
../src/TAN.cc ../src/SPODE.cc ../src/Ensemble.cc ../src/AODE.cc ../src/Mst.cc utils.cc utils.h)
|
||||
add_executable(${TEST_MAIN} ${TEST_SOURCES})
|
||||
target_link_libraries(${TEST_MAIN} PUBLIC "${TORCH_LIBRARIES}" Catch2::Catch2WithMain)
|
||||
add_test(NAME ${TEST_MAIN} COMMAND ${TEST_MAIN})
|
||||
|
Reference in New Issue
Block a user