-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Addition of the Loss derived type and of the MSE loss function (#175)
* Addition of the abstract DT loss_type and of the DT quadratic * Support of the loss_type for the derivative loss function * Addition of the MSE loss function * add documentation * Test program placeholder * Add loss test to CMake config * Minimal test for expected values * Bump version and copyright years --------- Co-authored-by: Vandenplas, Jeremie <[email protected]> Co-authored-by: milancurcic <[email protected]>
- Loading branch information
1 parent
cf47114
commit f7b6006
Showing
9 changed files
with
185 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
name = "neural-fortran" | ||
version = "0.15.1" | ||
version = "0.16.0" | ||
license = "MIT" | ||
author = "Milan Curcic" | ||
maintainer = "[email protected]" | ||
copyright = "Copyright 2018-2023, neural-fortran contributors" | ||
copyright = "Copyright 2018-2024, neural-fortran contributors" | ||
|
||
[build] | ||
external-modules = "hdf5" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
program test_loss | ||
|
||
use iso_fortran_env, only: stderr => error_unit | ||
use nf, only: mse, quadratic | ||
|
||
implicit none | ||
|
||
logical :: ok = .true. | ||
|
||
block | ||
|
||
type(mse) :: loss | ||
real :: true(2) = [1., 2.] | ||
real :: pred(2) = [3., 4.] | ||
|
||
if (.not. loss % eval(true, pred) == 4) then | ||
write(stderr, '(a)') 'expected output of mse % eval().. failed' | ||
ok = .false. | ||
end if | ||
|
||
if (.not. all(loss % derivative(true, pred) == [2, 2])) then | ||
write(stderr, '(a)') 'expected output of mse % derivative().. failed' | ||
ok = .false. | ||
end if | ||
|
||
end block | ||
|
||
block | ||
|
||
type(quadratic) :: loss | ||
real :: true(4) = [1., 2., 3., 4.] | ||
real :: pred(4) = [3., 4., 5., 6.] | ||
|
||
if (.not. loss % eval(true, pred) == 8) then | ||
write(stderr, '(a)') 'expected output of quadratic % eval().. failed' | ||
ok = .false. | ||
end if | ||
|
||
if (.not. all(loss % derivative(true, pred) == [2, 2, 2, 2])) then | ||
write(stderr, '(a)') 'expected output of quadratic % derivative().. failed' | ||
ok = .false. | ||
end if | ||
|
||
end block | ||
|
||
if (ok) then | ||
print '(a)', 'test_loss: All tests passed.' | ||
else | ||
write(stderr, '(a)') 'test_loss: One or more tests failed.' | ||
stop 1 | ||
end if | ||
|
||
end program test_loss |