-
Notifications
You must be signed in to change notification settings - Fork 0
/
mlp-Fs-tapenade-f.f
82 lines (79 loc) · 2.74 KB
/
mlp-Fs-tapenade-f.f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
subroutine magnitude_squared(n_x, x, r)
integer n_x, j
double precision x(n_x), r
r = 0d0
do j = 1, n_x
r = r+x(j)*x(j)
enddo
end
subroutine sum_layer_sigmoid(activities, n_elements, n_weights,
* weights, out)
integer i, j, n_elements, n_weights
double precision activities(n_weights-1)
double precision weights(n_elements*n_weights)
double precision out(n_elements)
do i = 1, n_elements
out(i) = weights((i-1)*n_weights+1)
do j = 1, n_weights-1
out(i) = out(i)+activities(j)*weights((i-1)*n_weights+j+1)
enddo
out(i) = 1d0/(exp(-1d0*out(i))+1d0)
enddo
end
subroutine forward_pass(n_ws_layers, ws_layers, n_layers_format,
* layers_format, n_in, in, n_out, out)
integer i, j, count, n_ws_layers, n_layers_format, n_in, n_out
double precision ws_layers(n_ws_layers), in(n_in), out(n_out)
integer layers_format(n_layers_format, 2)
double precision temp_weights(6), temp_in(2), temp_out(2)
count = 1
do i = 1, n_in
temp_in(i) = in(i)
enddo
do i = 1, n_layers_format
do j = 1, layers_format(i, 1)*layers_format(i, 2)
temp_weights(j) = ws_layers(count)
count = count+1
enddo
call sum_layer_sigmoid(temp_in, layers_format(i, 1),
* layers_format(i, 2), temp_weights, temp_out)
do j = 1, layers_format(i, 1)
temp_in(j) = temp_out(j)
enddo
enddo
do i = 1, n_out
out(i) = temp_out(i)
enddo
end
subroutine error_on_dataset(n_ws_layers, ws_layers,
* n_layers_format, layers_format, error)
integer i, j, n_ws_layers, n_layers_format
double precision ws_layers(n_ws_layers), xor_data(4, 3)
integer layers_format(n_layers_format, 2)
double precision in(2), out(1), absolute_error(1), mag, error
xor_data(1, 1) = 0d0
xor_data(1, 2) = 0d0
xor_data(1, 3) = 0d0
xor_data(2, 1) = 0d0
xor_data(2, 2) = 1d0
xor_data(2, 3) = 1d0
xor_data(3, 1) = 1d0
xor_data(3, 2) = 0d0
xor_data(3, 3) = 1d0
xor_data(4, 1) = 1d0
xor_data(4, 2) = 1d0
xor_data(4, 3) = 0d0
error = 0d0
do i = 1, 4
do j = 1, 2
in(j) = xor_data(i, j)
enddo
call forward_pass(n_ws_layers, ws_layers, n_layers_format,
* layers_format, 2, in, 1, out)
do j = 1, 1
absolute_error(j) = out(j)-xor_data(i, j+2)
enddo
call magnitude_squared(1, absolute_error, mag)
error = error+0.5d0*mag
enddo
end