The ParaMonte Documentation Website
Current view: top level - kernel - SpecMCMC_StartPointVec_mod.f90 (source / functions) Hit Total Coverage
Test: ParaMonte 1.5.1 :: MPI Parallel Kernel - Code Coverage Report Lines: 28 28 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 `startPointVec` 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_StartPointVec_mod
      49             : 
      50             :     use Constants_mod, only: RK
      51             :     implicit none
      52             : 
      53             :     character(*), parameter         :: MODULE_NAME = "@SpecMCMC_StartPointVec_mod"
      54             : 
      55             :     real(RK), allocatable           :: startPointVec(:) ! namelist input
      56             : 
      57             :     type                            :: StartPointVec_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 StartPointVec_type
      64             : 
      65             :     interface StartPointVec_type
      66             :         module procedure            :: construct
      67             :     end interface StartPointVec_type
      68             : 
      69             :     private :: construct, set, checkForSanity, nullifyNameListVar
      70             : 
      71             : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
      72             : 
      73             : contains
      74             : 
      75             : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
      76             : 
      77        1047 :     function construct() 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             :         type(StartPointVec_type) :: self
      85        1047 :         self%null   = NULL_RK
      86             :         self%desc   = &
      87             :         "startPointVec is a 64bit real-valued vector of length ndim (the dimension of the domain of the input objective function). &
      88             :         &For every element of startPointVec that is not provided as input, the default value will be the center of the domain of &
      89             :         &startPointVec as specified by domainLowerLimitVec and domainUpperLimitVec input variables. &
      90             :         &If the input variable randomStartPointRequested=TRUE (or true or t, all case-insensitive), then the missing &
      91             :         &elements of startPointVec will be initialized to values drawn randomly from within the corresponding &
      92        1047 :         &ranges specified by the input variables randomStartPointDomainLowerLimitVec and randomStartPointDomainUpperLimitVec."
      93        1047 :     end function construct
      94             : 
      95             : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
      96             : 
      97        1047 :     subroutine nullifyNameListVar(self,nd)
      98             : #if INTEL_COMPILER_ENABLED && defined DLL_ENABLED && (OS_IS_WINDOWS || defined OS_IS_DARWIN)
      99             :         !DEC$ ATTRIBUTES DLLEXPORT :: nullifyNameListVar
     100             : #endif
     101        1047 :         use Constants_mod, only: IK
     102             :         implicit none
     103             :         class(StartPointVec_type), intent(in)   :: self
     104             :         integer(IK), intent(in)                 :: nd
     105          12 :         if (allocated(startPointVec)) deallocate(startPointVec)
     106        2553 :         allocate(startPointVec(nd), source = self%null)
     107        1047 :     end subroutine nullifyNameListVar
     108             : 
     109             : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     110             : 
     111        4176 :     pure subroutine set(self, startPointVec)
     112             : #if INTEL_COMPILER_ENABLED && defined DLL_ENABLED && (OS_IS_WINDOWS || defined OS_IS_DARWIN)
     113             :         !DEC$ ATTRIBUTES DLLEXPORT :: set
     114             : #endif
     115        1047 :         use Constants_mod, only: IK, RK
     116             :         implicit none
     117             :         class(StartPointVec_type), intent(inout)    :: self
     118             :         real(RK), intent(in), optional              :: startPointVec(:)
     119        3630 :         if (present(startPointVec)) self%Val = startPointVec
     120        2088 :     end subroutine set
     121             : 
     122             : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     123             : 
     124        2070 :     subroutine checkForSanity(self, Err, methodName, SpecBase, randomStartPointRequested, randomStartPointDomainLowerLimitVec, randomStartPointDomainUpperLimitVec)
     125             : #if INTEL_COMPILER_ENABLED && defined DLL_ENABLED && (OS_IS_WINDOWS || defined OS_IS_DARWIN)
     126             :         !DEC$ ATTRIBUTES DLLEXPORT :: checkForSanity
     127             : #endif
     128        2088 :         use SpecBase_mod, only: SpecBase_type
     129             :         use Constants_mod, only: IK, RK
     130             :         use String_mod, only: num2str
     131             :         use Err_mod, only: Err_type
     132             :         implicit none
     133             :         class(StartPointVec_type), intent(inout)    :: self
     134             :         type(Err_type), intent(inout)               :: Err
     135             :         type(SpecBase_type), intent(in)             :: SpecBase
     136             :         character(*), intent(in)                    :: methodName
     137             :         logical, intent(in)                         :: randomStartPointRequested
     138             :         real(RK), intent(in)                        :: randomStartPointDomainLowerLimitVec(:)
     139             :         real(RK), intent(in)                        :: randomStartPointDomainUpperLimitVec(:)
     140             :         character(*), parameter                     :: PROCEDURE_NAME = "@checkForSanity()"
     141        1035 :         real(RK)                                    :: unifrnd
     142             :         integer(IK)                                 :: i
     143        2529 :         do i = 1, size(self%Val)
     144        2529 :             if (self%Val(i)==self%null) then
     145        1452 :                 if (randomStartPointRequested) then
     146          36 :                     call random_number(unifrnd)
     147          36 :                     self%Val(i) = randomStartPointDomainLowerLimitVec(i) + unifrnd * (randomStartPointDomainUpperLimitVec(i)-randomStartPointDomainLowerLimitVec(i))
     148             :                 else
     149        1416 :                     self%Val(i) = 0.5_RK * ( SpecBase%DomainLowerLimitVec%Val(i) + SpecBase%DomainUpperLimitVec%Val(i) )
     150             :                 end if
     151          42 :             elseif ( self%Val(i)<SpecBase%DomainLowerLimitVec%Val(i) .or. self%Val(i)>SpecBase%DomainUpperLimitVec%Val(i) ) then
     152          12 :                 Err%occurred = .true.
     153             :                 Err%msg =   Err%msg // &
     154             :                             MODULE_NAME // PROCEDURE_NAME // ": Error occurred. &
     155             :                             &The input requested value for the component " // num2str(i) // " of the vector startPointVec (" // &
     156          24 :                             num2str(self%Val(i)) // ") must be within the range of the sampling Domain defined &
     157             :                             &in the program: (" // &
     158             :                             num2str(SpecBase%DomainLowerLimitVec%Val(i)) // "," // & ! LCOV_EXCL_LINE
     159             :                             num2str(SpecBase%DomainUpperLimitVec%Val(i)) // & ! LCOV_EXCL_LINE
     160             :                             "). If you don't know an appropriate value for startPointVec, drop it from the input list. " // &
     161          12 :                             methodName // " will automatically assign an appropriate value to it.\n\n"
     162             :             end if
     163             :         end do
     164        1035 :         deallocate(startPointVec)
     165        2070 :     end subroutine checkForSanity
     166             : 
     167             : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     168             : 
     169             : end module SpecMCMC_StartPointVec_mod ! LCOV_EXCL_LINE

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