1
1
module mod_layer
2
2
3
- ! Defines the layer type and its methods.
3
+ ! ! Defines the layer type and its methods.
4
4
5
5
use mod_activation
6
6
use mod_kinds, only: ik, rk
@@ -12,13 +12,13 @@ module mod_layer
12
12
public :: array1d, array2d, db_init, db_co_sum, dw_init, dw_co_sum, layer_type
13
13
14
14
type :: layer_type
15
- real (rk), allocatable :: a(:) ! activations
16
- real (rk), allocatable :: b(:) ! biases
17
- real (rk), allocatable :: w(:,:) ! weights
18
- real (rk), allocatable :: z(:) ! arg. to activation function
15
+ real (rk), allocatable :: a(:) ! ! activations
16
+ real (rk), allocatable :: b(:) ! ! biases
17
+ real (rk), allocatable :: w(:,:) ! ! weights
18
+ real (rk), allocatable :: z(:) ! ! arg. to activation function
19
19
procedure (activation_function), pointer , nopass :: activation = > null ()
20
20
procedure (activation_function), pointer , nopass :: activation_prime = > null ()
21
- character (len= :), allocatable :: activation_str ! activation character string
21
+ character (len= :), allocatable :: activation_str ! ! activation character string
22
22
contains
23
23
procedure , public , pass(self) :: set_activation
24
24
end type layer_type
@@ -46,9 +46,9 @@ module mod_layer
46
46
contains
47
47
48
48
type (layer_type) function constructor(this_size, next_size) result(layer)
49
- ! Layer class constructor. this_size is the number of neurons in the layer.
50
- ! next_size is the number of neurons in the next layer, used to allocate
51
- ! the weights.
49
+ ! ! Layer class constructor. this_size is the number of neurons in the layer.
50
+ ! ! next_size is the number of neurons in the next layer, used to allocate
51
+ ! ! the weights.
52
52
integer (ik), intent (in ) :: this_size, next_size
53
53
allocate (layer % a(this_size))
54
54
allocate (layer % z(this_size))
@@ -59,21 +59,21 @@ type(layer_type) function constructor(this_size, next_size) result(layer)
59
59
end function constructor
60
60
61
61
pure type (array1d) function array1d_constructor(length) result(a)
62
- ! Overloads the default type constructor.
62
+ ! ! Overloads the default type constructor.
63
63
integer (ik), intent (in ) :: length
64
64
allocate (a % array(length))
65
65
a % array = 0
66
66
end function array1d_constructor
67
67
68
68
pure type (array2d) function array2d_constructor(dims) result(a)
69
- ! Overloads the default type constructor.
69
+ ! ! Overloads the default type constructor.
70
70
integer (ik), intent (in ) :: dims(2 )
71
71
allocate (a % array(dims(1 ), dims(2 )))
72
72
a % array = 0
73
73
end function array2d_constructor
74
74
75
75
pure subroutine db_init (db , dims )
76
- ! Initialises biases structure.
76
+ ! ! Initialises biases structure.
77
77
type (array1d), allocatable , intent (in out ) :: db(:)
78
78
integer (ik), intent (in ) :: dims(:)
79
79
integer (ik) :: n, nm
@@ -86,7 +86,7 @@ pure subroutine db_init(db, dims)
86
86
end subroutine db_init
87
87
88
88
pure subroutine dw_init (dw , dims )
89
- ! Initialises weights structure.
89
+ ! ! Initialises weights structure.
90
90
type (array2d), allocatable , intent (in out ) :: dw(:)
91
91
integer (ik), intent (in ) :: dims(:)
92
92
integer (ik) :: n, nm
@@ -99,7 +99,7 @@ pure subroutine dw_init(dw, dims)
99
99
end subroutine dw_init
100
100
101
101
subroutine db_co_sum (db )
102
- ! Performs a collective sum of bias tendencies.
102
+ ! ! Performs a collective sum of bias tendencies.
103
103
type (array1d), allocatable , intent (in out ) :: db(:)
104
104
integer (ik) :: n
105
105
do n = 2 , size (db)
@@ -110,7 +110,7 @@ subroutine db_co_sum(db)
110
110
end subroutine db_co_sum
111
111
112
112
subroutine dw_co_sum (dw )
113
- ! Performs a collective sum of weights tendencies.
113
+ ! ! Performs a collective sum of weights tendencies.
114
114
type (array2d), allocatable , intent (in out ) :: dw(:)
115
115
integer (ik) :: n
116
116
do n = 1 , size (dw) - 1
@@ -121,9 +121,9 @@ subroutine dw_co_sum(dw)
121
121
end subroutine dw_co_sum
122
122
123
123
pure elemental subroutine set_activation(self, activation)
124
- ! Sets the activation function. Input string must match one of
125
- ! provided activation functions, otherwise it defaults to sigmoid.
126
- ! If activation not present, defaults to sigmoid.
124
+ ! ! Sets the activation function. Input string must match one of
125
+ ! ! provided activation functions, otherwise it defaults to sigmoid.
126
+ ! ! If activation not present, defaults to sigmoid.
127
127
class(layer_type), intent (in out ) :: self
128
128
character (len=* ), intent (in ) :: activation
129
129
select case (trim (activation))
0 commit comments