Commit 7b1432a3 authored by Martin Beseda's avatar Martin Beseda
Browse files

FIX + ENH

* Added missing 'return' statements to constructor in Doxygen comments
* 'sigmoid' neuron renamed to 'logistic'
* Logistic neurons' activation function changed to generalised logistic
function (added new constructor with 'alpha coefficient' parameter)
* Removed out-commented blocks of code with cancelled interconnection_t
dependencies
parent 0a00950a
......@@ -6,7 +6,6 @@
!! @author Martin Beseda
!! @author Martin Mrovec
!! @date 2017
!! @todo Write constructors for classes!
module neuron_m
use time_measurement_m
use normal_m
......@@ -26,10 +25,6 @@ module neuron_m
real :: potential !< Neuron inner potential
real :: state !< State of the neuron (0/1 for binary n. etc.)
!> Parent interconnection - to check, if all inputs have already been accepted
!! @todo move to connection_t
!class(interconnection_t), pointer :: parent_interconnection
integer :: id !< Neuron ID
contains
......@@ -56,10 +51,6 @@ module neuron_m
!! @return Neuron ID
procedure :: get_id => get_id_impl
!> Getter to the 'parent_interconnection'
!! @return Pointer to the parent interconnetion instance
!! @todo move to connection_t class!
!procedure :: get_parent_interconnection => get_parent_interconnection_impl
end type neuron_t
abstract interface
......@@ -94,6 +85,7 @@ module neuron_m
interface mock_neuron_t
!> Constructor of mock_neuron_t class
!! @return Returns pointer to the instance of the class mock_neuron_t
module procedure :: new_mock_neuron
end interface mock_neuron_t
......@@ -102,7 +94,6 @@ module neuron_m
!-----------------------!
!> Binary neuron class - uses unit-step as the activation function
!! @todo write constructor with random init of threshold
type, extends(neuron_t) :: binary_neuron_t
private
......@@ -121,11 +112,13 @@ module neuron_m
interface binary_neuron_t
!> Non-parametric constructor of binary_neuron_t class (threshold
!! will be initialized by a random number from Gaussian distribution)
!! will be initialized by a random number from Gaussian distribution)
!! @return Pointer to the instance of the class binary_neuron_t
module procedure :: new_binary_neuron
!> Parametric constructor of binary_neuron_t class
!! @param[in] threshold Threshold for the unit-step activation function
!! @return Pointer to the instance of the class binary_neuron_t
module procedure :: new_binary_neuron_1
end interface binary_neuron_t
......@@ -149,30 +142,44 @@ module neuron_m
interface linear_neuron_t
!> Non-parametric constructor of linear_neuron_t class - a coef. is 1, b coef. is 0
!! @return Pointer to the instance of the class linear_neuron_t
module procedure :: new_linear_neuron
!> Constructor of linear_neuron_t class
!! @param[in] a_coef a coef. of the linear activation function
!! @param[in] b_coef b coef. of the linear activation fucntion
!! @return Pointer to the instance of the class linear_neuron_t
module procedure :: new_linear_neuron_2
end interface linear_neuron_t
!--------------------------!-------------------------------------------------------------------
! class sigmoidal_neuron_t !
!--------------------------!
!-------------------------!--------------------------------------------------------------------
! class logistic_neuron_t !
!-------------------------!
!> Logistic neuron class - uses generalised logistic function as an activation function
!! in the form f(x) = (1 + e^(-x))^(-alpha),
!! 'x' being the neuron potential here
type, extends(neuron_t) :: logistic_neuron_t
real, private :: alpha_coef
!> Sigmoidal neuron class - uses sigmoid as an activation function
type, extends(neuron_t) :: sigmoidal_neuron_t
contains
!> Activation function - sigmoid
procedure, private :: activate => sigmoid_activate_impl
end type sigmoidal_neuron_t
!> Activation function - generalised logistic f.
procedure, private :: activate => logistic_activate_impl
end type logistic_neuron_t
interface logistic_neuron_t
!> Non-parametric constructor of logistic_neuron_t class
!! Alpha coefficient is set to 1
!! @return Pointer to the instance of the class logistic_neuron_t
module procedure :: new_logistic_neuron
interface sigmoidal_neuron_t
!> constructor of sigmoidal_neuron_t class
module procedure :: new_sigmoidal_neuron
end interface sigmoidal_neuron_t
!> Constructor of the logistic_neuron_t class
!! @param[in] alpha_coef Alpha coefficient in the logistic activation function
!! @return Pointer to the instance of the class logistic_neuron_t
module procedure :: new_logistic_neuron_1
end interface logistic_neuron_t
contains
!------------------------!---------------------------------------------------------------------
......@@ -295,6 +302,7 @@ module neuron_m
!--------------!
!> Constructor of mock_neuron_t class
!! @return Returns pointer to the instance of the class mock_neuron_t
function new_mock_neuron() result(new_obj)
type(mock_neuron_t), pointer :: new_obj
#ifdef TIME_PROFILING
......@@ -352,7 +360,8 @@ module neuron_m
!--------------!
!> Non-parametric constructor of binary_neuron_t class (threshold
!! will be initialized by a random number from Gaussian distribution)
!! will be initialized by a random number from Gaussian distribution)
!! @return Pointer to the instance of the class binary_neuron_t
function new_binary_neuron() result(new_obj)
type(binary_neuron_t), pointer :: new_obj
integer :: values(8)
......@@ -377,6 +386,7 @@ module neuron_m
!> Constructor of binary_neuron_t class
!! @param[in] threshold Threshold used by unit-step activation function
!! @return Pointer to the instance of the class binary_neuron_t
function new_binary_neuron_1(threshold) result(new_obj)
real, intent(in) :: threshold
type(binary_neuron_t), pointer :: new_obj
......@@ -428,6 +438,7 @@ module neuron_m
!--------------!
!> Non-parametric constructor of linear_neuron_t class - a coef. is 1, b coef. is 0
!! @return Pointer to the instance of the class linear_neuron_t
function new_linear_neuron() result(new_obj)
type(linear_neuron_t), pointer :: new_obj
#ifdef TIME_PROFILING
......@@ -449,6 +460,7 @@ module neuron_m
!> Constructor of linear_neuron_t class
!! @param[in] a_coef a coef. of the linear activation function
!! @param[in] b_coef b coef. of the linear activation fucntion
!! @return Pointer to the instance of the class linear_neuron_t
function new_linear_neuron_2(a_coef, b_coef) result(new_obj)
real, intent(in) :: a_coef
real, intent(in) :: b_coef
......@@ -489,17 +501,19 @@ module neuron_m
#endif
end subroutine identity_potential_activate_impl
!--------------------------!
! class sigmoidal_neuron_t !
!--------------------------!
!-------------------------!
! class logistic_neuron_t !
!-------------------------!
!--------------!-----------------------------------------------------------------------------
! Constructors !
!--------------!
!> constructor of sigmoidal_neuron_t class
function new_sigmoidal_neuron() result(new_obj)
type(sigmoidal_neuron_t), pointer :: new_obj
!> Non-parametric constructor of logistic_neuron_t class
!! Alpha coefficient is set to 1
!! @return Pointer to the instance of the class logistic_neuron_t
function new_logistic_neuron() result(new_obj)
type(logistic_neuron_t), pointer :: new_obj
#ifdef TIME_PROFILING
real :: start_time
call time_profiling_start(start_time)
......@@ -507,28 +521,49 @@ module neuron_m
allocate(new_obj)
call new_obj%init_components()
new_obj%alpha_coef = 1
#ifdef TIME_PROFILING
call time_profiling_stop(start_time, 'new_logistic_neuron')
#endif
end function new_logistic_neuron
!> Constructor of the logistic_neuron_t class
!! @param[in] alpha_coef Alpha coefficient in the logistic activation function
!! @return Pointer to the instance of the class logistic_neuron_t
function new_logistic_neuron_1(alpha_coef) result(new_obj)
real, intent(in) :: alpha_coef
type(logistic_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%alpha_coef = alpha_coef
#ifdef TIME_PROFILING
call time_profiling_stop(start_time, 'new_sigmoidal_neuron')
call time_profiling_stop(start_time, 'new_logistic_neuron_1')
#endif
end function new_sigmoidal_neuron
end function new_logistic_neuron_1
!----------------!---------------------------------------------------------------------------
! Common methods !
!----------------!
!> Activation function - sigmoid
subroutine sigmoid_activate_impl(this)
class(sigmoidal_neuron_t), intent(inout) :: this
!> Activation function - logistic function
subroutine logistic_activate_impl(this)
class(logistic_neuron_t), intent(inout) :: this
#ifdef TIME_PROFILING
real :: start_time
call time_profiling_start(start_time)
#endif
this%state = 1.0/(1.0 + exp(-1*this%potential))
this%state = (1.0 + exp(-1*this%potential))**(-1*this%alpha_coef)
#ifdef TIME_PROFILING
call time_profiling_stop(start_time, 'sigmoid_activate_impl')
call time_profiling_stop(start_time, 'logistic_activate_impl')
#endif
end subroutine sigmoid_activate_impl
end subroutine logistic_activate_impl
end module neuron_m
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