The ParaMonte Documentation Website
Current view: top level - kernel - SpecMCMC_ProposalModel_mod.f90 (source / functions) Hit Total Coverage
Test: ParaMonte 1.5.1 :: MPI Parallel Kernel - Code Coverage Report Lines: 25 25 100.0 %
Date: 2021-01-08 13:07:16 Functions: 4 4 100.0 %
Legend: Lines: hit not hit

          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 `proposalModel` 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_ProposalModel_mod
      49             : 
      50             :     use Constants_mod, only: IK
      51             :     implicit none
      52             : 
      53             :     character(*), parameter         :: MODULE_NAME = "@SpecMCMC_ProposalModel_mod"
      54             : 
      55             :     integer(IK), parameter          :: MAX_LEN_PROPOSAL_MODEL = 63_IK
      56             : 
      57             :     character(:), allocatable       :: proposalModel ! namelist input
      58             : 
      59             :     type                            :: ProposalModel_type
      60             :         logical                     :: isUniform
      61             :         logical                     :: isNormal
      62             :         character(7)                :: uniform
      63             :         character(6)                :: normal
      64             :         character(:), allocatable   :: val
      65             :         character(:), allocatable   :: def
      66             :         character(:), allocatable   :: null
      67             :         character(:), allocatable   :: desc
      68             :     contains
      69             :         procedure, pass             :: set => setProposalModel, checkForSanity, nullifyNameListVar
      70             :     end type ProposalModel_type
      71             : 
      72             :     interface ProposalModel_type
      73             :         module procedure            :: constructProposalModel
      74             :     end interface ProposalModel_type
      75             : 
      76             :     private :: constructProposalModel, setProposalModel, checkForSanity, nullifyNameListVar
      77             : 
      78             : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
      79             : 
      80             : contains
      81             : 
      82             : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
      83             : 
      84        1047 :     function constructProposalModel() result(ProposalModelObj)
      85             : #if INTEL_COMPILER_ENABLED && defined DLL_ENABLED && (OS_IS_WINDOWS || defined OS_IS_DARWIN)
      86             :         !DEC$ ATTRIBUTES DLLEXPORT :: constructProposalModel
      87             : #endif
      88             :         use Decoration_mod, only: TAB
      89             :         use Constants_mod, only: NULL_SK, IK
      90             :         use String_mod, only: num2str
      91             :         implicit none
      92             :         type(ProposalModel_type)    :: ProposalModelObj
      93        1047 :         ProposalModelObj%isUniform  = .false.
      94        1047 :         ProposalModelObj%isNormal   = .false.
      95        1047 :         ProposalModelObj%uniform    = "uniform"
      96        1047 :         ProposalModelObj%normal     = "normal"
      97        1047 :         ProposalModelObj%def        = ProposalModelObj%normal
      98        1047 :         ProposalModelObj%null       = repeat(NULL_SK, MAX_LEN_PROPOSAL_MODEL)
      99             :         ProposalModelObj%desc       = &
     100             :         "proposalModel is a string variable containing the name of the proposal distribution for the MCMC sampler. &
     101             :         &The string value must be enclosed by either single or double quotation marks when provided as input. &
     102             :         &One option is currently supported:\n\n" // &
     103             :         "    proposalModel = '" // ProposalModelObj%normal // "'\n\n" // &
     104             :         "            This is equivalent to the multivariate normal distribution&
     105             :                      &, which is the most widely-used proposal model along with MCMC samplers.\n\n&
     106             :         &    proposalModel = '" // ProposalModelObj%uniform // "'\n\n" // &
     107             :         "            The proposals will be drawn uniformly from within a ndim-dimensional ellipsoid whose covariance matrix &
     108             :                      &and scale are initialized by the user and optionally adaptively updated throughout the simulation.\n\n&
     109        1047 :         &The default value is '" // ProposalModelObj%def // "'."
     110        1047 :     end function constructProposalModel
     111             : 
     112             : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     113             : 
     114        1047 :     subroutine nullifyNameListVar(ProposalModelObj)
     115             : #if INTEL_COMPILER_ENABLED && defined DLL_ENABLED && (OS_IS_WINDOWS || defined OS_IS_DARWIN)
     116             :         !DEC$ ATTRIBUTES DLLEXPORT :: nullifyNameListVar
     117             : #endif
     118             :         implicit none
     119             :         class(ProposalModel_type), intent(in) :: ProposalModelObj
     120        1047 :         proposalModel = ProposalModelObj%null
     121        1047 :     end subroutine nullifyNameListVar
     122             : 
     123             : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     124             : 
     125        1167 :     subroutine setProposalModel(ProposalModelObj,proposalModel)
     126             : #if INTEL_COMPILER_ENABLED && defined DLL_ENABLED && (OS_IS_WINDOWS || defined OS_IS_DARWIN)
     127             :         !DEC$ ATTRIBUTES DLLEXPORT :: setProposalModel
     128             : #endif
     129        1047 :         use String_mod, only: getLowerCase
     130             :         implicit none
     131             :         class(ProposalModel_type), intent(inout)    :: ProposalModelObj
     132             :         character(*), intent(in)                    :: proposalModel
     133        1167 :         ProposalModelObj%val = getLowerCase( trim(adjustl(proposalModel)) )
     134        1167 :         if (ProposalModelObj%val==ProposalModelObj%null) ProposalModelObj%val = ProposalModelObj%def
     135        1167 :         ProposalModelObj%isNormal   = ProposalModelObj%val == ProposalModelObj%normal
     136        1167 :         ProposalModelObj%isUniform  = ProposalModelObj%val == ProposalModelObj%uniform
     137        2334 :     end subroutine setProposalModel
     138             : 
     139             : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     140             : 
     141        1035 :     subroutine checkForSanity(ProposalModelObj,Err,methodName)
     142             : #if INTEL_COMPILER_ENABLED && defined DLL_ENABLED && (OS_IS_WINDOWS || defined OS_IS_DARWIN)
     143             :         !DEC$ ATTRIBUTES DLLEXPORT :: checkForSanity
     144             : #endif
     145        1167 :         use Err_mod, only: Err_type
     146             :         use String_mod, only: num2str
     147             :         implicit none
     148             :         class(ProposalModel_type), intent(in)   :: ProposalModelObj
     149             :         character(*), intent(in)                :: methodName
     150             :         type(Err_type), intent(inout)           :: Err
     151             :         character(*), parameter                 :: PROCEDURE_NAME = "@checkForSanity()"
     152        1035 :         if ( .not. (ProposalModelObj%isNormal .or. ProposalModelObj%isUniform) ) then
     153           6 :             Err%occurred = .true.
     154             :             Err%msg =   Err%msg // &
     155             :                         MODULE_NAME // PROCEDURE_NAME // ": Error occurred. &
     156             :                         &Invalid requested value for the proposalModel of " // methodName // ". The input requested &
     157             :                         &proposal model (" // ProposalModelObj%val // ") is not supported. &
     158             :                         &The variable proposalModel cannot be set to anything other than '" // &
     159             :                         ProposalModelObj%normal     // "', or '" // &
     160           6 :                         ProposalModelObj%uniform    // "'.\n\n"
     161             :         end if
     162        2070 :     end subroutine checkForSanity
     163             : 
     164             : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     165             : 
     166             : end module SpecMCMC_ProposalModel_mod ! LCOV_EXCL_LINE

ParaMonte: Plain Powerful Parallel Monte Carlo Library 
The Computational Data Science Lab
© Copyright 2012 - 2021