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 `proposalStartStdVec` 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_ProposalStartStdVec_mod
49 :
50 : use Constants_mod, only: RK
51 : implicit none
52 :
53 : character(*), parameter :: MODULE_NAME = "@SpecMCMC_ProposalStartStdVec_mod"
54 :
55 : real(RK), allocatable :: proposalStartStdVec(:) ! namelist input
56 :
57 : type :: ProposalStartStdVec_type
58 : real(RK), allocatable :: val(:)
59 : real(RK), allocatable :: def(:)
60 : real(RK) :: null
61 : character(:), allocatable :: desc
62 : contains
63 : procedure, pass :: set => setProposalStartCorMat, checkForSanity, nullifyNameListVar
64 : end type ProposalStartStdVec_type
65 :
66 : interface ProposalStartStdVec_type
67 : module procedure :: constructProposalStartStdVec
68 : end interface ProposalStartStdVec_type
69 :
70 : private :: constructProposalStartStdVec, setProposalStartCorMat, checkForSanity, nullifyNameListVar
71 :
72 : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
73 :
74 : contains
75 :
76 : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
77 :
78 1047 : function constructProposalStartStdVec(nd,methodName) result(self)
79 : #if INTEL_COMPILER_ENABLED && defined DLL_ENABLED && (OS_IS_WINDOWS || defined OS_IS_DARWIN)
80 : !DEC$ ATTRIBUTES DLLEXPORT :: constructProposalStartStdVec
81 : #endif
82 : use Constants_mod, only: IK, NULL_RK
83 : use String_mod, only: num2str
84 : implicit none
85 : integer(IK), intent(in) :: nd
86 : character(*), intent(in) :: methodName
87 : type(ProposalStartStdVec_type) :: self
88 : integer(IK) :: i
89 1047 : allocate( self%def(nd) )
90 2553 : self%def = 0._RK
91 2553 : do i = 1,nd
92 2553 : self%def(i) = 1._RK
93 : end do
94 1047 : self%null = NULL_RK
95 : self%desc = &
96 : "proposalStartStdVec is a real-valued positive vector of length ndim, where ndim is the dimension of the sampling space. &
97 : &It serves as the best-guess starting Standard Deviation of each of the components of the proposal distribution. &
98 : &If the initial covariance matrix (ProposalStartCovMat) is missing as an input variable to " // &
99 : methodName // ", then proposalStartStdVec (along with the input variable ProposalStartCorMat) will be used to construct &
100 : &the initial covariance matrix of the proposal distribution of the MCMC sampler. &
101 : &However, if ProposalStartCovMat is present as an input argument to " // methodName // ", then the input proposalStartStdVec &
102 : &along with the input ProposalStartCorMat will be completely ignored and the input value for ProposalStartCovMat &
103 : &will be used to construct the initial covariance matrix of the proposal distribution of " // methodName // ". &
104 1047 : &The default value of proposalStartStdVec is a vector of unit values (i.e., ones) of length ndim."
105 1047 : end function constructProposalStartStdVec
106 :
107 : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
108 :
109 1047 : subroutine nullifyNameListVar(self,nd)
110 : #if INTEL_COMPILER_ENABLED && defined DLL_ENABLED && (OS_IS_WINDOWS || defined OS_IS_DARWIN)
111 : !DEC$ ATTRIBUTES DLLEXPORT :: nullifyNameListVar
112 : #endif
113 1047 : use Constants_mod, only: IK
114 : implicit none
115 : class(ProposalStartStdVec_type), intent(in) :: self
116 : integer(IK), intent(in) :: nd
117 1044 : if (allocated(proposalStartStdVec)) deallocate(proposalStartStdVec)
118 1047 : allocate(proposalStartStdVec(nd))
119 2553 : proposalStartStdVec = self%null
120 1047 : end subroutine nullifyNameListVar
121 :
122 : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
123 :
124 2130 : subroutine setProposalStartCorMat(self,proposalStartStdVec)
125 : #if INTEL_COMPILER_ENABLED && defined DLL_ENABLED && (OS_IS_WINDOWS || defined OS_IS_DARWIN)
126 : !DEC$ ATTRIBUTES DLLEXPORT :: setProposalStartCorMat
127 : #endif
128 1047 : use Constants_mod, only: RK
129 : implicit none
130 : class(ProposalStartStdVec_type), intent(inout) :: self
131 : real(RK), intent(in) :: proposalStartStdVec(:)
132 2619 : self%val = proposalStartStdVec
133 2601 : where (self%val==self%null)
134 1065 : self%val = self%def
135 : end where
136 1065 : end subroutine setProposalStartCorMat
137 :
138 : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
139 :
140 1035 : subroutine checkForSanity(self,Err,methodName,nd)
141 : #if INTEL_COMPILER_ENABLED && defined DLL_ENABLED && (OS_IS_WINDOWS || defined OS_IS_DARWIN)
142 : !DEC$ ATTRIBUTES DLLEXPORT :: checkForSanity
143 : #endif
144 1065 : use Constants_mod, only: IK, RK
145 : use String_mod, only: num2str
146 : use Err_mod, only: Err_type
147 : implicit none
148 : class(ProposalStartStdVec_type), intent(in) :: self
149 : integer(IK), intent(in) :: nd
150 : character(*), intent(in) :: methodName
151 : type(Err_type), intent(inout) :: Err
152 : character(*), parameter :: PROCEDURE_NAME = "@checkForSanity()"
153 : integer(IK) :: i
154 2529 : do i = 1,nd
155 2529 : if (self%val(i)<=0._RK) then
156 6 : Err%occurred = .true.
157 : Err%msg = Err%msg // &
158 : MODULE_NAME // PROCEDURE_NAME // ": Error occurred. &
159 12 : &The input requested value (" // num2str(self%val(i)) // ") for the component " // &
160 : num2str(i) // " of the variable proposalStartStdVec for the proposal distribution of " // &
161 6 : methodName // " must be a positive real number.\n\n"
162 : end if
163 : end do
164 2070 : end subroutine checkForSanity
165 :
166 : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
167 :
168 : end module SpecMCMC_ProposalStartStdVec_mod ! LCOV_EXCL_LINE
|