Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
lib4neuro
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
MolDyn
lib4neuro
Commits
296713ea
Commit
296713ea
authored
7 years ago
by
Martin Beseda
Browse files
Options
Downloads
Patches
Plain Diff
ENH: Added classes for neurons with tanh and arctan activation functions.
parent
9479e6a1
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/data_kinds_4neuro_m.f90
+7
-2
7 additions, 2 deletions
src/data_kinds_4neuro_m.f90
src/neuron_m.f90
+128
-4
128 additions, 4 deletions
src/neuron_m.f90
with
135 additions
and
6 deletions
src/data_kinds_4neuro_m.f90
+
7
−
2
View file @
296713ea
#define SINGLE 4
#define DOUBLE 8
# define PREC DOUBLE
module
data_kinds_4neuro_m
integer
,
parameter
::
integer_4neuro
=
8
integer
,
parameter
::
real_4neuro
=
8
integer
,
parameter
::
integer_4neuro
=
PREC
integer
,
parameter
::
real_4neuro
=
PREC
end
module
data_kinds_4neuro_m
This diff is collapsed.
Click to expand it.
src/neuron_m.f90
+
128
−
4
View file @
296713ea
...
...
@@ -99,7 +99,6 @@ module neuron_m
real
(
kind
=
real_4neuro
)
::
threshold
!< When neuron potential exceeds this value, neuron becomes excited
contains
!> Activation function - transforms potential into the output state value
...
...
@@ -132,8 +131,8 @@ module neuron_m
private
!! Coefficients for the linear activation function in format 'f(x)=a*x + b'
real
(
kind
=
real_4neuro
)
::
a_coef
!
>
The coefficient 'a' in the activation function f(x)=a*x + b
real
(
kind
=
real_4neuro
)
::
b_coef
!
>
The coefficient 'b' in the activation function f(x)=a*x + b
real
(
kind
=
real_4neuro
)
::
a_coef
!
<
The coefficient 'a' in the activation function f(x)=a*x + b
real
(
kind
=
real_4neuro
)
::
b_coef
!
<
The coefficient 'b' in the activation function f(x)=a*x + b
contains
...
...
@@ -163,7 +162,7 @@ module neuron_m
type
,
extends
(
neuron_t
)
::
logistic_neuron_t
private
real
(
kind
=
real_4neuro
)
::
alpha_coef
real
(
kind
=
real_4neuro
)
::
alpha_coef
!< The alpha coefficient used in the activation function
contains
...
...
@@ -183,6 +182,38 @@ module neuron_m
module
procedure
::
new_logistic_neuron_1
end
interface
logistic_neuron_t
!---------------------!------------------------------------------------------------------------
! class tanh_neuron_t !
!---------------------!
!> Hyperbolic tangent neuron class - uses f(x) = (e^x - e^(-x))/(e^x + e^(-x)) as
!! an activation function, 'x' being the neuron potential.
type
,
extends
(
neuron_t
)
::
tanh_neuron_t
contains
!> Activation function - hyperbolic tangent
procedure
,
private
::
activate
=>
hyperbolic_tangent_activate_impl
end
type
tanh_neuron_t
interface
tanh_neuron_t
!> Constructor for an instance of the class tanh_neuron_t
module
procedure
::
new_tanh_neuron
end
interface
tanh_neuron_t
!> Arcus tangents neuron class - uses f(x)=tan^(-1)(x) as an
!! activation function, 'x' being the neuron potential
type
,
extends
(
neuron_t
)
::
arctan_neuron_t
contains
!> Activation function - arcus tangens
procedure
,
private
::
activate
=>
arcus_tangens_activate_impl
end
type
arctan_neuron_t
interface
arctan_neuron_t
!> Constructor for an instance of the class arctan_neuron_t
module
procedure
::
new_arctan_neuron
end
interface
arctan_neuron_t
contains
!------------------------!---------------------------------------------------------------------
! Method implementations !
...
...
@@ -567,5 +598,98 @@ module neuron_m
#endif
end
subroutine
logistic_activate_impl
!---------------------!
! class tanh_neuron_t !
!---------------------!
!--------------!------------------------------------------------------------------------------
! Constructors !
!--------------!
!> Constructor for an instance of the class tanh_neuron_t
function
new_tanh_neuron
()
result
(
new_obj
)
class
(
tanh_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_tanh_neuron'
)
#endif
end
function
new_tanh_neuron
!----------------!----------------------------------------------------------------------------
! Common methods !
!----------------!
!> Activation function - hyperbolic tangent
subroutine
hyperbolic_tangent_activate_impl
(
this
)
class
(
tanh_neuron_t
),
intent
(
inout
)
::
this
#ifdef TIME_PROFILING
real
::
start_time
call
time_profiling_start
(
start_time
)
#endif
#if PREC == DOUBLE
this
%
state
=
dtanh
(
this
%
potential
)
#else
this
%
state
=
tanh
(
this
%
potential
)
#endif
#ifdef TIME_PROFILING
call
time_profiling_stop
(
start_time
,
'hyperbolic_tangent_activate_impl'
)
#endif
end
subroutine
hyperbolic_tangent_activate_impl
!-----------------------!
! class arctan_neuron_t !
!-----------------------!
!--------------!------------------------------------------------------------------------------
! Constructors !
!--------------!
!> Constructor for an instance of the class arctan_neuron_t
function
new_arctan_neuron
()
result
(
new_obj
)
class
(
arctan_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_arctan_neuron'
)
#endif
end
function
new_arctan_neuron
!----------------!----------------------------------------------------------------------------
! Common methods !
!----------------!
!> Activation function - arcus tangens
subroutine
arcus_tangens_activate_impl
(
this
)
class
(
arctan_neuron_t
),
intent
(
inout
)
::
this
#ifdef TIME_PROFILING
real
::
start_time
call
time_profiling_start
(
start_time
)
#endif
#if PREC == DOUBLE
this
%
state
=
datan
(
this
%
potential
)
#else
this
%
state
=
atan
(
this
%
potential
)
#endif
#ifdef TIME_PROFILING
call
time_profiling_stop
(
start_time
,
'arcus_tangens_activate_impl'
)
#endif
end
subroutine
arcus_tangens_activate_impl
end
module
neuron_m
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment