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 `greedyAdaptationCount` 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_ChainSize_mod
49 :
50 : use Constants_mod, only: IK
51 : implicit none
52 :
53 : character(*), parameter :: MODULE_NAME = "@SpecMCMC_ChainSize_mod"
54 :
55 : integer(IK) :: chainSize ! namelist input
56 :
57 : type :: ChainSize_type
58 : integer(IK) :: val
59 : integer(IK) :: def
60 : integer(IK) :: null
61 : character(:), allocatable :: desc
62 : contains
63 : procedure, pass :: set => setChainSize, checkForSanity, nullifyNameListVar
64 : end type ChainSize_type
65 :
66 : interface ChainSize_type
67 : module procedure :: constructChainSize
68 : end interface ChainSize_type
69 :
70 : private :: constructChainSize, setChainSize, checkForSanity, nullifyNameListVar
71 :
72 : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
73 :
74 : contains
75 :
76 : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
77 :
78 1047 : function constructChainSize(methodName) result(ChainSizeObj)
79 : #if INTEL_COMPILER_ENABLED && defined DLL_ENABLED && (OS_IS_WINDOWS || defined OS_IS_DARWIN)
80 : !DEC$ ATTRIBUTES DLLEXPORT :: constructChainSize
81 : #endif
82 : use Constants_mod, only: IK, NULL_IK
83 : use String_mod, only: num2str
84 : implicit none
85 : character(*), intent(in) :: methodName
86 : type(ChainSize_type) :: ChainSizeObj
87 : #if defined CODECOV_ENABLED || defined SAMPLER_TEST_ENABLED
88 1047 : ChainSizeObj%def = 300_IK
89 : #else
90 : ChainSizeObj%def = 100000_IK
91 : #endif
92 1047 : ChainSizeObj%null = NULL_IK
93 : ChainSizeObj%desc = &
94 : "chainSize determines the number of non-refined, potentially auto-correlated, but unique, samples &
95 : &drawn by the MCMC sampler before stopping " // methodName // ". &
96 : &For example, if you specify chainSize = 10000, then 10000 unique sample points (with no duplicates) will be drawn &
97 : &from the target objective function that the user has provided. &
98 : &The input value for chainSize must be a positive integer of a minimum value ndim+1 or larger, &
99 : &where ndim is the number of variables that define the domain of the objective function to be sampled. &
100 1047 : &The default value is " // num2str(ChainSizeObj%def) // "."
101 1047 : end function constructChainSize
102 :
103 : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
104 :
105 1047 : subroutine nullifyNameListVar(ChainSizeObj)
106 : #if INTEL_COMPILER_ENABLED && defined DLL_ENABLED && (OS_IS_WINDOWS || defined OS_IS_DARWIN)
107 : !DEC$ ATTRIBUTES DLLEXPORT :: nullifyNameListVar
108 : #endif
109 : implicit none
110 : class(ChainSize_type), intent(in) :: ChainSizeObj
111 1047 : chainSize = ChainSizeObj%null
112 1047 : end subroutine nullifyNameListVar
113 :
114 : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
115 :
116 1227 : subroutine setChainSize(ChainSizeObj,chainSize)
117 : #if INTEL_COMPILER_ENABLED && defined DLL_ENABLED && (OS_IS_WINDOWS || defined OS_IS_DARWIN)
118 : !DEC$ ATTRIBUTES DLLEXPORT :: setChainSize
119 : #endif
120 1047 : use Constants_mod, only: IK
121 : implicit none
122 : class(ChainSize_type), intent(inout) :: ChainSizeObj
123 : integer(IK), intent(in) :: chainSize
124 1227 : ChainSizeObj%val = chainSize
125 1227 : if ( ChainSizeObj%val==ChainSizeObj%null ) then
126 1023 : ChainSizeObj%val = ChainSizeObj%def
127 : end if
128 1227 : end subroutine setChainSize
129 :
130 : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
131 :
132 1035 : subroutine checkForSanity(ChainSizeObj,Err,methodName,nd)
133 : #if INTEL_COMPILER_ENABLED && defined DLL_ENABLED && (OS_IS_WINDOWS || defined OS_IS_DARWIN)
134 : !DEC$ ATTRIBUTES DLLEXPORT :: checkForSanity
135 : #endif
136 1227 : use Constants_mod, only: IK
137 : use Err_mod, only: Err_type
138 : use String_mod, only: num2str
139 : implicit none
140 : class(ChainSize_type), intent(in) :: ChainSizeObj
141 : integer(IK), intent(in) :: nd
142 : character(*), intent(in) :: methodName
143 : type(Err_type), intent(inout) :: Err
144 : character(*), parameter :: PROCEDURE_NAME = "@checkForSanity()"
145 1035 : if ( ChainSizeObj%val<nd+1) then
146 12 : Err%occurred = .true.
147 : Err%msg = Err%msg // &
148 : MODULE_NAME // PROCEDURE_NAME // ": Error occurred. &
149 : &The input requested value for chainSize (" // num2str(ChainSizeObj%val) // ") can neither be negative &
150 : &nor smaller than ndim+1, where ndim represents the dimension of the sampling space, here ndim=" // &
151 : num2str(nd) // ". &
152 : &If you don't know an appropriate value for chainSize, drop it from the input list. " // &
153 12 : methodName // " will automatically assign an appropriate value to it.\n\n"
154 : end if
155 2070 : end subroutine checkForSanity
156 :
157 : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
158 :
159 : end module SpecMCMC_ChainSize_mod ! LCOV_EXCL_LINE
|