unmapped_network_s.F90 Source File


This file depends on

sourcefile~~unmapped_network_s.f90~~EfferentGraph sourcefile~unmapped_network_s.f90 unmapped_network_s.F90 sourcefile~neural_network_m.f90 neural_network_m.f90 sourcefile~unmapped_network_s.f90->sourcefile~neural_network_m.f90 sourcefile~activation_m.f90 activation_m.f90 sourcefile~neural_network_m.f90->sourcefile~activation_m.f90 sourcefile~double_precision_file_m.f90 double_precision_file_m.f90 sourcefile~neural_network_m.f90->sourcefile~double_precision_file_m.f90 sourcefile~kind_parameters_m.f90 kind_parameters_m.f90 sourcefile~neural_network_m.f90->sourcefile~kind_parameters_m.f90 sourcefile~metadata_m.f90 metadata_m.f90 sourcefile~neural_network_m.f90->sourcefile~metadata_m.f90 sourcefile~mini_batch_m.f90 mini_batch_m.f90 sourcefile~neural_network_m.f90->sourcefile~mini_batch_m.f90 sourcefile~tensor_m.f90 tensor_m.f90 sourcefile~neural_network_m.f90->sourcefile~tensor_m.f90 sourcefile~tensor_map_m.f90 tensor_map_m.f90 sourcefile~neural_network_m.f90->sourcefile~tensor_map_m.f90 sourcefile~double_precision_string_m.f90 double_precision_string_m.f90 sourcefile~double_precision_file_m.f90->sourcefile~double_precision_string_m.f90 sourcefile~metadata_m.f90->sourcefile~double_precision_string_m.f90 sourcefile~mini_batch_m.f90->sourcefile~kind_parameters_m.f90 sourcefile~input_output_pair_m.f90 input_output_pair_m.f90 sourcefile~mini_batch_m.f90->sourcefile~input_output_pair_m.f90 sourcefile~tensor_m.f90->sourcefile~kind_parameters_m.f90 sourcefile~tensor_map_m.f90->sourcefile~kind_parameters_m.f90 sourcefile~tensor_map_m.f90->sourcefile~tensor_m.f90 sourcefile~tensor_map_m.f90->sourcefile~double_precision_string_m.f90 sourcefile~input_output_pair_m.f90->sourcefile~kind_parameters_m.f90 sourcefile~input_output_pair_m.f90->sourcefile~tensor_m.f90

Source Code

! Copyright (c), The Regents of the University of California
! Terms of use are as specified in LICENSE.txt

#include "assert_macros.h"
#include "compound_assertions.h"

submodule(neural_network_m) unmapped_network_s
  use assert_m
  implicit none

  integer, parameter :: input_layer = 0 

contains

  module procedure double_precision_unmapped_from_json
    unmapped_network%neural_network_ = double_precision_from_json(file)
  end procedure

  module procedure default_real_infer_unmapped

    real, allocatable :: a(:,:)
    integer l

    associate(neural_network => self%neural_network_)

      call_assert_consistency(neural_network)

      associate( &
        w => neural_network%weights_ &
       ,b => neural_network%biases_ &
       ,n => neural_network%nodes_ &
       ,output_layer => ubound(neural_network%nodes_,1) &
      )
        allocate(a(maxval(n), input_layer:output_layer))

        a(1:n(input_layer),input_layer) = inputs%values()

        feed_forward: &
        do l = input_layer+1, output_layer
          associate(z => matmul(w(1:n(l),1:n(l-1),l), a(1:n(l-1),l-1)) + b(1:n(l),l))
            if (l .lt. output_layer) then
               a(1:n(l),l) = neural_network%activation_%evaluate(z)
            else
               a(1:n(l),l) = z(1:n(l))
            end if
          end associate
        end do feed_forward

        outputs = tensor_t(a(1:n(output_layer), output_layer))

      end associate
    end associate

  end procedure

  module procedure double_precision_infer_unmapped

    double precision, allocatable :: a(:,:)
    integer l

    associate(neural_network => self%neural_network_)

      call_assert_consistency(neural_network)

      associate( &
        w => neural_network%weights_ &
       ,b => neural_network%biases_ &
       ,n => neural_network%nodes_ &
       ,output_layer => ubound(neural_network%nodes_,1) &
      )

        allocate(a(maxval(n), input_layer:output_layer))

        a(1:n(input_layer),input_layer) = inputs%values()

        feed_forward: &
        do l = input_layer+1, output_layer
          associate(z => matmul(w(1:n(l),1:n(l-1),l), a(1:n(l-1),l-1)) + b(1:n(l),l))
            if (l .lt. output_layer) then
               a(1:n(l),l) = neural_network%activation_%evaluate(z)
            else
               a(1:n(l),l) = z(1:n(l))
            end if
          end associate
        end do feed_forward

        outputs = tensor_t(a(1:n(output_layer), output_layer))
      end associate
    end associate

  end procedure

end submodule unmapped_network_s