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 `randomStartPointDomainLowerLimitVec` attribute of samplers of class [ParaMCMC_type](@ref paramcmc_mod::paramcmc_type).
45 : !> For more information, see the description of this attribute in the body of the module.
46 : !> \author Amir Shahmoradi
47 :
48 : module SpecMCMC_RandomStartPointDomainLowerLimitVec_mod
49 :
50 : use Constants_mod, only: RK
51 : implicit none
52 :
53 : character(*), parameter :: MODULE_NAME = "@SpecMCMC_RandomStartPointDomainLowerLimitVec_mod"
54 :
55 : real(RK), allocatable :: RandomStartPointDomainLowerLimitVec(:) ! namelist input
56 :
57 : type :: RandomStartPointDomainLowerLimitVec_type
58 : real(RK), allocatable :: Val(:)
59 : real(RK) :: null
60 : character(:), allocatable :: desc
61 : contains
62 : procedure, pass :: set, checkForSanity, nullifyNameListVar
63 : end type RandomStartPointDomainLowerLimitVec_type
64 :
65 : interface RandomStartPointDomainLowerLimitVec_type
66 : module procedure :: construct
67 : end interface RandomStartPointDomainLowerLimitVec_type
68 :
69 : private :: construct, set, checkForSanity, nullifyNameListVar
70 :
71 : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
72 :
73 : contains
74 :
75 : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
76 :
77 1047 : function construct(methodName) result(self)
78 : #if INTEL_COMPILER_ENABLED && defined DLL_ENABLED && (OS_IS_WINDOWS || defined OS_IS_DARWIN)
79 : !DEC$ ATTRIBUTES DLLEXPORT :: construct
80 : #endif
81 : use Constants_mod, only: NULL_RK
82 : use String_mod, only: num2str
83 : implicit none
84 : character(*), intent(in) :: methodName
85 : type(RandomStartPointDomainLowerLimitVec_type) :: self
86 1047 : self%null = NULL_RK
87 : self%desc = &
88 : "RandomStartPointDomainLowerLimitVec represents the lower boundaries of the cubical domain from which the starting point(s) of &
89 : &the MCMC chain(s) will be initialized randomly (only if requested via the input variable randomStartPointRequested. &
90 : &This happens only when some or all of the elements of the input variable StartPoint are missing. &
91 : &In such cases, every missing value of input StartPoint will be set to the center point between RandomStartPointDomainLowerLimitVec &
92 : &and RandomStartPointDomainUpperLimit in the corresponding dimension. &
93 : &If RandomStartPointRequested=TRUE (or True, true, t, all case-insensitive), then the missing &
94 : &elements of StartPoint will be initialized to values drawn randomly from within the corresponding ranges specified by &
95 : &the input variable RandomStartPointDomainLowerLimitVec. &
96 : &As an input variable, RandomStartPointDomainLowerLimitVec is an ndim-dimensional vector of 64-bit real numbers, &
97 : &where ndim is the number of variables of the objective function. It is also possible to assign only select values of &
98 : &RandomStartPointDomainLowerLimitVec and leave the rest of the components to be assigned the default value. &
99 : &This is POSSIBLE ONLY when RandomStartPointDomainLowerLimitVec is defined inside the input file to "//methodName//". &
100 : &For example, having the following inside the input file, \n\n&
101 : & RandomStartPointDomainLowerLimitVec(3:5) = -100\n\n&
102 : & will only set the lower limits of the third, fourth, and the fifth dimensions to -100, or,\n\n&
103 : & RandomStartPointDomainLowerLimitVec(1) = -100, RandomStartPointDomainLowerLimitVec(2) = -1.e6 \n\n&
104 : & will set the lower limit on the first dimension to -100, and 1.e6 on the second dimension, or,\n\n&
105 : & RandomStartPointDomainLowerLimitVec = 3*-2.5e100\n\n&
106 : & will only set the lower limits on the first, second, and the third dimensions to -2.5*10^100, while the rest of &
107 : &the lower limits for the missing dimensions will be automatically set to the default value.\n\n&
108 : &The default values for all elements of RandomStartPointDomainLowerLimitVec are taken from the corresponding values in the input &
109 1047 : &variable domainLowerLimitVec."
110 1047 : end function construct
111 :
112 : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
113 :
114 1047 : subroutine nullifyNameListVar(self,nd)
115 : #if INTEL_COMPILER_ENABLED && defined DLL_ENABLED && (OS_IS_WINDOWS || defined OS_IS_DARWIN)
116 : !DEC$ ATTRIBUTES DLLEXPORT :: nullifyNameListVar
117 : #endif
118 1047 : use Constants_mod, only: IK
119 : implicit none
120 : class(RandomStartPointDomainLowerLimitVec_type), intent(in) :: self
121 : integer(IK), intent(in) :: nd
122 12 : if (allocated(randomStartPointDomainLowerLimitVec)) deallocate(randomStartPointDomainLowerLimitVec)
123 1047 : allocate(randomStartPointDomainLowerLimitVec(nd))
124 2553 : randomStartPointDomainLowerLimitVec(:) = self%null
125 1047 : end subroutine nullifyNameListVar
126 :
127 : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
128 :
129 3159 : subroutine set(self, randomStartPointDomainLowerLimitVec)
130 : #if INTEL_COMPILER_ENABLED && defined DLL_ENABLED && (OS_IS_WINDOWS || defined OS_IS_DARWIN)
131 : !DEC$ ATTRIBUTES DLLEXPORT :: set
132 : #endif
133 1047 : use Constants_mod, only: IK, RK
134 : implicit none
135 : class(RandomStartPointDomainLowerLimitVec_type), intent(inout) :: self
136 : real(RK), intent(in), optional :: randomStartPointDomainLowerLimitVec(:)
137 3666 : if (present(randomStartPointDomainLowerLimitVec)) self%Val = randomStartPointDomainLowerLimitVec
138 2088 : end subroutine set
139 :
140 : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
141 :
142 1035 : subroutine checkForSanity(self,Err,methodName,SpecBase,randomStartPointRequested)
143 : #if INTEL_COMPILER_ENABLED && defined DLL_ENABLED && (OS_IS_WINDOWS || defined OS_IS_DARWIN)
144 : !DEC$ ATTRIBUTES DLLEXPORT :: checkForSanity
145 : #endif
146 2088 : use SpecBase_mod, only: SpecBase_type
147 : use Constants_mod, only: RK
148 : use Err_mod, only: Err_type
149 : use String_mod, only: num2str
150 : implicit none
151 : class(RandomStartPointDomainLowerLimitVec_type), intent(inout) :: self
152 : type(Err_type), intent(inout) :: Err
153 : type(SpecBase_type), intent(in) :: SpecBase
154 : character(*), intent(in) :: methodName
155 : logical , intent(in) :: randomStartPointRequested
156 : character(*), parameter :: PROCEDURE_NAME = "@checkForSanity()"
157 : integer :: i
158 2529 : do i = 1,size(self%Val(:))
159 :
160 1494 : if (self%Val(i)==self%null) self%Val(i) = SpecBase%DomainLowerLimitVec%Val(i)
161 :
162 : ! check if the domain is set when random start point is requested
163 :
164 1494 : if ( randomStartPointRequested .and. self%Val(i)==SpecBase%DomainLowerLimitVec%def ) then
165 12 : Err%occurred = .true.
166 : Err%msg = Err%msg // &
167 : MODULE_NAME // PROCEDURE_NAME // ": Error occurred. &
168 : &You have requested a random start point by setting randomStartPointRequested to TRUE while the &
169 : &element #"//num2str(i)//" of RandomStartPointDomainLowerLimitVec has not been preset to a finite value. &
170 12 : &This information is essential otherwise, how could the sampler draw points randomly from within an unspecified domain?\n\n"
171 : end if
172 :
173 : ! check if the random start point domain is within the boundaries of the domain of the target.
174 :
175 2529 : if ( self%Val(i)<SpecBase%DomainLowerLimitVec%Val(i) ) then
176 6 : Err%occurred = .true.
177 : Err%msg = Err%msg // &
178 : MODULE_NAME // PROCEDURE_NAME // ": Error occurred. The component " // num2str(i) // &
179 12 : " of the variable RandomStartPointDomainLowerLimitVec (" // num2str(self%Val(i)) // &
180 : ") cannot be smaller than the corresponding component of the variable domainLowerLimitVec (" // &
181 : num2str(SpecBase%DomainLowerLimitVec%Val(i)) // "). If you don't know &an appropriate value to " // & ! LCOV_EXCL_LINE
182 : "set for RandomStartPointDomainLowerLimitVec, drop it from the input list. " // methodName // " will &
183 6 : &automatically assign an appropriate value to it.\n\n"
184 : end if
185 :
186 : end do
187 1035 : deallocate(randomStartPointDomainLowerLimitVec)
188 2070 : end subroutine checkForSanity
189 :
190 : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
191 :
192 : end module SpecMCMC_RandomStartPointDomainLowerLimitVec_mod ! LCOV_EXCL_LINE
|