Skip to content

Add a display method for class(network_type) #22

@Beliavsky

Description

@Beliavsky

Class(network_type) has a useful save method and corresponding load method, but to inspect the parameters of a neural network it is helpful if the fields of class(network_type) are labelled. I have coded a simple display method that can be added to file mod_network.f90.

  subroutine display(self, outu)
    ! prints the network with descriptive labels
    class(network_type), intent(in out) :: self
    integer, intent(in), optional :: outu
    integer(ik) :: fileunit, n
    integer :: outu_
    integer, parameter :: output_unit = 6
    if (present(outu)) then
      outu_ = outu
    else
      outu_ = output_unit
    end if
    write(outu_, fmt="('#layers = ',i0)") size(self%dims)
    write (outu_,"(/,2a10,a20)") "layer","#neurons","activation"
    do n = 1, size(self % dims)
      write(outu_, fmt="(2i10,a20)") n,self%dims(n),self%layers(n)%activation_str
    end do
    write (outu_,"(/,'biases:')")
    do n = 2, size(self % dims)
      write(outu_, fmt="(i4,10000f12.6)") n,self%layers(n)%b
    end do
    write (outu_,"(/,'weights:')")
    do n = 1, size(self % dims) - 1
      write(outu_, fmt="(i4,10000f12.6)") n,self%layers(n)%w
    end do
  end subroutine display

A neural net is saved to file with the save method as

           3
           1           2           1
           1 gaussian
           2 gaussian
           3 gaussian
  -1.16021264      -1.54174113    
  -2.42969489    
  -1.59757996     -0.921771944    
  0.510428071      0.936606824    

With the display method it is printed as

#layers = 3

     layer  #neurons          activation
         1         1            gaussian
         2         2            gaussian
         3         1            gaussian

biases:
   2   -1.160213   -1.541741
   3   -2.429695

weights:
   1   -1.597580   -0.921772
   2    0.510428    0.936607

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions