Commit 1c5d9cea authored by Michal Kravcenko's avatar Michal Kravcenko
Browse files

added the mother class for the Neuron object

parent fed66e14
<?xml version="1.0" encoding="UTF-8"?>
<module classpath="CMake" type="CPP_MODULE" version="4" />
\ No newline at end of file
<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
<?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
<?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
<?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
<?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
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 ()
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)
#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
#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
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment