27 use,
intrinsic :: iso_fortran_env
45 character(len=:),
allocatable :: current_log
54 type(namespace_t),
intent(in) :: namespace
56 real(real64),
dimension(2) :: x0, x, mass
57 real(real64) :: tol_grad = 1.0e-6_real64
58 real(real64) :: dt, energy
59 integer :: ierr, integrator
60 integer,
parameter :: max_iter = 1000
65 call parse_variable(namespace,
'GOFireIntegrator', option__gofireintegrator__verlet, integrator)
69 call io_rm(trim(current_log), namespace)
73 x0 = [3.0_real64, 4.0_real64]
81 call minimize_fire(2, 2, x, dt, tol_grad, max_iter,
rosenbrock_gradient_2d,
write_iter_info, energy, ierr, mass, integrator)
83 write(
message(1),
"(a,i6,a)")
"FIRE (Rosenbrock) algorithm converged in ", -ierr,
" iterations"
84 write(
message(2),
"(a,2(f8.4,a))")
" The minimum is found to be at (", x(1),
", ", x(2),
")"
85 write(
message(3),
"(a)")
" Analytical minimum is (1,1)."
91 call io_rm(trim(current_log), namespace)
93 x0 = [3.0_real64, -4.0_real64]
97 call minimize_fire(2, 2, x, dt, tol_grad, max_iter, &
100 write(
message(1),
"(a,i6,a)")
"FIRE (Sphere) converged in ", -ierr,
" iterations"
101 write(
message(2),
"(a,2(f8.4,a))")
" Minimum found at (", x(1),
", ", x(2),
")"
102 write(
message(3),
"(a)")
" Analytical minimum is (0,0)."
109 call io_rm(trim(current_log), namespace)
111 x0 = [3.0_real64, 4.0_real64]
114 tol_grad = 1e-10_real64
116 call minimize_fire(2, 2, x, dt, tol_grad, max_iter, &
119 write(
message(1),
"(a,i6,a)")
"FIRE (Rastrigin) converged in ", -ierr,
" iterations"
120 write(
message(2),
"(a,2(f8.4,a))")
" Minimum found at (", x(1),
", ", x(2),
")"
121 write(
message(3),
"(a)")
" Analytical minimum is (0,0)."
124 deallocate(current_log)
137 integer,
intent(in) :: n
138 real(real64),
intent(in) :: x(n)
139 real(real64),
intent(inout) :: val
140 integer,
intent(in) :: getgrad
141 real(real64),
intent(inout) :: grad(n)
143 real(real64),
parameter :: a =
m_one
144 real(real64),
parameter :: b = 100.0_real64
151 grad(1) = -
m_two * (a-x(1)) -
m_four * b * (x(2) -x(1)**2) * x(1)
152 grad(2) =
m_two * b * (x(2) -x(1)**2)
161 integer,
intent(in) :: n
162 real(real64),
intent(in) :: x(n)
163 real(real64),
intent(inout) :: val
164 integer,
intent(in) :: getgrad
165 real(real64),
intent(inout) :: grad(n)
170 val = dot_product(x, x)
186 integer,
intent(in) :: n
187 real(real64),
intent(in) :: x(n)
188 real(real64),
intent(inout) :: val
189 integer,
intent(in) :: getgrad
190 real(real64),
intent(inout) :: grad(n)
192 real(real64),
parameter :: a = 10.0_real64
210 subroutine write_iter_info(iter, n, val, maxdr, maxgrad, x) !< output
for each iteration step
211 integer,
intent(in) :: iter
212 integer,
intent(in) :: n
213 real(real64),
intent(in) :: val
214 real(real64),
intent(in) :: maxdr
215 real(real64),
intent(in) :: maxgrad
216 real(real64),
intent(in) :: x(n)
223 write(iunit,
'(a10, 3a20)')
'# iter',
'x',
'y',
'max_force'
225 write(iunit,
'(i10,3f20.10)') iter, x(1), x(2), maxgrad
234 character(len=*),
intent(in) :: name
235 if (
allocated(current_log))
deallocate(current_log)
236 allocate(
character(len=len_trim(name)) :: current_log)
237 current_log = trim(name)
double sin(double __x) __attribute__((__nothrow__
double cos(double __x) __attribute__((__nothrow__
real(real64), parameter, public m_two
real(real64), parameter, public m_four
real(real64), parameter, public m_pi
some mathematical constants
real(real64), parameter, public m_one
subroutine, public io_close(iunit, grp)
subroutine, public io_rm(fname, namespace)
integer function, public io_open(file, namespace, action, status, form, position, die, recl, grp)
subroutine, public messages_new_line()
character(len=256), dimension(max_lines), public message
to be output by fatal, warning
subroutine, public messages_info(no_lines, iunit, debug_only, stress, all_nodes, namespace)
This modules takes care of testing optimizers using standard test functions.
subroutine write_iter_info(iter, n, val, maxdr, maxgrad, x)
Helper function required by the minimizer.
subroutine rosenbrock_gradient_2d(n, x, val, getgrad, grad)
Gradient of the Rosenbrock function.
subroutine set_log_file(name)
Set the logāfile name before running each test.
subroutine rastrigin_gradient_2d(n, x, val, getgrad, grad)
Gradient of the Rastrigin function.
subroutine, public test_optimizers(namespace)
Unit tests for different optimizers.
subroutine sphere_gradient_2d(n, x, val, getgrad, grad)
Gradient of the sphere function.
type(mpi_grp_t), public mpi_world
type(namespace_t), public global_namespace
brief This module defines the class unit_t which is used by the unit_systems_oct_m module.
This module defines the unit system, used for input and output.