Skip to content

Commit 6753ef4

Browse files
committed
fc2d_layer: add example for 2d mlp
1 parent f8fb977 commit 6753ef4

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

example/simple_2d_mlp.f90

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
program simple
2+
use nf, only: dense, fc2d, flatten, linear2d, input, network, sgd, relu, tanhf
3+
implicit none
4+
type(network) :: net
5+
real, allocatable :: x(:, :), y(:)
6+
integer, parameter :: num_iterations = 25
7+
integer :: n
8+
9+
print '("Simple")'
10+
print '(60("="))'
11+
12+
net = network([ &
13+
input(4, 5), &
14+
fc2d(3, 2, activation=relu()), &
15+
flatten(), &
16+
dense(4, activation=tanhf()) &
17+
])
18+
19+
call net % print_info()
20+
21+
allocate(x(4, 5))
22+
call random_number(x)
23+
y = [0.123456, 0.246802, 0.9, 0.001]
24+
25+
do n = 0, num_iterations
26+
27+
call net % forward(x)
28+
call net % backward(y)
29+
call net % update(optimizer=sgd(learning_rate=0.05))
30+
31+
if (mod(n, 5) == 0) print *, n, net % predict(x)
32+
33+
end do
34+
35+
end program simple

0 commit comments

Comments
 (0)