Commit abede07e authored by Martin Beseda's avatar Martin Beseda
Browse files

ENH: Implemented classes mock_neuron_t, binary_neuron_t, linear_neuron_t and...

ENH: Implemented classes mock_neuron_t, binary_neuron_t, linear_neuron_t and sigmoidal_neuron_t in the module neuron_m.
parent 234aa80c
......@@ -5,7 +5,6 @@ program connection_mem_leak_test
type(mock_neuron_t), pointer :: n1_p
type(mock_neuron_t), pointer :: n2_p
type(mock_neuron_t), pointer :: dummy_p
type(interval_connection_t), pointer :: con1, con2
......
!> Module containing classes representing neurons
!! in neural networks.
!!
!! It uses 'time_measurement_m' module.
!! It uses 'time_measurement_m' and 'normal_m' modules.
!!
!! @author Martin Beseda
!! @author Martin Mrovec
......@@ -9,6 +9,7 @@
!! @todo Write constructors for classes!
module neuron_m
use time_measurement_m
use normal_m
implicit none
......@@ -118,6 +119,16 @@ module neuron_m
end type binary_neuron_t
interface binary_neuron_t
!> Non-parametric constructor of binary_neuron_t class (threshold
!! will be initialized by a random number from Gaussian distribution)
module procedure :: new_binary_neuron
!> Parametric constructor of binary_neuron_t class
!! @param threshold Threshold for the unit-step activation function
module procedure :: new_binary_neuron_1
end interface binary_neuron_t
!-----------------------!----------------------------------------------------------------------
! class linear_neuron_t !
!-----------------------!
......@@ -130,6 +141,11 @@ module neuron_m
procedure, private :: activate => identity_potential_activate_impl
end type linear_neuron_t
interface linear_neuron_t
!> Constructor of linear_neuron_t class
module procedure :: new_linear_neuron
end interface linear_neuron_t
!--------------------------!-------------------------------------------------------------------
! class sigmoidal_neuron_t !
!--------------------------!
......@@ -142,6 +158,11 @@ module neuron_m
procedure, private :: activate => sigmoid_activate_impl
end type sigmoidal_neuron_t
interface sigmoidal_neuron_t
!> constructor of sigmoidal_neuron_t class
module procedure :: new_sigmoidal_neuron
end interface sigmoidal_neuron_t
contains
!------------------------!---------------------------------------------------------------------
! Method implementations !
......@@ -274,6 +295,8 @@ module neuron_m
!--------------!------------------------------------------------------------------------------
! Constructors !
!--------------!
!> Constructor of mock_neuron_t class
function new_mock_neuron() result(new_obj)
type(mock_neuron_t), pointer :: new_obj
#ifdef TIME_PROFILING
......@@ -325,7 +348,53 @@ module neuron_m
!-----------------------!
! class binary_neuron_t !
!-----------------------!
!--------------!-----------------------------------------------------------------------------
! Constructors !
!--------------!
!> Non-parametric constructor of binary_neuron_t class (threshold
!! will be initialized by a random number from Gaussian distribution)
function new_binary_neuron() result(new_obj)
type(binary_neuron_t), pointer :: new_obj
integer :: values(8)
#ifdef TIME_PROFILING
real :: start_time
call time_profiling_start(start_time)
#endif
allocate(new_obj)
call new_obj%init_components()
! Get current time and use milliseconds (values(8))
! as a seed
call date_and_time(values=values)
! Generate random number from Gaussian distribution
! and use it to initialize the component 'threshold'
new_obj%threshold = r4_normal_01(values(8))
#ifdef TIME_PROFILING
call time_profiling_stop(start_time, 'new_binary_neuron')
#endif
end function new_binary_neuron
!> Constructor of binary_neuron_t class
!! @param[in] threshold Threshold used by unit-step activation function
function new_binary_neuron_1(threshold) result(new_obj)
real, intent(in) :: threshold
type(binary_neuron_t), pointer :: new_obj
#ifdef TIME_PROFILING
real :: start_time
call time_profiling_start(start_time)
#endif
allocate(new_obj)
call new_obj%init_components()
new_obj%threshold = threshold
#ifdef TIME_PROFILING
call time_profiling_stop(start_time, 'new_binary_neuron_1')
#endif
end function new_binary_neuron_1
!----------------!---------------------------------------------------------------------------
! Common methods !
!----------------!
......@@ -355,7 +424,27 @@ module neuron_m
!-----------------------!
! class linear_neuron_t !
!-----------------------!
!--------------!-----------------------------------------------------------------------------
! Constructors !
!--------------!
!> Constructor of linear_neuron_t class
function new_linear_neuron() result(new_obj)
type(linear_neuron_t), pointer :: new_obj
#ifdef TIME_PROFILING
real :: start_time
call time_profiling_start(start_time)
#endif
allocate(new_obj)
call new_obj%init_components()
#ifdef TIME_PROFILING
call time_profiling_stop(start_time, 'new_linear_neuron')
#endif
end function new_linear_neuron
!----------------!---------------------------------------------------------------------------
! Common methods !
!----------------!
......@@ -379,6 +468,26 @@ module neuron_m
! class sigmoidal_neuron_t !
!--------------------------!
!--------------!-----------------------------------------------------------------------------
! Constructors !
!--------------!
!> constructor of sigmoidal_neuron_t class
function new_sigmoidal_neuron() result(new_obj)
type(sigmoidal_neuron_t), pointer :: new_obj
#ifdef TIME_PROFILING
real :: start_time
call time_profiling_start(start_time)
#endif
allocate(new_obj)
call new_obj%init_components()
#ifdef TIME_PROFILING
call time_profiling_stop(start_time, 'new_sigmoidal_neuron')
#endif
end function new_sigmoidal_neuron
!----------------!---------------------------------------------------------------------------
! Common methods !
!----------------!
......
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