The ParaMonte Documentation Website
Current view: top level - kernel - SpecMCMC_RandomStartPointDomainUpperLimitVec_mod.f90 (source / functions) Hit Total Coverage
Test: ParaMonte 1.5.1 :: Coarray Parallel Kernel - Code Coverage Report Lines: 31 31 100.0 %
Date: 2021-01-08 12:59:07 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 `randomStartPointDomainUpperLimitVec` 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_RandomStartPointDomainUpperLimitVec_mod
      49             : 
      50             :     use Constants_mod, only: RK
      51             :     implicit none
      52             : 
      53             :     character(*), parameter         :: MODULE_NAME = "@SpecMCMC_RandomStartPointDomainUpperLimit_mod"
      54             : 
      55             :     real(RK), allocatable           :: randomStartPointDomainUpperLimitVec(:) ! namelist input
      56             : 
      57             :     type                            :: RandomStartPointDomainUpperLimitVec_type
      58             :         real(RK), allocatable       :: Val(:)
      59             :         real(RK)                    :: null
      60             :         character(:), allocatable   :: desc
      61             :     contains
      62             :         procedure, pass             :: set, checkForSanity, nullifyNameListVar
      63             :     end type RandomStartPointDomainUpperLimitVec_type
      64             : 
      65             :     interface RandomStartPointDomainUpperLimitVec_type
      66             :         module procedure            :: construct
      67             :     end interface RandomStartPointDomainUpperLimitVec_type
      68             : 
      69             :     private :: construct, set, checkForSanity, nullifyNameListVar
      70             : 
      71             : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
      72             : 
      73             : contains
      74             : 
      75             : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
      76             : 
      77        1047 :     function construct(methodName) result(self)
      78             : #if INTEL_COMPILER_ENABLED && defined DLL_ENABLED && (OS_IS_WINDOWS || defined OS_IS_DARWIN)
      79             :         !DEC$ ATTRIBUTES DLLEXPORT :: construct
      80             : #endif
      81             :         use Constants_mod, only: NULL_RK
      82             :         use String_mod, only: num2str
      83             :         implicit none
      84             :         character(*), intent(in)                        :: methodName
      85             :         type(RandomStartPointDomainUpperLimitVec_type)  :: self
      86        1047 :         self%null = NULL_RK
      87             :         self%desc = &
      88             :         "randomStartPointDomainUpperLimitVec represents the upper boundaries of the cubical domain from which the starting point(s) of &
      89             :         &the MCMC chain(s) will be initialized randomly (only if requested via the input variable randomStartPointRequested. &
      90             :         &This happens only when some or all of the elements of the input variable StartPoint are missing. &
      91             :         &In such cases, every missing value of input StartPoint will be set to the center point between randomStartPointDomainUpperLimitVec &
      92             :         &and randomStartPointDomainLowerLimitVec in the corresponding dimension. &
      93             :         &If RandomStartPointRequested=TRUE (or True, true, t, all case-insensitive), then the missing &
      94             :         &elements of StartPoint will be initialized to values drawn randomly from within the corresponding ranges specified by &
      95             :         &the input variable randomStartPointDomainUpperLimitVec. &
      96             :         &As an input variable, randomStartPointDomainUpperLimitVec is an ndim-dimensional vector of 64-bit real numbers, &
      97             :         &where ndim is the number of variables of the objective function. It is also possible to assign only select values of &
      98             :         &randomStartPointDomainUpperLimitVec and leave the rest of the components to be assigned the default value. &
      99             :         &This is POSSIBLE ONLY when randomStartPointDomainUpperLimitVec is defined inside the input file to "//methodName//". &
     100             :         &For example, having the following inside the input file, \n\n&
     101             :         &    randomStartPointDomainUpperLimitVec(3:5) = -100\n\n&
     102             :         &            will only set the upper limits of the third, fourth, and the fifth dimensions to -100, or,\n\n&
     103             :         &    randomStartPointDomainUpperLimitVec(1) = -100, randomStartPointDomainUpperLimitVec(2) = -1.e6 \n\n&
     104             :         &            will set the upper limit on the first dimension to -100, and 1.e6 on the second dimension, or,\n\n&
     105             :         &    randomStartPointDomainUpperLimitVec = 3*-2.5e100\n\n&
     106             :         &            will only set the upper limits on the first, second, and the third dimensions to -2.5*10^100, while the rest of &
     107             :                     &the upper limits for the missing dimensions will be automatically set to the default value.\n\n&
     108             :         &The default values for all elements of randomStartPointDomainUpperLimitVec are taken from the corresponding values in the input &
     109        1047 :         &variable domainUpperLimitVec."
     110        1047 :     end function construct
     111             : 
     112             : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     113             : 
     114        1047 :     subroutine nullifyNameListVar(self,nd)
     115             : #if INTEL_COMPILER_ENABLED && defined DLL_ENABLED && (OS_IS_WINDOWS || defined OS_IS_DARWIN)
     116             :         !DEC$ ATTRIBUTES DLLEXPORT :: nullifyNameListVar
     117             : #endif
     118        1047 :         use Constants_mod, only: IK
     119             :         implicit none
     120             :         class(RandomStartPointDomainUpperLimitVec_type), intent(in) :: self
     121             :         integer(IK), intent(in)                                     :: nd
     122          12 :         if (allocated(randomStartPointDomainUpperLimitVec)) deallocate(randomStartPointDomainUpperLimitVec)
     123        1047 :         allocate(randomStartPointDomainUpperLimitVec(nd))
     124        2553 :         randomStartPointDomainUpperLimitVec(:) = self%null
     125        1047 :     end subroutine nullifyNameListVar
     126             : 
     127             : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     128             : 
     129        3159 :     pure subroutine set(self,randomStartPointDomainUpperLimitVec)
     130             : #if INTEL_COMPILER_ENABLED && defined DLL_ENABLED && (OS_IS_WINDOWS || defined OS_IS_DARWIN)
     131             :         !DEC$ ATTRIBUTES DLLEXPORT :: set
     132             : #endif
     133        1047 :         use SpecBase_mod, only: SpecBase_type
     134             :         use Constants_mod, only: IK, RK
     135             :         implicit none
     136             :         class(RandomStartPointDomainUpperLimitVec_type), intent(inout)  :: self
     137             :         real(RK), intent(in), optional                                  :: randomStartPointDomainUpperLimitVec(:)
     138        3666 :         if (present(randomStartPointDomainUpperLimitVec)) self%Val = randomStartPointDomainUpperLimitVec
     139        2088 :     end subroutine set
     140             : 
     141             : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     142             : 
     143        2070 :     subroutine checkForSanity(self, Err, methodName, SpecBase, randomStartPointRequested, randomStartPointDomainLowerLimitVec)
     144             : #if INTEL_COMPILER_ENABLED && defined DLL_ENABLED && (OS_IS_WINDOWS || defined OS_IS_DARWIN)
     145             :         !DEC$ ATTRIBUTES DLLEXPORT :: checkForSanity
     146             : #endif
     147        2088 :         use SpecBase_mod, only: SpecBase_type
     148             :         use Constants_mod, only: RK
     149             :         use Err_mod, only: Err_type
     150             :         use String_mod, only: num2str
     151             :         implicit none
     152             :         class(RandomStartPointDomainUpperLimitVec_type), intent(inout)  :: self
     153             :         type(Err_type), intent(inout)                                   :: Err
     154             :         type(SpecBase_type), intent(in)                                 :: SpecBase
     155             :         character(*), intent(in)                                        :: methodName
     156             :         logical, intent(in)                                             :: randomStartPointRequested
     157             :         real(RK), intent(in)                                            :: randomStartPointDomainLowerLimitVec(:)
     158             :         character(*), parameter                                         :: PROCEDURE_NAME = "@checkForSanity()"
     159             :         integer                                                         :: i
     160        2529 :         do i = 1,size(self%Val(:))
     161             : 
     162        1494 :             if (self%Val(i)==self%null) self%Val(i) = SpecBase%DomainUpperLimitVec%Val(i)
     163             : 
     164             :             ! check if the domain is set when random start point is requested
     165             : 
     166        1494 :             if ( randomStartPointRequested .and. self%Val(i)==SpecBase%DomainUpperLimitVec%def ) then
     167          12 :                 Err%occurred = .true.
     168             :                 Err%msg =   Err%msg // &
     169             :                             MODULE_NAME // PROCEDURE_NAME // ": Error occurred. &
     170             :                             &You have requested a random start point by setting randomStartPointRequested to TRUE while the &
     171             :                             &element #"//num2str(i)//" of RandomStartPointDomainLowerLimitVec has not been preset to a finite value. &
     172          12 :                             &This information is essential otherwise, how could the sampler draw points randomly from within an unspecified domain?\n\n"
     173             :             end if
     174             : 
     175             :             ! the upper boundary of the domain of random-start-point must be smaller than the upper boundary of the target's domain.
     176             : 
     177        1494 :             if ( self%Val(i)>SpecBase%DomainUpperLimitVec%Val(i) ) then
     178           6 :                 Err%occurred = .true.
     179             :                 Err%msg =   Err%msg // &
     180             :                             MODULE_NAME // PROCEDURE_NAME // ": Error occurred. The component " // num2str(i) // &
     181          12 :                             " of the variable randomStartPointDomainUpperLimitVec (" // num2str(self%Val(i)) // ") cannot be " // &
     182             :                             "larger than the corresponding component of the variable domainUpperLimitVec (" // &
     183             :                             num2str(SpecBase%DomainUpperLimitVec%Val(i)) // "). If you don't know an appropriate " // & ! LCOV_EXCL_LINE
     184             :                             "value to set for randomStartPointDomainUpperLimitVec, drop it from the input list. " // &
     185           6 :                             methodName // " will automatically assign an appropriate value to it.\n\n"
     186             :             end if
     187             : 
     188             :             ! the upper boundary of the domain of random-start-point must be smaller than the corresponding lower boundary.
     189             : 
     190        2529 :             if ( self%Val(i)<=randomStartPointDomainLowerLimitVec(i) ) then
     191          24 :                 Err%occurred = .true.
     192             :                 Err%msg =   Err%msg // &
     193             :                             PROCEDURE_NAME // ": Error occurred. The input upper limit value in the component " // num2str(i) // &
     194             :                             " of the variable randomStartPointDomainUpperLimitVec cannot be smaller than or equal to the corresponding input &
     195             :                             &lower limit value in randomStartPointDomainLowerLimitVec:\n" // &
     196          24 :                             "    randomStartPointDomainLowerLimitVec(" // num2str(i) // ") = " // num2str(randomStartPointDomainLowerLimitVec(i)) // "\n" // &
     197          48 :                             "    randomStartPointDomainUpperLimitVec(" // num2str(i) // ") = " // num2str(self%Val(i)) // "\n\n"
     198             :             end if
     199             : 
     200             :         end do
     201        1035 :         deallocate(randomStartPointDomainUpperLimitVec)
     202        2070 :     end subroutine checkForSanity
     203             : 
     204             : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     205             : 
     206             : end module SpecMCMC_RandomStartPointDomainUpperLimitVec_mod ! LCOV_EXCL_LINE

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