mirror of
https://github.com/rmontanana/mdlp.git
synced 2025-08-21 10:26:02 +00:00
Compare commits
1 Commits
ac235e92e6
...
37cbe50352
Author | SHA1 | Date | |
---|---|---|---|
|
37cbe50352 |
15
.github/workflows/build.yml
vendored
15
.github/workflows/build.yml
vendored
@@ -13,7 +13,7 @@ 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
|
- uses: actions/checkout@v4.1.6
|
||||||
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
|
||||||
- name: Install sonar-scanner and build-wrapper
|
- name: Install sonar-scanner and build-wrapper
|
||||||
@@ -28,16 +28,17 @@ 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 -DCMAKE_BUILD_TYPE=Debug -DENABLE_TESTING=ON
|
cmake -S . -B build -Wno-dev -DCMAKE_PREFIX_PATH=$(pwd)/libtorch -DENABLE_TESTING=ON
|
||||||
build-wrapper-linux-x86-64 --out-dir ${{ env.BUILD_WRAPPER_OUT_DIR }} cmake --build build/ --config Debug
|
build-wrapper-linux-x86-64 --out-dir ${{ env.BUILD_WRAPPER_OUT_DIR }} cmake --build build/ --config Release
|
||||||
cmake --build build -j 4
|
|
||||||
cd build
|
cd build
|
||||||
ctest -C Debug --output-on-failure -j 4
|
make
|
||||||
gcovr -f ../CPPFImdlp.cpp -f ../Metrics.cpp -f ../BinDisc.cpp -f ../Discretizer.cpp --txt --sonarqube=coverage.xml
|
ctest -C Release --output-on-failure --test-dir tests
|
||||||
|
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.build-wrapper-output="${{ env.BUILD_WRAPPER_OUT_DIR }}" \
|
||||||
--define sonar.coverageReportPaths=build/coverage.xml
|
--define sonar.coverageReportPaths=coverage.xml
|
||||||
|
@@ -1,9 +1,3 @@
|
|||||||
// ****************************************************************
|
|
||||||
// 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"
|
||||||
|
@@ -1,9 +1,3 @@
|
|||||||
// ****************************************************************
|
|
||||||
// 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
|
||||||
|
|
||||||
|
@@ -6,15 +6,6 @@ include_directories(${TORCH_INCLUDE_DIRS})
|
|||||||
add_library(mdlp CPPFImdlp.cpp Metrics.cpp BinDisc.cpp Discretizer.cpp)
|
add_library(mdlp CPPFImdlp.cpp Metrics.cpp BinDisc.cpp Discretizer.cpp)
|
||||||
target_link_libraries(mdlp "${TORCH_LIBRARIES}")
|
target_link_libraries(mdlp "${TORCH_LIBRARIES}")
|
||||||
add_subdirectory(sample)
|
add_subdirectory(sample)
|
||||||
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fno-elide-constructors")
|
|
||||||
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3")
|
|
||||||
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)
|
||||||
endif(ENABLE_TESTING)
|
endif(ENABLE_TESTING)
|
@@ -1,9 +1,3 @@
|
|||||||
// ****************************************************************
|
|
||||||
// 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>
|
||||||
|
@@ -1,9 +1,3 @@
|
|||||||
// ****************************************************************
|
|
||||||
// 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,9 +1,3 @@
|
|||||||
// ****************************************************************
|
|
||||||
// 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 {
|
||||||
@@ -20,6 +14,11 @@ namespace mdlp {
|
|||||||
for (const precision_t& item : data) {
|
for (const precision_t& item : data) {
|
||||||
auto pos = bound(first, last, item);
|
auto pos = bound(first, last, item);
|
||||||
int number = pos - first;
|
int number = pos - first;
|
||||||
|
/*
|
||||||
|
OJO
|
||||||
|
*/
|
||||||
|
if (number < 0)
|
||||||
|
throw std::runtime_error("number is less than 0 in discretizer::transform");
|
||||||
discretizedData.push_back(number);
|
discretizedData.push_back(number);
|
||||||
}
|
}
|
||||||
return discretizedData;
|
return discretizedData;
|
||||||
|
@@ -1,9 +1,3 @@
|
|||||||
// ****************************************************************
|
|
||||||
// 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
|
||||||
|
|
||||||
@@ -30,6 +24,7 @@ namespace mdlp {
|
|||||||
torch::Tensor fit_transform_t(torch::Tensor& X_, torch::Tensor& y_);
|
torch::Tensor fit_transform_t(torch::Tensor& X_, torch::Tensor& y_);
|
||||||
static inline std::string version() { return "1.2.3"; };
|
static inline std::string version() { return "1.2.3"; };
|
||||||
protected:
|
protected:
|
||||||
|
void normalize_cutpoints();
|
||||||
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
|
bound_dir_t direction; // used in transform
|
||||||
|
25
Makefile
25
Makefile
@@ -1,32 +1,13 @@
|
|||||||
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 -j 8
|
@cmake --build build_release
|
||||||
|
|
||||||
test:
|
test:
|
||||||
@if [ -d build_debug ]; then rm -fr build_debug; fi
|
@echo "Testing..."
|
||||||
@mkdir build_debug
|
@cd tests && ./test
|
||||||
@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
|
|
||||||
|
@@ -1,9 +1,3 @@
|
|||||||
// ****************************************************************
|
|
||||||
// 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,9 +1,3 @@
|
|||||||
// ****************************************************************
|
|
||||||
// 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
|
||||||
|
|
||||||
|
10
README.md
10
README.md
@@ -1,7 +1,6 @@
|
|||||||
[](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
|
||||||
|
|
||||||
@@ -32,14 +31,15 @@ Other features:
|
|||||||
To run the sample, just execute the following commands:
|
To run the sample, just execute the following commands:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
make build
|
cmake -B build -S .
|
||||||
build_release/sample/sample -f iris -m 2
|
cmake --build build
|
||||||
build_release/sample/sample -h
|
build/sample/sample -f iris -m 2
|
||||||
|
build/sample/sample -h
|
||||||
```
|
```
|
||||||
|
|
||||||
## Test
|
## Test
|
||||||
|
|
||||||
To run the tests and see coverage (llvm with lcov and genhtml have to be installed), execute the following commands:
|
To run the tests and see coverage (llvm & gcovr have to be installed), execute the following commands:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
make test
|
make test
|
||||||
|
@@ -1,9 +1,3 @@
|
|||||||
// ****************************************************************
|
|
||||||
// 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>
|
||||||
|
@@ -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=2.0.0
|
sonar.projectVersion=1.2.1
|
||||||
# sonar.test.exclusions=tests/**
|
# sonar.test.exclusions=tests/**
|
||||||
# sonar.tests=tests/
|
# sonar.tests=tests/
|
||||||
# sonar.coverage.exclusions=tests/**,sample/**
|
# sonar.coverage.exclusions=tests/**,sample/**
|
||||||
@@ -12,4 +12,3 @@ sonar.projectVersion=2.0.0
|
|||||||
|
|
||||||
# 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
|
||||||
sonar.cfamily.compile-commands
|
|
@@ -1,9 +1,3 @@
|
|||||||
// ****************************************************************
|
|
||||||
// SPDX - FileCopyrightText: Copyright 2024 Ricardo Montañana Gómez
|
|
||||||
// SPDX - FileType: SOURCE
|
|
||||||
// SPDX - License - Identifier: MIT
|
|
||||||
// ****************************************************************
|
|
||||||
|
|
||||||
#include "ArffFiles.h"
|
#include "ArffFiles.h"
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
@@ -1,9 +1,3 @@
|
|||||||
// ****************************************************************
|
|
||||||
// SPDX - FileCopyrightText: Copyright 2024 Ricardo Montañana Gómez
|
|
||||||
// SPDX - FileType: SOURCE
|
|
||||||
// SPDX - License - Identifier: MIT
|
|
||||||
// ****************************************************************
|
|
||||||
|
|
||||||
#ifndef ARFFFILES_H
|
#ifndef ARFFFILES_H
|
||||||
#define ARFFFILES_H
|
#define ARFFFILES_H
|
||||||
|
|
||||||
|
@@ -1,9 +1,3 @@
|
|||||||
// ****************************************************************
|
|
||||||
// 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>
|
||||||
|
@@ -1,9 +1,3 @@
|
|||||||
// ****************************************************************
|
|
||||||
// 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>
|
||||||
@@ -26,7 +20,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);
|
||||||
@@ -57,42 +51,9 @@ 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(iris_quantile, Xt);
|
EXPECT_EQ(expected, 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)
|
||||||
|
@@ -1,9 +1,3 @@
|
|||||||
// ****************************************************************
|
|
||||||
// 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>
|
||||||
|
@@ -1,9 +1,3 @@
|
|||||||
// ****************************************************************
|
|
||||||
// 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"
|
||||||
#include "../CPPFImdlp.h"
|
#include "../CPPFImdlp.h"
|
||||||
|
@@ -1,9 +1,3 @@
|
|||||||
// ****************************************************************
|
|
||||||
// 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"
|
||||||
|
|
||||||
|
1
tests/Testing/Temporary/CTestCostData.txt
Normal file
1
tests/Testing/Temporary/CTestCostData.txt
Normal file
@@ -0,0 +1 @@
|
|||||||
|
---
|
3
tests/Testing/Temporary/LastTest.log
Normal file
3
tests/Testing/Temporary/LastTest.log
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
Start testing: Jul 03 18:09 CEST
|
||||||
|
----------------------------------------------------------
|
||||||
|
End testing: Jul 03 18:09 CEST
|
15
tests/test
Executable file
15
tests/test
Executable file
@@ -0,0 +1,15 @@
|
|||||||
|
#!/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 -j 8
|
||||||
|
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,9 +1,3 @@
|
|||||||
# ***************************************************************
|
|
||||||
# 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
|
||||||
|
|
||||||
|
@@ -1,38 +0,0 @@
|
|||||||
# ***************************************************************
|
|
||||||
# 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