update_message_duvenaud Subroutine

private subroutine update_message_duvenaud(this, input)

Update the message

Type Bound

duvenaud_msgpass_layer_type

Arguments

Type IntentOptional Attributes Name
class(duvenaud_msgpass_layer_type), intent(inout), target :: this

Instance of the message passing layer

class(array_type), intent(in), dimension(:,:), target :: input

Input to the message passing layer


Source Code

  subroutine update_message_duvenaud(this, input)
    !! Update the message
    implicit none

    ! Arguments
    class(duvenaud_msgpass_layer_type), intent(inout), target :: this
    !! Instance of the message passing layer
    class(array_type), dimension(:,:), intent(in), target :: input
    !! Input to the message passing layer

    ! Local variables
    integer :: s, t
    !! Batch index, time step
    logical :: has_activation
    type(array_type), pointer :: ptr1, ptr2, ptr3, ptr_edge, ptr_params
    !! Pointers to arrays


    if(allocated(this%z))then
       if(size(this%z,2).ne.size(input,2))then
          deallocate(this%z)
          allocate(this%z(this%num_time_steps,size(input,2)))
       end if
    else
       allocate(this%z(this%num_time_steps,size(input,2)))
    end if


    if(.not.allocated(this%activation))then
       has_activation = .false.
    else
       if(trim(this%activation%name).eq."none")then
          has_activation = .true.
       else
          has_activation = .true.
       end if
    end if
    do s = 1, size(input,2)
       ptr1 => input(1,s)
       ptr_edge => input(2,s)
       do t = 1, this%num_time_steps
          ptr2 => duvenaud_propagate( &
               ptr1, ptr_edge, &
               this%graph(s)%adj_ia, this%graph(s)%adj_ja &
          )

          ptr_params => this%params(t)
          ptr3 => duvenaud_update( &
               ptr2, ptr_params, &
               this%graph(s)%adj_ia, &
               this%min_vertex_degree, this%max_vertex_degree &
          )
          if(has_activation)then
             ptr3 => this%activation%apply( ptr3 )
          end if
          call this%z(t,s)%zero_grad()
          call this%z(t,s)%assign_and_deallocate_source(ptr3)
          this%z(t,s)%is_temporary = .false.
          ptr1 => this%z(t,s)
       end do
    end do

  end subroutine update_message_duvenaud