forked from modern-fortran/neural-fortran
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnf_loss.f90
42 lines (34 loc) · 1.16 KB
/
nf_loss.f90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
module nf_loss
!! This module will eventually provide a collection of loss functions and
!! their derivatives. For the time being it provides only the quadratic
!! function.
implicit none
private
public :: quadratic, quadratic_derivative
interface
pure module function quadratic(true, predicted) result(res)
!! Quadratic loss function:
!!
!! L = (predicted - true)**2 / 2
!!
real, intent(in) :: true(:)
!! True values, i.e. labels from training datasets
real, intent(in) :: predicted(:)
!! Values predicted by the network
real :: res(size(true))
!! Resulting loss values
end function quadratic
pure module function quadratic_derivative(true, predicted) result(res)
!! First derivative of the quadratic loss function:
!!
!! L' = predicted - true
!!
real, intent(in) :: true(:)
!! True values, i.e. labels from training datasets
real, intent(in) :: predicted(:)
!! Values predicted by the network
real :: res(size(true))
!! Resulting loss values
end function quadratic_derivative
end interface
end module nf_loss