refactor system types in library

Add new test taken from join_fit in FImdlp python
Update instructions in README
This commit is contained in:
2023-04-11 19:24:31 +02:00
parent 49c08bfe12
commit d77d27459b
7 changed files with 30 additions and 11 deletions

View File

@@ -27,7 +27,7 @@ string ArffFiles::getClassType() const {
return classType;
}
vector<vector<float>> &ArffFiles::getX() {
vector<mdlp::samples_t> &ArffFiles::getX() {
return X;
}
@@ -80,7 +80,7 @@ void ArffFiles::load(const string &fileName, bool classLast) {
}
void ArffFiles::generateDataset(bool classLast) {
X = vector<vector<float>>(attributes.size(), vector<float>(lines.size()));
X = vector<mdlp::samples_t>(attributes.size(), mdlp::samples_t(lines.size()));
auto yy = vector<string>(lines.size(), "");
int labelIndex = classLast ? static_cast<int>(attributes.size()) : 0;
for (size_t i = 0; i < lines.size(); i++) {

View File

@@ -3,6 +3,7 @@
#include <string>
#include <vector>
#include "../typesFImdlp.h"
using namespace std;
@@ -12,7 +13,7 @@ private:
vector<pair<string, string>> attributes;
string className;
string classType;
vector<vector<float>> X;
vector<mdlp::samples_t> X;
vector<int> y;
void generateDataset(bool);
@@ -32,7 +33,7 @@ public:
static string trim(const string &);
vector<vector<float>> &getX();
vector<mdlp::samples_t> &getX();
vector<int> &getY();

View File

@@ -111,6 +111,16 @@ namespace mdlp {
EXPECT_THROW_WITH_MESSAGE(testDepth.fit(X, y), invalid_argument, "max_depth must be greater than 0");
}
TEST_F(TestFImdlp, JoinFit) {
samples_t X_ = {1, 2, 2, 3, 4, 2, 3};
labels_t y_ = {0, 0, 1, 2, 3, 4, 5};
cutPoints_t expected = {1.5f, 2.5f};
fit(X_, y_);
auto computed = getCutPoints();
EXPECT_EQ(computed.size(), expected.size());
checkCutPoints(computed, expected);
}
TEST_F(TestFImdlp, FitErrorMaxCutPoints) {
auto testmin = CPPFImdlp(2, 10, -1);
auto testmax = CPPFImdlp(3, 0, 200);

View File

@@ -30,6 +30,14 @@ namespace mdlp {
ASSERT_NEAR(0.468996f, entropy(0, 10), precision);
}
TEST_F(TestMetrics, EntropyDouble) {
y = {0, 0, 1, 2, 3};
samples_t expected_entropies = {0.0, 0.0, 0.91829583, 1.5, 1.4575424759098898};
for (auto idx = 0; idx < y.size(); ++idx) {
ASSERT_NEAR(expected_entropies[idx], entropy(0, idx + 1), precision);
}
}
TEST_F(TestMetrics, InformationGain) {
ASSERT_NEAR(1, informationGain(0, 5, 10), precision);
ASSERT_NEAR(1, informationGain(0, 5, 10), precision); // For cache