diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index ae8d61bb2ac9e565cfa5c3bcf8bdac98add03fb7..5c40efbfe212dbf7a3e6e1f3f68ce1d370a9af74 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -10,7 +10,10 @@ job: - apt-get install -y -V cmake - apt-get install -y -V libboost-all-dev - apt-get install -y -V build-essential - - apt-get install -y -V g++-5 + - apt-get install -y -V g++-8 + - apt-get install -y -V git + - git clone https://github.com/ArashPartow/exprtk.git + - cp exprtk/exprtk.hpp /usr/include - ./build.sh script: "./run_tests.sh" diff --git a/.idea/vcs.xml b/.idea/vcs.xml index 94a25f7f4cb416c083d265558da75d457237d671..e16401ce9972b7883608e1747bba44ab12c19fdf 100644 --- a/.idea/vcs.xml +++ b/.idea/vcs.xml @@ -2,5 +2,6 @@ <project version="4"> <component name="VcsDirectoryMappings"> <mapping directory="$PROJECT_DIR$" vcs="Git" /> + <mapping directory="$PROJECT_DIR$/exprtk" vcs="Git" /> </component> </project> \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 2ebaa1fa3a0e79eb52d07dbd05aea5bdc159bc25..81dfd2375d218381f437a26a0c71a8bc27dfa56d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.0) -project(4neuro) +project(lib4neuro) #-------------------------------# # Default installation location # @@ -31,50 +31,43 @@ if(CMAKE_BUILD_TYPE MATCHES DEBUG) set(CMAKE_VERBOSE_MAKEFILE ON) endif() -# Processing user variables -if (WITH_TIME_PROFILING) - add_definitions(-DTIME_PROFILING) +#-------------------------# +# Find external libraries # +#-------------------------# +set(Boost_USE_MULTITHREADED ON) +find_package(Boost REQUIRED COMPONENTS serialization random) +if(Boost_FOUND) + message("Boost INCLUDE DIR: ${Boost_INCLUDE_DIRS}") + message("Boost LIB DIR: ${Boost_LIBRARY_DIRS}") + include_directories(${Boost_INCLUDE_DIRS}) endif() -# C & CXX compilers -if (WIN32) - set (CMAKE_C_COMPILER gcc) - set (CMAKE_CXX_COMPILER g++) -endif() +#find_package(exprt) #TODO write FindExprt.cmake script -# Write compiler variables to the file - to pass them to test script -file(APPEND compilers.env "export CXX=${CMAKE_CXX_COMPILER}\n") -file(APPEND compilers.env "export CC=${CMAKE_C_COMPILER}\n") +#------------------------------------------# +# Detect maximum available number of cores # +# and set corresponding build options # +#------------------------------------------# +include(ProcessorCount) +ProcessorCount(n_cores) +if(NOT n_cores EQUAL 0) + message("Build will be performed on ${n_cores} cores.") + set(CTEST_BUILD_FLAGS -j${N}) + set(ENV{N_CORES} ${N}) + set(ctest_test_args ${ctest_test_args} PARALLEL_LEVEL ${N}) +endif() -#----------------# -# User variables # -#----------------# +#---------------# +# Set variables # +#---------------# set(SRC_DIR src) set(PROJECT_BINARY_DIR build) - -#--------------------# -# Building libraries # -#--------------------# - set(CMAKE_LIBRARY_OUTPUT_DIRECTORY lib) set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY lib) -set(CMAKE_RUNTIME_OUTPUT_DIRECTORY bin) +include_directories(include ${SRC_DIR}) add_subdirectory(${SRC_DIR} ${PROJECT_BINARY_DIR}) - -message ("Current directory:" ${PWD}) +message ("Current directory:" ${CMAKE_CURRENT_SOURCE_DIR}) message ("SRC_DIR: " ${SRC_DIR}) -message ("BUILD_DIR:" ${BUILD_DIR}) -if (WIN32) - message ("Windows") -else () - message ("Not Windows") -endif () - -#find_package(Boost COMPONENTS unit_test_framework REQUIRED) -IF (Boost_FOUND) - message("Boost DIR: " ${Boost_INCLUDE_DIR}) - include_directories(${Boost_INCLUDE_DIR}) -endif() diff --git a/Makefile b/Makefile deleted file mode 100644 index dccdaa5b2ed8c4d6f9c09a830d61e1641770bffa..0000000000000000000000000000000000000000 --- a/Makefile +++ /dev/null @@ -1,428 +0,0 @@ -# CMAKE generated file: DO NOT EDIT! -# Generated by "Unix Makefiles" Generator, CMake Version 3.12 - -# Default target executed when no arguments are given to make. -default_target: all - -.PHONY : default_target - -# Allow only one "make -f Makefile2" at a time, but pass parallelism. -.NOTPARALLEL: - - -#============================================================================= -# Special targets provided by cmake. - -# Disable implicit rules so canonical targets will work. -.SUFFIXES: - - -# Remove some rules from gmake that .SUFFIXES does not remove. -SUFFIXES = - -.SUFFIXES: .hpux_make_needs_suffix_list - - -# Suppress display of executed commands. -$(VERBOSE).SILENT: - - -# A target that is always out of date. -cmake_force: - -.PHONY : cmake_force - -#============================================================================= -# Set environment variables for the build. - -# The shell in which to execute make rules. -SHELL = /bin/sh - -# The CMake executable. -CMAKE_COMMAND = /home/fluffymoo/.local/share/JetBrains/Toolbox/apps/CLion/ch-0/182.3684.76/bin/cmake/linux/bin/cmake - -# The command to remove a file. -RM = /home/fluffymoo/.local/share/JetBrains/Toolbox/apps/CLion/ch-0/182.3684.76/bin/cmake/linux/bin/cmake -E remove -f - -# Escaping for special characters. -EQUALS = = - -# The top-level source directory on which CMake was run. -CMAKE_SOURCE_DIR = /home/fluffymoo/4NEURO_BIATCH/4Neuro - -# The top-level build directory on which CMake was run. -CMAKE_BINARY_DIR = /home/fluffymoo/4NEURO_BIATCH/4Neuro - -#============================================================================= -# Targets provided globally by CMake. - -# Special rule for the target rebuild_cache -rebuild_cache: - @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running CMake to regenerate build system..." - /home/fluffymoo/.local/share/JetBrains/Toolbox/apps/CLion/ch-0/182.3684.76/bin/cmake/linux/bin/cmake -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) -.PHONY : rebuild_cache - -# Special rule for the target rebuild_cache -rebuild_cache/fast: rebuild_cache - -.PHONY : rebuild_cache/fast - -# Special rule for the target edit_cache -edit_cache: - @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "No interactive CMake dialog available..." - /home/fluffymoo/.local/share/JetBrains/Toolbox/apps/CLion/ch-0/182.3684.76/bin/cmake/linux/bin/cmake -E echo No\ interactive\ CMake\ dialog\ available. -.PHONY : edit_cache - -# Special rule for the target edit_cache -edit_cache/fast: edit_cache - -.PHONY : edit_cache/fast - -# The main all target -all: cmake_check_build_system - $(CMAKE_COMMAND) -E cmake_progress_start /home/fluffymoo/4NEURO_BIATCH/4Neuro/CMakeFiles /home/fluffymoo/4NEURO_BIATCH/4Neuro/CMakeFiles/progress.marks - $(MAKE) -f CMakeFiles/Makefile2 all - $(CMAKE_COMMAND) -E cmake_progress_start /home/fluffymoo/4NEURO_BIATCH/4Neuro/CMakeFiles 0 -.PHONY : all - -# The main clean target -clean: - $(MAKE) -f CMakeFiles/Makefile2 clean -.PHONY : clean - -# The main clean target -clean/fast: clean - -.PHONY : clean/fast - -# Prepare targets for installation. -preinstall: all - $(MAKE) -f CMakeFiles/Makefile2 preinstall -.PHONY : preinstall - -# Prepare targets for installation. -preinstall/fast: - $(MAKE) -f CMakeFiles/Makefile2 preinstall -.PHONY : preinstall/fast - -# clear depends -depend: - $(CMAKE_COMMAND) -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 1 -.PHONY : depend - -#============================================================================= -# Target rules for targets named net_test_2 - -# Build rule for target. -net_test_2: cmake_check_build_system - $(MAKE) -f CMakeFiles/Makefile2 net_test_2 -.PHONY : net_test_2 - -# fast build rule for target. -net_test_2/fast: - $(MAKE) -f build/CMakeFiles/net_test_2.dir/build.make build/CMakeFiles/net_test_2.dir/build -.PHONY : net_test_2/fast - -#============================================================================= -# Target rules for targets named neuron_test - -# Build rule for target. -neuron_test: cmake_check_build_system - $(MAKE) -f CMakeFiles/Makefile2 neuron_test -.PHONY : neuron_test - -# fast build rule for target. -neuron_test/fast: - $(MAKE) -f build/CMakeFiles/neuron_test.dir/build.make build/CMakeFiles/neuron_test.dir/build -.PHONY : neuron_test/fast - -#============================================================================= -# Target rules for targets named net_test_1 - -# Build rule for target. -net_test_1: cmake_check_build_system - $(MAKE) -f CMakeFiles/Makefile2 net_test_1 -.PHONY : net_test_1 - -# fast build rule for target. -net_test_1/fast: - $(MAKE) -f build/CMakeFiles/net_test_1.dir/build.make build/CMakeFiles/net_test_1.dir/build -.PHONY : net_test_1/fast - -#============================================================================= -# Target rules for targets named net_test_pde_1 - -# Build rule for target. -net_test_pde_1: cmake_check_build_system - $(MAKE) -f CMakeFiles/Makefile2 net_test_pde_1 -.PHONY : net_test_pde_1 - -# fast build rule for target. -net_test_pde_1/fast: - $(MAKE) -f build/CMakeFiles/net_test_pde_1.dir/build.make build/CMakeFiles/net_test_pde_1.dir/build -.PHONY : net_test_pde_1/fast - -#============================================================================= -# Target rules for targets named 4neuro - -# Build rule for target. -4neuro: cmake_check_build_system - $(MAKE) -f CMakeFiles/Makefile2 4neuro -.PHONY : 4neuro - -# fast build rule for target. -4neuro/fast: - $(MAKE) -f build/CMakeFiles/4neuro.dir/build.make build/CMakeFiles/4neuro.dir/build -.PHONY : 4neuro/fast - -#============================================================================= -# Target rules for targets named net_test_3 - -# Build rule for target. -net_test_3: cmake_check_build_system - $(MAKE) -f CMakeFiles/Makefile2 net_test_3 -.PHONY : net_test_3 - -# fast build rule for target. -net_test_3/fast: - $(MAKE) -f build/CMakeFiles/net_test_3.dir/build.make build/CMakeFiles/net_test_3.dir/build -.PHONY : net_test_3/fast - -#============================================================================= -# Target rules for targets named test_cases - -# Build rule for target. -test_cases: cmake_check_build_system - $(MAKE) -f CMakeFiles/Makefile2 test_cases -.PHONY : test_cases - -# fast build rule for target. -test_cases/fast: - $(MAKE) -f build/CMakeFiles/test_cases.dir/build.make build/CMakeFiles/test_cases.dir/build -.PHONY : test_cases/fast - -#============================================================================= -# Target rules for targets named binary_neuron_test - -# Build rule for target. -binary_neuron_test: cmake_check_build_system - $(MAKE) -f CMakeFiles/Makefile2 binary_neuron_test -.PHONY : binary_neuron_test - -# fast build rule for target. -binary_neuron_test/fast: - $(MAKE) -f build/CMakeFiles/binary_neuron_test.dir/build.make build/CMakeFiles/binary_neuron_test.dir/build -.PHONY : binary_neuron_test/fast - -#============================================================================= -# Target rules for targets named connection_weight_identity_test - -# Build rule for target. -connection_weight_identity_test: cmake_check_build_system - $(MAKE) -f CMakeFiles/Makefile2 connection_weight_identity_test -.PHONY : connection_weight_identity_test - -# fast build rule for target. -connection_weight_identity_test/fast: - $(MAKE) -f build/CMakeFiles/connection_weight_identity_test.dir/build.make build/CMakeFiles/connection_weight_identity_test.dir/build -.PHONY : connection_weight_identity_test/fast - -#============================================================================= -# Target rules for targets named boost_unit_test - -# Build rule for target. -boost_unit_test: cmake_check_build_system - $(MAKE) -f CMakeFiles/Makefile2 boost_unit_test -.PHONY : boost_unit_test - -# fast build rule for target. -boost_unit_test/fast: - $(MAKE) -f build/CMakeFiles/boost_unit_test.dir/build.make build/CMakeFiles/boost_unit_test.dir/build -.PHONY : boost_unit_test/fast - -#============================================================================= -# Target rules for targets named dataset_test - -# Build rule for target. -dataset_test: cmake_check_build_system - $(MAKE) -f CMakeFiles/Makefile2 dataset_test -.PHONY : dataset_test - -# fast build rule for target. -dataset_test/fast: - $(MAKE) -f build/CMakeFiles/dataset_test.dir/build.make build/CMakeFiles/dataset_test.dir/build -.PHONY : dataset_test/fast - -#============================================================================= -# Target rules for targets named neuron_serialization_example - -# Build rule for target. -neuron_serialization_example: cmake_check_build_system - $(MAKE) -f CMakeFiles/Makefile2 neuron_serialization_example -.PHONY : neuron_serialization_example - -# fast build rule for target. -neuron_serialization_example/fast: - $(MAKE) -f build/CMakeFiles/neuron_serialization_example.dir/build.make build/CMakeFiles/neuron_serialization_example.dir/build -.PHONY : neuron_serialization_example/fast - -#============================================================================= -# Target rules for targets named particle_swarm_test - -# Build rule for target. -particle_swarm_test: cmake_check_build_system - $(MAKE) -f CMakeFiles/Makefile2 particle_swarm_test -.PHONY : particle_swarm_test - -# fast build rule for target. -particle_swarm_test/fast: - $(MAKE) -f build/CMakeFiles/particle_swarm_test.dir/build.make build/CMakeFiles/particle_swarm_test.dir/build -.PHONY : particle_swarm_test/fast - -#============================================================================= -# Target rules for targets named particle_test - -# Build rule for target. -particle_test: cmake_check_build_system - $(MAKE) -f CMakeFiles/Makefile2 particle_test -.PHONY : particle_test - -# fast build rule for target. -particle_test/fast: - $(MAKE) -f build/CMakeFiles/particle_test.dir/build.make build/CMakeFiles/particle_test.dir/build -.PHONY : particle_test/fast - -#============================================================================= -# Target rules for targets named linear_neuron_test - -# Build rule for target. -linear_neuron_test: cmake_check_build_system - $(MAKE) -f CMakeFiles/Makefile2 linear_neuron_test -.PHONY : linear_neuron_test - -# fast build rule for target. -linear_neuron_test/fast: - $(MAKE) -f build/CMakeFiles/linear_neuron_test.dir/build.make build/CMakeFiles/linear_neuron_test.dir/build -.PHONY : linear_neuron_test/fast - -#============================================================================= -# Target rules for targets named connection_weight_test - -# Build rule for target. -connection_weight_test: cmake_check_build_system - $(MAKE) -f CMakeFiles/Makefile2 connection_weight_test -.PHONY : connection_weight_test - -# fast build rule for target. -connection_weight_test/fast: - $(MAKE) -f build/CMakeFiles/connection_weight_test.dir/build.make build/CMakeFiles/connection_weight_test.dir/build -.PHONY : connection_weight_test/fast - -#============================================================================= -# Target rules for targets named net_test_ode_1 - -# Build rule for target. -net_test_ode_1: cmake_check_build_system - $(MAKE) -f CMakeFiles/Makefile2 net_test_ode_1 -.PHONY : net_test_ode_1 - -# fast build rule for target. -net_test_ode_1/fast: - $(MAKE) -f build/CMakeFiles/net_test_ode_1.dir/build.make build/CMakeFiles/net_test_ode_1.dir/build -.PHONY : net_test_ode_1/fast - -#============================================================================= -# Target rules for targets named logistic_neuron_test - -# Build rule for target. -logistic_neuron_test: cmake_check_build_system - $(MAKE) -f CMakeFiles/Makefile2 logistic_neuron_test -.PHONY : logistic_neuron_test - -# fast build rule for target. -logistic_neuron_test/fast: - $(MAKE) -f build/CMakeFiles/logistic_neuron_test.dir/build.make build/CMakeFiles/logistic_neuron_test.dir/build -.PHONY : logistic_neuron_test/fast - -#============================================================================= -# Target rules for targets named neural_network_test - -# Build rule for target. -neural_network_test: cmake_check_build_system - $(MAKE) -f CMakeFiles/Makefile2 neural_network_test -.PHONY : neural_network_test - -# fast build rule for target. -neural_network_test/fast: - $(MAKE) -f build/CMakeFiles/neural_network_test.dir/build.make build/CMakeFiles/neural_network_test.dir/build -.PHONY : neural_network_test/fast - -#============================================================================= -# Target rules for targets named errorfunction_test - -# Build rule for target. -errorfunction_test: cmake_check_build_system - $(MAKE) -f CMakeFiles/Makefile2 errorfunction_test -.PHONY : errorfunction_test - -# fast build rule for target. -errorfunction_test/fast: - $(MAKE) -f build/CMakeFiles/errorfunction_test.dir/build.make build/CMakeFiles/errorfunction_test.dir/build -.PHONY : errorfunction_test/fast - -#============================================================================= -# Target rules for targets named NeuralNetworkSum_test - -# Build rule for target. -NeuralNetworkSum_test: cmake_check_build_system - $(MAKE) -f CMakeFiles/Makefile2 NeuralNetworkSum_test -.PHONY : NeuralNetworkSum_test - -# fast build rule for target. -NeuralNetworkSum_test/fast: - $(MAKE) -f build/CMakeFiles/NeuralNetworkSum_test.dir/build.make build/CMakeFiles/NeuralNetworkSum_test.dir/build -.PHONY : NeuralNetworkSum_test/fast - -# Help Target -help: - @echo "The following are some of the valid targets for this Makefile:" - @echo "... all (the default if no target is provided)" - @echo "... clean" - @echo "... depend" - @echo "... rebuild_cache" - @echo "... edit_cache" - @echo "... net_test_2" - @echo "... neuron_test" - @echo "... net_test_1" - @echo "... net_test_pde_1" - @echo "... 4neuro" - @echo "... net_test_3" - @echo "... test_cases" - @echo "... binary_neuron_test" - @echo "... connection_weight_identity_test" - @echo "... boost_unit_test" - @echo "... dataset_test" - @echo "... neuron_serialization_example" - @echo "... particle_swarm_test" - @echo "... particle_test" - @echo "... linear_neuron_test" - @echo "... connection_weight_test" - @echo "... net_test_ode_1" - @echo "... logistic_neuron_test" - @echo "... neural_network_test" - @echo "... errorfunction_test" - @echo "... NeuralNetworkSum_test" -.PHONY : help - - - -#============================================================================= -# Special targets to cleanup operation of make. - -# Special rule to run CMake to check the build system integrity. -# No rule that depends on this can have commands that come from listfiles -# because they might be regenerated. -cmake_check_build_system: - $(CMAKE_COMMAND) -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 0 -.PHONY : cmake_check_build_system - diff --git a/build.sh b/build.sh index ccf7c9ea7a03acef699b2e3f514c9d0b2fb9d82d..c1be4be9c4ca850b8bb48853e764b7d27b710915 100755 --- a/build.sh +++ b/build.sh @@ -9,67 +9,11 @@ # FORTRAN_COMPILER=gfortran # Build type (Release/Debug) BUILD_TYPE=Debug +CXX_COMPILER="g++-8" -# Turn of/off time profiling (1/0) -WITH_TIME_PROFILIN=1 - -CPP_COMPILER=g++ -#--------------#---------------------------------------------------------- -# Library path # -#--------------# - -MAKEFILE_TYPE="" -LIB_PATH="$PWD/build/lib" -#LIB_PATH_WIN="$CD\\build\\lib" - -echo ${LIB_PATH} -#echo ${LIB_PATH_WIN} - -case `uname -s` in - - Darwin) - echo 'OS X is not supported yet...' - exit -1 - ;; - - Linux) - MAKEFILE_TYPE="Unix Makefiles" - if [[ ${LD_LIBRARY_PATH} != *${LIB_PATH}* ]]; then - export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:${LIB_PATH} - fi - ;; - - CYGWIN*) - MAKEFILE_TYPE="Unix Makefiles" -# if [[ ${PATH} != *${LIB_PATH_WIN}* ]]; then -# export PATH=${PATH};${LIB_PATH_WIN} -# fi - ;; - - MINGW*) - MAKEFILE_TYPE="MinGW Makefiles" -# if [[ ${PATH} != *${LIB_PATH_WIN}* ]]; then -# export PATH=${PATH};${LIB_PATH_WIN} -# fi - ;; - - MSYS*) - MAKEFILE_TYPE="MSYS Makefiles" - echo ${MAKEFILE_TYPE} -# if [[ ${PATH} != *${LIB_PATH_WIN}* ]]; then -# export PATH=${PATH};${LIB_PATH_WIN} -# fi - ;; - - *) - echo "Your makefile generator `uname -s` is not yet supported. Please, write an issue to https://code.it4i.cz/moldyn/4Neuro" - exit -1 - ;; - -esac -#------------------------------------------------------------------------- - -rm -rf build CMakeCache.txt; -cmake -G "${MAKEFILE_TYPE}" -DCMAKE_BUILD_TYPE=${BUILD_TYPE} -DWITH_TIME_PROFILING:BOOLEAN=${WITH_TIME_PROFILING} . -make VERBOSE=1 && echo "Build complete." || exit -1; +rm -rf build CMakeCache.txt cmake_install.cmake CMakeFiles; +#cmake -G "${MAKEFILE_TYPE}" -DCMAKE_BUILD_TYPE=${BUILD_TYPE} -DCMAKE_CXX_COMPILER=g++-8 . +cmake -DCMAKE_BUILD_TYPE=${BUILD_TYPE} -DCMAKE_CXX_COMPILER=${CXX_COMPILER} . +#make VERBOSE=1 -j ${N_CORES} && echo "Build complete." || exit -1; +cmake --build . --config ${BUILD_TYPE} -- -j${N_CORES} #make install; diff --git a/clean.sh b/clean.sh index d783610fe2e3a40d690542926f9523d20ff84296..d2fe6a16d195cfa076bfbde97e92a621105a4d07 100755 --- a/clean.sh +++ b/clean.sh @@ -5,3 +5,6 @@ rm -rf docs/* rm -f src/*TestRunner* rm -f src/*.o src/*.mod rm -f src/funit.tmp src/*_fun.f90 +rm -f CMakeCache.txt +rm -f cmake_install.cmake +rm -rf CMakeFiles diff --git a/run_tests.sh b/run_tests.sh index 295d527064348a65386533a0085250af8f901804..ba3027530cd3bcd125c59c53c478ba53b6ad14e8 100755 --- a/run_tests.sh +++ b/run_tests.sh @@ -4,5 +4,5 @@ # UNIT TESTS # ############## for f in build/bin/unit-tests/*_test; do - ${f} + ${f} || exit -1 done diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 17c8048b172d3a05041eb4728b432c64ce9c9113..de7f0f5902f42d552ffcfebcd826666bb56dc006 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -5,82 +5,18 @@ add_library(4neuro SHARED Neuron/NeuronBinary.cpp Neuron/NeuronLinear.cpp Neuron/NeuronLogistic.cpp + Neuron/NeuronTanh.cpp + NetConnection/Connection.cpp Network/NeuralNetwork.cpp - NetConnection/ConnectionFunctionGeneral.cpp - NetConnection/ConnectionFunctionIdentity.cpp + Neuron/NeuronNeuralNet.cpp + NetConnection/ConnectionWeight.cpp + NetConnection/ConnectionWeightIdentity.cpp LearningMethods/ParticleSwarm.cpp DataSet/DataSet.cpp - ErrorFunction/ErrorFunctions.cpp Network/NeuralNetworkSum.cpp Network/NeuralNetworkSum.h Solvers/DESolver.cpp Solvers/DESolver.h Neuron/NeuronConstant.cpp Neuron/NeuronConstant.h) + ErrorFunction/ErrorFunctions.cpp Network/NeuralNetworkSum.cpp Network/NeuralNetworkSum.h Solvers/DESolver.cpp Solvers/DESolver.h) target_link_libraries(4neuro boost_serialization) -add_library(boost_unit_test SHARED tests/boost_test_lib_dummy.cpp) - -############ -# EXAMPLES # -############ -add_executable(test_cases main.cpp) -target_link_libraries(test_cases 4neuro) - -add_executable(neuron_serialization_example neuron_serialization_example.cpp) -target_link_libraries(neuron_serialization_example 4neuro) - -add_executable(net_test_1 net_test_1.cpp settings.h) -target_link_libraries(net_test_1 4neuro) - -add_executable(net_test_2 net_test_2.cpp) -target_link_libraries(net_test_2 4neuro) - -add_executable(net_test_3 net_test_3.cpp) -target_link_libraries(net_test_3 4neuro) - -add_executable(net_test_ode_1 net_test_ode_1.cpp) -target_link_libraries(net_test_ode_1 4neuro) - -add_executable(net_test_pde_1 net_test_pde_1.cpp) -target_link_libraries(net_test_pde_1 4neuro) - -############## -# UNIT TESTS # -############## -set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/unit-tests) - -add_executable(neuron_test tests/neuron_test.cpp) -target_link_libraries(neuron_test boost_unit_test 4neuro) - -add_executable(linear_neuron_test tests/NeuronLinear_test.cpp) -target_link_libraries(linear_neuron_test boost_unit_test 4neuro) - -add_executable(binary_neuron_test tests/NeuronBinary_test.cpp) -target_link_libraries(binary_neuron_test boost_unit_test 4neuro) - -add_executable(logistic_neuron_test tests/NeuronLogistic_test.cpp) -target_link_libraries(logistic_neuron_test boost_unit_test 4neuro) - - -add_executable(connection_weight_test tests/ConnectionWeight_test.cpp) -target_link_libraries(connection_weight_test boost_unit_test 4neuro) - -add_executable(neural_network_test tests/NeuralNetwork_test.cpp) -target_link_libraries(neural_network_test boost_unit_test 4neuro) - -add_executable(connection_weight_identity_test tests/ConnectionWeightIdentity_test.cpp) -target_link_libraries(connection_weight_identity_test boost_unit_test 4neuro) - -add_executable(dataset_test tests/DataSet_test.cpp) -target_link_libraries(dataset_test boost_unit_test 4neuro) - -add_executable(errorfunction_test tests/ErrorFunctions_test.cpp) -target_link_libraries(errorfunction_test boost_unit_test 4neuro) - -add_executable(particle_swarm_test tests/ParticleSwarm_test.cpp) -target_link_libraries(particle_swarm_test boost_unit_test 4neuro) - -add_executable(particle_test tests/Particle_test.cpp) -target_link_libraries(particle_test boost_unit_test 4neuro) - -add_executable(NeuralNetworkSum_test tests/NeuralNetworkSum_test.cpp) -target_link_libraries(NeuralNetworkSum_test boost_unit_test 4neuro) - - +add_library(boost_unit_test SHARED boost_test_lib_dummy.cpp) +add_library(exprtk SHARED exprtk.cpp) diff --git a/src/DataSet/DataSet.cpp b/src/DataSet/DataSet.cpp index a4a11a3c079204364476b4695228b5508c117dff..661ec79ed0d543bdd0d0e3577afb6fcc3995dbd3 100644 --- a/src/DataSet/DataSet.cpp +++ b/src/DataSet/DataSet.cpp @@ -33,13 +33,24 @@ DataSet::DataSet(std::vector<std::pair<std::vector<double>, std::vector<double>> DataSet::DataSet(double lower_bound, double upper_bound, unsigned int size, double output) { std::vector<std::pair<std::vector<double>, std::vector<double>>> new_data_vec; this->data = new_data_vec; - this->n_elements = size; + this->n_elements = 0; this->input_dim = 1; this->output_dim = 1; this->add_isotropic_data(lower_bound, upper_bound, size, output); } +DataSet::DataSet(std::vector<double> bounds, unsigned int no_elems_in_one_dim, std::vector<double> (*output_func)(std::vector<double>), unsigned int output_dim) { + std::vector<std::pair<std::vector<double>, std::vector<double>>> new_data_vec; + this->data = new_data_vec; + this->input_dim = bounds.size()/2; + this->output_dim = output_dim; + this->n_elements = 0; + + this->add_isotropic_data(bounds, no_elems_in_one_dim, output_func); +} + + void DataSet::add_data_pair(std::vector<double> inputs, std::vector<double> outputs) { if(inputs.size() != this->input_dim) { throw InvalidDimension("Bad input dimension."); @@ -66,6 +77,33 @@ void DataSet::add_isotropic_data(double lower_bound, double upper_bound, unsigne inp = {frac*i}; this->data.emplace_back(std::make_pair(inp, out)); } + + this->n_elements += size; +} + +void DataSet::add_isotropic_data(std::vector<double> bounds, unsigned int no_elems_in_one_dim, std::vector<double> (*output_func)(std::vector<double>)) { + // TODO add check of dataset dimensions + + std::vector<std::vector<double>> grid; + std::vector<double> tmp; + double frac; + + for(unsigned int i = 0; i < bounds.size(); i += 2) { + frac = (bounds[i] + bounds[i+1]) / (no_elems_in_one_dim - 1); + tmp.clear(); + for(double j = bounds[i]; j <= bounds[i+1]; j += frac) { + tmp.emplace_back(j); + } + + grid.emplace_back(tmp); + } + + grid = this->cartesian_product(&grid); + + for(const auto& vec : grid) { + this->n_elements++; + this->data.emplace_back(std::make_pair(vec, output_func(vec))); + } } std::vector<std::pair<std::vector<double>, std::vector<double>>>* DataSet::get_data() { @@ -110,4 +148,34 @@ void DataSet::store_text(std::string file_path) { boost::archive::text_oarchive oa(ofs); oa << *this; ofs.close(); +} + +template <class T> +std::vector<std::vector<T>> DataSet::cartesian_product(const std::vector<std::vector<T>>* v) { + std::vector<std::vector<double>> v_combined_old, v_combined, v_tmp; + std::vector<double> tmp; + + for(const auto& e : v->at(0)) { + tmp = {e}; + v_combined.emplace_back(tmp); + } + + for(unsigned int i = 1; i < v->size(); i++) { // Iterate through remaining vectors of 'v' + v_combined_old = v_combined; + v_combined.clear(); + + for(const auto& e : v->at(i)) { + for(const auto& vec : v_combined_old) { + tmp = vec; + tmp.emplace_back(e); + + /* Add only unique elements */ + if(std::find(v_combined.begin(), v_combined.end(), tmp) == v_combined.end()) { + v_combined.emplace_back(tmp); + } + } + } + } + + return v_combined; } \ No newline at end of file diff --git a/src/DataSet/DataSet.h b/src/DataSet/DataSet.h index 0cfbbea01396183f7873dc4d523492c908163142..2d47988d4415b657d3c3497b8d393939071b2ea1 100644 --- a/src/DataSet/DataSet.h +++ b/src/DataSet/DataSet.h @@ -12,6 +12,7 @@ #include <boost/range/size_type.hpp> #include <exception> #include <string> +#include <functional> /** * Class representing an error caused by an incorrect @@ -61,6 +62,9 @@ private: */ std::vector<std::pair<std::vector<double>, std::vector<double>>> data; + template <class T> + std::vector<std::vector<T>> cartesian_product(const std::vector<std::vector<T>>* v); + protected: /** * Serialization function @@ -165,6 +169,8 @@ public: */ DataSet(double lower_bound, double upper_bound, unsigned int size, double output); + DataSet(std::vector<double> bounds, unsigned int no_elems_in_one_dim, std::vector<double> (*output_func)(std::vector<double>), unsigned int output_dim); + /** * Getter for number of elements * @return Number of elements in the data set @@ -212,6 +218,20 @@ public: */ void add_isotropic_data(double lower_bound, double upper_bound, unsigned int size, double output); + /** + * Adds a new data with input values equidistantly positioned + * over the certain interval and the output value + * being constant + * + * Input can have arbitrary many dimensions, + * output can be an arbitrary function + * + * @param bounds Odd values are lower bounds and even values are corresponding upper bounds + * @param size Number of input-output pairs generated + * @param output_func Function determining output value + */ + void add_isotropic_data(std::vector<double> bounds, unsigned int no_elems_in_one_dim, std::vector<double> (*output_func)(std::vector<double>)); + //TODO Chebyshev - ch. interpolation points, i-th point = cos(i*alpha) from 0 to pi /** diff --git a/src/Graph/ElementaryFunctions/FunctionBase.cpp b/src/Graph/ElementaryFunctions/FunctionBase.cpp deleted file mode 100644 index 4c37d0da14a507119755ccec986d5e327d72ef1a..0000000000000000000000000000000000000000 --- a/src/Graph/ElementaryFunctions/FunctionBase.cpp +++ /dev/null @@ -1,15 +0,0 @@ -/** - * DESCRIPTION OF THE FILE - * - * @author Michal KravÄenko - * @date 4.7.18 - - */ - -#include "FunctionBase.h" - -FunctionBase::FunctionBase() {} - -FunctionBase::~FunctionBase() { - -} - diff --git a/src/Graph/ElementaryFunctions/FunctionBase.h b/src/Graph/ElementaryFunctions/FunctionBase.h deleted file mode 100644 index 9a6f9ec78e1323fd3888d934376e303a83c83d97..0000000000000000000000000000000000000000 --- a/src/Graph/ElementaryFunctions/FunctionBase.h +++ /dev/null @@ -1,31 +0,0 @@ -/** - * DESCRIPTION OF THE FILE - * - * @author Michal KravÄenko - * @date 4.7.18 - - */ - -#ifndef INC_4NEURO_FUNCTIONBASE_H -#define INC_4NEURO_FUNCTIONBASE_H - - -class FunctionBase { -public: - - FunctionBase(); - - virtual ~FunctionBase(); - - virtual double eval(double x) = 0; - - virtual FunctionBase* get_derivative() = 0; - -protected: - - FunctionBase* derivative = nullptr; - -private: -}; - - -#endif //INC_4NEURO_FUNCTIONBASE_H diff --git a/src/Graph/ElementaryFunctions/FunctionCosine.cpp b/src/Graph/ElementaryFunctions/FunctionCosine.cpp deleted file mode 100644 index c037adaa89c758b9a58edf90c33552bd7f8b4aca..0000000000000000000000000000000000000000 --- a/src/Graph/ElementaryFunctions/FunctionCosine.cpp +++ /dev/null @@ -1,26 +0,0 @@ -/** - * DESCRIPTION OF THE FILE - * - * @author Michal KravÄenko - * @date 4.7.18 - - */ - -#include "FunctionCosine.h" - -FunctionCosine::FunctionCosine(double period, double bias) { - this->period = period; - this->bias = bias; -} - -double FunctionCosine::eval(double x) { - return std::cos(x * this->period + this->bias); -} - -FunctionBase* FunctionCosine::get_derivative() { - - if(!this->derivative){ - this->derivative = new FunctionSine(); - } - - return this->derivative; -} \ No newline at end of file diff --git a/src/Graph/ElementaryFunctions/FunctionCosine.h b/src/Graph/ElementaryFunctions/FunctionCosine.h deleted file mode 100644 index 0ea13bb09b6311fc2c5b0fdded9d8614d013fcd6..0000000000000000000000000000000000000000 --- a/src/Graph/ElementaryFunctions/FunctionCosine.h +++ /dev/null @@ -1,34 +0,0 @@ -/** - * DESCRIPTION OF THE FILE - * - * @author Michal KravÄenko - * @date 4.7.18 - - */ - -#ifndef INC_4NEURO_FUNCTIONCOSINE_H -#define INC_4NEURO_FUNCTIONCOSINE_H - -#include <cmath> - -#include "FunctionBase.h" - -#include "FunctionSine.h" - - -class FunctionCosine: FunctionBase { -public: - FunctionCosine(double period, double bias); - - double eval(double x); - - FunctionBase* get_derivative(); - -private: - - double period = 0.0; - - double bias = 0.0; -}; - - -#endif //INC_4NEURO_FUNCTIONCOSINE_H diff --git a/src/Graph/ElementaryFunctions/FunctionExponential.cpp b/src/Graph/ElementaryFunctions/FunctionExponential.cpp deleted file mode 100644 index 9324529944d88a879a3bcfffef656100806f0be3..0000000000000000000000000000000000000000 --- a/src/Graph/ElementaryFunctions/FunctionExponential.cpp +++ /dev/null @@ -1,8 +0,0 @@ -/** - * DESCRIPTION OF THE FILE - * - * @author Michal KravÄenko - * @date 4.7.18 - - */ - -#include "FunctionExponential.h" diff --git a/src/Graph/ElementaryFunctions/FunctionExponential.h b/src/Graph/ElementaryFunctions/FunctionExponential.h deleted file mode 100644 index bcd2a2cdfa303b79f4c0a986f5ec26cbec1ab6cd..0000000000000000000000000000000000000000 --- a/src/Graph/ElementaryFunctions/FunctionExponential.h +++ /dev/null @@ -1,18 +0,0 @@ -/** - * DESCRIPTION OF THE FILE - * - * @author Michal KravÄenko - * @date 4.7.18 - - */ - -#ifndef INC_4NEURO_FUNCTIONEXPONENTIAL_H -#define INC_4NEURO_FUNCTIONEXPONENTIAL_H - -#include "FunctionBase.h" - -class FunctionExponential: FunctionBase { - -}; - - -#endif //INC_4NEURO_FUNCTIONEXPONENTIAL_H diff --git a/src/Graph/ElementaryFunctions/FunctionLogarithm.cpp b/src/Graph/ElementaryFunctions/FunctionLogarithm.cpp deleted file mode 100644 index e1db834d52238293bfae92506e18a0e4c11bbf18..0000000000000000000000000000000000000000 --- a/src/Graph/ElementaryFunctions/FunctionLogarithm.cpp +++ /dev/null @@ -1,8 +0,0 @@ -/** - * DESCRIPTION OF THE FILE - * - * @author Michal KravÄenko - * @date 4.7.18 - - */ - -#include "FunctionLogarithm.h" diff --git a/src/Graph/ElementaryFunctions/FunctionLogarithm.h b/src/Graph/ElementaryFunctions/FunctionLogarithm.h deleted file mode 100644 index 2efc61a7656407f46613b4351287026b3ada5e21..0000000000000000000000000000000000000000 --- a/src/Graph/ElementaryFunctions/FunctionLogarithm.h +++ /dev/null @@ -1,18 +0,0 @@ -/** - * DESCRIPTION OF THE FILE - * - * @author Michal KravÄenko - * @date 4.7.18 - - */ - -#ifndef INC_4NEURO_FUNCTIONLOGARITHM_H -#define INC_4NEURO_FUNCTIONLOGARITHM_H - -#include "FunctionBase.h" - -class FunctionLogarithm: FunctionBase { - -}; - - -#endif //INC_4NEURO_FUNCTIONLOGARITHM_H diff --git a/src/Graph/ElementaryFunctions/FunctionPolynomial.cpp b/src/Graph/ElementaryFunctions/FunctionPolynomial.cpp deleted file mode 100644 index cf5e693b3be11a2bfa66ce85816ecc04b89e7761..0000000000000000000000000000000000000000 --- a/src/Graph/ElementaryFunctions/FunctionPolynomial.cpp +++ /dev/null @@ -1,8 +0,0 @@ -/** - * DESCRIPTION OF THE FILE - * - * @author Michal KravÄenko - * @date 4.7.18 - - */ - -#include "FunctionPolynomial.h" diff --git a/src/Graph/ElementaryFunctions/FunctionPolynomial.h b/src/Graph/ElementaryFunctions/FunctionPolynomial.h deleted file mode 100644 index e5be747d5e4e791a1beb2e7048322deb82e866d1..0000000000000000000000000000000000000000 --- a/src/Graph/ElementaryFunctions/FunctionPolynomial.h +++ /dev/null @@ -1,18 +0,0 @@ -/** - * DESCRIPTION OF THE FILE - * - * @author Michal KravÄenko - * @date 4.7.18 - - */ - -#ifndef INC_4NEURO_FUNCTIONPOLYNOMIAL_H -#define INC_4NEURO_FUNCTIONPOLYNOMIAL_H - -#include "FunctionBase.h" - -class FunctionPolynomial: FunctionBase { - -}; - - -#endif //INC_4NEURO_FUNCTIONPOLYNOMIAL_H diff --git a/src/Graph/ElementaryFunctions/FunctionSine.cpp b/src/Graph/ElementaryFunctions/FunctionSine.cpp deleted file mode 100644 index 9771b10c85019612f34a3573c754751c63c38679..0000000000000000000000000000000000000000 --- a/src/Graph/ElementaryFunctions/FunctionSine.cpp +++ /dev/null @@ -1,8 +0,0 @@ -/** - * DESCRIPTION OF THE FILE - * - * @author Michal KravÄenko - * @date 4.7.18 - - */ - -#include "FunctionSine.h" diff --git a/src/Graph/ElementaryFunctions/FunctionSine.h b/src/Graph/ElementaryFunctions/FunctionSine.h deleted file mode 100644 index 3682767b81891cbe3dc4614611ae30c8e9f208cc..0000000000000000000000000000000000000000 --- a/src/Graph/ElementaryFunctions/FunctionSine.h +++ /dev/null @@ -1,18 +0,0 @@ -/** - * DESCRIPTION OF THE FILE - * - * @author Michal KravÄenko - * @date 4.7.18 - - */ - -#ifndef INC_4NEURO_FUNCTIONSINE_H -#define INC_4NEURO_FUNCTIONSINE_H - -#include "FunctionBase.h" - -class FunctionSine: FunctionBase { - -}; - - -#endif //INC_4NEURO_FUNCTIONSINE_H diff --git a/src/Graph/Graph.cpp b/src/Graph/Graph.cpp deleted file mode 100644 index a29f3407521515b8e4efba4190ab9f851ebc6a0c..0000000000000000000000000000000000000000 --- a/src/Graph/Graph.cpp +++ /dev/null @@ -1,8 +0,0 @@ -/** - * DESCRIPTION OF THE FILE - * - * @author Michal KravÄenko - * @date 4.7.18 - - */ - -#include "Graph.h" diff --git a/src/Graph/Graph.h b/src/Graph/Graph.h deleted file mode 100644 index 7c634781d555073be9e8b68fed5d5e82006b66ba..0000000000000000000000000000000000000000 --- a/src/Graph/Graph.h +++ /dev/null @@ -1,18 +0,0 @@ -/** - * DESCRIPTION OF THE FILE - * - * @author Michal KravÄenko - * @date 4.7.18 - - */ - -#ifndef INC_4NEURO_GRAPH_H -#define INC_4NEURO_GRAPH_H - -//TODO verification of decision making (for each input determine the magnitude of its influence over the output) -//TODO form a graph of the inverse function -class Graph { - -}; - - -#endif //INC_4NEURO_GRAPH_H diff --git a/src/Graph/VertexBase.cpp b/src/Graph/VertexBase.cpp deleted file mode 100644 index fd33aa37f57d9288acebe661c7a007a7895c2cb8..0000000000000000000000000000000000000000 --- a/src/Graph/VertexBase.cpp +++ /dev/null @@ -1,8 +0,0 @@ -/** - * DESCRIPTION OF THE FILE - * - * @author Michal KravÄenko - * @date 4.7.18 - - */ - -#include "VertexBase.h" diff --git a/src/Graph/VertexBase.h b/src/Graph/VertexBase.h deleted file mode 100644 index 9be5ff3565701a22241187fe175c2684b292bd83..0000000000000000000000000000000000000000 --- a/src/Graph/VertexBase.h +++ /dev/null @@ -1,17 +0,0 @@ -/** - * DESCRIPTION OF THE FILE - * - * @author Michal KravÄenko - * @date 4.7.18 - - */ - -#ifndef INC_4NEURO_VERTEXBASE_H -#define INC_4NEURO_VERTEXBASE_H - - -class VertexBase { - -}; - - -#endif //INC_4NEURO_VERTEXBASE_H diff --git a/src/Graph/VertexCompound.cpp b/src/Graph/VertexCompound.cpp deleted file mode 100644 index e87ad76ebbfb33cecf99c892d0132b54caeaee84..0000000000000000000000000000000000000000 --- a/src/Graph/VertexCompound.cpp +++ /dev/null @@ -1,8 +0,0 @@ -/** - * DESCRIPTION OF THE FILE - * - * @author Michal KravÄenko - * @date 4.7.18 - - */ - -#include "VertexCompound.h" diff --git a/src/Graph/VertexCompound.h b/src/Graph/VertexCompound.h deleted file mode 100644 index 6ccdb3b1cb6aaa7ecc4d988b44ca36dff0ef1be5..0000000000000000000000000000000000000000 --- a/src/Graph/VertexCompound.h +++ /dev/null @@ -1,17 +0,0 @@ -/** - * DESCRIPTION OF THE FILE - * - * @author Michal KravÄenko - * @date 4.7.18 - - */ - -#ifndef INC_4NEURO_VERTEXCOMPOUND_H -#define INC_4NEURO_VERTEXCOMPOUND_H - - -class VertexCompound { - -}; - - -#endif //INC_4NEURO_VERTEXCOMPOUND_H diff --git a/src/Graph/VertexConstant.cpp b/src/Graph/VertexConstant.cpp deleted file mode 100644 index aa8d1cd566b9bb60832027ebd296ed55bed29e4c..0000000000000000000000000000000000000000 --- a/src/Graph/VertexConstant.cpp +++ /dev/null @@ -1,8 +0,0 @@ -/** - * DESCRIPTION OF THE FILE - * - * @author Michal KravÄenko - * @date 4.7.18 - - */ - -#include "VertexConstant.h" diff --git a/src/Graph/VertexConstant.h b/src/Graph/VertexConstant.h deleted file mode 100644 index bf171a5bfddace701fd5ae99876b239dca32320a..0000000000000000000000000000000000000000 --- a/src/Graph/VertexConstant.h +++ /dev/null @@ -1,17 +0,0 @@ -/** - * DESCRIPTION OF THE FILE - * - * @author Michal KravÄenko - * @date 4.7.18 - - */ - -#ifndef INC_4NEURO_VERTEXCONSTANT_H -#define INC_4NEURO_VERTEXCONSTANT_H - - -class VertexConstant { - -}; - - -#endif //INC_4NEURO_VERTEXCONSTANT_H diff --git a/src/Graph/VertexSum.cpp b/src/Graph/VertexSum.cpp deleted file mode 100644 index b44f401720296aa33fb3610cd67c707455c783da..0000000000000000000000000000000000000000 --- a/src/Graph/VertexSum.cpp +++ /dev/null @@ -1,8 +0,0 @@ -/** - * DESCRIPTION OF THE FILE - * - * @author Michal KravÄenko - * @date 4.7.18 - - */ - -#include "VertexSum.h" diff --git a/src/Graph/VertexSum.h b/src/Graph/VertexSum.h deleted file mode 100644 index f5dc14acc8ef3b283bdee849c01f51820d712294..0000000000000000000000000000000000000000 --- a/src/Graph/VertexSum.h +++ /dev/null @@ -1,17 +0,0 @@ -/** - * DESCRIPTION OF THE FILE - * - * @author Michal KravÄenko - * @date 4.7.18 - - */ - -#ifndef INC_4NEURO_VERTEXSUM_H -#define INC_4NEURO_VERTEXSUM_H - - -class VertexSum { - -}; - - -#endif //INC_4NEURO_VERTEXSUM_H diff --git a/src/tests/boost_test_lib_dummy.cpp b/src/boost_test_lib_dummy.cpp similarity index 100% rename from src/tests/boost_test_lib_dummy.cpp rename to src/boost_test_lib_dummy.cpp diff --git a/src/examples/CMakeLists.txt b/src/examples/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..0c43395f43e88b50e79bdbea3e395a59077178bc --- /dev/null +++ b/src/examples/CMakeLists.txt @@ -0,0 +1,22 @@ +############ +# EXAMPLES # +############ + +add_executable(test_cases main.cpp) +target_link_libraries(test_cases 4neuro exprtk) + +add_executable(neuron_serialization_example neuron_serialization_example.cpp) +target_link_libraries(neuron_serialization_example 4neuro) + +add_executable(net_test_1 net_test_1.cpp) +target_link_libraries(net_test_1 4neuro) + +add_executable(net_test_2 net_test_2.cpp) +target_link_libraries(net_test_2 4neuro) + +add_executable(net_test_3 net_test_3.cpp) +target_link_libraries(net_test_3 4neuro) + +add_executable(net_test_ode_1 net_test_ode_1.cpp) +target_link_libraries(net_test_ode_1 4neuro) + diff --git a/src/main.cpp b/src/examples/main.cpp similarity index 86% rename from src/main.cpp rename to src/examples/main.cpp index ebf1402d8999e9f5d2a6da3e020c2608699de3b9..8c461bb6f70f99845a66509693fd06121724f3e5 100644 --- a/src/main.cpp +++ b/src/examples/main.cpp @@ -6,12 +6,23 @@ */ #include <iostream> +#include <cstdio> +#include <fstream> #include <vector> +#include <utility> +#include <algorithm> #include <boost/archive/text_oarchive.hpp> +#include <boost/archive/text_iarchive.hpp> #include "Network/NeuralNetwork.h" #include "Neuron/NeuronLinear.h" +#include "Neuron/NeuronLogistic.h" +#include "NetConnection/Connection.h" +#include "NetConnection/ConnectionWeightIdentity.h" #include "LearningMethods/ParticleSwarm.h" +#include "Neuron/NeuronBinary.h" +#include "Neuron/NeuronTanh.h" +#include "DataSet/DataSet.h" //TODO rewrite "tests" to separate examples @@ -60,7 +71,20 @@ void test1( ){ /** * Test of DataSet serialization */ +std::vector<double> out_f(std::vector<double> v) { + double sum = 0; + for(auto& e : v) { + sum += e; + } + + std::vector<double> out{sum*2, sum*3, sum*4}; + return out; +} + void test3() { + + /* Manually created data set */ + std::cout << "Manually created data set" << std::endl; std::vector<std::pair<std::vector<double>, std::vector<double>>> data_vec; std::vector<double> inp, out; @@ -80,6 +104,19 @@ void test3() { DataSet ds2("stored_data.4ds"); ds2.print_data(); + + /* Isotropic data set */ + std::cout << "Isotropic data set:" << std::endl; + std::vector<double> bounds{0,3,0,2}; + + std::cout << "original one:" << std::endl; + DataSet ds3(bounds, 5, out_f, 3); + ds3.print_data(); + ds3.store_text("stored_data2.4ds"); + + std::cout << "loaded one:" << std::endl; + DataSet ds4("stored_data2.4ds"); + ds4.print_data(); } double particle_swarm_test_function(double *x){ @@ -216,6 +253,8 @@ void test_particle_swarm_neural_net(){ // swarm_01.optimize(0.5, accuracy); //} + + int main(int argc, char** argv){ // test1(); diff --git a/src/net_test_1.cpp b/src/examples/net_test_1.cpp similarity index 98% rename from src/net_test_1.cpp rename to src/examples/net_test_1.cpp index 0296612f0a72a73537d6828758adb98ec7f086ea..c2c5da152d078508b6d8e9739b601c1ca53593f5 100644 --- a/src/net_test_1.cpp +++ b/src/examples/net_test_1.cpp @@ -9,7 +9,7 @@ #include <vector> -#include "../include/4neuro.h" +#include "4neuro.h" int main() { @@ -81,4 +81,4 @@ int main() { swarm_01.optimize(0.5, 0.02); return 0; -} \ No newline at end of file +} diff --git a/src/net_test_2.cpp b/src/examples/net_test_2.cpp similarity index 100% rename from src/net_test_2.cpp rename to src/examples/net_test_2.cpp diff --git a/src/net_test_3.cpp b/src/examples/net_test_3.cpp similarity index 100% rename from src/net_test_3.cpp rename to src/examples/net_test_3.cpp diff --git a/src/net_test_ode_1.cpp b/src/examples/net_test_ode_1.cpp similarity index 100% rename from src/net_test_ode_1.cpp rename to src/examples/net_test_ode_1.cpp diff --git a/src/net_test_pde_1.cpp b/src/examples/net_test_pde_1.cpp similarity index 100% rename from src/net_test_pde_1.cpp rename to src/examples/net_test_pde_1.cpp diff --git a/src/neuron_serialization_example.cpp b/src/examples/neuron_serialization_example.cpp similarity index 98% rename from src/neuron_serialization_example.cpp rename to src/examples/neuron_serialization_example.cpp index e5f4436797dc0b23e04c0c84c48b7c0829b7dcd9..d2f3d99c92f389c438ed5c5bb5b31edb416dc8a3 100644 --- a/src/neuron_serialization_example.cpp +++ b/src/examples/neuron_serialization_example.cpp @@ -12,7 +12,7 @@ #include <boost/archive/text_oarchive.hpp> #include <boost/archive/text_iarchive.hpp> -#include "../include/4neuro.h" +#include "4neuro.h" int main() { NeuronLinear n(2, 3); @@ -120,4 +120,4 @@ int main() { << n8.activation_function_get_parameter(0) << std::endl; return 0; -} \ No newline at end of file +} diff --git a/src/exprtk.cpp b/src/exprtk.cpp new file mode 100644 index 0000000000000000000000000000000000000000..cb6a8ebb2adf7b00eeef1e85f498a71735d6004d --- /dev/null +++ b/src/exprtk.cpp @@ -0,0 +1,5 @@ +// +// Created by martin on 8/8/18. +// + +#include <exprtk.hpp> \ No newline at end of file diff --git a/src/tests/CMakeLists.txt b/src/tests/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..dfb26d9d69a87090bd1222cb9eccbeb9726e2200 --- /dev/null +++ b/src/tests/CMakeLists.txt @@ -0,0 +1,46 @@ +############## +# UNIT TESTS # +############## + +add_executable(neuron_test neuron_test.cpp) +target_link_libraries(neuron_test boost_unit_test 4neuro) + +add_executable(linear_neuron_test NeuronLinear_test.cpp) +target_link_libraries(linear_neuron_test boost_unit_test 4neuro) + +add_executable(binary_neuron_test NeuronBinary_test.cpp) +target_link_libraries(binary_neuron_test boost_unit_test 4neuro) + +add_executable(logistic_neuron_test NeuronLogistic_test.cpp) +target_link_libraries(logistic_neuron_test boost_unit_test 4neuro) + +add_executable(tanh_neuron_test NeuronTanh.cpp) +target_link_libraries(tanh_neuron_test boost_unit_test 4neuro) + +add_executable(connection_weight_test ConnectionWeight_test.cpp) +target_link_libraries(connection_weight_test boost_unit_test 4neuro) + +add_executable(connection_test Connection_test.cpp) +target_link_libraries(connection_test boost_unit_test 4neuro) + +add_executable(neural_network_test NeuralNetwork_test.cpp) +target_link_libraries(neural_network_test boost_unit_test 4neuro) + +add_executable(connection_weight_identity_test ConnectionWeightIdentity_test.cpp) +target_link_libraries(connection_weight_identity_test boost_unit_test 4neuro) + +add_executable(dataset_test DataSet_test.cpp) +target_link_libraries(dataset_test boost_unit_test 4neuro) + +add_executable(errorfunction_test ErrorFunctions_test.cpp) +target_link_libraries(errorfunction_test boost_unit_test 4neuro) + +add_executable(particle_swarm_test ParticleSwarm_test.cpp) +target_link_libraries(particle_swarm_test boost_unit_test 4neuro) + +add_executable(particle_test Particle_test.cpp) +target_link_libraries(particle_test boost_unit_test 4neuro) + +add_executable(NeuralNetworkSum_test NeuralNetworkSum_test.cpp) +target_link_libraries(NeuralNetworkSum_test boost_unit_test 4neuro) + diff --git a/src/tests/Connection_test.cpp b/src/tests/Connection_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..29635b515654b6b16b701e96b36521b223dc9f3a --- /dev/null +++ b/src/tests/Connection_test.cpp @@ -0,0 +1,7 @@ + /** + * DESCRIPTION OF THE FILE + * + * @author Michal KravÄenko + * @date 9.8.18 - + */ +