diff --git a/fimdlp/CPPFImdlp.cpp b/fimdlp/CPPFImdlp.cpp index 516e958..08f9cc9 100644 --- a/fimdlp/CPPFImdlp.cpp +++ b/fimdlp/CPPFImdlp.cpp @@ -21,48 +21,47 @@ namespace CPPFImdlp { std::vector cutPts; std::vector cutIdx; - float xPrev, cutPoint, curx; - int yPrev, cury; - size_t idxPrev, idx; - bool first = true; + float xPrev, xCur, xPivot, cutPoint; + int yPrev, yCur, yPivot; + size_t idxPrev, idx, numElements; std::vector indices = sortIndices(X); - xPrev = X.at(indices.at(0)); - yPrev = y.at(indices.at(0)); - idxPrev = indices.at(0); + xCur = xPrev = X.at(indices.at(0)); + yCur = yPrev = y.at(indices.at(0)); + numElements = indices.size() - 1; + // idxPrev = indices.at(0); idx = 0; - while (idx < indices.size() - 1) + if (debug) + printf("*idx=%lu -> (-1, -1) Prev(%3.1f, %d) Elementos: %lu\n", idx, xCur, yCur, numElements); + while (idx < numElements) { - if (first) - { - first = false; - curx = X.at(indices.at(idx)); - cury = y.at(indices.at(idx)); - } + xPivot = xCur; + yPivot = yCur; if (debug) - printf(" (%3.1f, %d) Prev(%3.1f, %d)\n", idx, curx, cury, xPrev, yPrev); + printf(" Prev(%3.1f, %d) Pivot(%3.1f, %d) Cur(%3.1f, %d) \n", idx, xPrev, yPrev, xPivot, yPivot, xCur, yCur); // Read the same values and check class changes - while (idx < indices.size() - 1 && curx == xPrev) + do { idx++; - curx = X.at(indices.at(idx)); - cury = y.at(indices.at(idx)); - if (cury != yPrev && curx == xPrev) + xCur = X.at(indices.at(idx)); + yCur = y.at(indices.at(idx)); + if (yCur != yPivot && xCur == xPivot) { - yPrev = -1; + yPivot = -1; } if (debug) - printf(">idx=%lu -> (%3.1f, %d) Prev(%3.1f, %d)\n", idx, curx, cury, xPrev, yPrev); - } - if (yPrev == -1 || yPrev != cury) + printf(">idx=%lu -> Prev(%3.1f, %d) Pivot(%3.1f, %d) Cur(%3.1f, %d) \n", idx, xPrev, yPrev, xPivot, yPivot, xCur, yCur); + } while (idx < numElements && xCur == xPivot); + if (yPivot == -1 || yPrev != yCur) { - cutPoint = (xPrev + curx) / 2; - printf("Cutpoint (%3.1f, %d) -> (%3.1f, %d) = %3.1f", xPrev, yPrev, curx, cury, cutPoint); + cutPoint = (xPrev + xCur) / 2; + if (debug) + printf("Cutpoint idx=%lu Cur(%3.1f, %d) Prev(%3.1f, %d) Pivot(%3.1f, %d) = %3.1f \n", idx, xCur, yCur, xPrev, yPrev, xPivot, yPivot, cutPoint); cutPts.push_back(cutPoint); - cutIdx.push_back(idxPrev); + // cutIdx.push_back(idxPrev); } - yPrev = cury; - xPrev = curx; - idxPrev = indices.at(idx); + yPrev = yPivot; + xPrev = xPivot; + // idxPrev = indices.at(idxPivot); } return cutPts; } diff --git a/fimdlp/CPPFImdlp.h b/fimdlp/CPPFImdlp.h index dbfb4c4..413779e 100644 --- a/fimdlp/CPPFImdlp.h +++ b/fimdlp/CPPFImdlp.h @@ -1,7 +1,6 @@ #ifndef CPPFIMDLP_H #define CPPFIMDLP_H #include -#include #include namespace CPPFImdlp { diff --git a/fimdlp/Metrics.h b/fimdlp/Metrics.h index 96a9f44..c487cc9 100644 --- a/fimdlp/Metrics.h +++ b/fimdlp/Metrics.h @@ -1,8 +1,6 @@ #ifndef METRICS_H #define METRICS_H #include -#include -#include namespace CPPFImdlp { class Metrics diff --git a/fimdlp/cppfimdlp.cpython-310-darwin.so b/fimdlp/cppfimdlp.cpython-310-darwin.so deleted file mode 100755 index 1681329..0000000 Binary files a/fimdlp/cppfimdlp.cpython-310-darwin.so and /dev/null differ diff --git a/fimdlp/mdlp.py b/fimdlp/mdlp.py index 4f0b227..70ac5fb 100644 --- a/fimdlp/mdlp.py +++ b/fimdlp/mdlp.py @@ -61,7 +61,7 @@ class FImdlp(TransformerMixin, BaseEstimator): self.n_features_ = X.shape[1] self.X_ = X self.y_ = y - self.discretizer_ = CFImdlp(debug=True) + self.discretizer_ = CFImdlp(debug=False) return self def transform(self, X): @@ -108,7 +108,13 @@ class FImdlp(TransformerMixin, BaseEstimator): datax = self.X_[np.argsort(self.X_[:, i]), i] y_ = self.y_[np.argsort(self.X_[:, i])] Xcutpoints = self.discretizer_.cut_points(datax, y_) - print(f"New:{self.features_[i]:20s}: {Xcutpoints}") + print( + f"New ({len(Xcutpoints)}):{self.features_[i]:20s}: " + f"{Xcutpoints}" + ) Xcutpoints = self.discretizer_.cut_points_ant(datax, y_) - print(f"Ant:{self.features_[i]:20s}: {Xcutpoints}") + print( + f"Ant ({len(Xcutpoints)}):{self.features_[i]:20s}: " + f"{Xcutpoints}" + ) return X diff --git a/fimdlp/test b/fimdlp/test new file mode 100755 index 0000000..d273a7a Binary files /dev/null and b/fimdlp/test differ diff --git a/fimdlp/test.cpp b/fimdlp/test.cpp new file mode 100644 index 0000000..34ce62e --- /dev/null +++ b/fimdlp/test.cpp @@ -0,0 +1,18 @@ +#include "CPPFImdlp.h" +#include + +using namespace std; +int main(int argc, char *argv[], char *envp[]) +{ + { + CPPFImdlp::CPPFImdlp fimdlp = CPPFImdlp::CPPFImdlp(true); + vector X = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; + vector y = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1}; + vector cutPts = fimdlp.cutPoints(X, y); + for (auto &cutPt : cutPts) + { + cout << cutPt << endl; + } + return 0; + } +} \ No newline at end of file diff --git a/sample.py b/sample.py index 3768a2a..e13031d 100644 --- a/sample.py +++ b/sample.py @@ -8,15 +8,15 @@ X = data.data y = data.target features = data.feature_names test = FImdlp() -# test.fit(X, y, features=features).transform(X) +test.fit(X, y, features=features).transform(X) -X = np.array( - [ - [5.1, 3.5, 1.4, 0.2], - [5.2, 3.0, 1.4, 0.2], - [5.3, 3.2, 1.3, 0.2], - [5.3, 3.1, 1.5, 0.2], - ] -) -y = np.array([0, 0, 0, 1]) -test.fit(X, y).transform(X) +# X = np.array( +# [ +# [5.1, 3.5, 1.4, 0.2], +# [5.2, 3.0, 1.4, 0.2], +# [5.3, 3.2, 1.3, 0.2], +# [5.3, 3.1, 1.5, 0.2], +# ] +# ) +# y = np.array([0, 0, 0, 1]) +# test.fit(X, y).transform(X)