Skip to content
Snippets Groups Projects
Commit 490999a1 authored by Sebastian Müller's avatar Sebastian Müller 🐈
Browse files

tests: update SCE unit test

parent de25b7ac
No related branches found
No related tags found
1 merge request!81Rework optimization routines
module test_mo_sce module test_mo_sce
use funit use funit
use mo_kind, only: i4, i8, dp use mo_kind, only: i4, i8, dp
use mo_sce, only: sce use mo_sce, only: sce
use mo_opt_functions, only: eval_dummy, ackley_objective, griewank_objective use mo_opt_functions, only: ackley, griewank
use mo_optimization_utils, only: eval_interface, objective_interface use mo_optimization_utils, only: function_optimizee
use mo_message, only: error_message use mo_message, only: error_message
implicit none implicit none
real(dp), dimension(:), allocatable :: pini real(dp), dimension(:), allocatable :: pini
...@@ -21,9 +21,8 @@ module test_mo_sce ...@@ -21,9 +21,8 @@ module test_mo_sce
integer(i4) :: n integer(i4) :: n
logical :: parallel logical :: parallel
procedure(eval_interface), pointer :: eval type(function_optimizee) :: objective
procedure(objective_interface), pointer :: obj_func
contains contains
@test @test
...@@ -31,7 +30,7 @@ contains ...@@ -31,7 +30,7 @@ contains
real(dp) :: t = 1.e-7_dp real(dp) :: t = 1.e-7_dp
integer(i4) :: iPar integer(i4) :: iPar
! Dimension of test function = number of parameters ! Dimension of test function = number of parameters
n = 30 n = 30
...@@ -51,10 +50,9 @@ contains ...@@ -51,10 +50,9 @@ contains
mask(:) = .true. mask(:) = .true.
pini(:) = 0.5_dp pini(:) = 0.5_dp
parallel=.false. parallel=.false.
eval => eval_dummy objective%func_pointer => ackley
obj_func => ackley_objective opt = sce( &
opt = sce(eval, & ! Mandatory IN: eval function objective, & ! Mandatory INOUT: objective
obj_func, & ! Mandatory IN: Objective function
pini, & ! Mandatory IN: initial guess pini, & ! Mandatory IN: initial guess
prange, & ! Mandatory IN: range for each parameter (min, max) prange, & ! Mandatory IN: range for each parameter (min, max)
mymaxn=30000_i8, & ! Optional IN: maximal number of function evaluations mymaxn=30000_i8, & ! Optional IN: maximal number of function evaluations
...@@ -97,7 +95,7 @@ contains ...@@ -97,7 +95,7 @@ contains
write(*,*) '' write(*,*) ''
write(*,*) 'number of function evaluations: neval = ', neval write(*,*) 'number of function evaluations: neval = ', neval
write(*,*) 'best function value found: bestf = ', obj_func(opt, eval) write(*,*) 'best function value found: bestf = ', objective%evaluate(opt)
write(*,*) 'global minimal function value: optf = ', 0.0_dp write(*,*) 'global minimal function value: optf = ', 0.0_dp
write(*,*) '' write(*,*) ''
...@@ -116,13 +114,13 @@ contains ...@@ -116,13 +114,13 @@ contains
end if end if
! Check restart ! Check restart
bestf = 0. bestf = 0.
neval = 0 neval = 0
history = 0. history = 0.
opt = sce(eval, & ! Mandatory IN : Objective function opt = sce( &
obj_func, & ! Mandatory IN: Objective function objective, & ! Mandatory INOUT: objective
pini, & ! Mandatory IN : initial guess pini, & ! Mandatory IN : initial guess
prange, & ! Mandatory IN : range for each parameter (min, max) prange, & ! Mandatory IN : range for each parameter (min, max)
restart=.true., & ! Do the restart restart=.true., & ! Do the restart
...@@ -134,7 +132,7 @@ contains ...@@ -134,7 +132,7 @@ contains
write(*,*) '' write(*,*) ''
write(*,*) 'number of function evaluations: neval = ', neval write(*,*) 'number of function evaluations: neval = ', neval
write(*,*) 'best function value found: bestf = ', obj_func(opt, eval) write(*,*) 'best function value found: bestf = ', objective%evaluate(opt)
write(*,*) 'global minimal function value: optf = ', 0.0_dp write(*,*) 'global minimal function value: optf = ', 0.0_dp
write(*,*) '' write(*,*) ''
...@@ -159,7 +157,7 @@ contains ...@@ -159,7 +157,7 @@ contains
real(dp) :: t = 1.e-7_dp real(dp) :: t = 1.e-7_dp
integer(i4) :: iPar integer(i4) :: iPar
! Dimension of test function = number of parameters ! Dimension of test function = number of parameters
n = 3 n = 3
...@@ -179,10 +177,9 @@ contains ...@@ -179,10 +177,9 @@ contains
mask(:) = .true. mask(:) = .true.
pini(:) = 0.5_dp pini(:) = 0.5_dp
parallel=.false. parallel=.false.
eval => eval_dummy objective%func_pointer => griewank
obj_func => griewank_objective opt = sce( &
opt = sce(eval, & ! Mandatory IN: eval function objective, & ! Mandatory INOUT: objective
obj_func, & ! Mandatory IN: Objective function
pini, & ! Mandatory IN: initial guess pini, & ! Mandatory IN: initial guess
prange, & ! Mandatory IN: range for each parameter (min, max) prange, & ! Mandatory IN: range for each parameter (min, max)
mymaxn=30000_i8, & ! Optional IN: maximal number of function evaluations mymaxn=30000_i8, & ! Optional IN: maximal number of function evaluations
...@@ -225,7 +222,7 @@ contains ...@@ -225,7 +222,7 @@ contains
write(*,*) '' write(*,*) ''
write(*,*) 'number of function evaluations: neval = ', neval write(*,*) 'number of function evaluations: neval = ', neval
write(*,*) 'best function value found: bestf = ', obj_func(opt, eval) write(*,*) 'best function value found: bestf = ', objective%evaluate(opt)
write(*,*) 'global minimal function value: optf = ', 0.0_dp write(*,*) 'global minimal function value: optf = ', 0.0_dp
write(*,*) '' write(*,*) ''
...@@ -244,13 +241,13 @@ contains ...@@ -244,13 +241,13 @@ contains
end if end if
! Check restart ! Check restart
bestf = 0. bestf = 0.
neval = 0 neval = 0
history = 0. history = 0.
opt = sce(eval, & ! Mandatory IN : Objective function opt = sce( &
obj_func, & ! Mandatory IN: Objective function objective, & ! Mandatory INOUT: objective
pini, & ! Mandatory IN : initial guess pini, & ! Mandatory IN : initial guess
prange, & ! Mandatory IN : range for each parameter (min, max) prange, & ! Mandatory IN : range for each parameter (min, max)
restart=.true., & ! Do the restart restart=.true., & ! Do the restart
...@@ -262,7 +259,7 @@ contains ...@@ -262,7 +259,7 @@ contains
write(*,*) '' write(*,*) ''
write(*,*) 'number of function evaluations: neval = ', neval write(*,*) 'number of function evaluations: neval = ', neval
write(*,*) 'best function value found: bestf = ', obj_func(opt, eval) write(*,*) 'best function value found: bestf = ', objective%evaluate(opt)
write(*,*) 'global minimal function value: optf = ', 0.0_dp write(*,*) 'global minimal function value: optf = ', 0.0_dp
write(*,*) '' write(*,*) ''
...@@ -281,5 +278,5 @@ contains ...@@ -281,5 +278,5 @@ contains
deallocate(pini, prange, opt, mask) deallocate(pini, prange, opt, mask)
end subroutine test_sce_griewank end subroutine test_sce_griewank
end module test_mo_sce end module test_mo_sce
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment