@@ -16,94 +16,86 @@ module mod_activation
1616 public :: tanhf, tanh_prime
1717
1818 interface
19+
1920 pure function activation_function (x )
2021 import :: rk
2122 real (rk), intent (in ) :: x(:)
2223 real (rk) :: activation_function(size (x))
2324 end function activation_function
24- end interface
2525
26- contains
27-
28- pure function gaussian (x ) result(res)
29- ! ! Gaussian activation function.
30- real (rk), intent (in ) :: x(:)
31- real (rk) :: res(size (x))
32- res = exp (- x** 2 )
33- end function gaussian
34-
35- pure function gaussian_prime (x ) result(res)
36- ! ! First derivative of the Gaussian activation function.
37- real (rk), intent (in ) :: x(:)
38- real (rk) :: res(size (x))
39- res = - 2 * x * gaussian(x)
40- end function gaussian_prime
41-
42- pure function relu (x ) result(res)
43- ! ! REctified Linear Unit (RELU) activation function.
44- real (rk), intent (in ) :: x(:)
45- real (rk) :: res(size (x))
46- res = max (0 ., x)
47- end function relu
48-
49- pure function relu_prime (x ) result(res)
50- ! ! First derivative of the REctified Linear Unit (RELU) activation function.
51- real (rk), intent (in ) :: x(:)
52- real (rk) :: res(size (x))
53- where (x > 0 )
54- res = 1
55- elsewhere
56- res = 0
57- end where
58- end function relu_prime
59-
60- pure function sigmoid (x ) result(res)
61- ! ! Sigmoid activation function.
62- real (rk), intent (in ) :: x(:)
63- real (rk) :: res(size (x))
64- res = 1 / (1 + exp (- x))
65- end function sigmoid
66-
67- pure function sigmoid_prime (x ) result(res)
68- ! ! First derivative of the sigmoid activation function.
69- real (rk), intent (in ) :: x(:)
70- real (rk) :: res(size (x))
71- res = sigmoid(x) * (1 - sigmoid(x))
72- end function sigmoid_prime
73-
74- pure function step (x ) result(res)
75- ! ! Step activation function.
76- real (rk), intent (in ) :: x(:)
77- real (rk) :: res(size (x))
78- where (x > 0 )
79- res = 1
80- elsewhere
81- res = 0
82- end where
83- end function step
84-
85- pure function step_prime (x ) result(res)
86- ! ! First derivative of the step activation function.
87- real (rk), intent (in ) :: x(:)
88- real (rk) :: res(size (x))
89- res = 0
90- end function step_prime
91-
92- pure function tanhf (x ) result(res)
93- ! ! Tangent hyperbolic activation function.
94- ! ! Same as the intrinsic tanh, but must be
95- ! ! defined here so that we can use procedure
96- ! ! pointer with it.
97- real (rk), intent (in ) :: x(:)
98- real (rk) :: res(size (x))
99- res = tanh (x)
100- end function tanhf
101-
102- pure function tanh_prime (x ) result(res)
103- ! ! First derivative of the tanh activation function.
104- real (rk), intent (in ) :: x(:)
105- real (rk) :: res(size (x))
106- res = 1 - tanh (x)** 2
107- end function tanh_prime
26+ pure module function gaussian(x) result(res)
27+ ! ! Gaussian activation function.
28+ implicit none
29+ real (rk), intent (in ) :: x(:)
30+ real (rk) :: res(size (x))
31+ end function gaussian
32+
33+ pure module function gaussian_prime(x) result(res)
34+ ! ! First derivative of the Gaussian activation function.
35+ implicit none
36+ real (rk), intent (in ) :: x(:)
37+ real (rk) :: res(size (x))
38+ end function gaussian_prime
39+
40+ pure module function relu(x) result(res)
41+ ! ! REctified Linear Unit (RELU) activation function.
42+ implicit none
43+ real (rk), intent (in ) :: x(:)
44+ real (rk) :: res(size (x))
45+ end function relu
46+
47+ pure module function relu_prime(x) result(res)
48+ ! ! First derivative of the REctified Linear Unit (RELU) activation function.
49+ implicit none
50+ real (rk), intent (in ) :: x(:)
51+ real (rk) :: res(size (x))
52+ end function relu_prime
53+
54+ pure module function sigmoid(x) result(res)
55+ ! ! Sigmoid activation function.
56+ implicit none
57+ real (rk), intent (in ) :: x(:)
58+ real (rk) :: res(size (x))
59+ end function sigmoid
60+
61+ pure module function sigmoid_prime(x) result(res)
62+ ! ! First derivative of the sigmoid activation function.
63+ implicit none
64+ real (rk), intent (in ) :: x(:)
65+ real (rk) :: res(size (x))
66+ end function sigmoid_prime
67+
68+ pure module function step(x) result(res)
69+ ! ! Step activation function.
70+ implicit none
71+ real (rk), intent (in ) :: x(:)
72+ real (rk) :: res(size (x))
73+ end function step
74+
75+ pure module function step_prime(x) result(res)
76+ ! ! First derivative of the step activation function.
77+ implicit none
78+ real (rk), intent (in ) :: x(:)
79+ real (rk) :: res(size (x))
80+ end function step_prime
81+
82+ pure module function tanhf(x) result(res)
83+ ! ! Tangent hyperbolic activation function.
84+ ! ! Same as the intrinsic tanh, but must be
85+ ! ! defined here so that we can use procedure
86+ ! ! pointer with it.
87+ implicit none
88+ real (rk), intent (in ) :: x(:)
89+ real (rk) :: res(size (x))
90+ end function tanhf
91+
92+ pure module function tanh_prime(x) result(res)
93+ ! ! First derivative of the tanh activation function.
94+ implicit none
95+ real (rk), intent (in ) :: x(:)
96+ real (rk) :: res(size (x))
97+ end function tanh_prime
98+
99+ end interface
108100
109101end module mod_activation
0 commit comments