The ParaMonte Documentation Website
Current view: top level - kernel - SpecMCMC_ProposalModel_mod.f90 (source / functions) Hit Total Coverage
Test: ParaMonte 1.5.1 :: Serial Kernel - Code Coverage Report Lines: 25 25 100.0 %
Date: 2021-01-08 13:03:42 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         349 :     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         349 :         ProposalModelObj%isUniform  = .false.
      94         349 :         ProposalModelObj%isNormal   = .false.
      95         349 :         ProposalModelObj%uniform    = "uniform"
      96         349 :         ProposalModelObj%normal     = "normal"
      97         349 :         ProposalModelObj%def        = ProposalModelObj%normal
      98         349 :         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         349 :         &The default value is '" // ProposalModelObj%def // "'."
     110         349 :     end function constructProposalModel
     111             : 
     112             : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     113             : 
     114         349 :     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         349 :         proposalModel = ProposalModelObj%null
     121         349 :     end subroutine nullifyNameListVar
     122             : 
     123             : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     124             : 
     125         389 :     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         349 :         use String_mod, only: getLowerCase
     130             :         implicit none
     131             :         class(ProposalModel_type), intent(inout)    :: ProposalModelObj
     132             :         character(*), intent(in)                    :: proposalModel
     133         389 :         ProposalModelObj%val = getLowerCase( trim(adjustl(proposalModel)) )
     134         389 :         if (ProposalModelObj%val==ProposalModelObj%null) ProposalModelObj%val = ProposalModelObj%def
     135         389 :         ProposalModelObj%isNormal   = ProposalModelObj%val == ProposalModelObj%normal
     136         389 :         ProposalModelObj%isUniform  = ProposalModelObj%val == ProposalModelObj%uniform
     137         778 :     end subroutine setProposalModel
     138             : 
     139             : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     140             : 
     141         345 :     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         389 :         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         345 :         if ( .not. (ProposalModelObj%isNormal .or. ProposalModelObj%isUniform) ) then
     153           2 :             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           2 :                         ProposalModelObj%uniform    // "'.\n\n"
     161             :         end if
     162         690 :     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