nnet.f90 1.68 KB
Newer Older
1
2
3
4
5
! Hauptprogramm: Neural Network - Ansatz
!
! Implementiert den Datentyp "neuron" und führt alle Unit Tests aus
! Ausgabe in das File "nnet.out"

Wolfgang Kilian's avatar
Wolfgang Kilian committed
6
7
8
9
10
11
12
13
program nnet

  implicit none

  integer :: u

  open (newunit = u, file = "nnet.out", action = "write", status = "replace")

Wolfgang Kilian's avatar
Wolfgang Kilian committed
14
15
16
17
  call  test_kinds
  write (u, *)

  call test_empty_neuron
18
19
  write (u, *)
  call test_init_neuron
20
21
  write (u, *)
  call test_apply_neuron
Wolfgang Kilian's avatar
Wolfgang Kilian committed
22
  
Wolfgang Kilian's avatar
Wolfgang Kilian committed
23
24
  close (u)

Wolfgang Kilian's avatar
Wolfgang Kilian committed
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
contains

  ! Test: doppelt-genaue Zahl (sqrt(2))
  subroutine test_kinds
    use kinds, only: wp

    write (u, "(A)")  "* Test: kinds"
    write (u, "(F12.9)")  sqrt (2._wp)

  end subroutine test_kinds

  ! Test: leeres Neuron, nicht initialisiert
  subroutine test_empty_neuron
    use neurons, only: neuron

    type(neuron) :: n

    write (u, "(A)")  "* Test: empty neuron"
    call n%write (u)
    
  end subroutine test_empty_neuron
  
47
48
49
50
51
52
53
54
55
56
57
58
59
  ! Test: initialisiertes Neuron
  subroutine test_init_neuron
    use kinds, only: wp
    use neurons, only: neuron

    type(neuron) :: n

    write (u, "(A)")  "* Test: initialized neuron"
    call n%init (0.5_wp, [0.1_wp, 0.2_wp])
    call n%write (u)
    
  end subroutine test_init_neuron
  
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
  ! Test: Neuron auf Datenpunkt angewendet
  subroutine test_apply_neuron
    use kinds, only: wp
    use neurons, only: neuron

    type(neuron) :: n
    real(wp), dimension(2) :: x = [0.3_wp, 0.4_wp]

    write (u, "(A)")  "* Test: apply neuron to data"
    call n%init (0.5_wp, [0.1_wp, 0.2_wp])
    call n%write (u)
    write (u, "(1x,A)")  "Input:"
    write (u, "(3x,A,*(1x,F11.9))")  "x    =", x
    write (u, "(1x,A)")  "Output:"
    write (u, "(3x,A,*(1x,F11.9))")  "z    =", n%apply (x)
  
  end subroutine test_apply_neuron
  
Wolfgang Kilian's avatar
Wolfgang Kilian committed
78
end program nnet