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 [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_GreedyAdaptationCount_mod
49 :
50 : use Constants_mod, only: IK
51 : implicit none
52 :
53 : character(*), parameter :: MODULE_NAME = "@SpecDRAM_GreedyAdaptationCount_mod"
54 :
55 : integer(IK) :: greedyAdaptationCount ! namelist input
56 :
57 : type :: GreedyAdaptationCount_type
58 : integer(IK) :: val
59 : integer(IK) :: def
60 : integer(IK) :: null
61 : character(:), allocatable :: desc
62 : contains
63 : procedure, pass :: set => setGreedyAdaptationCount, checkForSanity, nullifyNameListVar
64 : end type GreedyAdaptationCount_type
65 :
66 : interface GreedyAdaptationCount_type
67 : module procedure :: constructGreedyAdaptationCount
68 : end interface GreedyAdaptationCount_type
69 :
70 : private :: constructGreedyAdaptationCount, setGreedyAdaptationCount, checkForSanity, nullifyNameListVar
71 :
72 : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
73 :
74 : contains
75 :
76 : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
77 :
78 349 : function constructGreedyAdaptationCount(methodName) result(GreedyAdaptationCountObj)
79 : #if INTEL_COMPILER_ENABLED && defined DLL_ENABLED && (OS_IS_WINDOWS || defined OS_IS_DARWIN)
80 : !DEC$ ATTRIBUTES DLLEXPORT :: constructGreedyAdaptationCount
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(GreedyAdaptationCount_type) :: GreedyAdaptationCountObj
87 349 : GreedyAdaptationCountObj%def = 0
88 349 : GreedyAdaptationCountObj%null = NULL_IK
89 : GreedyAdaptationCountObj%desc = &
90 : "If greedyAdaptationCount is set to a positive integer then the first greedyAdaptationCount number of &
91 : &the adaptive updates of the sampler will be made using only the 'unique' accepted points in the MCMC chain. &
92 : &This is useful, for example, when the function to be sampled by " // methodName // " is high dimensional, &
93 : &in which case, the adaptive updates to " // methodName // "'s sampler distribution will less likely lead to &
94 : &numerical instabilities, for example, a singular covariance matrix for the multivariate proposal sampler. &
95 : &The variable greedyAdaptationCount must be a non-negative integer, and not larger than the value of adaptiveUpdateCount. &
96 : &If it is larger, it will be automatically set to adaptiveUpdateCount for the simulation. &
97 349 : &The default value is " // num2str(GreedyAdaptationCountObj%def) // "."
98 349 : end function constructGreedyAdaptationCount
99 :
100 : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
101 :
102 349 : subroutine nullifyNameListVar(GreedyAdaptationCountObj)
103 : #if INTEL_COMPILER_ENABLED && defined DLL_ENABLED && (OS_IS_WINDOWS || defined OS_IS_DARWIN)
104 : !DEC$ ATTRIBUTES DLLEXPORT :: nullifyNameListVar
105 : #endif
106 : implicit none
107 : class(GreedyAdaptationCount_type), intent(in) :: GreedyAdaptationCountObj
108 349 : greedyAdaptationCount = GreedyAdaptationCountObj%null
109 349 : end subroutine nullifyNameListVar
110 :
111 : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
112 :
113 367 : subroutine setGreedyAdaptationCount(GreedyAdaptationCountObj,greedyAdaptationCount)
114 : #if INTEL_COMPILER_ENABLED && defined DLL_ENABLED && (OS_IS_WINDOWS || defined OS_IS_DARWIN)
115 : !DEC$ ATTRIBUTES DLLEXPORT :: setGreedyAdaptationCount
116 : #endif
117 349 : use Constants_mod, only: IK
118 : implicit none
119 : class(GreedyAdaptationCount_type), intent(inout) :: GreedyAdaptationCountObj
120 : integer(IK), intent(in) :: greedyAdaptationCount
121 367 : GreedyAdaptationCountObj%val = greedyAdaptationCount
122 367 : if ( GreedyAdaptationCountObj%val==GreedyAdaptationCountObj%null ) then
123 341 : GreedyAdaptationCountObj%val = GreedyAdaptationCountObj%def
124 : end if
125 367 : end subroutine setGreedyAdaptationCount
126 :
127 : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
128 :
129 345 : subroutine checkForSanity(GreedyAdaptationCountObj,Err,methodName)
130 : #if INTEL_COMPILER_ENABLED && defined DLL_ENABLED && (OS_IS_WINDOWS || defined OS_IS_DARWIN)
131 : !DEC$ ATTRIBUTES DLLEXPORT :: checkForSanity
132 : #endif
133 367 : use Constants_mod, only: IK
134 : use Err_mod, only: Err_type
135 : use String_mod, only: num2str
136 : implicit none
137 : class(GreedyAdaptationCount_type), intent(in) :: GreedyAdaptationCountObj
138 : character(*), intent(in) :: methodName
139 : type(Err_type), intent(inout) :: Err
140 : character(*), parameter :: PROCEDURE_NAME = "@checkForSanity()"
141 345 : if ( GreedyAdaptationCountObj%val<0_IK) then
142 2 : Err%occurred = .true.
143 : Err%msg = Err%msg // &
144 : MODULE_NAME // PROCEDURE_NAME // ": Error occurred. &
145 : &The input requested value for greedyAdaptationCount (" // num2str(GreedyAdaptationCountObj%val) // ") &
146 : &can not be negative. If you are not sure of the appropriate value for greedyAdaptationCount, drop it &
147 2 : &from the input list. " // methodName // " will automatically assign an appropriate value to it.\n\n"
148 : end if
149 690 : end subroutine checkForSanity
150 :
151 : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
152 :
153 : end module SpecDRAM_GreedyAdaptationCount_mod ! LCOV_EXCL_LINE
|