Skip to content

Instantly share code, notes, and snippets.

@OneAdder
Created February 16, 2025 20:21
Show Gist options
  • Save OneAdder/1090c066d8a9e3c0557c2968000ba463 to your computer and use it in GitHub Desktop.
Save OneAdder/1090c066d8a9e3c0557c2968000ba463 to your computer and use it in GitHub Desktop.
program simple_2d
use nf, only: input, network, sgd, linear2d, mse, flatten
implicit none
type(network) :: net
real :: x(3, 4) = reshape(&
[0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2],&
[3, 4])
real :: y(3) = [0.12, 0.1, 0.3]
type(mse) :: mean_se = mse()
integer, parameter :: num_iterations = 500
integer :: n
net = network([ &
input(3, 4), &
linear2d(3, 4, 1), &
flatten() &
])
call net % print_info()
do n = 0, 5
call net % forward(x)
call net % backward(y, mean_se)
call net % update(optimizer=sgd(learning_rate=1.))
print '(i4,2(3x,f8.6))', n, net % predict(x)
end do
end program simple_2d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment