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 349 : 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 349 : allocate( self%def(nd) )
90 851 : self%def = 0._RK
91 851 : do i = 1,nd
92 851 : self%def(i) = 1._RK
93 : end do
94 349 : 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 349 : &The default value of proposalStartStdVec is a vector of unit values (i.e., ones) of length ndim."
105 349 : end function constructProposalStartStdVec
106 :
107 : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
108 :
109 349 : 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 349 : use Constants_mod, only: IK
114 : implicit none
115 : class(ProposalStartStdVec_type), intent(in) :: self
116 : integer(IK), intent(in) :: nd
117 348 : if (allocated(proposalStartStdVec)) deallocate(proposalStartStdVec)
118 349 : allocate(proposalStartStdVec(nd))
119 851 : proposalStartStdVec = self%null
120 349 : end subroutine nullifyNameListVar
121 :
122 : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
123 :
124 710 : 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 349 : use Constants_mod, only: RK
129 : implicit none
130 : class(ProposalStartStdVec_type), intent(inout) :: self
131 : real(RK), intent(in) :: proposalStartStdVec(:)
132 873 : self%val = proposalStartStdVec
133 867 : where (self%val==self%null)
134 355 : self%val = self%def
135 : end where
136 355 : end subroutine setProposalStartCorMat
137 :
138 : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
139 :
140 345 : 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 355 : 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 843 : do i = 1,nd
155 843 : if (self%val(i)<=0._RK) then
156 2 : Err%occurred = .true.
157 : Err%msg = Err%msg // &
158 : MODULE_NAME // PROCEDURE_NAME // ": Error occurred. &
159 4 : &The input requested value (" // num2str(self%val(i)) // ") for the component " // &
160 : num2str(i) // " of the variable proposalStartStdVec for the proposal distribution of " // &
161 2 : methodName // " must be a positive real number.\n\n"
162 : end if
163 : end do
164 690 : end subroutine checkForSanity
165 :
166 : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
167 :
168 : end module SpecMCMC_ProposalStartStdVec_mod ! LCOV_EXCL_LINE
|