-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement python bindings with basic example
- Loading branch information
Showing
9 changed files
with
147 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import desbordante | ||
import pandas as pd | ||
|
||
ERROR = 0.3 | ||
PER_TUPLE = 'per_tuple' | ||
PER_VALUE = 'per_value' | ||
TABLE = 'examples/datasets/glitchy_sensor_2.csv' | ||
|
||
|
||
def print_results(verifier): | ||
error = verifier.get_error() | ||
if error <= ERROR: | ||
print('PFD holds') | ||
else: | ||
print(f'PFD with error {ERROR} does not hold') | ||
print(f'But it holds with error {error}') | ||
print() | ||
print('Additional info:') | ||
print(f'Number of rows violating PFD: {verifier.get_num_violating_rows()}') | ||
print(f'Number of clusters violating PFD: {verifier.get_num_violating_clusters()}') | ||
print() | ||
|
||
table = pd.read_csv(TABLE) | ||
violating_clusters = verifier.get_violating_clusters() | ||
number_names = ['First', 'Second', 'Third'] | ||
cluster_number = 0 | ||
for violating_cluster in violating_clusters: | ||
print(f'{number_names[cluster_number]} violating cluster:') | ||
cluster_number += 1 | ||
violating_series = [] | ||
for i, row in table.iterrows(): | ||
if i not in violating_cluster: | ||
continue | ||
violating_series.append(row) | ||
print(pd.DataFrame(violating_series)) | ||
print() | ||
|
||
# Loading input data | ||
algo = desbordante.pfd_verification.algorithms.Default() | ||
algo.load_data(table=(TABLE, ',', True)) | ||
|
||
# Print dataset | ||
print(f'Dataset: {TABLE}') | ||
print(pd.read_csv(TABLE)) | ||
print() | ||
|
||
# Checking whether PFD (DeviceId) -> (Data) holds for PerValue measure | ||
algo.execute(lhs_indices=[1], rhs_indices=[2], error=ERROR, pfd_error_measure=PER_VALUE) | ||
print('-' * 80) | ||
print(f'Checking whether PFD (DeviceId) -> (Data) holds for {PER_VALUE} error measure') | ||
print('-' * 80) | ||
print_results(algo) | ||
|
||
# Checking whether the same PFD holds for PerTuple measure | ||
algo.execute(lhs_indices=[1], rhs_indices=[2], error=ERROR, pfd_error_measure=PER_TUPLE) | ||
print('-' * 80) | ||
print(f'Checking whether the same PFD holds for {PER_TUPLE} error measure:') | ||
print('-' * 80) | ||
print_results(algo) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
Id,DeviceId,Data | ||
1,D-1,1001 | ||
2,D-1,1002 | ||
3,D-1,1003 | ||
4,D-1,1004 | ||
5,D-1,1005 | ||
6,D-1,1006 | ||
7,D-2,1000 | ||
8,D-2,1001 | ||
9,D-2,1000 | ||
10,D-3,1010 | ||
11,D-4,1011 | ||
12,D-4,1011 | ||
13,D-5,1015 | ||
14,D-5,1014 | ||
15,D-5,1015 | ||
16,D-5,1015 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#include "bind_pfd_verification.h" | ||
|
||
#include <pybind11/pybind11.h> | ||
#include <pybind11/stl.h> | ||
|
||
#include "algorithms/fd/pfd_verifier/pfd_verifier.h" | ||
#include "py_util/bind_primitive.h" | ||
|
||
namespace { | ||
namespace py = pybind11; | ||
} // namespace | ||
|
||
namespace python_bindings { | ||
void BindPfdVerification(py::module_& main_module) { | ||
using namespace algos; | ||
auto pfd_verification_module = main_module.def_submodule("pfd_verification"); | ||
|
||
BindPrimitiveNoBase<PFDVerifier>(pfd_verification_module, "PFDVerifier") | ||
.def("get_num_violating_clusters", &PFDVerifier::GetNumViolatingClusters) | ||
.def("get_num_violating_rows", &PFDVerifier::GetNumViolatingRows) | ||
.def("get_violating_clusters", &PFDVerifier::GetViolatingClusters) | ||
.def("get_error", &PFDVerifier::GetError); | ||
main_module.attr("pfd_verification") = pfd_verification_module; | ||
} | ||
} // namespace python_bindings |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#pragma once | ||
|
||
#include <pybind11/pybind11.h> | ||
|
||
namespace python_bindings { | ||
void BindPfdVerification(pybind11::module_& main_module); | ||
} // namespace python_bindings |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters