get_params Module Function

pure module function get_params(this) result(params)

Get learnable parameters

Arguments

Type IntentOptional Attributes Name
class(network_type), intent(in) :: this

Instance of network

Return Value real(kind=real32), dimension(this%num_params)

Parameters


Source Code

  pure module function get_params(this) result(params)
    !! Get learnable parameters
    implicit none

    ! Arguments
    class(network_type), intent(in) :: this
    !! Instance of network
    real(real32), dimension(this%num_params) :: params
    !! Parameters

    ! Local variables
    integer :: l, i, start_idx, end_idx
    !! Loop index

    start_idx = 0
    end_idx   = 0
    do l = 1, this%num_layers
       select type(current => this%model(l)%layer)
       class is(learnable_layer_type)
          do i = 1, size(current%params)
             start_idx = end_idx + 1
             end_idx = end_idx + size(current%params(i)%val, 1)
             params(start_idx:end_idx) = current%params(i)%val(:,1)
          end do
       end select
    end do

  end function get_params