diff --git a/.idea/4Neuro.iml b/.idea/4Neuro.iml new file mode 100644 index 0000000000000000000000000000000000000000..f08604bb65b25149b195f9e9f282f9683a428592 --- /dev/null +++ b/.idea/4Neuro.iml @@ -0,0 +1,2 @@ +<?xml version="1.0" encoding="UTF-8"?> +<module classpath="CMake" type="CPP_MODULE" version="4" /> \ No newline at end of file diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml new file mode 100644 index 0000000000000000000000000000000000000000..30aa626c23142d59e94cc76327172301f159b618 --- /dev/null +++ b/.idea/codeStyles/Project.xml @@ -0,0 +1,29 @@ +<component name="ProjectCodeStyleConfiguration"> + <code_scheme name="Project" version="173"> + <Objective-C-extensions> + <file> + <option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Import" /> + <option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Macro" /> + <option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Typedef" /> + <option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Enum" /> + <option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Constant" /> + <option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Global" /> + <option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Struct" /> + <option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="FunctionPredecl" /> + <option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Function" /> + </file> + <class> + <option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Property" /> + <option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Synthesize" /> + <option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="InitMethod" /> + <option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="StaticMethod" /> + <option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="InstanceMethod" /> + <option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="DeallocMethod" /> + </class> + <extensions> + <pair source="cpp" header="h" fileNamingConvention="NONE" /> + <pair source="c" header="h" fileNamingConvention="NONE" /> + </extensions> + </Objective-C-extensions> + </code_scheme> +</component> \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000000000000000000000000000000000000..8822db8f1c2b8ceffb5d86c69dd1952cf6552980 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="CMakeWorkspace" PROJECT_DIR="$PROJECT_DIR$" /> + <component name="JavaScriptSettings"> + <option name="languageLevel" value="ES6" /> + </component> +</project> \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000000000000000000000000000000000000..66b9c130f08e9bd0253185a5e3f5aed105412a77 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="ProjectModuleManager"> + <modules> + <module fileurl="file://$PROJECT_DIR$/.idea/4Neuro.iml" filepath="$PROJECT_DIR$/.idea/4Neuro.iml" /> + </modules> + </component> +</project> \ No newline at end of file diff --git a/.idea/usage.statistics.xml b/.idea/usage.statistics.xml new file mode 100644 index 0000000000000000000000000000000000000000..901600e288acfe196f0a6d47ceed4749802b0bb1 --- /dev/null +++ b/.idea/usage.statistics.xml @@ -0,0 +1,37 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="FUSProjectUsageTrigger"> + <session id="-930103607"> + <usages-collector id="statistics.file.extensions.open"> + <counts> + <entry key="Makefile" value="1" /> + <entry key="cpp" value="1" /> + <entry key="f90" value="1" /> + <entry key="h" value="1" /> + <entry key="txt" value="2" /> + </counts> + </usages-collector> + <usages-collector id="statistics.file.types.open"> + <counts> + <entry key="CMakeLists.txt" value="2" /> + <entry key="ObjectiveC" value="2" /> + <entry key="PLAIN_TEXT" value="2" /> + </counts> + </usages-collector> + <usages-collector id="statistics.file.extensions.edit"> + <counts> + <entry key="cpp" value="478" /> + <entry key="h" value="1861" /> + <entry key="txt" value="74" /> + </counts> + </usages-collector> + <usages-collector id="statistics.file.types.edit"> + <counts> + <entry key="CMakeLists.txt" value="74" /> + <entry key="Doxygen file" value="27" /> + <entry key="ObjectiveC" value="2312" /> + </counts> + </usages-collector> + </session> + </component> +</project> \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000000000000000000000000000000000000..94a25f7f4cb416c083d265558da75d457237d671 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="VcsDirectoryMappings"> + <mapping directory="$PROJECT_DIR$" vcs="Git" /> + </component> +</project> \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 12cf163567d1383c7f2d8c826b030652d9eb9b87..8472e15738c91117fcef6088e410df7e164dae89 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,8 @@ cmake_minimum_required(VERSION 3.0) +project(NeuronLib) +set (NeuronLib_VERSION_MAJOR 0) +set (NeuronLib_VERSION_MINOR 1) + message ("Before enable language") enable_language(Fortran) if (WIN32) @@ -28,12 +32,10 @@ if (NOT CMAKE_BUILD_TYPE) endif (NOT CMAKE_BUILD_TYPE) #--------------------------------# -# Setting Fortran compiler flags # +# Setting C++ compiler flags # #--------------------------------# -# TODO overit, jak rychle jede kod s funroll-loops -# funroll-all-loops a bez prepinace -set(standard "-std=f2008") +set(standard "-std=c++17") #--------------------# # Automatic settings # @@ -62,26 +64,7 @@ message ("CMAKE_Fortran_COMPILER full path: " ${CMAKE_Fortran_COMPILER}) message ("Fortran compiler: " ${Fortran_COMPILER_NAME}) message ("Build type:" ${CMAKE_BUILD_TYPE}) -if (Fortran_COMPILER_NAME MATCHES "gfortran.*") - # gfortran - set (CMAKE_Fortran_FLAGS_RELEASE "-funroll-loops -fno-f2c -O3 ${standard} -cpp") - set (CMAKE_Fortran_FLAGS_DEBUG "-fno-f2c -O0 -g ${standard} -cpp -fimplicit-none -Wall -pedantic -fcheck=all -fbacktrace") -elseif (Fortran_COMPILER_NAME MATCHES "f95") - set (CMAKE_Fortran_FLAGS_RELEASE "-funroll-loops -fno-f2c -O3 ${standard} -cpp") - set (CMAKE_Fortran_FLAGS_DEBUG "-fno-f2c -O0 -g ${standard} -cpp -fimplicit-none -Wall -pedantic -fcheck=all -fbacktrace") -elseif (Fortran_COMPILER_NAME MATCHES "ifort.*") - # ifort (untested) - set (CMAKE_Fortran_FLAGS_RELEASE "-f77rtl -O3 ${standard} -cpp") - set (CMAKE_Fortran_FLAGS_DEBUG "-f77rtl -O0 -g ${standard} -cpp -fimplicit-none -Wall -pedantic -fcheck=all -fbacktrace") -elseif (Fortran_COMPILER_NAME MATCHES "g77") - # g77 - set (CMAKE_Fortran_FLAGS_RELEASE "-funroll-loops -fno-f2c -O3 -m32 ${standard} -cpp") - set (CMAKE_Fortran_FLAGS_DEBUG "-fno-f2c -O0 -g -m32 ${standard} -cpp -fimplicit-none -Wall -pedantic -fcheck=all -fbacktrace") -else (Fortran_COMPILER_NAME MATCHES "gfortran.*") - message ("No optimized Fortran compiler flags are known, we just try -O2 and we DO NOT support directives preprocessing (i.e. all conditional blocks will be compiled)...") - set (CMAKE_Fortran_FLAGS_RELEASE "-O2 ${standard}") - set (CMAKE_Fortran_FLAGS_DEBUG "-O0 -g ${standard} -Wall -pedantic -fcheck=all") -endif (Fortran_COMPILER_NAME MATCHES "gfortran.*") + #----------------# # User variables # @@ -103,22 +86,11 @@ message ("BUILD_DIR:" ${BUILD_DIR}) message ("LIB_DIR: " ${LIB_DIR}) if (WIN32) - add_executable(connection_m_mem_leak_test ${SRC_DIR}/connection_m_mem_leak_test.f90) - target_link_libraries(connection_m_mem_leak_test connection_m) - add_executable(net_m_mem_leak_test ${SRC_DIR}/net_m_mem_leak_test.f90) - target_link_libraries(net_m_mem_leak_test net_m) message ("Windows") else () - add_executable(connection_m_mem_leak_test.out ${SRC_DIR}/connection_m_mem_leak_test.f90) - target_link_libraries(connection_m_mem_leak_test.out connection_m) - - #add_executable(net_m_mem_leak_test.out ${SRC_DIR}/net_m_mem_leak_test.f90) - #target_link_libraries(net_m_mem_leak_test.out net_m) - add_executable(neuron_m_mem_leak_test.out ${SRC_DIR}/neuron_m_mem_leak_test.f90) - target_link_libraries(neuron_m_mem_leak_test.out neuron_m) message ("Not Windows") endif () diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index c433c1d275e57c3206115f092f3dbccfc23fb237..4457cf05e3aa7d848671580c741d6879d5517a08 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,30 +1,3 @@ -project(Modules) -enable_language(Fortran) -set_property(GLOBAL PROPERTY LINKER_LANGUAGE Fortran) - - -add_library(abstract_base_m SHARED abstract_base_m.f90) - -add_library(normal_m SHARED normal_m.f90) - -add_library(data_kinds_4neuro_m SHARED data_kinds_4neuro_m.f90) - -add_library(container_m SHARED container_m.f90) -target_link_libraries(container_m abstract_base_m data_kinds_4neuro_m abstract_base_m) - -add_library(time_measurement_m SHARED time_measurement_m.f90) -target_link_libraries(time_measurement_m data_kinds_4neuro_m abstract_base_m) - -add_library(neuron_m SHARED neuron_m.f90) -target_link_libraries(neuron_m time_measurement_m normal_m abstract_base_m) - -add_library(connection_m SHARED connection_m.f90) -target_link_libraries(connection_m neuron_m time_measurement_m normal_m abstract_base_m container_m) - -#add_library(interconnection_m SHARED net_m.f90) -#target_link_libraries(interconnection_m data_kinds_4neuro_m time_measurement_m abstract_base_m) - -#add_library(net_m SHARED net_m.f90) -#target_link_libraries(net_m interconnection_m data_kinds_4neuro_m time_measurement_m neuron_m connection_m abstract_base_m container_m) +add_library(${SRC_DIR} neuron.cpp) diff --git a/src/neuron.cpp b/src/neuron.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f2a8a473af4d2bc844a63f4d5ab2e5992ce378ab --- /dev/null +++ b/src/neuron.cpp @@ -0,0 +1,45 @@ + +#include "neuron.h" + +Neuron::~Neuron() { + if(this->activation_function_parameters){ + delete [] this->activation_function_parameters; + this->activation_function_parameters = nullptr; + } +} + +void Neuron::adjust_potential(double input_signal) { + this->potential += input_signal; +} + +double Neuron::get_potential() { + return this->potential; +} + +void Neuron::set_potential(double value) { + this->potential = value; +} + +double Neuron::get_state() { + return this->state; +} + +void Neuron::set_state(double value) { + this->state = value; +} + +int Neuron::activation_function_get_n_parameters(){ + return this->n_activation_function_parameters; +} + +void Neuron::activation_function_adjust_parameter(int param_idx, double value) { + this->activation_function_parameters[param_idx] += value; +} + +void Neuron::activation_function_set_parameter(int param_idx, double value) { + this->activation_function_parameters[param_idx] = value; +} + +double Neuron::activation_function_get_parameter(int param_idx) { + return this->activation_function_parameters[param_idx]; +} \ No newline at end of file diff --git a/src/neuron.h b/src/neuron.h new file mode 100644 index 0000000000000000000000000000000000000000..08ae745ac4434e8a9db61e7df25fc0cde041d870 --- /dev/null +++ b/src/neuron.h @@ -0,0 +1,125 @@ +#ifndef NEURON_H_ +#define NEURON_H_ + + /** + * Module containing classes representing neurons + * in neural networks. + * + * @author Martin Beseda + * @author Martin Mrovec + * @author Michal KravÄŤenko + * @date 2017 - 2018 + */ + + + /** + * Abstract class representing a general neuron + */ +class Neuron{ + +private: + /** + * Inner potential of the neuron (input of the activation function) + */ + double potential = 0.0; + + /** + * State of the neuron (output of the activation function) + */ + double state = 0.0; + + /** + * array of the activation function parameters + */ + double *activation_function_parameters = nullptr; + + /** + * Number of parameters of the activation function + */ + int n_activation_function_parameters = 0; + +public: + + /** + * Destructor of the Neuron object + * this level deallocates the array 'activation_function_parameters' + */ + virtual ~Neuron(); + + /** + * Performs the activation function and stores the result into the 'state' property + */ + virtual void activate() = 0; + + /** + * Adds the input signal value to the current potential + * @param[in] input_signal Input value + */ + virtual void adjust_potential(double input_signal); + + /** + * Getter to the 'potential' property + * @return Value of the neuron's potential (real number) + */ + virtual double get_potential(); + + /** + * Setter to the 'potential' property + * @param value Value of the neuron's potential (real number) + */ + virtual void set_potential(double value); + + /** + * Getter to the 'state' property + * @return Value of the current neuron's state + */ + virtual double get_state(); + + /** + * Setter to the 'state' component + * @param value Value of the current neuron's state + */ + virtual void set_state(double value); + + /** + * Returns the number of parameters the activation function relies on + * @return Number of the parameters + */ + virtual int activation_function_get_n_parameters(); + + /** + * Calculates the partial derivative of the activation function + * with respect to the parameter and the current potential + * @param param_idx Index of the parameter to calculate derivative of + * @return Partial derivative of the activation function according to the + * 'param_idx'-th parameter + */ + virtual double activation_function_get_partial_derivative(int param_idx) = 0; + + /** + * Adjusts the parameter with index 'param_idx' of the activation function + * by the value prescribed by 'value' + * @param param_idx Index of the parameter to be adjusted + * @param value Value of the adjustment + */ + virtual void activation_function_adjust_parameter(int param_idx, double value); + + /** + * Sets the parameter with index 'param_idx' of the activation function + * to the value prescribed by 'value' + * @param param_idx + * @param value + */ + virtual void activation_function_set_parameter(int param_idx, double value); + + /** + * Gets the parameter with index 'param_idx' of the activation function + * @param param_idx + */ + virtual double activation_function_get_parameter(int param_idx); + + +}; /* end of Neuron class */ + + +#endif /* NEURON_H_ */ \ No newline at end of file