diff --git a/src/main.cpp b/src/main.cpp index b922322d..0402f56f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,17 +1,18 @@ -#include -#include -#include #include #include +#include +#include +#include #include +#include "aijack/collaborative/tree/secureboost/secureboost.h" +#include "aijack/collaborative/tree/xgboost/node.h" +#include "aijack/collaborative/tree/xgboost/xgboost.h" #include "aijack/defense/dp/core//rdp.cpp" #include "aijack/defense/dp/core//search.cpp" #include "aijack/defense/kanonymity/core/anonymizer.h" -#include "aijack/defense/paillier/src/paillier.h" #include "aijack/defense/paillier/src/keygenerator.h" -#include "aijack/collaborative/tree/xgboost/xgboost.h" -#include "aijack/collaborative/tree/secureboost/secureboost.h" +#include "aijack/defense/paillier/src/paillier.h" #define STRINGIFY(x) #x #define MACRO_STRINGIFY(x) STRINGIFY(x) @@ -22,150 +23,147 @@ namespace py = pybind11; template using overload_cast_ = pybind11::detail::overload_cast_impl; -PYBIND11_MODULE(aijack_cpp_core, m) -{ - m.doc() = R"pbdoc( +PYBIND11_MODULE(aijack_cpp_core, m) { + m.doc() = R"pbdoc( c++ backend for aijack )pbdoc"; - m.def("eps_gaussian", - &eps_gaussian, R"pbdoc(eps_gaussian)pbdoc"); - - m.def("eps_laplace", - &eps_laplace, R"pbdoc(eps_laplace)pbdoc"); - - m.def("eps_randresp", - &eps_randresp, R"pbdoc(eps_randresp)pbdoc"); - - m.def("culc_tightupperbound_lowerbound_of_rdp_with_theorem6and8_of_zhu_2019", - &culc_tightupperbound_lowerbound_of_rdp_with_theorem6and8_of_zhu_2019, - R"pbdoc(culc_tightupperbound_lowerbound_of_rdp_with_theorem6and8_of_zhu_2019)pbdoc"); - - m.def("culc_upperbound_of_rdp_with_Sampled_Gaussian_Mechanism", - &culc_upperbound_of_rdp_with_Sampled_Gaussian_Mechanism, - R"pbdoc(culc_upperbound_of_rdp_with_Sampled_Gaussian_Mechanism)pbdoc"); - - m.def("_ternary_search", - &_ternary_search, R"pbdoc(_ternary_search)pbdoc"); - - m.def("_ternary_search_int", - &_ternary_search_int, R"pbdoc(_ternary_search_int)pbdoc"); - - m.def("_greedy_search", - &_greedy_search, R"pbdoc(_greedy_search)pbdoc"); - - m.def("_greedy_search_frac", - &_greedy_search_frac, R"pbdoc(_greey_search_frac)pbdoc"); - - py::class_(m, "PaillierKeyGenerator") - .def(py::init()) - .def("generate_keypair", &PaillierKeyGenerator::generate_keypair); - - py::class_(m, "PaillierPublicKey") - .def("encrypt", &PaillierPublicKey::encrypt) - .def("encrypt", &PaillierPublicKey::encrypt) - .def("encrypt", &PaillierPublicKey::encrypt) - .def("encrypt", &PaillierPublicKey::encrypt) - .def("get_publickeyvalues", &PaillierPublicKey::get_publickeyvalues); - - py::class_(m, "PaillierCipherText") - .def("__add__", overload_cast_()(&PaillierCipherText::operator+)) - .def("__add__", overload_cast_()(&PaillierCipherText::operator+)) - .def("__add__", overload_cast_()(&PaillierCipherText::operator+)) - .def("__add__", overload_cast_()(&PaillierCipherText::operator+)) - .def("__add__", overload_cast_()(&PaillierCipherText::operator+)) - .def("__mul__", overload_cast_()(&PaillierCipherText::operator*)) - .def("__mul__", overload_cast_()(&PaillierCipherText::operator*)) - .def("__mul__", overload_cast_()(&PaillierCipherText::operator*)) - .def("__mul__", overload_cast_()(&PaillierCipherText::operator*)) - .def("get_value", &PaillierCipherText::get_value); - - py::class_(m, "PaillierSecretKey") - .def("decrypt2int", &PaillierSecretKey::decrypt2int) - .def("decrypt2long", &PaillierSecretKey::decrypt2long) - .def("decrypt2float", &PaillierSecretKey::decrypt2float) - .def("decrypt2double", &PaillierSecretKey::decrypt2double) - .def("get_publickeyvalues", &PaillierSecretKey::get_publickeyvalues) - .def("get_secretkeyvalues", &PaillierSecretKey::get_secretkeyvalues); - - py::class_(m, "XGBoostParty") - .def(py::init>, int, vector, int, - int, float, int, bool, int>()) - .def("get_lookup_table", &XGBoostParty::get_lookup_table); - - py::class_(m, "SecureBoostParty") - .def(py::init>, int, vector, int, - int, float, int, bool, int>()) - .def("get_lookup_table", &SecureBoostParty::get_lookup_table) - .def("set_publickey", &SecureBoostParty::set_publickey) - .def("set_secretkey", &SecureBoostParty::set_secretkey); - - py::class_(m, "XGBoostNode") - .def("get_idxs", &XGBoostNode::get_idxs) - .def("get_party_id", &XGBoostNode::get_party_id) - .def("get_record_id", &XGBoostNode::get_record_id) - .def("get_val", &XGBoostNode::get_val) - .def("get_score", &XGBoostNode::get_score) - .def("get_left", &XGBoostNode::get_left) - .def("get_right", &XGBoostNode::get_right) - .def("is_leaf", &XGBoostNode::is_leaf); - - py::class_(m, "SecureBoostNode") - .def("get_idxs", &SecureBoostNode::get_idxs) - .def("get_party_id", &SecureBoostNode::get_party_id) - .def("get_record_id", &SecureBoostNode::get_record_id) - .def("get_val", &SecureBoostNode::get_val) - .def("get_score", &SecureBoostNode::get_score) - .def("get_left", &SecureBoostNode::get_left) - .def("get_right", &SecureBoostNode::get_right) - .def("is_leaf", &SecureBoostNode::is_leaf); - - py::class_(m, "XGBoostTree") - .def("get_root_xgboost_node", &XGBoostTree::get_root_xgboost_node) - .def("print", &XGBoostTree::print) - .def("predict", &XGBoostTree::predict); - - py::class_(m, "SecureBoostTree") - .def("print", &SecureBoostTree::print) - .def("predict", &SecureBoostTree::predict); - - py::class_(m, "XGBoostClassifier") - .def(py::init()) - .def("fit", &XGBoostClassifier::fit) - .def("get_init_pred", &XGBoostClassifier::get_init_pred) - .def("load_estimators", &XGBoostClassifier::load_estimators) - .def("get_estimators", &XGBoostClassifier::get_estimators) - .def("predict_raw", &XGBoostClassifier::predict_raw) - .def("predict_proba", &XGBoostClassifier::predict_proba); - - py::class_(m, "SecureBoostClassifier") - .def(py::init()) - .def("fit", &SecureBoostClassifier::fit) - .def("get_init_pred", &SecureBoostClassifier::get_init_pred) - .def("load_estimators", &SecureBoostClassifier::load_estimators) - .def("get_estimators", &SecureBoostClassifier::get_estimators) - .def("predict_raw", &SecureBoostClassifier::predict_raw) - .def("predict_proba", &SecureBoostClassifier::predict_proba); - - py::class_(m, "DataFrame") - .def(py::init, map, int>()) - .def("insert_continuous", &DataFrame::insert_continuous) - .def("insert_categorical", &DataFrame::insert_categorical) - .def("insert_continuous_column", &DataFrame::insert_continuous_column) - .def("insert_categorical_column", &DataFrame::insert_categorical_column) - .def("get_data_continuous", &DataFrame::get_data_continuous) - .def("get_data_categorical", &DataFrame::get_data_categorical); - - py::class_(m, "Mondrian") - .def(py::init()) - .def("get_final_partitions", &Mondrian::get_final_partitions) - .def("anonymize", &Mondrian::anonymize); + m.def("eps_gaussian", &eps_gaussian, R"pbdoc(eps_gaussian)pbdoc"); + + m.def("eps_laplace", &eps_laplace, R"pbdoc(eps_laplace)pbdoc"); + + m.def("eps_randresp", &eps_randresp, R"pbdoc(eps_randresp)pbdoc"); + + m.def( + "culc_tightupperbound_lowerbound_of_rdp_with_theorem6and8_of_zhu_2019", + &culc_tightupperbound_lowerbound_of_rdp_with_theorem6and8_of_zhu_2019, + R"pbdoc(culc_tightupperbound_lowerbound_of_rdp_with_theorem6and8_of_zhu_2019)pbdoc"); + + m.def("culc_upperbound_of_rdp_with_Sampled_Gaussian_Mechanism", + &culc_upperbound_of_rdp_with_Sampled_Gaussian_Mechanism, + R"pbdoc(culc_upperbound_of_rdp_with_Sampled_Gaussian_Mechanism)pbdoc"); + + m.def("_ternary_search", &_ternary_search, R"pbdoc(_ternary_search)pbdoc"); + + m.def("_ternary_search_int", &_ternary_search_int, + R"pbdoc(_ternary_search_int)pbdoc"); + + m.def("_greedy_search", &_greedy_search, R"pbdoc(_greedy_search)pbdoc"); + + m.def("_greedy_search_frac", &_greedy_search_frac, + R"pbdoc(_greey_search_frac)pbdoc"); + + py::class_(m, "PaillierKeyGenerator") + .def(py::init()) + .def("generate_keypair", &PaillierKeyGenerator::generate_keypair); + + py::class_(m, "PaillierPublicKey") + .def("encrypt", &PaillierPublicKey::encrypt) + .def("encrypt", &PaillierPublicKey::encrypt) + .def("encrypt", &PaillierPublicKey::encrypt) + .def("encrypt", &PaillierPublicKey::encrypt) + .def("get_publickeyvalues", &PaillierPublicKey::get_publickeyvalues); + + py::class_(m, "PaillierCipherText") + .def("__add__", overload_cast_()(&PaillierCipherText::operator+)) + .def("__add__", overload_cast_()(&PaillierCipherText::operator+)) + .def("__add__", overload_cast_()(&PaillierCipherText::operator+)) + .def("__add__", overload_cast_()(&PaillierCipherText::operator+)) + .def("__add__", + overload_cast_()(&PaillierCipherText::operator+)) + .def("__mul__", overload_cast_()(&PaillierCipherText::operator*)) + .def("__mul__", overload_cast_()(&PaillierCipherText::operator*)) + .def("__mul__", overload_cast_()(&PaillierCipherText::operator*)) + .def("__mul__", overload_cast_()(&PaillierCipherText::operator*)) + .def("get_value", &PaillierCipherText::get_value); + + py::class_(m, "PaillierSecretKey") + .def("decrypt2int", &PaillierSecretKey::decrypt2int) + .def("decrypt2long", &PaillierSecretKey::decrypt2long) + .def("decrypt2float", &PaillierSecretKey::decrypt2float) + .def("decrypt2double", &PaillierSecretKey::decrypt2double) + .def("get_publickeyvalues", &PaillierSecretKey::get_publickeyvalues) + .def("get_secretkeyvalues", &PaillierSecretKey::get_secretkeyvalues); + + py::class_(m, "XGBoostParty") + .def(py::init>, int, vector, int, int, float, + int, bool, int>()) + .def("get_lookup_table", &XGBoostParty::get_lookup_table); + + py::class_(m, "SecureBoostParty") + .def(py::init>, int, vector, int, int, float, + int, bool, int>()) + .def("get_lookup_table", &SecureBoostParty::get_lookup_table) + .def("set_publickey", &SecureBoostParty::set_publickey) + .def("set_secretkey", &SecureBoostParty::set_secretkey); + + py::class_(m, "XGBoostNode") + .def("get_idxs", &XGBoostNode::get_idxs) + .def("get_party_id", &XGBoostNode::get_party_id) + .def("get_record_id", &XGBoostNode::get_record_id) + .def("get_num_parties", &XGBoostNode::get_num_parties) + .def("get_val", &XGBoostNode::get_val) + .def("get_score", &XGBoostNode::get_score) + .def("get_left", &XGBoostNode::get_left) + .def("get_right", &XGBoostNode::get_right) + .def("is_leaf", &XGBoostNode::is_leaf); + + py::class_(m, "SecureBoostNode") + .def("get_idxs", &SecureBoostNode::get_idxs) + .def("get_party_id", &SecureBoostNode::get_party_id) + .def("get_record_id", &SecureBoostNode::get_record_id) + .def("get_val", &SecureBoostNode::get_val) + .def("get_score", &SecureBoostNode::get_score) + .def("get_left", &SecureBoostNode::get_left) + .def("get_right", &SecureBoostNode::get_right) + .def("is_leaf", &SecureBoostNode::is_leaf); + + py::class_(m, "XGBoostTree") + .def("get_root_xgboost_node", &XGBoostTree::get_root_xgboost_node) + .def("print", &XGBoostTree::print) + .def("predict", &XGBoostTree::predict); + + py::class_(m, "SecureBoostTree") + .def("print", &SecureBoostTree::print) + .def("predict", &SecureBoostTree::predict); + + py::class_(m, "XGBoostClassifier") + .def(py::init()) + .def("fit", &XGBoostClassifier::fit) + .def("get_init_pred", &XGBoostClassifier::get_init_pred) + .def("load_estimators", &XGBoostClassifier::load_estimators) + .def("get_estimators", &XGBoostClassifier::get_estimators) + .def("predict_raw", &XGBoostClassifier::predict_raw) + .def("predict_proba", &XGBoostClassifier::predict_proba); + + py::class_(m, "SecureBoostClassifier") + .def(py::init()) + .def("fit", &SecureBoostClassifier::fit) + .def("get_init_pred", &SecureBoostClassifier::get_init_pred) + .def("load_estimators", &SecureBoostClassifier::load_estimators) + .def("get_estimators", &SecureBoostClassifier::get_estimators) + .def("predict_raw", &SecureBoostClassifier::predict_raw) + .def("predict_proba", &SecureBoostClassifier::predict_proba); + + py::class_(m, "DataFrame") + .def(py::init, map, int>()) + .def("insert_continuous", &DataFrame::insert_continuous) + .def("insert_categorical", &DataFrame::insert_categorical) + .def("insert_continuous_column", &DataFrame::insert_continuous_column) + .def("insert_categorical_column", &DataFrame::insert_categorical_column) + .def("get_data_continuous", &DataFrame::get_data_continuous) + .def("get_data_categorical", &DataFrame::get_data_categorical); + + py::class_(m, "Mondrian") + .def(py::init()) + .def("get_final_partitions", &Mondrian::get_final_partitions) + .def("anonymize", &Mondrian::anonymize); #ifdef VERSION_INFO - m.attr("__version__") = MACRO_STRINGIFY(VERSION_INFO); + m.attr("__version__") = MACRO_STRINGIFY(VERSION_INFO); #else - m.attr("__version__") = "dev"; + m.attr("__version__") = "dev"; #endif }