Commit b25cd750 authored by bes0030's avatar bes0030
Browse files

Merge branch 'dev' of code.it4i.cz:bes0030/4Neuro into dev

parents 8cd9b6c1 c4b02587
......@@ -6,3 +6,6 @@
compilers.env
*TestRunner*
*_fun.f90
src/funit.tmp
*.swp
/Release/
......@@ -105,10 +105,18 @@ 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)
message ("Not Windows")
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)
message ("Not Windows")
endif ()
......@@ -2375,7 +2375,7 @@ DOT_IMAGE_FORMAT = png
# The default value is: NO.
# This tag requires that the tag HAVE_DOT is set to YES.
INTERACTIVE_SVG = NO
INTERACTIVE_SVG = YES
# The DOT_PATH tag can be used to specify the path where the dot tool can be
# found. If left blank, it is assumed the dot tool can be found in the path.
......
......@@ -11,7 +11,7 @@
BUILD_TYPE=Debug
# Turn of/off time profiling (1/0)
WITH_TIME_PROFILING=0
WITH_TIME_PROFILIN=1
#--------------#----------------------------------------------------------
# Library path #
......@@ -27,7 +27,7 @@ echo ${LIB_PATH}
case `uname -s` in
Darwin)
echo 'OS X not supported! Buy a normal computer, please.'
echo 'OS X is not supported yet...'
exit -1
;;
......
echo "Generating documentation into folder 'docs'...";
doxygen >/dev/null && echo "Documenation was generated." || exit -1;
doxygen 2>&1 >/dev/null | grep -v 'normal_m.f90' && echo "Documenation was generated." || exit -1;
cd docs/latex;
echo "Building LaTeX documentation../";
make >/dev/null && echo "Documentation was built." || exit -1;
......
......@@ -4,3 +4,4 @@ rm -rf build
rm -rf docs/*
rm -f src/*TestRunner*
rm -f src/*.o src/*.mod
rm -f src/funit.tmp src/*_fun.f90
......@@ -10,13 +10,20 @@ echo "#------------------#"
FUNIT_SCRIPTS=connection_m
cd src;
for F in ${FUNIT_SCRIPTS}; do
funit ${F};
TEST_STATUS=0;
funit ${F} || TEST_STATUS=1;
if [[ TEST_STATUS -gt 0 ]]; then
echo "ERROR: Unit test failed!"
exit -1;
fi
done
echo "#---------------------#-------------------------------------------------------------------------------"
echo "# Memcheck testing... #"
echo "#---------------------#"
MEM_TEST_SCRIPTS=connection_m_mem_leak_test.out
MEM_TEST_SCRIPTS=connection_m_mem_leak_test.out net_m_mem_leak_test.out
cd ../build;
......
project(Modules)
enable_language(Fortran)
add_library(neuron_dummy_m SHARED neuron_dummy_m.f90)
set_target_properties(neuron_dummy_m PROPERTIES LINKER_LANGUAGE Fortran)
set_property(GLOBAL PROPERTY LINKER_LANGUAGE Fortran)
add_library(time_measurement_m SHARED time_measurement_m.f90)
set_target_properties(time_measurement_m PROPERTIES LINKER_LANGUAGE Fortran)
add_library(abstract_base_m SHARED abstract_base_m.f90)
add_library(normal_m SHARED normal_m.f90)
set_target_properties(normal_m PROPERTIES LINKER_LANGUAGE Fortran)
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)
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)
set_target_properties(connection_m PROPERTIES LINKER_LANGUAGE Fortran)
target_link_libraries(connection_m neuron_dummy_m time_measurement_m normal_m)
target_link_libraries(connection_m neuron_m time_measurement_m normal_m abstract_base_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)
!> Module containing a class abstract_base_t, which is a parental
!! class for all other classes in 4neuro. It makes creating a
!! common container for all classes possible.
!!
!! @author Martin Beseda
!! @date 2018
module abstract_base_m
implicit none
public
!------------------!-----------------------------------------
! Type definitions !
!------------------!
!-----------------------!------------------------------------
! class abstract_base_t !
!-----------------------!
!> Abstract class covering all the other classes in 4neuro
type, abstract :: abstract_base_t
end type
end module abstract_base_m
This diff is collapsed.
!> Unit test suite for connections (synapses)
!! in neural networks.
!!
!! @author Martin Beseda
!! @author Martin Mrovec
!! @date 2017
test_suite connection_m
! Global variables declaration
type(neuron_t), target :: n1
type(neuron_t), target :: n2
type(neuron_t), pointer :: n1_p
type(neuron_t), pointer :: n2_p
type(neuron_t), pointer :: dummy_p
type(connection_t), pointer :: con
!------------------------!---------------------------------------------------------------
! Setup before each test !
!------------------------!
setup
write(*,*) '+------------------------+'
write(*,*) '| SETUP BEFORE UNIT TEST |'
write(*,*) '+------------------------+'
write(*,*) 'Creating instances of the class neuron_t...'
n1 = neuron_t(21.3)
n2 = neuron_t(13.7)
write(*,*) 'Assigning instances to pointer...'
n1_p => n1
n2_p => n2
write(*,*) 'Creating an instance of the class interval_connection_t...'
con => connection_t(n1_p, n2_p, 5.25)
nullify(dummy_p)
write(*,*) 'Ready for test.'
end setup
!-------------------------!--------------------------------------------------------------
! Cleanup after each test !
!-------------------------!
teardown
write(*,*) '+-------------------------+'
write(*,*) '| CLEANUP AFTER UNIT TEST |'
write(*,*) '+-------------------------+'
write(*,*) 'Deallocating everything.'
deallocate(con)
nullify(dummy_p)
write(*,*) 'Cleaned succesfully.'
end teardown
!-------!--------------------------------------------------------------------------------
! Tests !
!-------!
!-----------------------------!
! Test of getters and setters !
!-----------------------------!
test getters_setters
write(*,*) '+++ Test of getters and setters ...'
! Test of get_weight
assert_real_equal(con%get_weight(), 5.25e+0)
! Test of adjust_weight
call con%adjust_weight(1.0)
assert_real_equal(con%get_weight(), 6.25e+0)
write(*,*) '... finished +++'
end test
!----------------------------------!
! Test of input and output neurons !
!----------------------------------!
test input_and_output_neurons
write(*,*) '+++ Test of input and output neurons ...'
! Input neuron
dummy_p => con%get_input_neuron()
assert_real_equal(dummy_p%get_state(),21.3d+0)
! Output neuron
dummy_p => con%get_output_neuron()
assert_real_equal(dummy_p%get_state(),13.7d+0)
write(*,*) '... finished +++'
end test
!--------------------------!
! Test of passing a signal !
!--------------------------!
test pass_signal
write(*,*) '+++ Test of passing a signal ...'
dummy_p => con%get_output_neuron()
call con%pass_signal()
assert_real_equal(dummy_p%get_state(), 111.825d+0)
write(*,*) '... finished +++'
end test
end test_suite
!> Unit test suite for connections (synapses)
!! in neural networks.
!!
!! @author Martin Beseda
!! @author Martin Mrovec
!! @date 2017
test_suite connection_m
! Global variables declaration
class(neuron_t), pointer :: n1_p
class(neuron_t), pointer :: n2_p
class(neuron_t), pointer :: dummy_p
type(connection_t), pointer :: con
!------------------------!---------------------------------------------------------------
! Setup before each test !
!------------------------!
setup
write(*,*) '+------------------------+'
write(*,*) '| SETUP BEFORE UNIT TEST |'
write(*,*) '+------------------------+'
write(*,*) 'Creating instances of the class mock_neuron_t...'
n1_p => mock_neuron_t()
n2_p => mock_neuron_t()
write(*,*) 'Creating an instance of the class interval_connection_t...'
con => connection_t(n1_p, n2_p, real(5.25, real_4neuro))
nullify(dummy_p)
write(*,*) 'Ready for test.'
end setup
!-------------------------!--------------------------------------------------------------
! Cleanup after each test !
!-------------------------!
teardown
write(*,*) '+-------------------------+'
write(*,*) '| CLEANUP AFTER UNIT TEST |'
write(*,*) '+-------------------------+'
write(*,*) 'Deallocating everything.'
deallocate(con)
nullify(dummy_p)
write(*,*) 'Cleaned succesfully.'
end teardown
!-------!--------------------------------------------------------------------------------
! Tests !
!-------!
!-----------------------------!
! Test of getters and setters !
!-----------------------------!
test getters_setters
write(*,*) '+++ Test of getters and setters ...'
! Test of get_weight
assert_real_equal(con%get_weight(), 5.25e+0)
! Test of adjust_weight
call con%adjust_weight(real(1.0, real_4neuro))
assert_real_equal(con%get_weight(), 6.25e+0)
write(*,*) '... finished +++'
end test
!----------------------------------!
! Test of input and output neurons !
!----------------------------------!
test input_and_output_neurons
write(*,*) '+++ Test of input and output neurons ...'
! Input neuron
dummy_p => con%get_input_neuron()
assert_real_equal(dummy_p%get_state(),15.0e+0)
! Output neuron
dummy_p => con%get_output_neuron()
assert_real_equal(dummy_p%get_state(),15.0e+0)
write(*,*) '... finished +++'
end test
!--------------------------!
! Test of passing a signal !
!--------------------------!
test pass_signal
write(*,*) '+++ Test of passing a signal ...'
dummy_p => con%get_output_neuron()
call con%pass_signal()
assert_real_equal(dummy_p%get_potential(), 78.75e+0)
write(*,*) '... finished +++'
end test
end test_suite
program connection_mem_leak_test
use connection_m
use neuron_dummy_m
use neuron_m
use normal_m
use data_kinds_4neuro_m
type(neuron_t), target :: n1
type(neuron_t), target :: n2
type(neuron_t), pointer :: n1_p
type(neuron_t), pointer :: n2_p
type(neuron_t), pointer :: dummy_p
type(interval_connection_t), pointer :: con1, con2
type(mock_neuron_t), target :: n1, n2
type(mock_neuron_t), pointer :: n1_p, n2_p
type(connection_t) :: con1, con2
print *, '+---------------------------------------------------------+'
print *, '| STARTING MEMORY LEAK TESTING OF THE MODULE CONNECTION_M |'
print *, '+---------------------------------------------------------+'
print *, 'Creating instances of the class neuron_t...'
n1 = neuron_t(21.3)
n2 = neuron_t(13.7)
print *, 'neuron_t instances were created successfully.'
n1 = mock_neuron_t()
n2 = mock_neuron_t()
print *, 'Assigning instances to pointer...'
n1_p => n1
n2_p => n2
print *, 'Assignment was successful.'
print *, 'Creating an instance of the class interval_connection_t with 3-parameters constructor...'
con1 => interval_connection_t(input_neuron=n1_p, &
output_neuron=n2_p,&
weight=5.25)
print *, 'Creating an instance of the class interval_connection_t with 2-parameters constructor...'
con2 => interval_connection_t(input_neuron=n1_p, output_neuron=n2_p)
con2 = connection_t(input_neuron=n1_p, output_neuron=n2_p)
print *, 'Creating an instance of the class interval_connection_t with 3-parameters constructor...'
con1 = connection_t(input_neuron=n1_p, output_neuron=n2_p, weight=real(5.25, real_4neuro))
deallocate(con1)
deallocate(con2)
end program connection_mem_leak_test
!> Module containing declaration of a container type 'container_t'.
!! This class "wraps" pointers, so it's possible to store them
!! into arrays.
!!
!! @author Martin Beseda
!! @date 2018
module container_m
use abstract_base_m
use data_kinds_4neuro_m
implicit none
public
!> Represents a container for a single container_t pointer
type :: container_t
! Variable content is public to make usage of this class with one
! specific purpose as simple as possible.
class(abstract_base_t), pointer, public :: content
contains
!> Scalar desctructor for single instances of the class container_t
final :: destroy_container
!> Array desctructor for arrays of instances of the class container_t
final :: destroy_container_array
end type container_t
interface container_t
!> Constructor of container_t class
!! @return Instance of the class container_t with nullified content
module procedure :: new_container_empty
!> Constructor of container_t class
!! @param[in] content_in container to be contained (pointer)
!! @return Pointer to the instance of the class container_t with assigned content
module procedure :: new_container_assigned
end interface container_t
contains
!--------------!------------------------------------------------------------------------
! Constructors !
!--------------!
!> Constructor of container_t class
!! @return Instance of the class container_t with nullified content
function new_container_empty() result(new_obj)
type(container_t), pointer :: new_obj
#ifdef TIME_PROFILING
real :: start_time
call time_profiling_start(start_time)
#endif
allocate(new_obj)
new_obj%content => null()
#ifdef TIME_PROFILING
call time_profiling_stop(start_time, 'new_container_empty')
#endif
end function new_container_empty
!> Constructor of container_t class
!! @param[in] content_in connection to be contained (pointer)
!! @return Pointer to the instance of the class connection_t with assigned content
function new_container_assigned(content_in) result(new_obj)
class(abstract_base_t), pointer, intent(in) :: content_in
class(container_t), pointer :: new_obj
#ifdef TIME_PROFILING
real :: start_time
call time_profiling_start(start_time)
#endif
allocate(new_obj)
new_obj%content => content_in
#ifdef TIME_PROFILING
call time_profiling_stop(start_time, 'new_container_assigned')
#endif
end function new_container_assigned
!--------------!------------------------------------------------------------------------
! Destructors !
!--------------!
!> Scalar desctructor for single instances of the class container_t
subroutine destroy_container(this)
type(container_t), intent(inout) :: this
#ifdef TIME_PROFILING
real :: start_time
call time_profiling_start(start_time)
#endif
nullify(this%content)
#ifdef TIME_PROFILING
call time_profiling_stop(start_time, 'destroy_container')
#endif
end subroutine destroy_container
!> Array desctructor for arrays of instances of the class container_t
subroutine destroy_container_array(this)
type(container_t), intent(inout) :: this(:)
integer(kind=integer_4neuro) :: i
#ifdef TIME_PROFILING
real :: start_time
call time_profiling_start(start_time)
#endif
do i = 1, size(this)
nullify(this(i)%content)
end do
#ifdef TIME_PROFILING
call time_profiling_stop(start_time, 'destroy_container_array')
#endif
end subroutine destroy_container_array
end module container_m
#define SINGLE 4
#define DOUBLE 8
# define PREC DOUBLE
module data_kinds_4neuro_m
integer, parameter :: integer_4neuro = PREC
integer, parameter :: real_4neuro = PREC
end module data_kinds_4neuro_m
!> Module containing classes representing the whole
!! neural network.
!!
!! It uses 'neuron_m' module.
!!
!! @author Martin Beseda
!! @date 2018
module net_m
use data_kinds_4neuro_m
use time_measurement_m
use neuron_m
use connection_m
use container_m
implicit none
public
!-------------!------------------------------------------------------------------------------
! class net_t !
!-------------!
!> Class representing a general network
type :: net_t
private
character(:), allocatable :: net_type !< Type of the net
integer(kind=integer_4neuro) :: num_of_neurons !< Number of neurons in the net
character(:), allocatable :: training_method !< Used training method
class(neuron_t), allocatable :: neuron_arr(:) !< Array containing all neurons
integer(kind=integer_4neuro), allocatable :: input_neuron_arr(:) !< Array of input neuron indices
integer(kind=integer_4neuro), allocatable :: output_neuron_arr(:) !< Array of output neuron indices
class(connection_t), allocatable :: connection_arr(:) !< Array of all connections
contains
!> Prints information about the network to the standard output.
procedure :: print_info => print_info_impl
!> Saves the network instance to the Fortran binary file
procedure :: save_net_bin => save_net_bin_impl
!> Implementation of write function enabling the storage of
!! allocatable arrays.
procedure :: write_sample => write_sample_impl
!> Implementation of read function enabling to read
!! the whole instance of net_t stored as binary file.
procedure :: read_sample => read_sample_impl
generic :: write(unformatted) => write_sample
generic :: read(unformatted) => read_sample
end type net_t
interface net_t
!> Constructor of net_t class
!! Loads complete info about network from file
!! @param[in] filepath Path to the file with network configuration
!! @return An instance of the class net_t
module procedure :: new_net_1
end interface net_t
!------------------!---------------------------------------------------------------------
! class mock_net_t !
!------------------!
!> Mock net_t class
type, extends(net_t) :: mock_net_t
end type mock_net_t
interface mock_net_t
!> Non-parametric constructor of mock_net_t class
!! @return An instance of the class mock_net_t
module procedure :: new_mock_net
end interface mock_net_t
contains
!------------------------!---------------------------------------------------------------
! Method implementations !
!------------------------!
!-------------!--------------------------------------------------------------------------
! class net_t !
!-------------!
!--------------!-------------------------------------------------------------------------
! Constructors !
!--------------!
!> Constructor of net_t class
!! Loads complete info about network from Fortran binary file
!! @param[in] filepath Path to the JSON file with network configuration
!! @return An instance of the class net_t
function new_net_1(filepath) result(new_obj)
character(len=*), intent(in) :: filepath
type(net_t) :: new_obj
character(len=50) :: str !TODO udelat dynamicky, ne s fixni delkou
#ifdef TIME_PROFILING
real :: start_time</