jacobian

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

commit 52c389b017298f07a363362afd73ecf54be816af
parent 3902178663cfd0c5de3727adad3a417370099217
Author: David Freifeld <freifeld.david@gmail.com>
Date:   Sat, 27 Mar 2021 23:46:04 -0700

Futher progress with Python binds

Diffstat:
Msrc/bpnn.hpp | 6++----
Msrc/pybind.cpp | 60++++++++++++++++++++++++++++++++++++------------------------
2 files changed, 38 insertions(+), 28 deletions(-)

diff --git a/src/bpnn.hpp b/src/bpnn.hpp @@ -53,6 +53,7 @@ protected: std::function<void(void)> decay; std::function<void(std::vector<Eigen::MatrixXf>, int, int)> grad_calc; std::function<void(std::vector<Eigen::MatrixXf>, int)> update; + void next_batch(int fd); public: int data; int val_data; @@ -77,8 +78,6 @@ public: float l, float ratio, bool early_exit=true, float cutoff=0); ~Network(); void add_layer(int nodes, const char* name, std::function<float(float)> activation, std::function<float(float)> activation_deriv); - void init_decay(const char* type, ...); - void init_optimizer(const char* name, ...); void initialize(); void set_activation(int index, std::function<float(float)> custom, std::function<float(float)> custom_deriv); void feedforward(); @@ -86,8 +85,7 @@ public: void list_net(); float cost(); float accuracy(); - Eigen::MatrixXf backpropagate(); - void next_batch(int fd); + Eigen::MatrixXf backpropagate(); void validate(const char* path); void train(); float get_acc() {return epoch_acc;} diff --git a/src/pybind.cpp b/src/pybind.cpp @@ -8,30 +8,42 @@ #include <pybind11/pybind11.h> #include <pybind11/functional.h> #include "bpnn.hpp" +#include "utils.hpp" namespace py = pybind11; -PYBIND11_MODULE(_jacobian, m) { - m.doc() = "Fast machine learning in C++"; // optional module docstring - py::enum_<Regularization>(m, "Regularization") - .value("L1", Regularization::L1) - .value("L2", Regularization::L2) - .export_values(); - py::class_<Network>(m, "Network") - .def(py::init<char*, int, float, float, Regularization, float, float, bool, float>()) - .def("add_layer", &Network::add_layer, py::arg("nodes"), py::arg("name"), py::arg("activation"), py::arg("activation_deriv")) - .def("initialize", &Network::initialize) - //.def("init_decay", &Network::init_decay, py::arg("type"), py::arg("a_0"), py::arg("k")) - //.def("set_activation", &Network::set_activation) - .def("feedforward", &Network::feedforward) - .def("backpropagate", &Network::backpropagate) - .def("list_net", &Network::list_net) - .def("cost", &Network::cost) - .def("accuracy", &Network::accuracy) - //.def("update_layer", &Network::update_layer, py::arg("vals"), py::arg("len"), py::arg("index")) - .def("next_batch", &Network::next_batch) - .def("train", &Network::train) - .def("get_acc", &Network::get_acc) - .def("get_cost", &Network::get_cost) - .def("get_val_acc", &Network::get_val_acc) - .def("get_val_cost", &Network::get_val_cost); +PYBIND11_MODULE(_jacobian, m) +{ + m.doc() = "Fast machine learning in C++"; // optional module docstring + py::enum_<Regularization>(m, "Regularization") + .value("L1", Regularization::L1) + .value("L2", Regularization::L2) + .export_values(); + py::class_<Network>(m, "Network") + .def(py::init<char *, int, float, float, Regularization, float, + float, bool, float>(), + py::arg("path"), py::arg("batch"), py::arg("learn_rate"), + py::arg("bias_rate"), py::arg("regularization"), + py::arg("lambda"), py::arg("ratio"), + py::arg("early_exit") = true, py::arg("cutoff") = 0) + .def("add_layer", &Network::add_layer, py::arg("nodes"), + py::arg("name"), py::arg("activation"), + py::arg("activation_deriv")) + .def("initialize", &Network::initialize) + .def("set_activation", &Network::set_activation, + py::arg("index"), py::arg("custom"), + py::arg("custom_deriv")) + .def("feedforward", &Network::feedforward) + .def("backpropagate", &Network::backpropagate) + .def("list_net", &Network::list_net) + .def("cost", &Network::cost) + .def("accuracy", &Network::accuracy) + .def("train", &Network::train) + .def("get_acc", &Network::get_acc) + .def("get_cost", &Network::get_cost) + .def("get_val_acc", &Network::get_val_acc) + .def("get_val_cost", &Network::get_val_cost); + m.def("linear", &linear, py::arg("x")); + m.def("linear_deriv", &linear_deriv, py::arg("x")); + m.def("sigmoid", &sigmoid, py::arg("x")); + m.def("sigmoid_deriv", &sigmoid_deriv, py::arg("x")); }