Line data Source code
1 : !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2 : !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
3 : !!!!
4 : !!!! MIT License
5 : !!!!
6 : !!!! ParaMonte: plain powerful parallel Monte Carlo library.
7 : !!!!
8 : !!!! Copyright (C) 2012-present, The Computational Data Science Lab
9 : !!!!
10 : !!!! This file is part of the ParaMonte library.
11 : !!!!
12 : !!!! Permission is hereby granted, free of charge, to any person obtaining a
13 : !!!! copy of this software and associated documentation files (the "Software"),
14 : !!!! to deal in the Software without restriction, including without limitation
15 : !!!! the rights to use, copy, modify, merge, publish, distribute, sublicense,
16 : !!!! and/or sell copies of the Software, and to permit persons to whom the
17 : !!!! Software is furnished to do so, subject to the following conditions:
18 : !!!!
19 : !!!! The above copyright notice and this permission notice shall be
20 : !!!! included in all copies or substantial portions of the Software.
21 : !!!!
22 : !!!! THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 : !!!! EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 : !!!! MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
25 : !!!! IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
26 : !!!! DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
27 : !!!! OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
28 : !!!! OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 : !!!!
30 : !!!! ACKNOWLEDGMENT
31 : !!!!
32 : !!!! ParaMonte is an honor-ware and its currency is acknowledgment and citations.
33 : !!!! As per the ParaMonte library license agreement terms, if you use any parts of
34 : !!!! this library for any purposes, kindly acknowledge the use of ParaMonte in your
35 : !!!! work (education/research/industry/development/...) by citing the ParaMonte
36 : !!!! library as described on this page:
37 : !!!!
38 : !!!! https://github.com/cdslaborg/paramonte/blob/main/ACKNOWLEDGMENT.md
39 : !!!!
40 : !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
41 : !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
42 :
43 : !> \brief
44 : !> This module contains the classes and procedures for setting up the `adaptiveUpdateCount` attribute of samplers of class [ParaDRAM_type](@ref paradram_mod::paradram_type).
45 : !> For more information, see the description of this attribute in the body of the module.
46 : !> \author Amir Shahmoradi
47 :
48 : module SpecDRAM_AdaptiveUpdateCount_mod
49 :
50 : use Constants_mod, only: IK
51 : implicit none
52 :
53 : character(*), parameter :: MODULE_NAME = "@SpecDRAM_AdaptiveUpdateCount_mod"
54 :
55 : integer(IK) :: adaptiveUpdateCount ! namelist input
56 :
57 : type :: AdaptiveUpdateCount_type
58 : integer(IK) :: val
59 : integer(IK) :: def
60 : integer(IK) :: null
61 : character(:), allocatable :: desc
62 : contains
63 : procedure, pass :: set => setAdaptiveUpdateCount, checkForSanity, nullifyNameListVar
64 : end type AdaptiveUpdateCount_type
65 :
66 : interface AdaptiveUpdateCount_type
67 : module procedure :: constructAdaptiveUpdateCount
68 : end interface AdaptiveUpdateCount_type
69 :
70 : private :: constructAdaptiveUpdateCount, setAdaptiveUpdateCount, checkForSanity, nullifyNameListVar
71 :
72 : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
73 :
74 : contains
75 :
76 : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
77 :
78 1047 : function constructAdaptiveUpdateCount(methodName) result(self)
79 : #if INTEL_COMPILER_ENABLED && defined DLL_ENABLED && (OS_IS_WINDOWS || defined OS_IS_DARWIN)
80 : !DEC$ ATTRIBUTES DLLEXPORT :: constructAdaptiveUpdateCount
81 : #endif
82 : use Constants_mod, only: IK, NULL_IK, POSINF_IK
83 : use String_mod, only: num2str
84 : implicit none
85 : character(*), intent(in) :: methodName
86 : type(AdaptiveUpdateCount_type) :: self
87 : !integer(IK), intent(in) :: chainSizeDef, adaptiveUpdatePeriodDef
88 : !self%def = chainSizeDef / ( 2 * adaptiveUpdatePeriodDef )
89 1047 : self%def = POSINF_IK
90 1047 : self%null = NULL_IK
91 : self%desc = &
92 : "adaptiveUpdateCount represents the total number of adaptive updates that will be made &
93 : &to the parameters of the proposal distribution to increase the efficiency of the sampler &
94 : &thus increasing the overall sampling efficiency of " // methodName // ". &
95 : &Every adaptiveUpdatePeriod number of calls to the objective function, the parameters of the proposal distribution &
96 : &will be updated until either the total number of adaptive updates reaches the value of adaptiveUpdateCount. &
97 : &This variable must be a non-negative integer. As a rule of thumb, it may be appropriate to &
98 : &set the input variable chainSize > 2 * adaptiveUpdatePeriod * adaptiveUpdateCount, &
99 : &to ensure ergodicity and stationarity of the MCMC sampler. &
100 : &If adaptiveUpdateCount=0, then the proposal distribution parameters will be fixed to &
101 : &the initial input values throughout the entire MCMC sampling. &
102 1047 : &The default value is " // num2str(self%def) // "."
103 1047 : end function constructAdaptiveUpdateCount
104 :
105 : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
106 :
107 1047 : subroutine nullifyNameListVar(self)
108 : #if INTEL_COMPILER_ENABLED && defined DLL_ENABLED && (OS_IS_WINDOWS || defined OS_IS_DARWIN)
109 : !DEC$ ATTRIBUTES DLLEXPORT :: nullifyNameListVar
110 : #endif
111 : implicit none
112 : class(AdaptiveUpdateCount_type), intent(in) :: self
113 1047 : adaptiveUpdateCount = self%null
114 2094 : end subroutine nullifyNameListVar
115 :
116 : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
117 :
118 1059 : subroutine setAdaptiveUpdateCount(self,adaptiveUpdateCount)
119 : #if INTEL_COMPILER_ENABLED && defined DLL_ENABLED && (OS_IS_WINDOWS || defined OS_IS_DARWIN)
120 : !DEC$ ATTRIBUTES DLLEXPORT :: setAdaptiveUpdateCount
121 : #endif
122 1047 : use Constants_mod, only: IK
123 : implicit none
124 : class(AdaptiveUpdateCount_type), intent(inout) :: self
125 : integer(IK), intent(in) :: adaptiveUpdateCount
126 1059 : self%val = adaptiveUpdateCount
127 1029 : if ( self%val==self%null ) self%val = self%def
128 1059 : end subroutine setAdaptiveUpdateCount
129 :
130 : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
131 :
132 1035 : subroutine checkForSanity(self,Err,methodName)
133 : #if INTEL_COMPILER_ENABLED && defined DLL_ENABLED && (OS_IS_WINDOWS || defined OS_IS_DARWIN)
134 : !DEC$ ATTRIBUTES DLLEXPORT :: checkForSanity
135 : #endif
136 1059 : use Constants_mod, only: IK
137 : use Err_mod, only: Err_type
138 : use String_mod, only: num2str
139 : implicit none
140 : class(AdaptiveUpdateCount_type), intent(in) :: self
141 : character(*), intent(in) :: methodName
142 : type(Err_type), intent(inout) :: Err
143 : character(*), parameter :: PROCEDURE_NAME = "@checkForSanity()"
144 1035 : if ( self%val<0) then
145 6 : Err%occurred = .true.
146 : Err%msg = Err%msg // &
147 : MODULE_NAME // PROCEDURE_NAME // ": Error occurred. &
148 : &The input requested value for adaptiveUpdateCount (" // num2str(self%val) // ") &
149 : &can not be negative. If you are not sure of the appropriate value for adaptiveUpdateCount, drop it &
150 6 : &from the input list. " // methodName // " will automatically assign an appropriate value to it.\n\n"
151 : end if
152 2070 : end subroutine checkForSanity
153 :
154 : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
155 :
156 : end module SpecDRAM_AdaptiveUpdateCount_mod ! LCOV_EXCL_LINE
|