move limits include to CPPFImdlp header

This commit is contained in:
2023-03-22 18:17:11 +01:00
parent 77135739cf
commit 42e83b3d26
2 changed files with 28 additions and 18 deletions

View File

@@ -2,7 +2,6 @@
#include <algorithm>
#include <set>
#include <cmath>
#include <limits>
#include "CPPFImdlp.h"
#include "Metrics.h"
@@ -10,14 +9,16 @@ namespace mdlp {
CPPFImdlp::CPPFImdlp(size_t min_length_, int max_depth_, float proposed): min_length(min_length_),
max_depth(max_depth_),
proposed_cuts(proposed) {
proposed_cuts(proposed)
{
}
CPPFImdlp::CPPFImdlp() = default;
CPPFImdlp::~CPPFImdlp() = default;
size_t CPPFImdlp::compute_max_num_cut_points() const {
size_t CPPFImdlp::compute_max_num_cut_points() const
{
// Set the actual maximum number of cut points as a number or as a percentage of the number of samples
if (proposed_cuts == 0) {
return numeric_limits<size_t>::max();
@@ -30,7 +31,8 @@ namespace mdlp {
return static_cast<size_t>(proposed_cuts);
}
void CPPFImdlp::fit(samples_t &X_, labels_t &y_) {
void CPPFImdlp::fit(samples_t& X_, labels_t& y_)
{
X = X_;
y = y_;
num_cut_points = compute_max_num_cut_points();
@@ -53,7 +55,8 @@ namespace mdlp {
computeCutPoints(0, X.size(), 1);
}
pair<precision_t, size_t> CPPFImdlp::valueCutPoint(size_t start, size_t cut, size_t end) {
pair<precision_t, size_t> CPPFImdlp::valueCutPoint(size_t start, size_t cut, size_t end)
{
size_t n;
size_t m;
size_t idxPrev = cut - 1 >= start ? cut - 1 : cut;
@@ -85,7 +88,8 @@ namespace mdlp {
return { (actual + previous) / 2, cut };
}
void CPPFImdlp::computeCutPoints(size_t start, size_t end, int depth_) {
void CPPFImdlp::computeCutPoints(size_t start, size_t end, int depth_)
{
size_t cut;
pair<precision_t, size_t> result;
if (cutPoints.size() == num_cut_points)
@@ -106,7 +110,8 @@ namespace mdlp {
}
}
size_t CPPFImdlp::getCandidate(size_t start, size_t end) {
size_t CPPFImdlp::getCandidate(size_t start, size_t end)
{
/* Definition 1: A binary discretization for A is determined by selecting the cut point TA for which
E(A, TA; S) is minimal amongst all the candidate cut points. */
size_t candidate = numeric_limits<size_t>::max();
@@ -139,7 +144,8 @@ namespace mdlp {
return candidate;
}
bool CPPFImdlp::mdlp(size_t start, size_t cut, size_t end) {
bool CPPFImdlp::mdlp(size_t start, size_t cut, size_t end)
{
int k;
int k1;
int k2;
@@ -163,7 +169,8 @@ namespace mdlp {
}
// Argsort from https://stackoverflow.com/questions/1577475/c-sorting-and-keeping-track-of-indexes
indices_t CPPFImdlp::sortIndices(samples_t &X_, labels_t &y_) {
indices_t CPPFImdlp::sortIndices(samples_t& X_, labels_t& y_)
{
indices_t idx(X_.size());
iota(idx.begin(), idx.end(), 0);
stable_sort(idx.begin(), idx.end(), [&X_, &y_](size_t i1, size_t i2) {
@@ -175,12 +182,14 @@ namespace mdlp {
return idx;
}
cutPoints_t CPPFImdlp::getCutPoints() {
cutPoints_t CPPFImdlp::getCutPoints()
{
sort(cutPoints.begin(), cutPoints.end());
return cutPoints;
}
int CPPFImdlp::get_depth() const {
int CPPFImdlp::get_depth() const
{
return depth;
}
}

View File

@@ -3,6 +3,7 @@
#include "typesFImdlp.h"
#include "Metrics.h"
#include <limits>
#include <utility>
#include <string>