jacobian

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

commit b25230feccf35bc45913fc40482784754d572152
parent 3dfec848dd016155442d71b2fb08578e21af0355
Author: David Freifeld <freifeld.david@gmail.com>
Date:   Sun,  9 Aug 2020 15:38:53 -0700

Working on python packaging

Diffstat:
M.github/workflows/ubuntu-latest.yml | 2+-
MCMakeLists.txt | 2+-
Mjacobian/__init__.py | 2+-
Asetup.py | 22++++++++++++++++++++++
Msrc/bpnn.cpp | 17+++++------------
5 files changed, 30 insertions(+), 15 deletions(-)

diff --git a/.github/workflows/ubuntu-latest.yml b/.github/workflows/ubuntu-latest.yml @@ -14,7 +14,7 @@ jobs: steps: - uses: actions/checkout@v2 - name: install - run: git clone https://gitlab.com/libeigen/eigen.git + run: git clone https://gitlab.com/libeigen/eigen.git && cd eigen && cp -R Eigen /usr/local/include/ && cd .. # python 3 -m pip install pytest # git clone https://github.com/pybind/pybind11.git # mkdir build diff --git a/CMakeLists.txt b/CMakeLists.txt @@ -33,7 +33,7 @@ if (PYTHON) project(jacobian) find_package(pybind11 CONFIG REQUIRED) include_directories(${pybind11_INCLUDE_DIRS}) - pybind11_add_module(jacobian example.cpp ./src/bpnn.cpp ./src/utils.cpp) + pybind11_add_module(_jacobian example.cpp ./src/bpnn.cpp ./src/utils.cpp) endif (PYTHON) if (CXX) diff --git a/jacobian/__init__.py b/jacobian/__init__.py @@ -1 +1 @@ -from .jacobian import * +from ._jacobian import * diff --git a/setup.py b/setup.py @@ -0,0 +1,22 @@ +from subprocess import CalledProcessError + +kwargs = dict( + name='Jacobian', + version='0.8', + author='David Freifeld', + author_email='freifeld.david@gmail.com', + description='A Python library for neural networks.', + long_description='', + ext_modules=[CMakeExtension('jacobian._jacobian')], + cmdclass=dict(build_ext=CMakeBuild), + zip_safe=False, + packages=['cmake_example'] +) + +# likely there are more exceptions, take a look at yarl example +try: + setup(**kwargs) +except CalledProcessError: + print('Failed to build extension!') + del kwargs['ext_modules'] + setup(**kwargs) diff --git a/src/bpnn.cpp b/src/bpnn.cpp @@ -9,9 +9,6 @@ #include "utils.hpp" #include <ctime> #include <random> -#include <Eigen/MatrixFunctions> -#include <Eigen/unsupported/CXX11/Tensor> -#include <indicators/progress_bar.hpp> #define SHUFFLED_PATH "./shuffled.txt" #define VAL_PATH "./test.txt" @@ -63,15 +60,11 @@ void Layer::init_weights(Layer next) Network::Network(char* path, int batch_sz, float learn_rate, float bias_rate, int regularization, float l, float ratio, bool early_exit, float cutoff) :lambda(l), learning_rate(learn_rate), bias_lr(bias_rate), batch_size(batch_sz), reg_type(regularization), early_stop(early_exit), threshold(cutoff) { - assert( > 0 || batch_size < total_instances); assert(reg_type == 1 || reg_type == 2); // L1 and L2 are only relevant regularizations - try { - int total_instances = prep_file(path, SHUFFLED_PATH); - val_instances = split_file(SHUFFLED_PATH, total_instances, ratio); - data = fopen(TRAIN_PATH, "r"); - val_data = fopen(VAL_PATH, "r"); - } - catch (...) std::cout << "Exception occured when loading data file." << "\n"; + int total_instances = prep_file(path, SHUFFLED_PATH); + val_instances = split_file(SHUFFLED_PATH, total_instances, ratio); + data = fopen(TRAIN_PATH, "r"); + val_data = fopen(VAL_PATH, "r"); instances = total_instances - val_instances; assert(batch_size > 0 || batch_size < instances); decay = [this]() -> void { @@ -113,7 +106,7 @@ void Network::init_decay(char* type, ...) learning_rate = 1 - epochs/max_ep; }; } - else std::cout << "Invalid << "\n"; + else std::cout << "Invalid decay function." << "\n"; va_end(args); }