mirror of
https://github.com/rmontanana/mdlp.git
synced 2025-08-21 10:26:02 +00:00
Compare commits
1 Commits
cb9babace1
...
v2.0.0
Author | SHA1 | Date | |
---|---|---|---|
|
e36d9af8f9 |
18
.github/workflows/build.yml
vendored
18
.github/workflows/build.yml
vendored
@@ -13,9 +13,10 @@ jobs:
|
|||||||
env:
|
env:
|
||||||
BUILD_WRAPPER_OUT_DIR: build_wrapper_output_directory # Directory where build-wrapper output will be placed
|
BUILD_WRAPPER_OUT_DIR: build_wrapper_output_directory # Directory where build-wrapper output will be placed
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4.1.6
|
- uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
|
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
|
||||||
|
submodules: recursive
|
||||||
- name: Install sonar-scanner and build-wrapper
|
- name: Install sonar-scanner and build-wrapper
|
||||||
uses: SonarSource/sonarcloud-github-c-cpp@v2
|
uses: SonarSource/sonarcloud-github-c-cpp@v2
|
||||||
- name: Install lcov & gcovr
|
- name: Install lcov & gcovr
|
||||||
@@ -28,17 +29,16 @@ jobs:
|
|||||||
unzip libtorch-cxx11-abi-shared-with-deps-2.3.1+cpu.zip
|
unzip libtorch-cxx11-abi-shared-with-deps-2.3.1+cpu.zip
|
||||||
- name: Tests & build-wrapper
|
- name: Tests & build-wrapper
|
||||||
run: |
|
run: |
|
||||||
cmake -S . -B build -Wno-dev -DCMAKE_PREFIX_PATH=$(pwd)/libtorch -DENABLE_TESTING=ON
|
cmake -S . -B build -Wno-dev -DCMAKE_PREFIX_PATH=$(pwd)/libtorch -DCMAKE_BUILD_TYPE=Debug -DENABLE_TESTING=ON
|
||||||
build-wrapper-linux-x86-64 --out-dir ${{ env.BUILD_WRAPPER_OUT_DIR }} cmake --build build/ --config Release
|
build-wrapper-linux-x86-64 --out-dir ${{ env.BUILD_WRAPPER_OUT_DIR }} cmake --build build/ --config Debug
|
||||||
|
cmake --build build -j 4
|
||||||
cd build
|
cd build
|
||||||
make
|
ctest -C Debug --output-on-failure -j 4
|
||||||
ctest -C Release --output-on-failure --test-dir tests
|
gcovr -f ../src/CPPFImdlp.cpp -f ../src/Metrics.cpp -f ../src/BinDisc.cpp -f ../src/Discretizer.cpp --txt --sonarqube=coverage.xml
|
||||||
cd ..
|
|
||||||
gcovr -f CPPFImdlp.cpp -f Metrics.cpp -f BinDisc.cpp -f Discretizer.cpp --txt --sonarqube=coverage.xml
|
|
||||||
- name: Run sonar-scanner
|
- name: Run sonar-scanner
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
|
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
|
||||||
run: |
|
run: |
|
||||||
sonar-scanner --define sonar.cfamily.build-wrapper-output="${{ env.BUILD_WRAPPER_OUT_DIR }}" \
|
sonar-scanner --define sonar.cfamily.compile-commands="${{ env.BUILD_WRAPPER_OUT_DIR }}" \
|
||||||
--define sonar.coverageReportPaths=coverage.xml
|
--define sonar.coverageReportPaths=build/coverage.xml
|
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
[submodule "tests/lib/Files"]
|
||||||
|
path = tests/lib/Files
|
||||||
|
url = https://github.com/rmontanana/ArffFiles.git
|
@@ -1,11 +1,34 @@
|
|||||||
cmake_minimum_required(VERSION 3.20)
|
cmake_minimum_required(VERSION 3.20)
|
||||||
|
|
||||||
project(mdlp)
|
project(mdlp)
|
||||||
set(CMAKE_CXX_STANDARD 17)
|
set(CMAKE_CXX_STANDARD 17)
|
||||||
|
cmake_policy(SET CMP0135 NEW)
|
||||||
|
|
||||||
find_package(Torch REQUIRED)
|
find_package(Torch REQUIRED)
|
||||||
include_directories(${TORCH_INCLUDE_DIRS})
|
|
||||||
add_library(mdlp CPPFImdlp.cpp Metrics.cpp BinDisc.cpp Discretizer.cpp)
|
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fno-elide-constructors")
|
||||||
target_link_libraries(mdlp "${TORCH_LIBRARIES}")
|
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3")
|
||||||
add_subdirectory(sample)
|
if (NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
|
||||||
|
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fno-default-inline")
|
||||||
|
endif()
|
||||||
|
|
||||||
if (ENABLE_TESTING)
|
if (ENABLE_TESTING)
|
||||||
|
MESSAGE("Debug mode")
|
||||||
|
enable_testing()
|
||||||
|
set(CODE_COVERAGE ON)
|
||||||
|
SET(GCC_COVERAGE_LINK_FLAGS " ${GCC_COVERAGE_LINK_FLAGS} -lgcov --coverage")
|
||||||
add_subdirectory(tests)
|
add_subdirectory(tests)
|
||||||
|
else(ENABLE_TESTING)
|
||||||
|
MESSAGE("Release mode")
|
||||||
endif(ENABLE_TESTING)
|
endif(ENABLE_TESTING)
|
||||||
|
|
||||||
|
|
||||||
|
add_subdirectory(sample)
|
||||||
|
|
||||||
|
include_directories(
|
||||||
|
${TORCH_INCLUDE_DIRS}
|
||||||
|
${mdlp_SOURCE_DIR}/src
|
||||||
|
)
|
||||||
|
|
||||||
|
add_library(mdlp src/CPPFImdlp.cpp src/Metrics.cpp src/BinDisc.cpp src/Discretizer.cpp)
|
||||||
|
target_link_libraries(mdlp "${TORCH_LIBRARIES}")
|
25
Makefile
25
Makefile
@@ -1,13 +1,32 @@
|
|||||||
SHELL := /bin/bash
|
SHELL := /bin/bash
|
||||||
.DEFAULT_GOAL := build
|
.DEFAULT_GOAL := build
|
||||||
.PHONY: build test
|
.PHONY: build test
|
||||||
|
lcov := lcov
|
||||||
|
|
||||||
build:
|
build:
|
||||||
@if [ -d build_release ]; then rm -fr build_release; fi
|
@if [ -d build_release ]; then rm -fr build_release; fi
|
||||||
@mkdir build_release
|
@mkdir build_release
|
||||||
@cmake -B build_release -S . -DCMAKE_BUILD_TYPE=Release -DENABLE_TESTING=OFF
|
@cmake -B build_release -S . -DCMAKE_BUILD_TYPE=Release -DENABLE_TESTING=OFF
|
||||||
@cmake --build build_release
|
@cmake --build build_release -j 8
|
||||||
|
|
||||||
test:
|
test:
|
||||||
@echo "Testing..."
|
@if [ -d build_debug ]; then rm -fr build_debug; fi
|
||||||
@cd tests && ./test
|
@mkdir build_debug
|
||||||
|
@cmake -B build_debug -S . -DCMAKE_BUILD_TYPE=Debug -DENABLE_TESTING=ON
|
||||||
|
@cmake --build build_debug -j 8
|
||||||
|
@cd build_debug/tests && ctest --output-on-failure -j 8
|
||||||
|
@cd build_debug/tests && $(lcov) --capture --directory ../ --demangle-cpp --ignore-errors source,source --ignore-errors mismatch --output-file coverage.info >/dev/null 2>&1; \
|
||||||
|
$(lcov) --remove coverage.info '/usr/*' --output-file coverage.info >/dev/null 2>&1; \
|
||||||
|
$(lcov) --remove coverage.info 'lib/*' --output-file coverage.info >/dev/null 2>&1; \
|
||||||
|
$(lcov) --remove coverage.info 'libtorch/*' --output-file coverage.info >/dev/null 2>&1; \
|
||||||
|
$(lcov) --remove coverage.info 'tests/*' --output-file coverage.info >/dev/null 2>&1; \
|
||||||
|
$(lcov) --remove coverage.info 'gtest/*' --output-file coverage.info >/dev/null 2>&1;
|
||||||
|
@genhtml build_debug/tests/coverage.info --demangle-cpp --output-directory build_debug/tests/coverage --title "Discretizer mdlp Coverage Report" -s -k -f --legend
|
||||||
|
@echo "* Coverage report is generated at build_debug/tests/coverage/index.html"
|
||||||
|
@which python || (echo ">>> Please install python"; exit 1)
|
||||||
|
@if [ ! -f build_debug/tests/coverage.info ]; then \
|
||||||
|
echo ">>> No coverage.info file found!"; \
|
||||||
|
exit 1; \
|
||||||
|
fi
|
||||||
|
@echo ">>> Updating coverage badge..."
|
||||||
|
@env python update_coverage.py build_debug/tests
|
10
README.md
10
README.md
@@ -1,6 +1,7 @@
|
|||||||
[](https://github.com/rmontanana/mdlp/actions/workflows/build.yml)
|
[](https://github.com/rmontanana/mdlp/actions/workflows/build.yml)
|
||||||
[](https://sonarcloud.io/summary/new_code?id=rmontanana_mdlp)
|
[](https://sonarcloud.io/summary/new_code?id=rmontanana_mdlp)
|
||||||
[](https://sonarcloud.io/summary/new_code?id=rmontanana_mdlp)
|
[](https://sonarcloud.io/summary/new_code?id=rmontanana_mdlp)
|
||||||
|
[](html/index.html)
|
||||||
|
|
||||||
# <img src="logo.png" alt="logo" width="50"/> mdlp
|
# <img src="logo.png" alt="logo" width="50"/> mdlp
|
||||||
|
|
||||||
@@ -31,15 +32,14 @@ Other features:
|
|||||||
To run the sample, just execute the following commands:
|
To run the sample, just execute the following commands:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
cmake -B build -S .
|
make build
|
||||||
cmake --build build
|
build_release/sample/sample -f iris -m 2
|
||||||
build/sample/sample -f iris -m 2
|
build_release/sample/sample -h
|
||||||
build/sample/sample -h
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## Test
|
## Test
|
||||||
|
|
||||||
To run the tests and see coverage (llvm & gcovr have to be installed), execute the following commands:
|
To run the tests and see coverage (llvm with lcov and genhtml have to be installed), execute the following commands:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
make test
|
make test
|
||||||
|
@@ -2,5 +2,10 @@ set(CMAKE_CXX_STANDARD 17)
|
|||||||
|
|
||||||
set(CMAKE_BUILD_TYPE Debug)
|
set(CMAKE_BUILD_TYPE Debug)
|
||||||
|
|
||||||
add_executable(sample sample.cpp ../tests/ArffFiles.cpp)
|
include_directories(
|
||||||
|
${mdlp_SOURCE_DIR}/src
|
||||||
|
${mdlp_SOURCE_DIR}/tests/lib/Files
|
||||||
|
)
|
||||||
|
|
||||||
|
add_executable(sample sample.cpp )
|
||||||
target_link_libraries(sample mdlp "${TORCH_LIBRARIES}")
|
target_link_libraries(sample mdlp "${TORCH_LIBRARIES}")
|
||||||
|
@@ -1,3 +1,9 @@
|
|||||||
|
// ****************************************************************
|
||||||
|
// SPDX - FileCopyrightText: Copyright 2024 Ricardo Montañana Gómez
|
||||||
|
// SPDX - FileType: SOURCE
|
||||||
|
// SPDX - License - Identifier: MIT
|
||||||
|
// ****************************************************************
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
@@ -6,10 +12,10 @@
|
|||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
#include <torch/torch.h>
|
#include <torch/torch.h>
|
||||||
#include "../Discretizer.h"
|
#include <ArffFiles.hpp>
|
||||||
#include "../CPPFImdlp.h"
|
#include "Discretizer.h"
|
||||||
#include "../BinDisc.h"
|
#include "CPPFImdlp.h"
|
||||||
#include "../tests/ArffFiles.h"
|
#include "BinDisc.h"
|
||||||
|
|
||||||
const string PATH = "tests/datasets/";
|
const string PATH = "tests/datasets/";
|
||||||
|
|
||||||
@@ -144,7 +150,7 @@ void process_file(const string& path, const string& file_name, bool class_last,
|
|||||||
auto result = test.fit_transform_t(Xt, yt);
|
auto result = test.fit_transform_t(Xt, yt);
|
||||||
std::cout << "Transformed data (torch)...: " << std::endl;
|
std::cout << "Transformed data (torch)...: " << std::endl;
|
||||||
for (int i = 130; i < 135; i++) {
|
for (int i = 130; i < 135; i++) {
|
||||||
std::cout << std::fixed << std::setprecision(1) << Xt[i].item<float>() << " " << result[i].item<int>() << std::endl;
|
std::cout << std::fixed << std::setprecision(1) << Xt[i].item<mdlp::precision_t>() << " " << result[i].item<int>() << std::endl;
|
||||||
}
|
}
|
||||||
auto disc = mdlp::BinDisc(3);
|
auto disc = mdlp::BinDisc(3);
|
||||||
auto res_v = disc.fit_transform(X[0], y);
|
auto res_v = disc.fit_transform(X[0], y);
|
||||||
@@ -152,7 +158,7 @@ void process_file(const string& path, const string& file_name, bool class_last,
|
|||||||
auto res_t = disc.transform_t(Xt);
|
auto res_t = disc.transform_t(Xt);
|
||||||
std::cout << "Transformed data (BinDisc)...: " << std::endl;
|
std::cout << "Transformed data (BinDisc)...: " << std::endl;
|
||||||
for (int i = 130; i < 135; i++) {
|
for (int i = 130; i < 135; i++) {
|
||||||
std::cout << std::fixed << std::setprecision(1) << Xt[i].item<float>() << " " << res_v[i] << " " << res_t[i].item<int>() << std::endl;
|
std::cout << std::fixed << std::setprecision(1) << Xt[i].item<mdlp::precision_t>() << " " << res_v[i] << " " << res_t[i].item<int>() << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -3,7 +3,7 @@ sonar.organization=rmontanana
|
|||||||
|
|
||||||
# This is the name and version displayed in the SonarCloud UI.
|
# This is the name and version displayed in the SonarCloud UI.
|
||||||
sonar.projectName=mdlp
|
sonar.projectName=mdlp
|
||||||
sonar.projectVersion=1.2.1
|
sonar.projectVersion=2.0.0
|
||||||
# sonar.test.exclusions=tests/**
|
# sonar.test.exclusions=tests/**
|
||||||
# sonar.tests=tests/
|
# sonar.tests=tests/
|
||||||
# sonar.coverage.exclusions=tests/**,sample/**
|
# sonar.coverage.exclusions=tests/**,sample/**
|
||||||
@@ -11,4 +11,4 @@ sonar.projectVersion=1.2.1
|
|||||||
#sonar.sources=.
|
#sonar.sources=.
|
||||||
|
|
||||||
# Encoding of the source code. Default is default system encoding
|
# Encoding of the source code. Default is default system encoding
|
||||||
sonar.sourceEncoding=UTF-8
|
sonar.sourceEncoding=UTF-8
|
@@ -1,3 +1,9 @@
|
|||||||
|
// ****************************************************************
|
||||||
|
// SPDX - FileCopyrightText: Copyright 2024 Ricardo Montañana Gómez
|
||||||
|
// SPDX - FileType: SOURCE
|
||||||
|
// SPDX - License - Identifier: MIT
|
||||||
|
// ****************************************************************
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include "BinDisc.h"
|
#include "BinDisc.h"
|
||||||
@@ -24,8 +30,10 @@ namespace mdlp {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (strategy == strategy_t::QUANTILE) {
|
if (strategy == strategy_t::QUANTILE) {
|
||||||
|
direction = bound_dir_t::RIGHT;
|
||||||
fit_quantile(X);
|
fit_quantile(X);
|
||||||
} else if (strategy == strategy_t::UNIFORM) {
|
} else if (strategy == strategy_t::UNIFORM) {
|
||||||
|
direction = bound_dir_t::RIGHT;
|
||||||
fit_uniform(X);
|
fit_uniform(X);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -46,31 +54,30 @@ namespace mdlp {
|
|||||||
}
|
}
|
||||||
return linspc;
|
return linspc;
|
||||||
}
|
}
|
||||||
size_t clip(const size_t n, size_t lower, size_t upper)
|
size_t clip(const size_t n, const size_t lower, const size_t upper)
|
||||||
{
|
{
|
||||||
return std::max(lower, std::min(n, upper));
|
return std::max(lower, std::min(n, upper));
|
||||||
}
|
}
|
||||||
std::vector<precision_t> percentile(samples_t& data, std::vector<precision_t>& percentiles)
|
std::vector<precision_t> percentile(samples_t& data, const std::vector<precision_t>& percentiles)
|
||||||
{
|
{
|
||||||
// Implementation taken from https://dpilger26.github.io/NumCpp/doxygen/html/percentile_8hpp_source.html
|
// Implementation taken from https://dpilger26.github.io/NumCpp/doxygen/html/percentile_8hpp_source.html
|
||||||
std::vector<precision_t> results;
|
std::vector<precision_t> results;
|
||||||
bool first = true;
|
bool first = true;
|
||||||
results.reserve(percentiles.size());
|
results.reserve(percentiles.size());
|
||||||
for (auto percentile : percentiles) {
|
for (auto percentile : percentiles) {
|
||||||
const size_t i = static_cast<size_t>(std::floor(static_cast<double>(data.size() - 1) * percentile / 100.));
|
const auto i = static_cast<size_t>(std::floor(static_cast<precision_t>(data.size() - 1) * percentile / 100.));
|
||||||
const auto indexLower = clip(i, 0, data.size() - 2);
|
const auto indexLower = clip(i, 0, data.size() - 2);
|
||||||
const double percentI = static_cast<double>(indexLower) / static_cast<double>(data.size() - 1);
|
const precision_t percentI = static_cast<precision_t>(indexLower) / static_cast<precision_t>(data.size() - 1);
|
||||||
const double fraction =
|
const precision_t fraction =
|
||||||
(percentile / 100.0 - percentI) /
|
(percentile / 100.0 - percentI) /
|
||||||
(static_cast<double>(indexLower + 1) / static_cast<double>(data.size() - 1) - percentI);
|
(static_cast<precision_t>(indexLower + 1) / static_cast<precision_t>(data.size() - 1) - percentI);
|
||||||
const auto value = data[indexLower] + (data[indexLower + 1] - data[indexLower]) * fraction;
|
if (const auto value = data[indexLower] + (data[indexLower + 1] - data[indexLower]) * fraction; value != results.back() || first) // first needed as results.back() return is undefined for empty vectors
|
||||||
if (value != results.back() || first) // first needed as results.back() return is undefined for empty vectors
|
|
||||||
results.push_back(value);
|
results.push_back(value);
|
||||||
first = false;
|
first = false;
|
||||||
}
|
}
|
||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
void BinDisc::fit_quantile(samples_t& X)
|
void BinDisc::fit_quantile(const samples_t& X)
|
||||||
{
|
{
|
||||||
auto quantiles = linspace(0.0, 100.0, n_bins + 1);
|
auto quantiles = linspace(0.0, 100.0, n_bins + 1);
|
||||||
auto data = X;
|
auto data = X;
|
||||||
@@ -83,9 +90,9 @@ namespace mdlp {
|
|||||||
}
|
}
|
||||||
cutPoints = percentile(data, quantiles);
|
cutPoints = percentile(data, quantiles);
|
||||||
}
|
}
|
||||||
void BinDisc::fit_uniform(samples_t& X)
|
void BinDisc::fit_uniform(const samples_t& X)
|
||||||
{
|
{
|
||||||
auto minmax = std::minmax_element(X.begin(), X.end());
|
auto [vmin, vmax] = std::minmax_element(X.begin(), X.end());
|
||||||
cutPoints = linspace(*minmax.first, *minmax.second, n_bins + 1);
|
cutPoints = linspace(*vmin, *vmax, n_bins + 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -1,3 +1,9 @@
|
|||||||
|
// ****************************************************************
|
||||||
|
// SPDX - FileCopyrightText: Copyright 2024 Ricardo Montañana Gómez
|
||||||
|
// SPDX - FileType: SOURCE
|
||||||
|
// SPDX - License - Identifier: MIT
|
||||||
|
// ****************************************************************
|
||||||
|
|
||||||
#ifndef BINDISC_H
|
#ifndef BINDISC_H
|
||||||
#define BINDISC_H
|
#define BINDISC_H
|
||||||
|
|
||||||
@@ -18,8 +24,8 @@ namespace mdlp {
|
|||||||
void fit(samples_t& X_, labels_t& y) override;
|
void fit(samples_t& X_, labels_t& y) override;
|
||||||
void fit(samples_t& X);
|
void fit(samples_t& X);
|
||||||
private:
|
private:
|
||||||
void fit_uniform(samples_t&);
|
void fit_uniform(const samples_t&);
|
||||||
void fit_quantile(samples_t&);
|
void fit_quantile(const samples_t&);
|
||||||
int n_bins;
|
int n_bins;
|
||||||
strategy_t strategy;
|
strategy_t strategy;
|
||||||
};
|
};
|
@@ -1,3 +1,9 @@
|
|||||||
|
// ****************************************************************
|
||||||
|
// SPDX - FileCopyrightText: Copyright 2024 Ricardo Montañana Gómez
|
||||||
|
// SPDX - FileType: SOURCE
|
||||||
|
// SPDX - License - Identifier: MIT
|
||||||
|
// ****************************************************************
|
||||||
|
|
||||||
#include <numeric>
|
#include <numeric>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <set>
|
#include <set>
|
||||||
@@ -12,6 +18,7 @@ namespace mdlp {
|
|||||||
max_depth(max_depth_),
|
max_depth(max_depth_),
|
||||||
proposed_cuts(proposed)
|
proposed_cuts(proposed)
|
||||||
{
|
{
|
||||||
|
direction = bound_dir_t::RIGHT;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t CPPFImdlp::compute_max_num_cut_points() const
|
size_t CPPFImdlp::compute_max_num_cut_points() const
|
||||||
@@ -20,11 +27,11 @@ namespace mdlp {
|
|||||||
if (proposed_cuts == 0) {
|
if (proposed_cuts == 0) {
|
||||||
return numeric_limits<size_t>::max();
|
return numeric_limits<size_t>::max();
|
||||||
}
|
}
|
||||||
if (proposed_cuts < 0 || proposed_cuts > static_cast<float>(X.size())) {
|
if (proposed_cuts < 0 || proposed_cuts > static_cast<precision_t>(X.size())) {
|
||||||
throw invalid_argument("wrong proposed num_cuts value");
|
throw invalid_argument("wrong proposed num_cuts value");
|
||||||
}
|
}
|
||||||
if (proposed_cuts < 1)
|
if (proposed_cuts < 1)
|
||||||
return static_cast<size_t>(round(static_cast<float>(X.size()) * proposed_cuts));
|
return static_cast<size_t>(round(static_cast<precision_t>(X.size()) * proposed_cuts));
|
||||||
return static_cast<size_t>(proposed_cuts); // The 2 extra cutpoints should not be considered here as this parameter is considered before they are added
|
return static_cast<size_t>(proposed_cuts); // The 2 extra cutpoints should not be considered here as this parameter is considered before they are added
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -59,9 +66,9 @@ namespace mdlp {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Insert first & last X value to the cutpoints as them shall be ignored in transform
|
// Insert first & last X value to the cutpoints as them shall be ignored in transform
|
||||||
auto minmax = std::minmax_element(X.begin(), X.end());
|
auto [vmin, vmax] = std::minmax_element(X.begin(), X.end());
|
||||||
cutPoints.push_back(*minmax.second);
|
cutPoints.push_back(*vmax);
|
||||||
cutPoints.insert(cutPoints.begin(), *minmax.first);
|
cutPoints.insert(cutPoints.begin(), *vmin);
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
@@ -1,3 +1,9 @@
|
|||||||
|
// ****************************************************************
|
||||||
|
// SPDX - FileCopyrightText: Copyright 2024 Ricardo Montañana Gómez
|
||||||
|
// SPDX - FileType: SOURCE
|
||||||
|
// SPDX - License - Identifier: MIT
|
||||||
|
// ****************************************************************
|
||||||
|
|
||||||
#ifndef CPPFIMDLP_H
|
#ifndef CPPFIMDLP_H
|
||||||
#define CPPFIMDLP_H
|
#define CPPFIMDLP_H
|
||||||
|
|
@@ -1,23 +1,26 @@
|
|||||||
|
// ****************************************************************
|
||||||
|
// SPDX - FileCopyrightText: Copyright 2024 Ricardo Montañana Gómez
|
||||||
|
// SPDX - FileType: SOURCE
|
||||||
|
// SPDX - License - Identifier: MIT
|
||||||
|
// ****************************************************************
|
||||||
|
|
||||||
#include "Discretizer.h"
|
#include "Discretizer.h"
|
||||||
|
|
||||||
namespace mdlp {
|
namespace mdlp {
|
||||||
|
|
||||||
labels_t& Discretizer::transform(const samples_t& data)
|
labels_t& Discretizer::transform(const samples_t& data)
|
||||||
{
|
{
|
||||||
discretizedData.clear();
|
discretizedData.clear();
|
||||||
discretizedData.reserve(data.size());
|
discretizedData.reserve(data.size());
|
||||||
// CutPoints always have more than two items
|
// CutPoints always have at least two items
|
||||||
// Have to ignore first and last cut points provided
|
// Have to ignore first and last cut points provided
|
||||||
auto first = cutPoints.begin() + 1;
|
auto first = cutPoints.begin() + 1;
|
||||||
auto last = cutPoints.end() - 1;
|
auto last = cutPoints.end() - 1;
|
||||||
|
auto bound = direction == bound_dir_t::LEFT ? std::lower_bound<std::vector<precision_t>::iterator, precision_t> : std::upper_bound<std::vector<precision_t>::iterator, precision_t>;
|
||||||
for (const precision_t& item : data) {
|
for (const precision_t& item : data) {
|
||||||
auto upper = std::lower_bound(first, last, item);
|
auto pos = bound(first, last, item);
|
||||||
int number = upper - first;
|
auto number = pos - first;
|
||||||
/*
|
discretizedData.push_back(static_cast<label_t>(number));
|
||||||
OJO
|
|
||||||
*/
|
|
||||||
if (number < 0)
|
|
||||||
throw std::runtime_error("number is less than 0 in discretizer::transform");
|
|
||||||
discretizedData.push_back(number);
|
|
||||||
}
|
}
|
||||||
return discretizedData;
|
return discretizedData;
|
||||||
}
|
}
|
||||||
@@ -26,26 +29,26 @@ namespace mdlp {
|
|||||||
fit(X_, y_);
|
fit(X_, y_);
|
||||||
return transform(X_);
|
return transform(X_);
|
||||||
}
|
}
|
||||||
void Discretizer::fit_t(torch::Tensor& X_, torch::Tensor& y_)
|
void Discretizer::fit_t(const torch::Tensor& X_, const torch::Tensor& y_)
|
||||||
{
|
{
|
||||||
auto num_elements = X_.numel();
|
auto num_elements = X_.numel();
|
||||||
samples_t X(X_.data_ptr<precision_t>(), X_.data_ptr<precision_t>() + num_elements);
|
samples_t X(X_.data_ptr<precision_t>(), X_.data_ptr<precision_t>() + num_elements);
|
||||||
labels_t y(y_.data_ptr<int>(), y_.data_ptr<int>() + num_elements);
|
labels_t y(y_.data_ptr<int>(), y_.data_ptr<int>() + num_elements);
|
||||||
fit(X, y);
|
fit(X, y);
|
||||||
}
|
}
|
||||||
torch::Tensor Discretizer::transform_t(torch::Tensor& X_)
|
torch::Tensor Discretizer::transform_t(const torch::Tensor& X_)
|
||||||
{
|
{
|
||||||
auto num_elements = X_.numel();
|
auto num_elements = X_.numel();
|
||||||
samples_t X(X_.data_ptr<float>(), X_.data_ptr<float>() + num_elements);
|
samples_t X(X_.data_ptr<precision_t>(), X_.data_ptr<precision_t>() + num_elements);
|
||||||
auto result = transform(X);
|
auto result = transform(X);
|
||||||
return torch::tensor(result, torch::kInt32);
|
return torch::tensor(result, torch_label_t);
|
||||||
}
|
}
|
||||||
torch::Tensor Discretizer::fit_transform_t(torch::Tensor& X_, torch::Tensor& y_)
|
torch::Tensor Discretizer::fit_transform_t(const torch::Tensor& X_, const torch::Tensor& y_)
|
||||||
{
|
{
|
||||||
auto num_elements = X_.numel();
|
auto num_elements = X_.numel();
|
||||||
samples_t X(X_.data_ptr<precision_t>(), X_.data_ptr<precision_t>() + num_elements);
|
samples_t X(X_.data_ptr<precision_t>(), X_.data_ptr<precision_t>() + num_elements);
|
||||||
labels_t y(y_.data_ptr<int>(), y_.data_ptr<int>() + num_elements);
|
labels_t y(y_.data_ptr<int>(), y_.data_ptr<int>() + num_elements);
|
||||||
auto result = fit_transform(X, y);
|
auto result = fit_transform(X, y);
|
||||||
return torch::tensor(result, torch::kInt32);
|
return torch::tensor(result, torch_label_t);
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -1,12 +1,23 @@
|
|||||||
|
// ****************************************************************
|
||||||
|
// SPDX - FileCopyrightText: Copyright 2024 Ricardo Montañana Gómez
|
||||||
|
// SPDX - FileType: SOURCE
|
||||||
|
// SPDX - License - Identifier: MIT
|
||||||
|
// ****************************************************************
|
||||||
|
|
||||||
#ifndef DISCRETIZER_H
|
#ifndef DISCRETIZER_H
|
||||||
#define DISCRETIZER_H
|
#define DISCRETIZER_H
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <torch/torch.h>
|
|
||||||
#include "typesFImdlp.h"
|
#include "typesFImdlp.h"
|
||||||
|
#include <torch/torch.h>
|
||||||
|
|
||||||
namespace mdlp {
|
namespace mdlp {
|
||||||
|
enum class bound_dir_t {
|
||||||
|
LEFT,
|
||||||
|
RIGHT
|
||||||
|
};
|
||||||
|
const auto torch_label_t = torch::kInt32;
|
||||||
class Discretizer {
|
class Discretizer {
|
||||||
public:
|
public:
|
||||||
Discretizer() = default;
|
Discretizer() = default;
|
||||||
@@ -15,13 +26,14 @@ namespace mdlp {
|
|||||||
virtual void fit(samples_t& X_, labels_t& y_) = 0;
|
virtual void fit(samples_t& X_, labels_t& y_) = 0;
|
||||||
labels_t& transform(const samples_t& data);
|
labels_t& transform(const samples_t& data);
|
||||||
labels_t& fit_transform(samples_t& X_, labels_t& y_);
|
labels_t& fit_transform(samples_t& X_, labels_t& y_);
|
||||||
void fit_t(torch::Tensor& X_, torch::Tensor& y_);
|
void fit_t(const torch::Tensor& X_, const torch::Tensor& y_);
|
||||||
torch::Tensor transform_t(torch::Tensor& X_);
|
torch::Tensor transform_t(const torch::Tensor& X_);
|
||||||
torch::Tensor fit_transform_t(torch::Tensor& X_, torch::Tensor& y_);
|
torch::Tensor fit_transform_t(const torch::Tensor& X_, const torch::Tensor& y_);
|
||||||
static inline std::string version() { return "1.2.3"; };
|
static inline std::string version() { return "1.2.3"; };
|
||||||
protected:
|
protected:
|
||||||
labels_t discretizedData = labels_t();
|
labels_t discretizedData = labels_t();
|
||||||
cutPoints_t cutPoints; // At least two cutpoints must be provided, the first and the last will be ignored in transform
|
cutPoints_t cutPoints; // At least two cutpoints must be provided, the first and the last will be ignored in transform
|
||||||
|
bound_dir_t direction; // used in transform
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
@@ -1,3 +1,9 @@
|
|||||||
|
// ****************************************************************
|
||||||
|
// SPDX - FileCopyrightText: Copyright 2024 Ricardo Montañana Gómez
|
||||||
|
// SPDX - FileType: SOURCE
|
||||||
|
// SPDX - License - Identifier: MIT
|
||||||
|
// ****************************************************************
|
||||||
|
|
||||||
#include "Metrics.h"
|
#include "Metrics.h"
|
||||||
#include <set>
|
#include <set>
|
||||||
#include <cmath>
|
#include <cmath>
|
@@ -1,3 +1,9 @@
|
|||||||
|
// ****************************************************************
|
||||||
|
// SPDX - FileCopyrightText: Copyright 2024 Ricardo Montañana Gómez
|
||||||
|
// SPDX - FileType: SOURCE
|
||||||
|
// SPDX - License - Identifier: MIT
|
||||||
|
// ****************************************************************
|
||||||
|
|
||||||
#ifndef CCMETRICS_H
|
#ifndef CCMETRICS_H
|
||||||
#define CCMETRICS_H
|
#define CCMETRICS_H
|
||||||
|
|
@@ -8,8 +8,9 @@
|
|||||||
using namespace std;
|
using namespace std;
|
||||||
namespace mdlp {
|
namespace mdlp {
|
||||||
typedef float precision_t;
|
typedef float precision_t;
|
||||||
|
typedef int label_t;
|
||||||
typedef std::vector<precision_t> samples_t;
|
typedef std::vector<precision_t> samples_t;
|
||||||
typedef std::vector<int> labels_t;
|
typedef std::vector<label_t> labels_t;
|
||||||
typedef std::vector<size_t> indices_t;
|
typedef std::vector<size_t> indices_t;
|
||||||
typedef std::vector<precision_t> cutPoints_t;
|
typedef std::vector<precision_t> cutPoints_t;
|
||||||
typedef std::map<std::pair<int, int>, precision_t> cacheEnt_t;
|
typedef std::map<std::pair<int, int>, precision_t> cacheEnt_t;
|
@@ -1,132 +0,0 @@
|
|||||||
#include "ArffFiles.h"
|
|
||||||
#include <fstream>
|
|
||||||
#include <sstream>
|
|
||||||
#include <map>
|
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
ArffFiles::ArffFiles() = default;
|
|
||||||
|
|
||||||
vector<string> ArffFiles::getLines() const
|
|
||||||
{
|
|
||||||
return lines;
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned long int ArffFiles::getSize() const
|
|
||||||
{
|
|
||||||
return lines.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
vector<pair<string, string>> ArffFiles::getAttributes() const
|
|
||||||
{
|
|
||||||
return attributes;
|
|
||||||
}
|
|
||||||
|
|
||||||
string ArffFiles::getClassName() const
|
|
||||||
{
|
|
||||||
return className;
|
|
||||||
}
|
|
||||||
|
|
||||||
string ArffFiles::getClassType() const
|
|
||||||
{
|
|
||||||
return classType;
|
|
||||||
}
|
|
||||||
|
|
||||||
vector<mdlp::samples_t>& ArffFiles::getX()
|
|
||||||
{
|
|
||||||
return X;
|
|
||||||
}
|
|
||||||
|
|
||||||
vector<int>& ArffFiles::getY()
|
|
||||||
{
|
|
||||||
return y;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ArffFiles::load(const string& fileName, bool classLast)
|
|
||||||
{
|
|
||||||
ifstream file(fileName);
|
|
||||||
if (!file.is_open()) {
|
|
||||||
throw invalid_argument("Unable to open file");
|
|
||||||
}
|
|
||||||
string line;
|
|
||||||
string keyword;
|
|
||||||
string attribute;
|
|
||||||
string type;
|
|
||||||
string type_w;
|
|
||||||
while (getline(file, line)) {
|
|
||||||
if (line.empty() || line[0] == '%' || line == "\r" || line == " ") {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (line.find("@attribute") != string::npos || line.find("@ATTRIBUTE") != string::npos) {
|
|
||||||
stringstream ss(line);
|
|
||||||
ss >> keyword >> attribute;
|
|
||||||
type = "";
|
|
||||||
while (ss >> type_w)
|
|
||||||
type += type_w + " ";
|
|
||||||
attributes.emplace_back(trim(attribute), trim(type));
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (line[0] == '@') {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
lines.push_back(line);
|
|
||||||
}
|
|
||||||
file.close();
|
|
||||||
if (attributes.empty())
|
|
||||||
throw invalid_argument("No attributes found");
|
|
||||||
if (classLast) {
|
|
||||||
className = get<0>(attributes.back());
|
|
||||||
classType = get<1>(attributes.back());
|
|
||||||
attributes.pop_back();
|
|
||||||
} else {
|
|
||||||
className = get<0>(attributes.front());
|
|
||||||
classType = get<1>(attributes.front());
|
|
||||||
attributes.erase(attributes.begin());
|
|
||||||
}
|
|
||||||
generateDataset(classLast);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void ArffFiles::generateDataset(bool classLast)
|
|
||||||
{
|
|
||||||
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++) {
|
|
||||||
stringstream ss(lines[i]);
|
|
||||||
string value;
|
|
||||||
int pos = 0;
|
|
||||||
int xIndex = 0;
|
|
||||||
while (getline(ss, value, ',')) {
|
|
||||||
if (pos++ == labelIndex) {
|
|
||||||
yy[i] = value;
|
|
||||||
} else {
|
|
||||||
X[xIndex++][i] = stof(value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
y = factorize(yy);
|
|
||||||
}
|
|
||||||
|
|
||||||
string ArffFiles::trim(const string& source)
|
|
||||||
{
|
|
||||||
string s(source);
|
|
||||||
s.erase(0, s.find_first_not_of(" '\n\r\t"));
|
|
||||||
s.erase(s.find_last_not_of(" '\n\r\t") + 1);
|
|
||||||
return s;
|
|
||||||
}
|
|
||||||
|
|
||||||
vector<int> ArffFiles::factorize(const vector<string>& labels_t)
|
|
||||||
{
|
|
||||||
vector<int> yy;
|
|
||||||
yy.reserve(labels_t.size());
|
|
||||||
map<string, int> labelMap;
|
|
||||||
int i = 0;
|
|
||||||
for (const string& label : labels_t) {
|
|
||||||
if (labelMap.find(label) == labelMap.end()) {
|
|
||||||
labelMap[label] = i++;
|
|
||||||
}
|
|
||||||
yy.push_back(labelMap[label]);
|
|
||||||
}
|
|
||||||
return yy;
|
|
||||||
}
|
|
@@ -1,35 +0,0 @@
|
|||||||
#ifndef ARFFFILES_H
|
|
||||||
#define ARFFFILES_H
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include <vector>
|
|
||||||
#include "../typesFImdlp.h"
|
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
class ArffFiles {
|
|
||||||
private:
|
|
||||||
vector<string> lines;
|
|
||||||
vector<pair<string, string>> attributes;
|
|
||||||
string className;
|
|
||||||
string classType;
|
|
||||||
vector<mdlp::samples_t> X;
|
|
||||||
vector<int> y;
|
|
||||||
|
|
||||||
void generateDataset(bool);
|
|
||||||
|
|
||||||
public:
|
|
||||||
ArffFiles();
|
|
||||||
void load(const string&, bool = true);
|
|
||||||
vector<string> getLines() const;
|
|
||||||
unsigned long int getSize() const;
|
|
||||||
string getClassName() const;
|
|
||||||
string getClassType() const;
|
|
||||||
static string trim(const string&);
|
|
||||||
vector<mdlp::samples_t>& getX();
|
|
||||||
vector<int>& getY();
|
|
||||||
vector<pair<string, string>> getAttributes() const;
|
|
||||||
static vector<int> factorize(const vector<string>& labels_t);
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
@@ -1,9 +1,15 @@
|
|||||||
|
// ****************************************************************
|
||||||
|
// SPDX - FileCopyrightText: Copyright 2024 Ricardo Montañana Gómez
|
||||||
|
// SPDX - FileType: SOURCE
|
||||||
|
// SPDX - License - Identifier: MIT
|
||||||
|
// ****************************************************************
|
||||||
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include "gtest/gtest.h"
|
#include "gtest/gtest.h"
|
||||||
#include "ArffFiles.h"
|
#include <ArffFiles.hpp>
|
||||||
#include "../BinDisc.h"
|
#include "BinDisc.h"
|
||||||
#include "Experiments.hpp"
|
#include "Experiments.hpp"
|
||||||
|
|
||||||
namespace mdlp {
|
namespace mdlp {
|
||||||
@@ -75,7 +81,7 @@ namespace mdlp {
|
|||||||
EXPECT_NEAR(7.0, cuts.at(2), margin);
|
EXPECT_NEAR(7.0, cuts.at(2), margin);
|
||||||
EXPECT_NEAR(10.0, cuts.at(3), margin);
|
EXPECT_NEAR(10.0, cuts.at(3), margin);
|
||||||
auto labels = transform(X);
|
auto labels = transform(X);
|
||||||
labels_t expected = { 0, 0, 0, 0, 1, 1, 1, 2, 2, 2 };
|
labels_t expected = { 0, 0, 0, 1, 1, 1, 2, 2, 2, 2 };
|
||||||
EXPECT_EQ(expected, labels);
|
EXPECT_EQ(expected, labels);
|
||||||
}
|
}
|
||||||
TEST_F(TestBinDisc3Q, X10BinsQuantile)
|
TEST_F(TestBinDisc3Q, X10BinsQuantile)
|
||||||
@@ -89,7 +95,7 @@ namespace mdlp {
|
|||||||
EXPECT_NEAR(7.0, cuts.at(2), margin);
|
EXPECT_NEAR(7.0, cuts.at(2), margin);
|
||||||
EXPECT_NEAR(10.0, cuts.at(3), margin);
|
EXPECT_NEAR(10.0, cuts.at(3), margin);
|
||||||
auto labels = transform(X);
|
auto labels = transform(X);
|
||||||
labels_t expected = { 0, 0, 0, 0, 1, 1, 1, 2, 2, 2 };
|
labels_t expected = { 0, 0, 0, 1, 1, 1, 2, 2, 2, 2 };
|
||||||
EXPECT_EQ(expected, labels);
|
EXPECT_EQ(expected, labels);
|
||||||
}
|
}
|
||||||
TEST_F(TestBinDisc3U, X11BinsUniform)
|
TEST_F(TestBinDisc3U, X11BinsUniform)
|
||||||
@@ -237,7 +243,7 @@ namespace mdlp {
|
|||||||
EXPECT_NEAR(10.0, cuts.at(3), margin);
|
EXPECT_NEAR(10.0, cuts.at(3), margin);
|
||||||
EXPECT_NEAR(13.0, cuts.at(4), margin);
|
EXPECT_NEAR(13.0, cuts.at(4), margin);
|
||||||
auto labels = transform(X);
|
auto labels = transform(X);
|
||||||
labels_t expected = { 0, 0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3 };
|
labels_t expected = { 0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3, 3 };
|
||||||
EXPECT_EQ(expected, labels);
|
EXPECT_EQ(expected, labels);
|
||||||
}
|
}
|
||||||
TEST_F(TestBinDisc4Q, X13BinsQuantile)
|
TEST_F(TestBinDisc4Q, X13BinsQuantile)
|
||||||
@@ -252,7 +258,7 @@ namespace mdlp {
|
|||||||
EXPECT_NEAR(10.0, cuts.at(3), margin);
|
EXPECT_NEAR(10.0, cuts.at(3), margin);
|
||||||
EXPECT_NEAR(13.0, cuts.at(4), margin);
|
EXPECT_NEAR(13.0, cuts.at(4), margin);
|
||||||
auto labels = transform(X);
|
auto labels = transform(X);
|
||||||
labels_t expected = { 0, 0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3 };
|
labels_t expected = { 0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3, 3 };
|
||||||
EXPECT_EQ(expected, labels);
|
EXPECT_EQ(expected, labels);
|
||||||
}
|
}
|
||||||
TEST_F(TestBinDisc4U, X14BinsUniform)
|
TEST_F(TestBinDisc4U, X14BinsUniform)
|
||||||
@@ -297,7 +303,7 @@ namespace mdlp {
|
|||||||
EXPECT_NEAR(11.5, cuts.at(3), margin);
|
EXPECT_NEAR(11.5, cuts.at(3), margin);
|
||||||
EXPECT_NEAR(15.0, cuts.at(4), margin);
|
EXPECT_NEAR(15.0, cuts.at(4), margin);
|
||||||
auto labels = transform(X);
|
auto labels = transform(X);
|
||||||
labels_t expected = { 3, 1, 3, 3, 1, 0, 3, 2, 2, 2, 1, 0, 0, 1, 0 };
|
labels_t expected = { 3, 2, 3, 3, 1, 0, 3, 2, 2, 2, 1, 0, 0, 1, 0 };
|
||||||
EXPECT_EQ(expected, labels);
|
EXPECT_EQ(expected, labels);
|
||||||
}
|
}
|
||||||
TEST_F(TestBinDisc4Q, X15BinsQuantile)
|
TEST_F(TestBinDisc4Q, X15BinsQuantile)
|
||||||
@@ -312,7 +318,7 @@ namespace mdlp {
|
|||||||
EXPECT_NEAR(11.5, cuts.at(3), margin);
|
EXPECT_NEAR(11.5, cuts.at(3), margin);
|
||||||
EXPECT_NEAR(15.0, cuts.at(4), margin);
|
EXPECT_NEAR(15.0, cuts.at(4), margin);
|
||||||
auto labels = transform(X);
|
auto labels = transform(X);
|
||||||
labels_t expected = { 3, 3, 3, 3, 1, 0, 1, 2, 2, 2, 1, 0, 0, 1, 0 };
|
labels_t expected = { 3, 3, 3, 3, 1, 0, 2, 2, 2, 2, 1, 0, 0, 1, 0 };
|
||||||
EXPECT_EQ(expected, labels);
|
EXPECT_EQ(expected, labels);
|
||||||
}
|
}
|
||||||
TEST_F(TestBinDisc4U, RepeatedValuesUniform)
|
TEST_F(TestBinDisc4U, RepeatedValuesUniform)
|
||||||
@@ -328,7 +334,7 @@ namespace mdlp {
|
|||||||
EXPECT_NEAR(3.0, cuts.at(3), margin);
|
EXPECT_NEAR(3.0, cuts.at(3), margin);
|
||||||
EXPECT_NEAR(4.0, cuts.at(4), margin);
|
EXPECT_NEAR(4.0, cuts.at(4), margin);
|
||||||
auto labels = transform(X);
|
auto labels = transform(X);
|
||||||
labels_t expected = { 0, 0, 0, 0, 1, 1, 2, 2, 2, 3 };
|
labels_t expected = { 0, 1, 1, 1, 2, 2, 3, 3, 3, 3 };
|
||||||
EXPECT_EQ(expected, labels);
|
EXPECT_EQ(expected, labels);
|
||||||
}
|
}
|
||||||
TEST_F(TestBinDisc4Q, RepeatedValuesQuantile)
|
TEST_F(TestBinDisc4Q, RepeatedValuesQuantile)
|
||||||
@@ -344,67 +350,55 @@ namespace mdlp {
|
|||||||
EXPECT_NEAR(3.0, cuts.at(3), margin);
|
EXPECT_NEAR(3.0, cuts.at(3), margin);
|
||||||
EXPECT_NEAR(4.0, cuts.at(4), margin);
|
EXPECT_NEAR(4.0, cuts.at(4), margin);
|
||||||
auto labels = transform(X);
|
auto labels = transform(X);
|
||||||
labels_t expected = { 0, 0, 0, 0, 1, 1, 2, 2, 2, 3 };
|
labels_t expected = { 0, 1, 1, 1, 2, 2, 3, 3, 3, 3 };
|
||||||
EXPECT_EQ(expected, labels);
|
EXPECT_EQ(expected, labels);
|
||||||
}
|
}
|
||||||
TEST_F(TestBinDisc4U, irisUniform)
|
|
||||||
{
|
|
||||||
ArffFiles file;
|
|
||||||
file.load(data_path + "iris.arff", true);
|
|
||||||
vector<samples_t>& X = file.getX();
|
|
||||||
fit(X[0]);
|
|
||||||
auto Xt = transform(X[0]);
|
|
||||||
labels_t expected = { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 3, 2, 2, 1, 2, 1, 2, 0, 2, 0, 0, 1, 1, 1, 1, 2, 1, 1, 2, 1, 1, 1, 2, 1, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 1, 1, 1, 1, 1, 0, 1, 1, 1, 2, 0, 1, 2, 1, 3, 2, 2, 3, 0, 3, 2, 3, 2, 2, 2, 1, 1, 2, 2, 3, 3, 1, 2, 1, 3, 2, 2, 3, 2, 1, 2, 3, 3, 3, 2, 2, 1, 3, 2, 2, 1, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 1 };
|
|
||||||
EXPECT_EQ(expected, Xt);
|
|
||||||
auto Xtt = fit_transform(X[0], file.getY());
|
|
||||||
EXPECT_EQ(expected, Xtt);
|
|
||||||
auto Xt_t = torch::tensor(X[0], torch::kFloat32);
|
|
||||||
auto y_t = torch::tensor(file.getY(), torch::kInt32);
|
|
||||||
auto Xtt_t = fit_transform_t(Xt_t, y_t);
|
|
||||||
for (int i = 0; i < expected.size(); i++)
|
|
||||||
EXPECT_EQ(expected[i], Xtt_t[i].item<int>());
|
|
||||||
}
|
|
||||||
TEST_F(TestBinDisc4Q, irisQuantile)
|
|
||||||
{
|
|
||||||
ArffFiles file;
|
|
||||||
file.load(data_path + "iris.arff", true);
|
|
||||||
vector<samples_t>& X = file.getX();
|
|
||||||
fit(X[0]);
|
|
||||||
auto Xt = transform(X[0]);
|
|
||||||
labels_t expected = { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 2, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 0, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 3, 3, 3, 1, 3, 1, 2, 0, 3, 1, 0, 2, 2, 2, 1, 3, 1, 2, 2, 1, 2, 2, 2, 2, 3, 3, 3, 3, 2, 1, 1, 1, 2, 2, 1, 2, 3, 2, 1, 1, 1, 2, 2, 0, 1, 1, 1, 2, 1, 1, 2, 2, 3, 2, 3, 3, 0, 3, 3, 3, 3, 3, 3, 1, 2, 3, 3, 3, 3, 2, 3, 1, 3, 2, 3, 3, 2, 2, 3, 3, 3, 3, 3, 2, 2, 3, 2, 3, 2, 3, 3, 3, 2, 3, 3, 3, 2, 3, 2, 2 };
|
|
||||||
EXPECT_EQ(expected, Xt);
|
|
||||||
auto Xtt = fit_transform(X[0], file.getY());
|
|
||||||
EXPECT_EQ(expected, Xtt);
|
|
||||||
auto Xt_t = torch::tensor(X[0], torch::kFloat32);
|
|
||||||
auto y_t = torch::tensor(file.getY(), torch::kInt32);
|
|
||||||
auto Xtt_t = fit_transform_t(Xt_t, y_t);
|
|
||||||
for (int i = 0; i < expected.size(); i++)
|
|
||||||
EXPECT_EQ(expected[i], Xtt_t[i].item<int>());
|
|
||||||
fit_t(Xt_t, y_t);
|
|
||||||
auto Xt_t2 = transform_t(Xt_t);
|
|
||||||
for (int i = 0; i < expected.size(); i++)
|
|
||||||
EXPECT_EQ(expected[i], Xt_t2[i].item<int>());
|
|
||||||
}
|
|
||||||
TEST(TestBinDiscGeneric, Fileset)
|
TEST(TestBinDiscGeneric, Fileset)
|
||||||
{
|
{
|
||||||
Experiments exps(data_path + "tests.txt");
|
Experiments exps(data_path + "tests.txt");
|
||||||
int num = 0;
|
int num = 0;
|
||||||
while (exps.is_next()) {
|
while (exps.is_next()) {
|
||||||
|
++num;
|
||||||
Experiment exp = exps.next();
|
Experiment exp = exps.next();
|
||||||
std::cout << "Exp #: " << ++num << " From: " << exp.from_ << " To: " << exp.to_ << " Step: " << exp.step_ << " Bins: " << exp.n_bins_ << " Strategy: " << exp.strategy_ << std::endl;
|
BinDisc disc(exp.n_bins_, exp.strategy_[0] == 'Q' ? strategy_t::QUANTILE : strategy_t::UNIFORM);
|
||||||
BinDisc disc(exp.n_bins_, exp.strategy_ == "Q" ? strategy_t::QUANTILE : strategy_t::UNIFORM);
|
std::vector<precision_t> test;
|
||||||
std::vector<float> test;
|
if (exp.type_ == experiment_t::RANGE) {
|
||||||
for (float i = exp.from_; i < exp.to_; i += exp.step_) {
|
for (float i = exp.from_; i < exp.to_; i += exp.step_) {
|
||||||
test.push_back(i);
|
test.push_back(i);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
test = exp.dataset_;
|
||||||
}
|
}
|
||||||
// show_vector(test, "Test");
|
// show_vector(test, "Test");
|
||||||
auto empty = std::vector<int>();
|
auto empty = std::vector<int>();
|
||||||
auto Xt = disc.fit_transform(test, empty);
|
auto Xt = disc.fit_transform(test, empty);
|
||||||
auto cuts = disc.getCutPoints();
|
auto cuts = disc.getCutPoints();
|
||||||
EXPECT_EQ(exp.discretized_data_.size(), Xt.size());
|
EXPECT_EQ(exp.discretized_data_.size(), Xt.size());
|
||||||
for (int i = 0; i < exp.discretized_data_.size(); ++i) {
|
auto flag = false;
|
||||||
if (exp.discretized_data_.at(i) != Xt.at(i)) {
|
size_t n_errors = 0;
|
||||||
std::cout << "Error at " << i << " Expected: " << exp.discretized_data_.at(i) << " Got: " << Xt.at(i) << std::endl;
|
if (num < 40) {
|
||||||
|
//
|
||||||
|
// Check discretization of only the first 40 tests as after we cannot ensure the same codification due to precision problems
|
||||||
|
//
|
||||||
|
for (int i = 0; i < exp.discretized_data_.size(); ++i) {
|
||||||
|
if (exp.discretized_data_.at(i) != Xt.at(i)) {
|
||||||
|
if (!flag) {
|
||||||
|
if (exp.type_ == experiment_t::RANGE)
|
||||||
|
std::cout << "+Exp #: " << num << " From: " << exp.from_ << " To: " << exp.to_ << " Step: " << exp.step_ << " Bins: " << exp.n_bins_ << " Strategy: " << exp.strategy_ << std::endl;
|
||||||
|
else {
|
||||||
|
std::cout << "+Exp #: " << num << " strategy: " << exp.strategy_ << " " << " n_bins: " << exp.n_bins_ << " ";
|
||||||
|
show_vector(exp.dataset_, "Dataset");
|
||||||
|
}
|
||||||
|
show_vector(cuts, "Cuts");
|
||||||
|
std::cout << "Error at " << i << " test[i]=" << test.at(i) << " Expected: " << exp.discretized_data_.at(i) << " Got: " << Xt.at(i) << std::endl;
|
||||||
|
flag = true;
|
||||||
|
EXPECT_EQ(exp.discretized_data_.at(i), Xt.at(i));
|
||||||
|
}
|
||||||
|
n_errors++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (flag) {
|
||||||
|
std::cout << "*** Found " << n_errors << " mistakes in this experiment dataset" << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
EXPECT_EQ(exp.cutpoints_.size(), cuts.size());
|
EXPECT_EQ(exp.cutpoints_.size(), cuts.size());
|
||||||
@@ -412,5 +406,6 @@ namespace mdlp {
|
|||||||
EXPECT_NEAR(exp.cutpoints_.at(i), cuts.at(i), margin);
|
EXPECT_NEAR(exp.cutpoints_.at(i), cuts.at(i), margin);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
std::cout << "* Number of experiments tested: " << num << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,6 +1,3 @@
|
|||||||
cmake_minimum_required(VERSION 3.20)
|
|
||||||
set(CMAKE_CXX_STANDARD 17)
|
|
||||||
cmake_policy(SET CMP0135 NEW)
|
|
||||||
include(FetchContent)
|
include(FetchContent)
|
||||||
include_directories(${GTEST_INCLUDE_DIRS})
|
include_directories(${GTEST_INCLUDE_DIRS})
|
||||||
FetchContent_Declare(
|
FetchContent_Declare(
|
||||||
@@ -11,28 +8,30 @@ FetchContent_Declare(
|
|||||||
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
|
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
|
||||||
FetchContent_MakeAvailable(googletest)
|
FetchContent_MakeAvailable(googletest)
|
||||||
|
|
||||||
find_package(Torch REQUIRED)
|
include_directories(
|
||||||
|
${TORCH_INCLUDE_DIRS}
|
||||||
|
${mdlp_SOURCE_DIR}/src
|
||||||
|
${mdlp_SOURCE_DIR}/tests/lib/Files
|
||||||
|
)
|
||||||
|
|
||||||
enable_testing()
|
add_executable(Metrics_unittest ${mdlp_SOURCE_DIR}/src/Metrics.cpp Metrics_unittest.cpp)
|
||||||
|
|
||||||
include_directories(${TORCH_INCLUDE_DIRS})
|
|
||||||
|
|
||||||
add_executable(Metrics_unittest ../Metrics.cpp Metrics_unittest.cpp)
|
|
||||||
target_link_libraries(Metrics_unittest GTest::gtest_main)
|
target_link_libraries(Metrics_unittest GTest::gtest_main)
|
||||||
target_compile_options(Metrics_unittest PRIVATE --coverage)
|
target_compile_options(Metrics_unittest PRIVATE --coverage)
|
||||||
target_link_options(Metrics_unittest PRIVATE --coverage)
|
target_link_options(Metrics_unittest PRIVATE --coverage)
|
||||||
|
|
||||||
add_executable(FImdlp_unittest ../CPPFImdlp.cpp ArffFiles.cpp ../Metrics.cpp FImdlp_unittest.cpp ../Discretizer.cpp)
|
add_executable(FImdlp_unittest FImdlp_unittest.cpp
|
||||||
|
${mdlp_SOURCE_DIR}/src/CPPFImdlp.cpp ${mdlp_SOURCE_DIR}/src/Metrics.cpp ${mdlp_SOURCE_DIR}/src/Discretizer.cpp)
|
||||||
target_link_libraries(FImdlp_unittest GTest::gtest_main "${TORCH_LIBRARIES}")
|
target_link_libraries(FImdlp_unittest GTest::gtest_main "${TORCH_LIBRARIES}")
|
||||||
target_compile_options(FImdlp_unittest PRIVATE --coverage)
|
target_compile_options(FImdlp_unittest PRIVATE --coverage)
|
||||||
target_link_options(FImdlp_unittest PRIVATE --coverage)
|
target_link_options(FImdlp_unittest PRIVATE --coverage)
|
||||||
|
|
||||||
add_executable(BinDisc_unittest ../BinDisc.cpp ArffFiles.cpp BinDisc_unittest.cpp ../Discretizer.cpp)
|
add_executable(BinDisc_unittest BinDisc_unittest.cpp ${mdlp_SOURCE_DIR}/src/BinDisc.cpp ${mdlp_SOURCE_DIR}/src/Discretizer.cpp)
|
||||||
target_link_libraries(BinDisc_unittest GTest::gtest_main "${TORCH_LIBRARIES}")
|
target_link_libraries(BinDisc_unittest GTest::gtest_main "${TORCH_LIBRARIES}")
|
||||||
target_compile_options(BinDisc_unittest PRIVATE --coverage)
|
target_compile_options(BinDisc_unittest PRIVATE --coverage)
|
||||||
target_link_options(BinDisc_unittest PRIVATE --coverage)
|
target_link_options(BinDisc_unittest PRIVATE --coverage)
|
||||||
|
|
||||||
add_executable(Discretizer_unittest ../BinDisc.cpp ../CPPFImdlp.cpp ArffFiles.cpp ../Metrics.cpp ../Discretizer.cpp Discretizer_unittest.cpp)
|
add_executable(Discretizer_unittest Discretizer_unittest.cpp
|
||||||
|
${mdlp_SOURCE_DIR}/src/BinDisc.cpp ${mdlp_SOURCE_DIR}/src/CPPFImdlp.cpp ${mdlp_SOURCE_DIR}/src/Metrics.cpp ${mdlp_SOURCE_DIR}/src/Discretizer.cpp )
|
||||||
target_link_libraries(Discretizer_unittest GTest::gtest_main "${TORCH_LIBRARIES}")
|
target_link_libraries(Discretizer_unittest GTest::gtest_main "${TORCH_LIBRARIES}")
|
||||||
target_compile_options(Discretizer_unittest PRIVATE --coverage)
|
target_compile_options(Discretizer_unittest PRIVATE --coverage)
|
||||||
target_link_options(Discretizer_unittest PRIVATE --coverage)
|
target_link_options(Discretizer_unittest PRIVATE --coverage)
|
||||||
|
@@ -1,11 +1,17 @@
|
|||||||
|
// ****************************************************************
|
||||||
|
// SPDX - FileCopyrightText: Copyright 2024 Ricardo Montañana Gómez
|
||||||
|
// SPDX - FileType: SOURCE
|
||||||
|
// SPDX - License - Identifier: MIT
|
||||||
|
// ****************************************************************
|
||||||
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <ArffFiles.hpp>
|
||||||
#include "gtest/gtest.h"
|
#include "gtest/gtest.h"
|
||||||
#include "ArffFiles.h"
|
#include "Discretizer.h"
|
||||||
#include "../Discretizer.h"
|
#include "BinDisc.h"
|
||||||
#include "../BinDisc.h"
|
#include "CPPFImdlp.h"
|
||||||
#include "../CPPFImdlp.h"
|
|
||||||
|
|
||||||
namespace mdlp {
|
namespace mdlp {
|
||||||
const float margin = 1e-4;
|
const float margin = 1e-4;
|
||||||
@@ -20,7 +26,7 @@ namespace mdlp {
|
|||||||
return "../../tests/datasets/";
|
return "../../tests/datasets/";
|
||||||
}
|
}
|
||||||
const std::string data_path = set_data_path();
|
const std::string data_path = set_data_path();
|
||||||
|
const labels_t iris_quantile = { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 2, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 0, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 3, 3, 3, 1, 3, 1, 2, 0, 3, 1, 0, 2, 2, 2, 1, 3, 1, 2, 2, 1, 2, 2, 2, 2, 3, 3, 3, 3, 2, 1, 1, 1, 2, 2, 1, 2, 3, 2, 1, 1, 1, 2, 2, 0, 1, 1, 1, 2, 1, 1, 2, 2, 3, 2, 3, 3, 0, 3, 3, 3, 3, 3, 3, 1, 2, 3, 3, 3, 3, 2, 3, 1, 3, 2, 3, 3, 2, 2, 3, 3, 3, 3, 3, 2, 2, 3, 2, 3, 2, 3, 3, 3, 2, 3, 3, 3, 2, 3, 2, 2 };
|
||||||
TEST(Discretizer, Version)
|
TEST(Discretizer, Version)
|
||||||
{
|
{
|
||||||
Discretizer* disc = new BinDisc(4, strategy_t::UNIFORM);
|
Discretizer* disc = new BinDisc(4, strategy_t::UNIFORM);
|
||||||
@@ -29,7 +35,6 @@ namespace mdlp {
|
|||||||
std::cout << "Version computed: " << version;
|
std::cout << "Version computed: " << version;
|
||||||
EXPECT_EQ("1.2.3", version);
|
EXPECT_EQ("1.2.3", version);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(Discretizer, BinIrisUniform)
|
TEST(Discretizer, BinIrisUniform)
|
||||||
{
|
{
|
||||||
ArffFiles file;
|
ArffFiles file;
|
||||||
@@ -52,12 +57,198 @@ namespace mdlp {
|
|||||||
auto y = labels_t();
|
auto y = labels_t();
|
||||||
disc->fit(X[0], y);
|
disc->fit(X[0], y);
|
||||||
auto Xt = disc->transform(X[0]);
|
auto Xt = disc->transform(X[0]);
|
||||||
labels_t expected = { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 2, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 0, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 3, 3, 3, 1, 3, 1, 2, 0, 3, 1, 0, 2, 2, 2, 1, 3, 1, 2, 2, 1, 2, 2, 2, 2, 3, 3, 3, 3, 2, 1, 1, 1, 2, 2, 1, 2, 3, 2, 1, 1, 1, 2, 2, 0, 1, 1, 1, 2, 1, 1, 2, 2, 3, 2, 3, 3, 0, 3, 3, 3, 3, 3, 3, 1, 2, 3, 3, 3, 3, 2, 3, 1, 3, 2, 3, 3, 2, 2, 3, 3, 3, 3, 3, 2, 2, 3, 2, 3, 2, 3, 3, 3, 2, 3, 3, 3, 2, 3, 2, 2 };
|
|
||||||
delete disc;
|
delete disc;
|
||||||
EXPECT_EQ(expected, Xt);
|
EXPECT_EQ(iris_quantile, Xt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(Discretizer, BinIrisQuantileTorch)
|
||||||
|
{
|
||||||
|
ArffFiles file;
|
||||||
|
Discretizer* disc = new BinDisc(4, strategy_t::QUANTILE);
|
||||||
|
file.load(data_path + "iris.arff", true);
|
||||||
|
auto X = file.getX();
|
||||||
|
auto y = file.getY();
|
||||||
|
auto X_torch = torch::tensor(X[0], torch::kFloat32);
|
||||||
|
auto yt = torch::tensor(y, torch::kInt32);
|
||||||
|
disc->fit_t(X_torch, yt);
|
||||||
|
torch::Tensor Xt = disc->transform_t(X_torch);
|
||||||
|
delete disc;
|
||||||
|
EXPECT_EQ(iris_quantile.size(), Xt.size(0));
|
||||||
|
for (int i = 0; i < iris_quantile.size(); ++i) {
|
||||||
|
EXPECT_EQ(iris_quantile.at(i), Xt[i].item<int>());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
TEST(Discretizer, BinIrisQuantileTorchFit_transform)
|
||||||
|
{
|
||||||
|
ArffFiles file;
|
||||||
|
Discretizer* disc = new BinDisc(4, strategy_t::QUANTILE);
|
||||||
|
file.load(data_path + "iris.arff", true);
|
||||||
|
auto X = file.getX();
|
||||||
|
auto y = file.getY();
|
||||||
|
auto X_torch = torch::tensor(X[0], torch::kFloat32);
|
||||||
|
auto yt = torch::tensor(y, torch::kInt32);
|
||||||
|
torch::Tensor Xt = disc->fit_transform_t(X_torch, yt);
|
||||||
|
delete disc;
|
||||||
|
EXPECT_EQ(iris_quantile.size(), Xt.size(0));
|
||||||
|
for (int i = 0; i < iris_quantile.size(); ++i) {
|
||||||
|
EXPECT_EQ(iris_quantile.at(i), Xt[i].item<int>());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
TEST(Discretizer, FImdlpIris)
|
TEST(Discretizer, FImdlpIris)
|
||||||
{
|
{
|
||||||
|
auto labelsq = {
|
||||||
|
1,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
1,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
1,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
2,
|
||||||
|
1,
|
||||||
|
1,
|
||||||
|
1,
|
||||||
|
1,
|
||||||
|
1,
|
||||||
|
1,
|
||||||
|
1,
|
||||||
|
0,
|
||||||
|
1,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
1,
|
||||||
|
1,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
1,
|
||||||
|
1,
|
||||||
|
1,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
1,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
1,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
1,
|
||||||
|
0,
|
||||||
|
1,
|
||||||
|
0,
|
||||||
|
1,
|
||||||
|
0,
|
||||||
|
3,
|
||||||
|
3,
|
||||||
|
3,
|
||||||
|
1,
|
||||||
|
3,
|
||||||
|
1,
|
||||||
|
2,
|
||||||
|
0,
|
||||||
|
3,
|
||||||
|
1,
|
||||||
|
0,
|
||||||
|
2,
|
||||||
|
2,
|
||||||
|
2,
|
||||||
|
1,
|
||||||
|
3,
|
||||||
|
1,
|
||||||
|
2,
|
||||||
|
2,
|
||||||
|
1,
|
||||||
|
2,
|
||||||
|
2,
|
||||||
|
2,
|
||||||
|
2,
|
||||||
|
3,
|
||||||
|
3,
|
||||||
|
3,
|
||||||
|
3,
|
||||||
|
2,
|
||||||
|
1,
|
||||||
|
1,
|
||||||
|
1,
|
||||||
|
2,
|
||||||
|
2,
|
||||||
|
1,
|
||||||
|
2,
|
||||||
|
3,
|
||||||
|
2,
|
||||||
|
1,
|
||||||
|
1,
|
||||||
|
1,
|
||||||
|
2,
|
||||||
|
2,
|
||||||
|
0,
|
||||||
|
1,
|
||||||
|
1,
|
||||||
|
1,
|
||||||
|
2,
|
||||||
|
1,
|
||||||
|
1,
|
||||||
|
2,
|
||||||
|
2,
|
||||||
|
3,
|
||||||
|
2,
|
||||||
|
3,
|
||||||
|
3,
|
||||||
|
0,
|
||||||
|
3,
|
||||||
|
3,
|
||||||
|
3,
|
||||||
|
3,
|
||||||
|
3,
|
||||||
|
3,
|
||||||
|
1,
|
||||||
|
2,
|
||||||
|
3,
|
||||||
|
3,
|
||||||
|
3,
|
||||||
|
3,
|
||||||
|
2,
|
||||||
|
3,
|
||||||
|
1,
|
||||||
|
3,
|
||||||
|
2,
|
||||||
|
3,
|
||||||
|
3,
|
||||||
|
2,
|
||||||
|
2,
|
||||||
|
3,
|
||||||
|
3,
|
||||||
|
3,
|
||||||
|
3,
|
||||||
|
3,
|
||||||
|
2,
|
||||||
|
2,
|
||||||
|
3,
|
||||||
|
2,
|
||||||
|
3,
|
||||||
|
2,
|
||||||
|
3,
|
||||||
|
3,
|
||||||
|
3,
|
||||||
|
2,
|
||||||
|
3,
|
||||||
|
3,
|
||||||
|
3,
|
||||||
|
2,
|
||||||
|
3,
|
||||||
|
2,
|
||||||
|
2,
|
||||||
|
};
|
||||||
labels_t expected = {
|
labels_t expected = {
|
||||||
5, 3, 4, 4, 5, 5, 5, 5, 2, 4, 5, 5, 3, 3, 5, 5, 5, 5, 5, 5, 5, 5,
|
5, 3, 4, 4, 5, 5, 5, 5, 2, 4, 5, 5, 3, 3, 5, 5, 5, 5, 5, 5, 5, 5,
|
||||||
5, 4, 5, 3, 5, 5, 5, 4, 4, 5, 5, 5, 4, 4, 5, 4, 3, 5, 5, 0, 4, 5,
|
5, 4, 5, 3, 5, 5, 5, 4, 4, 5, 5, 5, 4, 4, 5, 4, 3, 5, 5, 0, 4, 5,
|
||||||
|
@@ -1,3 +1,9 @@
|
|||||||
|
// ****************************************************************
|
||||||
|
// SPDX - FileCopyrightText: Copyright 2024 Ricardo Montañana Gómez
|
||||||
|
// SPDX - FileType: SOURCE
|
||||||
|
// SPDX - License - Identifier: MIT
|
||||||
|
// ****************************************************************
|
||||||
|
|
||||||
#ifndef EXPERIMENTS_HPP
|
#ifndef EXPERIMENTS_HPP
|
||||||
#define EXPERIMENTS_HPP
|
#define EXPERIMENTS_HPP
|
||||||
#include<sstream>
|
#include<sstream>
|
||||||
@@ -6,14 +12,40 @@
|
|||||||
#include<fstream>
|
#include<fstream>
|
||||||
#include<vector>
|
#include<vector>
|
||||||
#include<tuple>
|
#include<tuple>
|
||||||
#include "../typesFImdlp.h"
|
#include "typesFImdlp.h"
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
void show_vector(const std::vector<T>& data, std::string title)
|
||||||
|
{
|
||||||
|
std::cout << title << ": ";
|
||||||
|
std::string sep = "";
|
||||||
|
for (const auto& d : data) {
|
||||||
|
std::cout << sep << d;
|
||||||
|
sep = ", ";
|
||||||
|
}
|
||||||
|
std::cout << std::endl;
|
||||||
|
}
|
||||||
|
enum class experiment_t {
|
||||||
|
RANGE,
|
||||||
|
VECTOR
|
||||||
|
};
|
||||||
class Experiment {
|
class Experiment {
|
||||||
public:
|
public:
|
||||||
Experiment(float from_, float to_, float step_, int n_bins, std::string strategy, std::vector<int> data_discretized, std::vector<float> cutpoints) :
|
Experiment(float from_, float to_, float step_, int n_bins, std::string strategy, std::vector<int> data_discretized, std::vector<mdlp::precision_t> cutpoints) :
|
||||||
from_{ from_ }, to_{ to_ }, step_{ step_ }, n_bins_{ n_bins }, strategy_{ strategy }, discretized_data_{ data_discretized }, cutpoints_{ cutpoints }
|
from_{ from_ }, to_{ to_ }, step_{ step_ }, n_bins_{ n_bins }, strategy_{ strategy }, discretized_data_{ data_discretized }, cutpoints_{ cutpoints }, type_{ experiment_t::RANGE }
|
||||||
{
|
{
|
||||||
if (strategy != "Q" && strategy != "U") {
|
validate_strategy();
|
||||||
throw std::invalid_argument("Invalid strategy " + strategy);
|
|
||||||
|
}
|
||||||
|
Experiment(std::vector<mdlp::precision_t> dataset, int n_bins, std::string strategy, std::vector<int> data_discretized, std::vector<mdlp::precision_t> cutpoints) :
|
||||||
|
n_bins_{ n_bins }, strategy_{ strategy }, dataset_{ dataset }, discretized_data_{ data_discretized }, cutpoints_{ cutpoints }, type_{ experiment_t::VECTOR }
|
||||||
|
{
|
||||||
|
validate_strategy();
|
||||||
|
}
|
||||||
|
void validate_strategy()
|
||||||
|
{
|
||||||
|
if (strategy_ != "Q" && strategy_ != "U") {
|
||||||
|
throw std::invalid_argument("Invalid strategy " + strategy_);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
float from_;
|
float from_;
|
||||||
@@ -21,8 +53,10 @@ public:
|
|||||||
float step_;
|
float step_;
|
||||||
int n_bins_;
|
int n_bins_;
|
||||||
std::string strategy_;
|
std::string strategy_;
|
||||||
|
std::vector<mdlp::precision_t> dataset_;
|
||||||
std::vector<int> discretized_data_;
|
std::vector<int> discretized_data_;
|
||||||
std::vector<float> cutpoints_;
|
std::vector<mdlp::precision_t> cutpoints_;
|
||||||
|
experiment_t type_;
|
||||||
};
|
};
|
||||||
class Experiments {
|
class Experiments {
|
||||||
public:
|
public:
|
||||||
@@ -76,33 +110,30 @@ private:
|
|||||||
}
|
}
|
||||||
Experiment parse_experiment(std::string& line)
|
Experiment parse_experiment(std::string& line)
|
||||||
{
|
{
|
||||||
|
// Read experiment lines
|
||||||
|
std::string experiment, data, cuts, strategy;
|
||||||
|
std::getline(test_file, experiment);
|
||||||
|
std::getline(test_file, data);
|
||||||
|
std::getline(test_file, cuts);
|
||||||
|
// split data into variables
|
||||||
|
float from_, to_, step_;
|
||||||
|
int n_bins;
|
||||||
|
std::vector<mdlp::precision_t> dataset;
|
||||||
|
auto data_discretized = parse_vector<int>(data);
|
||||||
|
auto cutpoints = parse_vector<mdlp::precision_t>(cuts);
|
||||||
if (line == "RANGE") {
|
if (line == "RANGE") {
|
||||||
std::getline(test_file, line);
|
tie(from_, to_, step_, n_bins, strategy) = parse_header(experiment);
|
||||||
auto [from_, to_, step_, n_bins, strategy] = parse_header(line);
|
return Experiment{ from_, to_, step_, n_bins, strategy, data_discretized, cutpoints };
|
||||||
} else {
|
|
||||||
std::getline(test_file, line);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
std::getline(test_file, line);
|
strategy = experiment.substr(0, 1);
|
||||||
auto data_discretized = parse_vector<int>(line);
|
n_bins = std::stoi(experiment.substr(1, 1));
|
||||||
std::getline(test_file, line);
|
data = experiment.substr(3, experiment.size() - 4);
|
||||||
auto cutpoints = parse_vector<float>(line);
|
dataset = parse_vector<mdlp::precision_t>(data);
|
||||||
return Experiment{ from_, to_, step_, n_bins, strategy, data_discretized, cutpoints };
|
return Experiment(dataset, n_bins, strategy, data_discretized, cutpoints);
|
||||||
}
|
}
|
||||||
std::ifstream test_file;
|
std::ifstream test_file;
|
||||||
std::string filename;
|
std::string filename;
|
||||||
std::string line;
|
std::string line;
|
||||||
bool exp_end;
|
bool exp_end;
|
||||||
};
|
};
|
||||||
template <typename T>
|
|
||||||
void show_vector(const std::vector<T>& data, std::string title)
|
|
||||||
{
|
|
||||||
std::cout << title << ": ";
|
|
||||||
std::string sep = "";
|
|
||||||
for (const auto& d : data) {
|
|
||||||
std::cout << sep << d;
|
|
||||||
sep = ", ";
|
|
||||||
}
|
|
||||||
std::cout << std::endl;
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
@@ -1,9 +1,15 @@
|
|||||||
#include "gtest/gtest.h"
|
// ****************************************************************
|
||||||
#include "../Metrics.h"
|
// SPDX - FileCopyrightText: Copyright 2024 Ricardo Montañana Gómez
|
||||||
#include "../CPPFImdlp.h"
|
// SPDX - FileType: SOURCE
|
||||||
|
// SPDX - License - Identifier: MIT
|
||||||
|
// ****************************************************************
|
||||||
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include "ArffFiles.h"
|
#include <ArffFiles.hpp>
|
||||||
|
#include "gtest/gtest.h"
|
||||||
|
#include "Metrics.h"
|
||||||
|
#include "CPPFImdlp.h"
|
||||||
|
|
||||||
#define EXPECT_THROW_WITH_MESSAGE(stmt, etype, whatstring) EXPECT_THROW( \
|
#define EXPECT_THROW_WITH_MESSAGE(stmt, etype, whatstring) EXPECT_THROW( \
|
||||||
try { \
|
try { \
|
||||||
|
@@ -1,5 +1,11 @@
|
|||||||
|
// ****************************************************************
|
||||||
|
// SPDX - FileCopyrightText: Copyright 2024 Ricardo Montañana Gómez
|
||||||
|
// SPDX - FileType: SOURCE
|
||||||
|
// SPDX - License - Identifier: MIT
|
||||||
|
// ****************************************************************
|
||||||
|
|
||||||
#include "gtest/gtest.h"
|
#include "gtest/gtest.h"
|
||||||
#include "../Metrics.h"
|
#include "Metrics.h"
|
||||||
|
|
||||||
namespace mdlp {
|
namespace mdlp {
|
||||||
class TestMetrics : public Metrics, public testing::Test {
|
class TestMetrics : public Metrics, public testing::Test {
|
||||||
|
@@ -3,6 +3,9 @@
|
|||||||
# discretized data
|
# discretized data
|
||||||
# cut points
|
# cut points
|
||||||
#
|
#
|
||||||
|
#
|
||||||
|
# Range experiments
|
||||||
|
#
|
||||||
RANGE
|
RANGE
|
||||||
0, 100, 1, 4, Q
|
0, 100, 1, 4, Q
|
||||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,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 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2
|
||||||
0.0, 33.0, 66.0, 99.0
|
0.0, 33.0, 66.0, 99.0
|
||||||
RANGE
|
RANGE
|
||||||
0, 50, 1, 3, Q
|
0, 50, 1, 3, Q
|
||||||
@@ -21,7 +24,7 @@ RANGE
|
|||||||
0.0, 16.33333, 32.66667, 49.0
|
0.0, 16.33333, 32.66667, 49.0
|
||||||
RANGE
|
RANGE
|
||||||
0, 10, 1, 3, Q
|
0, 10, 1, 3, Q
|
||||||
0, 0, 0, 0, 1, 1, 1, 2, 2, 2
|
0, 0, 0, 1, 1, 1, 2, 2, 2, 2
|
||||||
0.0, 3.0, 6.0, 9.0
|
0.0, 3.0, 6.0, 9.0
|
||||||
RANGE
|
RANGE
|
||||||
0, 100, 1, 4, U
|
0, 100, 1, 4, U
|
||||||
@@ -53,7 +56,7 @@ RANGE
|
|||||||
1.0, 3.66667, 6.33333, 9.0
|
1.0, 3.66667, 6.33333, 9.0
|
||||||
RANGE
|
RANGE
|
||||||
1, 11, 1, 3, Q
|
1, 11, 1, 3, Q
|
||||||
0, 0, 0, 1, 1, 1, 1, 2, 2, 2
|
0, 0, 0, 1, 1, 1, 2, 2, 2, 2
|
||||||
1.0, 4.0, 7.0, 10.0
|
1.0, 4.0, 7.0, 10.0
|
||||||
RANGE
|
RANGE
|
||||||
1, 11, 1, 3, U
|
1, 11, 1, 3, U
|
||||||
@@ -91,6 +94,9 @@ RANGE
|
|||||||
1, 15, 1, 3, U
|
1, 15, 1, 3, U
|
||||||
0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 2
|
0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 2
|
||||||
1.0, 5.33333, 9.66667, 14.0
|
1.0, 5.33333, 9.66667, 14.0
|
||||||
|
#
|
||||||
|
# Vector experiments
|
||||||
|
#
|
||||||
VECTOR
|
VECTOR
|
||||||
Q3[3.0, 1.0, 1.0, 3.0, 1.0, 1.0, 3.0, 1.0, 1.0]
|
Q3[3.0, 1.0, 1.0, 3.0, 1.0, 1.0, 3.0, 1.0, 1.0]
|
||||||
1, 0, 0, 1, 0, 0, 1, 0, 0
|
1, 0, 0, 1, 0, 0, 1, 0, 0
|
||||||
@@ -141,9 +147,76 @@ U3[15.0, 8.0, 12.0, 14.0, 6.0, 1.0, 13.0, 11.0, 10.0, 9.0, 7.0, 4.0, 3.0, 5.0, 2
|
|||||||
1.0, 5.66667, 10.33333, 15.0
|
1.0, 5.66667, 10.33333, 15.0
|
||||||
VECTOR
|
VECTOR
|
||||||
Q3[0.0, 1.0, 1.0, 1.0, 2.0, 2.0, 3.0, 3.0, 3.0, 4.0]
|
Q3[0.0, 1.0, 1.0, 1.0, 2.0, 2.0, 3.0, 3.0, 3.0, 4.0]
|
||||||
0, 0, 0, 0, 1, 1, 2, 2, 2, 2
|
0, 1, 1, 1, 1, 1, 2, 2, 2, 2
|
||||||
0.0, 1.0, 3.0, 4.0
|
0.0, 1.0, 3.0, 4.0
|
||||||
VECTOR
|
VECTOR
|
||||||
U3[0.0, 1.0, 1.0, 1.0, 2.0, 2.0, 3.0, 3.0, 3.0, 4.0]
|
U3[0.0, 1.0, 1.0, 1.0, 2.0, 2.0, 3.0, 3.0, 3.0, 4.0]
|
||||||
0, 0, 0, 0, 1, 1, 2, 2, 2, 2
|
0, 0, 0, 0, 1, 1, 2, 2, 2, 2
|
||||||
0.0, 1.33333, 2.66667, 4.0
|
0.0, 1.33333, 2.66667, 4.0
|
||||||
|
#
|
||||||
|
# Vector experiments with iris
|
||||||
|
#
|
||||||
|
VECTOR
|
||||||
|
Q3[5.1, 4.9, 4.7, 4.6, 5.0, 5.4, 4.6, 5.0, 4.4, 4.9, 5.4, 4.8, 4.8, 4.3, 5.8, 5.7, 5.4, 5.1, 5.7, 5.1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, 1.8, 1.8, 1.8, 2.1, 1.6, 1.9, 2.0, 2.2, 1.5, 1.4, 2.3, 2.4, 1.8, 1.8, 2.1, 2.4, 2.3, 1.9, 2.3, 2.5, 2.3, 1.9, 2.0, 2.3, 1.8]
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2, 2, 2, 2, 1, 2, 2, 1, 2, 1, 2, 2, 2, 2, 1, 2, 1, 2, 2, 2, 1, 2, 2, 2, 2, 2, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 1, 2, 1, 1, 2, 1, 2, 2, 1, 2, 3, 3, 3, 2, 3, 3, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 2, 3, 3, 2, 3, 3, 3, 2, 3, 2, 2, 2, 3, 2, 3, 3, 3, 2, 2, 3, 3, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2
|
||||||
|
0.1, 0.7, 1.3, 1.9, 2.5
|
||||||
|
32
tests/k.cpp
32
tests/k.cpp
@@ -1,32 +0,0 @@
|
|||||||
#include <iostream>
|
|
||||||
#include <vector>
|
|
||||||
#include <algorithm> // For std::lower_bound
|
|
||||||
|
|
||||||
std::vector<int> searchsorted(const std::vector<float>& cuts, const std::vector<float>& data) {
|
|
||||||
std::vector<int> indices;
|
|
||||||
indices.reserve(data.size());
|
|
||||||
|
|
||||||
for (const float& value : data) {
|
|
||||||
// Find the first position in 'a' where 'value' could be inserted to maintain order
|
|
||||||
auto it = std::lower_bound(cuts.begin(), cuts.end(), value);
|
|
||||||
// Calculate the index
|
|
||||||
int index = it - cuts.begin();
|
|
||||||
indices.push_back(index);
|
|
||||||
}
|
|
||||||
|
|
||||||
return indices;
|
|
||||||
}
|
|
||||||
|
|
||||||
int main() {
|
|
||||||
std::vector<float> cuts = { 10.0 };
|
|
||||||
std::vector<float> data = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0 };
|
|
||||||
|
|
||||||
std::vector<int> result = searchsorted(cuts, data);
|
|
||||||
|
|
||||||
for (int idx : result) {
|
|
||||||
std::cout << idx << " ";
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
1
tests/lib/Files
Submodule
1
tests/lib/Files
Submodule
Submodule tests/lib/Files added at a5316928d4
102
tests/t.cpp
102
tests/t.cpp
@@ -1,102 +0,0 @@
|
|||||||
#include <iostream>
|
|
||||||
#include <algorithm>
|
|
||||||
#include <cmath>
|
|
||||||
#include <vector>
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
typedef float precision_t;
|
|
||||||
|
|
||||||
std::vector<int> transform(const std::vector<float> cutPoints, const std::vector<float>& data)
|
|
||||||
{
|
|
||||||
std::vector<int> discretizedData;
|
|
||||||
discretizedData.reserve(data.size());
|
|
||||||
for (const float& item : data) {
|
|
||||||
auto upper = std::lower_bound(cutPoints.begin(), cutPoints.end(), item);
|
|
||||||
discretizedData.push_back(upper - cutPoints.begin());
|
|
||||||
}
|
|
||||||
return discretizedData;
|
|
||||||
}
|
|
||||||
template <typename T>
|
|
||||||
void show_vector(const std::vector<T>& data, std::string title)
|
|
||||||
{
|
|
||||||
std::cout << title << ": ";
|
|
||||||
std::string sep = "";
|
|
||||||
for (const auto& d : data) {
|
|
||||||
std::cout << sep << d;
|
|
||||||
sep = ", ";
|
|
||||||
}
|
|
||||||
std::cout << std::endl;
|
|
||||||
}
|
|
||||||
std::vector<precision_t> linspace(precision_t start, precision_t end, int num)
|
|
||||||
{
|
|
||||||
if (start == end) {
|
|
||||||
return { start, end };
|
|
||||||
}
|
|
||||||
precision_t delta = (end - start) / static_cast<precision_t>(num - 1);
|
|
||||||
std::vector<precision_t> linspc;
|
|
||||||
for (size_t i = 0; i < num - 1; ++i) {
|
|
||||||
precision_t val = start + delta * static_cast<precision_t>(i);
|
|
||||||
linspc.push_back(val);
|
|
||||||
}
|
|
||||||
return linspc;
|
|
||||||
}
|
|
||||||
size_t clip(const size_t n, size_t lower, size_t upper)
|
|
||||||
{
|
|
||||||
return std::max(lower, std::min(n, upper));
|
|
||||||
}
|
|
||||||
std::vector<precision_t> percentile(std::vector<precision_t>& data, std::vector<precision_t>& percentiles)
|
|
||||||
{
|
|
||||||
// Implementation taken from https://dpilger26.github.io/NumCpp/doxygen/html/percentile_8hpp_source.html
|
|
||||||
std::vector<precision_t> results;
|
|
||||||
results.reserve(percentiles.size());
|
|
||||||
for (auto percentile : percentiles) {
|
|
||||||
const size_t i = static_cast<size_t>(std::floor(static_cast<double>(data.size() - 1) * percentile / 100.));
|
|
||||||
const auto indexLower = clip(i, 0, data.size() - 2);
|
|
||||||
const double percentI = static_cast<double>(indexLower) / static_cast<double>(data.size() - 1);
|
|
||||||
const double fraction =
|
|
||||||
(percentile / 100.0 - percentI) /
|
|
||||||
(static_cast<double>(indexLower + 1) / static_cast<double>(data.size() - 1) - percentI);
|
|
||||||
const auto value = data[indexLower] + (data[indexLower + 1] - data[indexLower]) * fraction;
|
|
||||||
if (value != results.back())
|
|
||||||
results.push_back(value);
|
|
||||||
}
|
|
||||||
return results;
|
|
||||||
}
|
|
||||||
int main()
|
|
||||||
{
|
|
||||||
// std::vector<float> test;
|
|
||||||
// std::vector<float> cuts = { 0, 24.75, 49.5, 74.25, 10000 };
|
|
||||||
// for (int i = 0; i < 100; ++i) {
|
|
||||||
// test.push_back(i);
|
|
||||||
// }
|
|
||||||
// auto Xt = transform(cuts, test);
|
|
||||||
// show_vector(Xt, "Discretized data:");
|
|
||||||
// std::vector<float> test2 = { 0,1,2,3,4,5,6,7,8,9,10,11 };
|
|
||||||
// std::vector<float> cuts2 = { 0,1,2,3,4,5,6,7,8,9 };
|
|
||||||
// auto Xt2 = transform(cuts2, test2);
|
|
||||||
// show_vector(Xt2, "discretized data2: ");
|
|
||||||
auto quantiles = linspace(0.0, 100.0, 3 + 1);
|
|
||||||
std::vector<float> data = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0 };
|
|
||||||
std::vector<float> cutPoints;
|
|
||||||
std::sort(data.begin(), data.end());
|
|
||||||
cutPoints = percentile(data, quantiles);
|
|
||||||
cutPoints.push_back(std::numeric_limits<precision_t>::max());
|
|
||||||
data.push_back(15);
|
|
||||||
data.push_back(0);
|
|
||||||
cutPoints.pop_back();
|
|
||||||
cutPoints.erase(cutPoints.begin());
|
|
||||||
cutPoints.clear();
|
|
||||||
cutPoints.push_back(9.0);
|
|
||||||
auto Xt = transform(cutPoints, data);
|
|
||||||
show_vector(data, "Original data");
|
|
||||||
show_vector(Xt, "Discretized data");
|
|
||||||
show_vector(cutPoints, "Cutpoints");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
n_bins = 3
|
|
||||||
data = [1,2,3,4,5,6,7,8,9,10]
|
|
||||||
quantiles = np.linspace(0, 100, n_bins + 1)
|
|
||||||
bin_edges = np.percentile(data, quantiles)
|
|
||||||
|
|
||||||
*/
|
|
15
tests/test
15
tests/test
@@ -1,15 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
if [ -d build ] && [ "$1" != "run" ]; then
|
|
||||||
rm -fr build
|
|
||||||
fi
|
|
||||||
if [ -d gcovr-report ] ; then
|
|
||||||
rm -fr gcovr-report
|
|
||||||
fi
|
|
||||||
cmake -S . -B build -Wno-dev -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_FLAGS="--coverage" -DCMAKE_C_FLAGS="--coverage"
|
|
||||||
cmake --build build
|
|
||||||
cd build
|
|
||||||
ctest --output-on-failure
|
|
||||||
cd ..
|
|
||||||
mkdir gcovr-report
|
|
||||||
cd ..
|
|
||||||
gcovr --gcov-filter "CPPFImdlp.cpp" --gcov-filter "Metrics.cpp" --gcov-filter "BinDisc.cpp" --gcov-filter "Discretizer.cpp" --txt --sonarqube=tests/gcovr-report/coverage.xml --exclude-noncode-lines
|
|
@@ -1,412 +0,0 @@
|
|||||||
from scipy.io.arff import loadarff
|
|
||||||
from sklearn.preprocessing import KBinsDiscretizer
|
|
||||||
|
|
||||||
|
|
||||||
def test(clf, X, expected, title):
|
|
||||||
X = [[x] for x in X]
|
|
||||||
clf.fit(X)
|
|
||||||
computed = [int(x[0]) for x in clf.transform(X)]
|
|
||||||
print(f"{title}")
|
|
||||||
print(f"{computed=}")
|
|
||||||
print(f"{expected=}")
|
|
||||||
assert computed == expected
|
|
||||||
print("-" * 80)
|
|
||||||
|
|
||||||
|
|
||||||
# Test Uniform Strategy
|
|
||||||
clf3u = KBinsDiscretizer(
|
|
||||||
n_bins=3, encode="ordinal", strategy="uniform", subsample=200_000
|
|
||||||
)
|
|
||||||
clf3q = KBinsDiscretizer(
|
|
||||||
n_bins=3, encode="ordinal", strategy="quantile", subsample=200_000
|
|
||||||
)
|
|
||||||
clf4u = KBinsDiscretizer(
|
|
||||||
n_bins=4, encode="ordinal", strategy="uniform", subsample=200_000
|
|
||||||
)
|
|
||||||
clf4q = KBinsDiscretizer(
|
|
||||||
n_bins=4, encode="ordinal", strategy="quantile", subsample=200_000
|
|
||||||
)
|
|
||||||
#
|
|
||||||
X = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0]
|
|
||||||
labels = [0, 0, 0, 1, 1, 1, 2, 2, 2]
|
|
||||||
test(clf3u, X, labels, title="Easy3BinsUniform")
|
|
||||||
test(clf3q, X, labels, title="Easy3BinsQuantile")
|
|
||||||
#
|
|
||||||
X = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0]
|
|
||||||
labels = [0, 0, 0, 1, 1, 1, 2, 2, 2, 2]
|
|
||||||
# En C++ se obtiene el mismo resultado en ambos, no como aquí
|
|
||||||
labels2 = [0, 0, 0, 1, 1, 1, 1, 2, 2, 2]
|
|
||||||
test(clf3u, X, labels, title="X10BinsUniform")
|
|
||||||
test(clf3q, X, labels2, title="X10BinsQuantile")
|
|
||||||
#
|
|
||||||
X = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0]
|
|
||||||
labels = [0, 0, 0, 0, 1, 1, 1, 2, 2, 2, 2]
|
|
||||||
# En C++ se obtiene el mismo resultado en ambos, no como aquí
|
|
||||||
# labels2 = [0, 0, 0, 1, 1, 1, 1, 2, 2, 2]
|
|
||||||
test(clf3u, X, labels, title="X11BinsUniform")
|
|
||||||
test(clf3q, X, labels, title="X11BinsQuantile")
|
|
||||||
#
|
|
||||||
X = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0]
|
|
||||||
labels = [0, 0, 0, 0, 0, 0]
|
|
||||||
test(clf3u, X, labels, title="ConstantUniform")
|
|
||||||
test(clf3q, X, labels, title="ConstantQuantile")
|
|
||||||
#
|
|
||||||
X = [3.0, 1.0, 1.0, 3.0, 1.0, 1.0, 3.0, 1.0, 1.0]
|
|
||||||
labels = [2, 0, 0, 2, 0, 0, 2, 0, 0]
|
|
||||||
labels2 = [1, 0, 0, 1, 0, 0, 1, 0, 0] # igual que en C++
|
|
||||||
test(clf3u, X, labels, title="EasyRepeatedUniform")
|
|
||||||
test(clf3q, X, labels2, title="EasyRepeatedQuantile")
|
|
||||||
#
|
|
||||||
X = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0]
|
|
||||||
labels = [0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3]
|
|
||||||
test(clf4u, X, labels, title="Easy4BinsUniform")
|
|
||||||
test(clf4q, X, labels, title="Easy4BinsQuantile")
|
|
||||||
#
|
|
||||||
X = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0]
|
|
||||||
labels = [0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3, 3]
|
|
||||||
test(clf4u, X, labels, title="X13BinsUniform")
|
|
||||||
test(clf4q, X, labels, title="X13BinsQuantile")
|
|
||||||
#
|
|
||||||
X = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0]
|
|
||||||
labels = [0, 0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3, 3]
|
|
||||||
test(clf4u, X, labels, title="X14BinsUniform")
|
|
||||||
test(clf4q, X, labels, title="X14BinsQuantile")
|
|
||||||
#
|
|
||||||
X1 = [15.0, 8.0, 12.0, 14.0, 6.0, 1.0, 13.0, 11.0, 10.0, 9.0, 7.0, 4.0, 3.0, 5.0, 2.0]
|
|
||||||
X2 = [15.0, 13.0, 12.0, 14.0, 6.0, 1.0, 8.0, 11.0, 10.0, 9.0, 7.0, 4.0, 3.0, 5.0, 2.0]
|
|
||||||
labels1 = [3, 2, 3, 3, 1, 0, 3, 2, 2, 2, 1, 0, 0, 1, 0]
|
|
||||||
labels2 = [3, 3, 3, 3, 1, 0, 2, 2, 2, 2, 1, 0, 0, 1, 0]
|
|
||||||
test(clf4u, X1, labels1, title="X15BinsUniform")
|
|
||||||
test(clf4q, X2, labels2, title="X15BinsQuantile")
|
|
||||||
#
|
|
||||||
X = [0.0, 1.0, 1.0, 1.0, 2.0, 2.0, 3.0, 3.0, 3.0, 4.0]
|
|
||||||
labels = [0, 1, 1, 1, 2, 2, 3, 3, 3, 3]
|
|
||||||
test(clf4u, X, labels, title="RepeatedValuesUniform")
|
|
||||||
test(clf4q, X, labels, title="RepeatedValuesQuantile")
|
|
||||||
|
|
||||||
print(f"Uniform {clf4u.bin_edges_=}")
|
|
||||||
print(f"Quaintile {clf4q.bin_edges_=}")
|
|
||||||
print("-" * 80)
|
|
||||||
#
|
|
||||||
data, meta = loadarff("tests/datasets/iris.arff")
|
|
||||||
|
|
||||||
labelsu = [
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
1,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
1,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
1,
|
|
||||||
1,
|
|
||||||
1,
|
|
||||||
0,
|
|
||||||
1,
|
|
||||||
0,
|
|
||||||
1,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
1,
|
|
||||||
0,
|
|
||||||
1,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
1,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
1,
|
|
||||||
0,
|
|
||||||
3,
|
|
||||||
2,
|
|
||||||
2,
|
|
||||||
1,
|
|
||||||
2,
|
|
||||||
1,
|
|
||||||
2,
|
|
||||||
0,
|
|
||||||
2,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
1,
|
|
||||||
1,
|
|
||||||
1,
|
|
||||||
1,
|
|
||||||
2,
|
|
||||||
1,
|
|
||||||
1,
|
|
||||||
2,
|
|
||||||
1,
|
|
||||||
1,
|
|
||||||
1,
|
|
||||||
2,
|
|
||||||
1,
|
|
||||||
2,
|
|
||||||
2,
|
|
||||||
2,
|
|
||||||
2,
|
|
||||||
1,
|
|
||||||
1,
|
|
||||||
1,
|
|
||||||
1,
|
|
||||||
1,
|
|
||||||
1,
|
|
||||||
1,
|
|
||||||
1,
|
|
||||||
2,
|
|
||||||
2,
|
|
||||||
1,
|
|
||||||
1,
|
|
||||||
1,
|
|
||||||
1,
|
|
||||||
1,
|
|
||||||
0,
|
|
||||||
1,
|
|
||||||
1,
|
|
||||||
1,
|
|
||||||
2,
|
|
||||||
0,
|
|
||||||
1,
|
|
||||||
2,
|
|
||||||
1,
|
|
||||||
3,
|
|
||||||
2,
|
|
||||||
2,
|
|
||||||
3,
|
|
||||||
0,
|
|
||||||
3,
|
|
||||||
2,
|
|
||||||
3,
|
|
||||||
2,
|
|
||||||
2,
|
|
||||||
2,
|
|
||||||
1,
|
|
||||||
1,
|
|
||||||
2,
|
|
||||||
2,
|
|
||||||
3,
|
|
||||||
3,
|
|
||||||
1,
|
|
||||||
2,
|
|
||||||
1,
|
|
||||||
3,
|
|
||||||
2,
|
|
||||||
2,
|
|
||||||
3,
|
|
||||||
2,
|
|
||||||
1,
|
|
||||||
2,
|
|
||||||
3,
|
|
||||||
3,
|
|
||||||
3,
|
|
||||||
2,
|
|
||||||
2,
|
|
||||||
1,
|
|
||||||
3,
|
|
||||||
2,
|
|
||||||
2,
|
|
||||||
1,
|
|
||||||
2,
|
|
||||||
2,
|
|
||||||
2,
|
|
||||||
1,
|
|
||||||
2,
|
|
||||||
2,
|
|
||||||
2,
|
|
||||||
2,
|
|
||||||
2,
|
|
||||||
2,
|
|
||||||
1,
|
|
||||||
]
|
|
||||||
labelsq = [
|
|
||||||
1,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
1,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
1,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
2,
|
|
||||||
1,
|
|
||||||
1,
|
|
||||||
1,
|
|
||||||
1,
|
|
||||||
1,
|
|
||||||
1,
|
|
||||||
1,
|
|
||||||
0,
|
|
||||||
1,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
1,
|
|
||||||
1,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
1,
|
|
||||||
1,
|
|
||||||
1,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
1,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
1,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
1,
|
|
||||||
0,
|
|
||||||
1,
|
|
||||||
0,
|
|
||||||
1,
|
|
||||||
0,
|
|
||||||
3,
|
|
||||||
3,
|
|
||||||
3,
|
|
||||||
1,
|
|
||||||
3,
|
|
||||||
1,
|
|
||||||
2,
|
|
||||||
0,
|
|
||||||
3,
|
|
||||||
1,
|
|
||||||
0,
|
|
||||||
2,
|
|
||||||
2,
|
|
||||||
2,
|
|
||||||
1,
|
|
||||||
3,
|
|
||||||
1,
|
|
||||||
2,
|
|
||||||
2,
|
|
||||||
1,
|
|
||||||
2,
|
|
||||||
2,
|
|
||||||
2,
|
|
||||||
2,
|
|
||||||
3,
|
|
||||||
3,
|
|
||||||
3,
|
|
||||||
3,
|
|
||||||
2,
|
|
||||||
1,
|
|
||||||
1,
|
|
||||||
1,
|
|
||||||
2,
|
|
||||||
2,
|
|
||||||
1,
|
|
||||||
2,
|
|
||||||
3,
|
|
||||||
2,
|
|
||||||
1,
|
|
||||||
1,
|
|
||||||
1,
|
|
||||||
2,
|
|
||||||
2,
|
|
||||||
0,
|
|
||||||
1,
|
|
||||||
1,
|
|
||||||
1,
|
|
||||||
2,
|
|
||||||
1,
|
|
||||||
1,
|
|
||||||
2,
|
|
||||||
2,
|
|
||||||
3,
|
|
||||||
2,
|
|
||||||
3,
|
|
||||||
3,
|
|
||||||
0,
|
|
||||||
3,
|
|
||||||
3,
|
|
||||||
3,
|
|
||||||
3,
|
|
||||||
3,
|
|
||||||
3,
|
|
||||||
1,
|
|
||||||
2,
|
|
||||||
3,
|
|
||||||
3,
|
|
||||||
3,
|
|
||||||
3,
|
|
||||||
2,
|
|
||||||
3,
|
|
||||||
1,
|
|
||||||
3,
|
|
||||||
2,
|
|
||||||
3,
|
|
||||||
3,
|
|
||||||
2,
|
|
||||||
2,
|
|
||||||
3,
|
|
||||||
3,
|
|
||||||
3,
|
|
||||||
3,
|
|
||||||
3,
|
|
||||||
2,
|
|
||||||
2,
|
|
||||||
3,
|
|
||||||
2,
|
|
||||||
3,
|
|
||||||
2,
|
|
||||||
3,
|
|
||||||
3,
|
|
||||||
3,
|
|
||||||
2,
|
|
||||||
3,
|
|
||||||
3,
|
|
||||||
3,
|
|
||||||
2,
|
|
||||||
3,
|
|
||||||
2,
|
|
||||||
2,
|
|
||||||
]
|
|
||||||
# test(clf4u, data["sepallength"], labelsu, title="IrisUniform")
|
|
||||||
# test(clf4q, data["sepallength"], labelsq, title="IrisQuantile")
|
|
||||||
sepallength = [[x] for x in data["sepallength"]]
|
|
||||||
clf4u.fit(sepallength)
|
|
||||||
clf4q.fit(sepallength)
|
|
||||||
computedu = clf4u.transform(sepallength)
|
|
||||||
computedq = clf4q.transform(sepallength)
|
|
||||||
wrongu = 0
|
|
||||||
wrongq = 0
|
|
||||||
for i in range(len(labelsu)):
|
|
||||||
if labelsu[i] != computedu[i]:
|
|
||||||
wrongu += 1
|
|
||||||
if labelsq[i] != computedq[i]:
|
|
||||||
wrongq += 1
|
|
||||||
print(f"Iris sepallength diff. between BinDisc & sklearn::KBins Uniform ={wrongu:3d}")
|
|
||||||
print(f"Iris sepallength diff. between BinDisc & sklearn::KBins Quantile ={wrongq:3d}")
|
|
@@ -1,3 +1,9 @@
|
|||||||
|
# ***************************************************************
|
||||||
|
# SPDX-FileCopyrightText: Copyright 2024 Ricardo Montañana Gómez
|
||||||
|
# SPDX-FileType: SOURCE
|
||||||
|
# SPDX-License-Identifier: MIT
|
||||||
|
# ***************************************************************
|
||||||
|
|
||||||
import json
|
import json
|
||||||
from sklearn.preprocessing import KBinsDiscretizer
|
from sklearn.preprocessing import KBinsDiscretizer
|
||||||
|
|
||||||
@@ -6,6 +12,7 @@ with open("datasets/tests.txt") as f:
|
|||||||
|
|
||||||
data = [x.strip() for x in data if x[0] != "#"]
|
data = [x.strip() for x in data if x[0] != "#"]
|
||||||
|
|
||||||
|
errors = False
|
||||||
for i in range(0, len(data), 4):
|
for i in range(0, len(data), 4):
|
||||||
experiment_type = data[i]
|
experiment_type = data[i]
|
||||||
print("Experiment:", data[i + 1])
|
print("Experiment:", data[i + 1])
|
||||||
@@ -28,23 +35,37 @@ for i in range(0, len(data), 4):
|
|||||||
expected_data = data[i + 2]
|
expected_data = data[i + 2]
|
||||||
cuts_data = data[i + 3]
|
cuts_data = data[i + 3]
|
||||||
disc.fit(X)
|
disc.fit(X)
|
||||||
|
#
|
||||||
|
# Normalize the cutpoints to remove numerical errors such as 33.0000000001
|
||||||
|
# instead of 33
|
||||||
|
#
|
||||||
|
for j in range(len(disc.bin_edges_[0])):
|
||||||
|
disc.bin_edges_[0][j] = round(disc.bin_edges_[0][j], 5)
|
||||||
result = disc.transform(X)
|
result = disc.transform(X)
|
||||||
result = [int(x) for x in result.flatten()]
|
result = [int(x) for x in result.flatten()]
|
||||||
expected = [int(x) for x in expected_data.split(",")]
|
expected = [int(x) for x in expected_data.split(",")]
|
||||||
|
#
|
||||||
|
# Check the Results
|
||||||
|
#
|
||||||
assert len(result) == len(expected)
|
assert len(result) == len(expected)
|
||||||
for j in range(len(result)):
|
for j in range(len(result)):
|
||||||
if result[j] != expected[j]:
|
if result[j] != expected[j]:
|
||||||
print("Error at", j, "Expected=", expected[j], "Result=", result[j])
|
print("* Error at", j, "Expected=", expected[j], "Result=", result[j])
|
||||||
|
errors = True
|
||||||
expected_cuts = disc.bin_edges_[0]
|
expected_cuts = disc.bin_edges_[0]
|
||||||
computed_cuts = [float(x) for x in cuts_data.split(",")]
|
computed_cuts = [float(x) for x in cuts_data.split(",")]
|
||||||
assert len(expected_cuts) == len(computed_cuts)
|
assert len(expected_cuts) == len(computed_cuts)
|
||||||
for j in range(len(expected_cuts)):
|
for j in range(len(expected_cuts)):
|
||||||
if round(expected_cuts[j], 5) != computed_cuts[j]:
|
if round(expected_cuts[j], 5) != computed_cuts[j]:
|
||||||
print(
|
print(
|
||||||
"Error at",
|
"* Error at",
|
||||||
j,
|
j,
|
||||||
"Expected=",
|
"Expected=",
|
||||||
expected_cuts[j],
|
expected_cuts[j],
|
||||||
"Result=",
|
"Result=",
|
||||||
computed_cuts[j],
|
computed_cuts[j],
|
||||||
)
|
)
|
||||||
|
errors = True
|
||||||
|
if errors:
|
||||||
|
raise Exception("There were errors!")
|
||||||
|
print("*** All tests run succesfully! ***")
|
||||||
|
@@ -6,7 +6,8 @@
|
|||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"from sklearn.preprocessing import KBinsDiscretizer"
|
"from sklearn.preprocessing import KBinsDiscretizer\n",
|
||||||
|
"from sklearn.datasets import load_iris"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -78,21 +79,43 @@
|
|||||||
" sep = \", \"\n",
|
" sep = \", \"\n",
|
||||||
" file.write(\"\\n\")\n",
|
" file.write(\"\\n\")\n",
|
||||||
"\n",
|
"\n",
|
||||||
|
"def normalize_cuts(cuts):\n",
|
||||||
|
" #\n",
|
||||||
|
" # Normalize the cutpoints to remove numerical errors such as 33.0000000001\n",
|
||||||
|
" # instead of 33\n",
|
||||||
|
" #\n",
|
||||||
|
" for k in range(cuts.shape[0]):\n",
|
||||||
|
" for i in range(len(cuts[k])):\n",
|
||||||
|
" cuts[k][i] = round(cuts[k][i], 5)\n",
|
||||||
|
"\n",
|
||||||
"with open(\"datasets/tests.txt\", \"w\") as file:\n",
|
"with open(\"datasets/tests.txt\", \"w\") as file:\n",
|
||||||
" file.write(\"#\\n\")\n",
|
" file.write(\"#\\n\")\n",
|
||||||
" file.write(\"# from, to, step, #bins, Q/U\\n\")\n",
|
" file.write(\"# from, to, step, #bins, Q/U\\n\")\n",
|
||||||
" file.write(\"# discretized data\\n\")\n",
|
" file.write(\"# discretized data\\n\")\n",
|
||||||
" file.write(\"# cut points\\n\")\n",
|
" file.write(\"# cut points\\n\")\n",
|
||||||
" file.write(\"#\\n\")\n",
|
" file.write(\"#\\n\")\n",
|
||||||
|
" #\n",
|
||||||
|
" # Range experiments\n",
|
||||||
|
" #\n",
|
||||||
|
" file.write(\"#\\n\")\n",
|
||||||
|
" file.write(\"# Range experiments\\n\")\n",
|
||||||
|
" file.write(\"#\\n\")\n",
|
||||||
" for experiment in experiments_range:\n",
|
" for experiment in experiments_range:\n",
|
||||||
" file.write(\"RANGE\\n\")\n",
|
" file.write(\"RANGE\\n\")\n",
|
||||||
" (from_, to_, step_, bins_, strategy) = experiment\n",
|
" (from_, to_, step_, bins_, strategy) = experiment\n",
|
||||||
" disc = KBinsDiscretizer(n_bins=bins_, encode='ordinal', strategy='quantile' if strategy.strip() == \"Q\" else 'uniform')\n",
|
" disc = KBinsDiscretizer(n_bins=bins_, encode='ordinal', strategy='quantile' if strategy.strip() == \"Q\" else 'uniform')\n",
|
||||||
" data = [[x] for x in range(from_, to_, step_)]\n",
|
" data = [[x] for x in range(from_, to_, step_)]\n",
|
||||||
" disc.fit(data)\n",
|
" disc.fit(data)\n",
|
||||||
|
" normalize_cuts(disc.bin_edges_)\n",
|
||||||
" result = disc.transform(data)\n",
|
" result = disc.transform(data)\n",
|
||||||
" file.write(f\"{from_}, {to_}, {step_}, {bins_}, {strategy}\\n\")\n",
|
" file.write(f\"{from_}, {to_}, {step_}, {bins_}, {strategy}\\n\")\n",
|
||||||
" write_lists(file, result, disc.bin_edges_[0])\n",
|
" write_lists(file, result, disc.bin_edges_[0])\n",
|
||||||
|
" #\n",
|
||||||
|
" # Vector experiments\n",
|
||||||
|
" #\n",
|
||||||
|
" file.write(\"#\\n\")\n",
|
||||||
|
" file.write(\"# Vector experiments\\n\")\n",
|
||||||
|
" file.write(\"#\\n\")\n",
|
||||||
" for n_bins, experiment in experiments_vectors:\n",
|
" for n_bins, experiment in experiments_vectors:\n",
|
||||||
" for strategy in [\"Q\", \"U\"]:\n",
|
" for strategy in [\"Q\", \"U\"]:\n",
|
||||||
" file.write(\"VECTOR\\n\")\n",
|
" file.write(\"VECTOR\\n\")\n",
|
||||||
@@ -104,8 +127,61 @@
|
|||||||
" strategy=\"quantile\" if strategy.strip() == \"Q\" else \"uniform\",\n",
|
" strategy=\"quantile\" if strategy.strip() == \"Q\" else \"uniform\",\n",
|
||||||
" )\n",
|
" )\n",
|
||||||
" data = [[x] for x in experiment]\n",
|
" data = [[x] for x in experiment]\n",
|
||||||
" result = disc.fit_transform(data)\n",
|
" disc.fit(data)\n",
|
||||||
" write_lists(file, result, disc.bin_edges_[0])"
|
" normalize_cuts(disc.bin_edges_)\n",
|
||||||
|
" result = disc.transform(data)\n",
|
||||||
|
" write_lists(file, result, disc.bin_edges_[0])\n",
|
||||||
|
" #\n",
|
||||||
|
" # Vector experiments iris\n",
|
||||||
|
" #\n",
|
||||||
|
" file.write(\"#\\n\");\n",
|
||||||
|
" file.write(\"# Vector experiments with iris\\n\");\n",
|
||||||
|
" file.write(\"#\\n\");\n",
|
||||||
|
" X, y = load_iris(return_X_y=True)\n",
|
||||||
|
" for i in range(X.shape[1]):\n",
|
||||||
|
" for n_bins in [3, 4]:\n",
|
||||||
|
" for strategy in [\"Q\", \"U\"]:\n",
|
||||||
|
" file.write(\"VECTOR\\n\")\n",
|
||||||
|
" experiment = X[:, i]\n",
|
||||||
|
" file.write(f\"{strategy}{n_bins}{experiment.tolist()}\\n\")\n",
|
||||||
|
" disc = KBinsDiscretizer(\n",
|
||||||
|
" n_bins=n_bins,\n",
|
||||||
|
" encode=\"ordinal\",\n",
|
||||||
|
" strategy=\"quantile\" if strategy.strip() == \"Q\" else \"uniform\")\n",
|
||||||
|
" data = [[x] for x in experiment]\n",
|
||||||
|
" disc.fit(data)\n",
|
||||||
|
" normalize_cuts(disc.bin_edges_)\n",
|
||||||
|
" result = disc.transform(data)\n",
|
||||||
|
" write_lists(file, result, disc.bin_edges_[0])"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 4,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"name": "stdout",
|
||||||
|
"output_type": "stream",
|
||||||
|
"text": [
|
||||||
|
"Cut points: [array([ 0., 33., 66., 99.])]\n",
|
||||||
|
"Mistaken transformed data disc.transform([[33]]) = [[0.]]\n",
|
||||||
|
"Reason of the mistake the cutpoint has decimals (double): 33.00000000000001\n"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"#\n",
|
||||||
|
"# Proving the mistakes due to floating point precision\n",
|
||||||
|
"#\n",
|
||||||
|
"from sklearn.preprocessing import KBinsDiscretizer\n",
|
||||||
|
"\n",
|
||||||
|
"data = [[x] for x in range(100)]\n",
|
||||||
|
"disc = KBinsDiscretizer(n_bins=3, encode=\"ordinal\", strategy=\"quantile\")\n",
|
||||||
|
"disc.fit(data)\n",
|
||||||
|
"print(\"Cut points: \", disc.bin_edges_)\n",
|
||||||
|
"print(\"Mistaken transformed data disc.transform([[33]]) =\", disc.transform([[33]]))\n",
|
||||||
|
"print(\"Reason of the mistake the cutpoint has decimals (double): \", disc.bin_edges_[0][1])"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
@@ -125,7 +201,7 @@
|
|||||||
"name": "python",
|
"name": "python",
|
||||||
"nbconvert_exporter": "python",
|
"nbconvert_exporter": "python",
|
||||||
"pygments_lexer": "ipython3",
|
"pygments_lexer": "ipython3",
|
||||||
"version": "3.11.8"
|
"version": "3.1.undefined"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"nbformat": 4,
|
"nbformat": 4,
|
||||||
|
38
update_coverage.py
Normal file
38
update_coverage.py
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
# ***************************************************************
|
||||||
|
# SPDX-FileCopyrightText: Copyright 2024 Ricardo Montañana Gómez
|
||||||
|
# SPDX-FileType: SOURCE
|
||||||
|
# SPDX-License-Identifier: MIT
|
||||||
|
# ***************************************************************
|
||||||
|
|
||||||
|
import subprocess
|
||||||
|
import sys
|
||||||
|
|
||||||
|
readme_file = "README.md"
|
||||||
|
print("Updating coverage...")
|
||||||
|
# Generate badge line
|
||||||
|
output = subprocess.check_output(
|
||||||
|
"lcov --summary " + sys.argv[1] + "/coverage.info",
|
||||||
|
shell=True,
|
||||||
|
)
|
||||||
|
value = output.decode("utf-8").strip()
|
||||||
|
percentage = 0
|
||||||
|
for line in value.splitlines():
|
||||||
|
if "lines" in line:
|
||||||
|
percentage = float(line.split(":")[1].split("%")[0])
|
||||||
|
break
|
||||||
|
print(f"Coverage: {percentage}%")
|
||||||
|
if percentage < 90:
|
||||||
|
print("⛔Coverage is less than 90%. I won't update the badge.")
|
||||||
|
sys.exit(1)
|
||||||
|
percentage_label = str(percentage).replace(".", ",")
|
||||||
|
coverage_line = f"[](html/index.html)"
|
||||||
|
# Update README.md
|
||||||
|
with open(readme_file, "r") as f:
|
||||||
|
lines = f.readlines()
|
||||||
|
with open(readme_file, "w") as f:
|
||||||
|
for line in lines:
|
||||||
|
if "img.shields.io/badge/Coverage" in line:
|
||||||
|
f.write(coverage_line + "\n")
|
||||||
|
else:
|
||||||
|
f.write(line)
|
||||||
|
print(f"✅Coverage updated with value: {percentage}")
|
Reference in New Issue
Block a user