13 use mo_kind,
only : i4, i8, dp
14 use mo_optimization_utils,
only : eval_interface, objective_interface
49 subroutine optimization(eval, objective, dirConfigOut, funcBest, maskpara)
51 use mo_anneal,
only : anneal
58 use mo_dds,
only : dds
59 use mo_mcmc,
only : mcmc, mcmc_stddev
60 use mo_message,
only : message, error_message
61 use mo_sce,
only : sce
62 use mo_string_utils,
only : num2str
63 use mo_timer,
only : timer_get, timer_start, &
65 use mo_xor4096,
only : get_timeseed
69 procedure(eval_interface),
intent(in),
pointer :: eval
72 procedure(objective_interface),
intent(in),
pointer :: objective
78 real(dp),
intent(out) :: funcbest
82 logical,
intent(out),
allocatable,
dimension(:) :: maskpara
90 real(dp),
allocatable,
dimension(:, :) :: burnin_paras
93 real(dp),
allocatable,
dimension(:, :) :: mcmc_paras
101 real(dp),
allocatable,
dimension(:, :) :: local_parameters
104 logical,
allocatable,
dimension(:) :: local_maskpara
110 character(256) :: tfile
113 character(256) :: pfile
119 call message(
' Start optimization')
127 allocate(maskpara(npara))
131 maskpara(ii) = .false.
138 allocate(local_maskpara(npara + 2))
142 local_maskpara(1 : npara) = maskpara(:)
143 local_parameters(npara + 1, 1) = 0.001_dp
144 local_parameters(npara + 1, 2) = 100._dp
145 local_parameters(npara + 1, 3) = 1._dp
146 local_parameters(npara + 1, 4) = 1._dp
147 local_parameters(npara + 1, 5) = 0._dp
148 local_parameters(npara + 2, 1) = 0.001_dp
149 local_parameters(npara + 2, 2) = 10._dp
150 local_parameters(npara + 2, 3) = 0.1_dp
151 local_parameters(npara + 2, 4) = 1._dp
152 local_parameters(npara + 2, 5) = 0._dp
153 local_maskpara(npara + 1 :) = .true.
157 local_maskpara(npara + 1 :) = .false.
161 allocate(local_maskpara(npara))
163 local_maskpara = maskpara
167 if (
seed .gt. 0_i8)
then
170 call get_timeseed(iseed)
175 call message(
' Use MCMC')
177 tfile = trim(adjustl(
dirconfigout)) //
'mcmc_tmp_parasets.nc'
184 call message(
' Use MCMC')
185 call mcmc(eval, objective, local_parameters(:, 3), local_parameters(:, 1 : 2), mcmc_paras, burnin_paras, &
186 paraselectmode_in = 2_i4, tmp_file = tfile, &
187 maskpara_in = local_maskpara, &
190 seed_in = iseed, loglike_in = .true., printflag_in = .true.)
193 call error_message(
'ERROR: A restart of this optimization method is not implemented yet!')
195 call message(
' Use MCMC_STDDEV')
196 call mcmc_stddev(eval, objective, local_parameters(:, 3), local_parameters(:, 1 : 2), mcmc_paras, burnin_paras, &
197 paraselectmode_in = 2_i4, tmp_file = tfile, &
198 maskpara_in = local_maskpara, &
199 seed_in = iseed, loglike_in = .true., printflag_in = .true.)
201 call error_message(
"Error objective: This opti_function is either not implemented yet.")
205 call message(
' Use DDS')
207 tfile = trim(adjustl(
dirconfigout)) //
'dds_results.out'
210 call error_message(
'ERROR: A restart of this optimization method is not implemented yet!')
214 local_parameters(:, 3) = dds(eval, objective, local_parameters(:, 3), local_parameters(:, 1 : 2), &
216 tmp_file = tfile, comm =
domainmeta%comMaster, mask = local_maskpara, &
219 local_parameters(:, 3) = dds(eval, objective, local_parameters(:, 3), local_parameters(:, 1 : 2), &
221 tmp_file = tfile, mask = local_maskpara, &
226 call message(
' Use Simulated Annealing')
228 tfile = trim(adjustl(
dirconfigout)) //
'anneal_results.out'
231 call error_message(
'ERROR: A restart of this optimization method is not implemented yet!')
236 local_parameters(:, 3) = anneal(eval, objective, local_parameters(:, 3), local_parameters(:, 1 : 2), &
237 temp =
sa_temp, seeds = (/iseed, iseed + 1000_i8, iseed + 2000_i8/), nitermax =
niterations, &
238 tmp_file = tfile, maskpara = local_maskpara, &
242 local_parameters(:, 3) = anneal(eval, objective, local_parameters(:, 3), local_parameters(:, 1 : 2), &
243 seeds = (/iseed, iseed + 1000_i8, iseed + 2000_i8/), nitermax =
niterations, &
244 tmp_file = tfile, maskpara = local_maskpara, &
248 call message(
' Use SCE')
250 tfile = trim(adjustl(
dirconfigout)) //
'sce_results.out'
251 pfile = trim(adjustl(
dirconfigout)) //
'sce_population.out'
254 local_parameters(:, 3) = sce(eval, objective, local_parameters(:, 3), local_parameters(:, 1 : 2), &
256 parallel = .false., mymask = local_maskpara, &
261 tmp_file = tfile, popul_file = pfile, &
264 call error_message(
'mRM',
'This optimization method is not implemented.')
267 call message(
' in ', trim(num2str(timer_get(
itimer),
'(F9.3)')),
' seconds.')
270 maskpara(:) = local_maskpara(1 : npara)
272 deallocate(local_parameters)
273 deallocate(local_maskpara)
Provides structures needed by mHM, mRM and/or mpr.
integer(i4), public niterations
integer(i4), public sce_nps
integer(i4), public sce_npg
integer(i4), public sce_ngs
logical, public optimize_restart
integer(i4), public opti_method
real(dp), dimension(nerror_model), public mcmc_error_params
logical, public mcmc_opti
integer(i4), public opti_function
Provides structures needed by mHM, mRM and/or mpr.
real(dp), dimension(:, :), allocatable, target, public global_parameters
type(domain_meta), public domainmeta
character(256), public dirconfigout
Wrapper subroutine for optimization against runoff and sm.
subroutine, public optimization(eval, objective, dirconfigout, funcbest, maskpara)
Wrapper for optimization.