Apply gradients to parameters to minimise loss using SGD optimiser Adaptive learning method
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(sgd_optimiser_type), | intent(inout) | :: | this |
Instance of the SGD optimiser |
||
| real(kind=real32), | intent(inout), | dimension(:) | :: | param |
Parameters |
|
| real(kind=real32), | intent(inout), | dimension(:) | :: | gradient |
Gradients |
pure subroutine minimise_sgd(this, param, gradient) !! Apply gradients to parameters to minimise loss using SGD optimiser implicit none ! Arguments class(sgd_optimiser_type), intent(inout) :: this !! Instance of the SGD optimiser real(real32), dimension(:), intent(inout) :: param !! Parameters real(real32), dimension(:), intent(inout) :: gradient !! Gradients ! Local variables real(real32) :: learning_rate !! Learning rate ! Decay learning rate and update iteration learning_rate = this%lr_decay%get_lr(this%learning_rate, this%iter) ! Apply regularisation if(this%regularisation) & call this%regulariser%regularise( param, gradient, learning_rate ) gradient = - learning_rate * gradient ! Update parameters if(this%momentum.gt.1.E-8_real32)then !! Adaptive learning method this%velocity = this%momentum * this%velocity + gradient if(this%nesterov)then param = param + this%momentum * this%velocity + gradient else param = param + this%velocity end if else ! Standard learning method this%velocity = gradient param = param + this%velocity end if end subroutine minimise_sgd