mirror of
https://github.com/Doctorado-ML/FImdlp.git
synced 2025-08-16 16:05:52 +00:00
Add debug output and precision
This commit is contained in:
@@ -3,35 +3,45 @@
|
||||
#include <iostream>
|
||||
namespace CPPFImdlp
|
||||
{
|
||||
CPPFImdlp::CPPFImdlp()
|
||||
CPPFImdlp::CPPFImdlp() : debug(false), precision(6)
|
||||
{
|
||||
divider = pow(10, precision);
|
||||
}
|
||||
CPPFImdlp::CPPFImdlp(int precision, bool debug) : debug(debug), precision(precision)
|
||||
{
|
||||
divider = pow(10, precision);
|
||||
}
|
||||
CPPFImdlp::~CPPFImdlp()
|
||||
{
|
||||
}
|
||||
std::vector<double> CPPFImdlp::cutPoints(std::vector<float> &X, std::vector<int> &y)
|
||||
std::vector<float> CPPFImdlp::cutPoints(std::vector<float> &X, std::vector<int> &y)
|
||||
{
|
||||
std::vector<double> cutPts;
|
||||
double antx;
|
||||
// int anty;
|
||||
std::vector<float> cutPts;
|
||||
float antx, cutPoint;
|
||||
int anty;
|
||||
std::vector<size_t> indices = sortIndices(X);
|
||||
antx = X.at(indices[0]);
|
||||
// anty = y.at(indices[0]);
|
||||
anty = y.at(indices[0]);
|
||||
for (auto index = indices.begin(); index != indices.end(); ++index)
|
||||
{
|
||||
// std::cout << X.at(*index) << " -> " << y.at(*index) << " // ";
|
||||
// Definition 2 Cut points are always on boundaries
|
||||
// if (y.at(*index) != anty && antx < X.at(*index))
|
||||
if (y.at(*index) != anty && antx < X.at(*index))
|
||||
// Weka implementation
|
||||
if (antx < X.at(*index))
|
||||
// if (antx < X.at(*index))
|
||||
{
|
||||
// std::cout << "* (" << X.at(*index) << ", " << antx << ") // ";
|
||||
cutPts.push_back((X.at(*index) + antx) / 2);
|
||||
// anty = y.at(*index);
|
||||
cutPoint = round((X.at(*index) + antx) / 2 * divider) / divider;
|
||||
if (debug)
|
||||
{
|
||||
std::cout << "Cut point: " << (antx + X.at(*index)) / 2 << " //";
|
||||
std::cout << X.at(*index) << " -> " << y.at(*index) << " anty= " << anty;
|
||||
std::cout << "* (" << X.at(*index) << ", " << antx << ")=" << ((X.at(*index) + antx) / 2) << std::endl;
|
||||
}
|
||||
cutPts.push_back(cutPoint);
|
||||
}
|
||||
antx = X.at(*index);
|
||||
anty = y.at(*index);
|
||||
}
|
||||
// std::cout << std::endl;
|
||||
return cutPts;
|
||||
}
|
||||
std::vector<size_t> CPPFImdlp::sortIndices(std::vector<float> &X)
|
||||
|
@@ -8,12 +8,17 @@ namespace CPPFImdlp
|
||||
class CPPFImdlp
|
||||
{
|
||||
private:
|
||||
std::vector<size_t> sortIndices(std::vector<float> &);
|
||||
bool debug;
|
||||
int precision;
|
||||
float divider;
|
||||
std::vector<size_t>
|
||||
sortIndices(std::vector<float> &);
|
||||
|
||||
public:
|
||||
CPPFImdlp();
|
||||
CPPFImdlp(int, bool debug = false);
|
||||
~CPPFImdlp();
|
||||
std::vector<double> cutPoints(std::vector<float> &, std::vector<int> &);
|
||||
std::vector<float> cutPoints(std::vector<float> &, std::vector<int> &);
|
||||
};
|
||||
}
|
||||
#endif
|
@@ -1,16 +1,18 @@
|
||||
# distutils: language = c++
|
||||
# cython: language_level = 3
|
||||
from libcpp.vector cimport vector
|
||||
from libcpp cimport bool
|
||||
|
||||
cdef extern from "CPPFImdlp.h" namespace "CPPFImdlp":
|
||||
cdef cppclass CPPFImdlp:
|
||||
CPPFImdlp() except +
|
||||
vector[double] cutPoints(vector[float]&, vector[int]&)
|
||||
CPPFImdlp(int, bool) except +
|
||||
vector[float] cutPoints(vector[float]&, vector[int]&)
|
||||
|
||||
cdef class CFImdlp:
|
||||
cdef CPPFImdlp *thisptr
|
||||
def __cinit__(self):
|
||||
self.thisptr = new CPPFImdlp()
|
||||
def __cinit__(self, precision=6, debug=False):
|
||||
self.thisptr = new CPPFImdlp(precision, debug)
|
||||
def __dealloc__(self):
|
||||
del self.thisptr
|
||||
def cut_points(self, X, y):
|
||||
|
Binary file not shown.
@@ -19,9 +19,6 @@ class FImdlp(TransformerMixin, BaseEstimator):
|
||||
The number of features of the data passed to :meth:`fit`.
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
def _check_params_fit(self, X, y, expected_args, kwargs):
|
||||
"""Check the common parameters passed to fit"""
|
||||
# Check that X and y have correct shape
|
||||
@@ -93,7 +90,7 @@ class FImdlp(TransformerMixin, BaseEstimator):
|
||||
# during fit.
|
||||
if X.shape[1] != self.n_features_:
|
||||
raise ValueError(
|
||||
"Shape of input is different from what was seen" "in `fit`"
|
||||
"Shape of input is different from what was seen in `fit`"
|
||||
)
|
||||
print("Cut points for each feature in Iris dataset:")
|
||||
yz = self.y_.copy()
|
||||
|
@@ -6,8 +6,8 @@ data = load_iris()
|
||||
X = data.data
|
||||
y = data.target
|
||||
features = data.feature_names
|
||||
# test = FImdlp()
|
||||
test = FImdlp()
|
||||
# Xcutpoints = test.fit(X, y, features=features).transform(X)
|
||||
clf = CFImdlp()
|
||||
clf = CFImdlp(debug=True)
|
||||
print("Cut points for feature 0 in Iris dataset:")
|
||||
print(clf.cut_points(X[:, 0], y))
|
||||
|
Reference in New Issue
Block a user