Begin refactor CMakeLists debug/release paths
This commit is contained in:
@@ -4,14 +4,14 @@
|
||||
#include "TestUtils.h"
|
||||
#include "Folding.h"
|
||||
|
||||
TEST_CASE("KFold Test", "[KFold]")
|
||||
TEST_CASE("KFold Test", "[Platform][KFold]")
|
||||
{
|
||||
// Initialize a KFold object with k=5 and a seed of 19.
|
||||
string file_name = GENERATE("glass", "iris", "ecoli", "diabetes");
|
||||
auto raw = RawDatasets(file_name, true);
|
||||
int nFolds = 5;
|
||||
platform::KFold kfold(nFolds, raw.nSamples, 19);s
|
||||
int number = raw.nSamples * (kfold.getNumberOfFolds() - 1) / kfold.getNumberOfFolds();
|
||||
platform::KFold kfold(nFolds, raw.nSamples, 19);
|
||||
int number = raw.nSamples * (kfold.getNumberOfFolds() - 1) / kfold.getNumberOfFolds();
|
||||
|
||||
SECTION("Number of Folds")
|
||||
{
|
||||
@@ -38,61 +38,57 @@ map<int, int> counts(vector<int> y, vector<int> indices)
|
||||
return result;
|
||||
}
|
||||
|
||||
TEST_CASE("StratifiedKFold Test", "[StratifiedKFold]")
|
||||
TEST_CASE("StratifiedKFold Test", "[Platform][StratifiedKFold]")
|
||||
{
|
||||
int nFolds = 3;
|
||||
// Initialize a StratifiedKFold object with k=3, using the y vector, and a seed of 17.
|
||||
string file_name = GENERATE("glass", "iris", "ecoli", "diabetes");
|
||||
int nFolds = GENERATE(3, 5, 10);
|
||||
auto raw = RawDatasets(file_name, true);
|
||||
platform::StratifiedKFold stratified_kfoldt(nFolds, raw.yt, 17);
|
||||
platform::StratifiedKFold stratified_kfoldv(nFolds, raw.yv, 17);
|
||||
int number = raw.nSamples * (stratified_kfold.getNumberOfFolds() - 1) / stratified_kfold.getNumberOfFolds();
|
||||
int number = raw.nSamples * (stratified_kfoldt.getNumberOfFolds() - 1) / stratified_kfoldt.getNumberOfFolds();
|
||||
|
||||
// SECTION("Number of Folds")
|
||||
// {
|
||||
// REQUIRE(stratified_kfold.getNumberOfFolds() == nFolds);
|
||||
// }
|
||||
SECTION("Fold Test")
|
||||
SECTION("Stratified Number of Folds")
|
||||
{
|
||||
REQUIRE(stratified_kfoldt.getNumberOfFolds() == nFolds);
|
||||
}
|
||||
SECTION("Stratified Fold Test")
|
||||
{
|
||||
// Test each fold's size and contents.
|
||||
auto counts = vector<int>(raw.classNumStates, 0);
|
||||
auto counts = map<int, vector<int>>();
|
||||
// Initialize the counts per Fold
|
||||
for (int i = 0; i < nFolds; ++i) {
|
||||
auto [train_indicest, test_indicest] = stratified_kfoldt.getFold(i);
|
||||
auto [train_indicesv, test_indicesv] = stratified_kfoldv.getFold(i);
|
||||
counts[i] = vector<int>(raw.classNumStates, 0);
|
||||
}
|
||||
// Check fold and compute counts of each fold
|
||||
for (int fold = 0; fold < nFolds; ++fold) {
|
||||
auto [train_indicest, test_indicest] = stratified_kfoldt.getFold(fold);
|
||||
auto [train_indicesv, test_indicesv] = stratified_kfoldv.getFold(fold);
|
||||
REQUIRE(train_indicest == train_indicesv);
|
||||
REQUIRE(test_indicest == test_indicesv);
|
||||
|
||||
bool result = train_indices.size() == number || train_indices.size() == number + 1;
|
||||
bool result = train_indicest.size() == number || train_indicest.size() == number + 1;
|
||||
REQUIRE(result);
|
||||
REQUIRE(train_indices.size() + test_indices.size() == raw.nSamples);
|
||||
auto train_t = torch::tensor(train_indices);
|
||||
REQUIRE(train_indicest.size() + test_indicest.size() == raw.nSamples);
|
||||
auto train_t = torch::tensor(train_indicest);
|
||||
auto ytrain = raw.yt.index({ train_t });
|
||||
cout << "dataset=" << file_name << endl;
|
||||
cout << "nSamples=" << raw.nSamples << endl;;
|
||||
cout << "number=" << number << endl;
|
||||
cout << "train_indices.size()=" << train_indices.size() << endl;
|
||||
cout << "test_indices.size()=" << test_indices.size() << endl;
|
||||
cout << "train_indices.size()=" << train_indicest.size() << endl;
|
||||
cout << "test_indices.size()=" << test_indicest.size() << endl;
|
||||
cout << "Class Name = " << raw.classNamet << endl;
|
||||
cout << "Features = ";
|
||||
for (const auto& item : raw.featurest) {
|
||||
cout << item << ", ";
|
||||
}
|
||||
cout << endl;
|
||||
cout << "Class States: ";
|
||||
for (const auto& item : raw.statest.at(raw.classNamet)) {
|
||||
cout << item << ", ";
|
||||
}
|
||||
cout << endl;
|
||||
// Check that the class labels have been equally assign to each fold
|
||||
for (const auto& idx : train_indices) {
|
||||
counts[ytrain[idx].item<int>()]++;
|
||||
for (const auto& idx : train_indicest) {
|
||||
counts[fold][ytrain[idx].item<int>()]++;
|
||||
}
|
||||
}
|
||||
// Test the fold counting of every class
|
||||
for (int fold = 0; fold < nFolds; ++fold) {
|
||||
for (int j = 1; j < nFolds - 1; ++j) {
|
||||
for (int k = 0; k < raw.classNumStates; ++k) {
|
||||
REQUIRE(abs(counts.at(fold).at(k) - counts.at(fold).at(j)) <= 1);
|
||||
}
|
||||
}
|
||||
int j = 0;
|
||||
for (const auto& item : counts) {
|
||||
cout << "j=" << j++ << item << endl;
|
||||
}
|
||||
|
||||
}
|
||||
REQUIRE(1 == 1);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user