Updates network weights and biases with gradients dw and db, scaled by learning rate eta. update biases update weights
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(network_type), | intent(inout) | :: | self | |||
| class(array2d), | intent(in) | :: | dw(:) | |||
| class(array1d), | intent(in) | :: | db(:) | |||
| real(kind=rk), | intent(in) | :: | eta |
pure subroutine update(self, dw, db, eta)
!! Updates network weights and biases with gradients dw and db,
!! scaled by learning rate eta.
class(network_type), intent(in out) :: self
class(array2d), intent(in) :: dw(:)
class(array1d), intent(in) :: db(:)
real(rk), intent(in) :: eta
integer(ik) :: n
associate(layers => self % layers, nm => size(self % dims))
!! update biases
do concurrent(n = 2:nm)
layers(n) % b = layers(n) % b - eta * db(n) % array
end do
!! update weights
do concurrent(n = 1:nm-1)
layers(n) % w = layers(n) % w - eta * dw(n) % array
end do
end associate
end subroutine update