Line data Source code
1 : !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2 : !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
3 : !!!! !!!!
4 : !!!! ParaMonte: Parallel Monte Carlo and Machine Learning Library. !!!!
5 : !!!! !!!!
6 : !!!! Copyright (C) 2012-present, The Computational Data Science Lab !!!!
7 : !!!! !!!!
8 : !!!! This file is part of the ParaMonte library. !!!!
9 : !!!! !!!!
10 : !!!! LICENSE !!!!
11 : !!!! !!!!
12 : !!!! https://github.com/cdslaborg/paramonte/blob/main/LICENSE.md !!!!
13 : !!!! !!!!
14 : !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
15 : !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
16 :
17 : !> \brief
18 : !> This include file contains procedure implementations of the tests of [pm_distGenExpGamma](@ref pm_distGenExpGamma).
19 : !>
20 : !> \author
21 : !> \AmirShahmoradi, Tuesday 2:06 AM, September 21, 2021, Dallas, TX
22 :
23 : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
24 :
25 : use pm_arraySpace, only: getLinSpace
26 :
27 : real(RKC) , parameter :: TOL = epsilon(0._RKC) * 100._RKC
28 : integer(IK) :: i
29 :
30 : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
31 : #if getGenExpGammaLogPDFNF_ENABLED
32 : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
33 :
34 : real(RKC) , allocatable :: Kappa(:), invOmega(:), LogTarget(:), LogTarget_ref(:), diff(:)
35 :
36 4 : assertion = .true._LK
37 :
38 : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
39 :
40 4 : call reset()
41 28 : Kappa = getLinSpace(0.1_RKC, 10._RKC, count = 5_IK)
42 28 : LogTarget_ref = -log_gamma(Kappa)
43 12 : invOmega = [1._RKC]
44 12 : allocate(LogTarget, diff, mold = LogTarget_ref)
45 :
46 24 : do i = 1_IK, size(Kappa, kind = IK)
47 20 : LogTarget(i) = getGenExpGammaLogPDFNF(Kappa(i))
48 20 : diff(i) = abs(LogTarget(i) - LogTarget_ref(i))
49 20 : assertion = assertion .and. diff(i) <= TOL
50 20 : call report()
51 24 : call test%assert(assertion, SK_"The logPDFNF must be computed correctly for the given input scalar value of `shape` and default `invScale`.")
52 : end do
53 :
54 24 : do i = 1_IK, size(Kappa, kind = IK)
55 20 : LogTarget(i) = getGenExpGammaLogPDFNF(Kappa(i), invOmega(1))
56 20 : diff(i) = abs(LogTarget(i) - LogTarget_ref(i))
57 20 : assertion = assertion .and. diff(i) <= TOL
58 20 : call report()
59 24 : call test%assert(assertion, SK_"The logPDFNF must be computed correctly for the given input scalar value of `shape` and `invScale = 1.`.")
60 : end do
61 :
62 : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
63 :
64 4 : call reset()
65 28 : Kappa = getLinSpace(0.1_RKC, 10._RKC, count = 5_IK)
66 12 : invOmega = [2._RKC]
67 28 : LogTarget_ref = -log_gamma(Kappa) + log(invOmega(1))
68 12 : allocate(LogTarget, diff, mold = LogTarget_ref)
69 :
70 24 : do i = 1_IK, size(Kappa, kind = IK)
71 20 : LogTarget(i) = getGenExpGammaLogPDFNF(Kappa(i), invOmega(1))
72 20 : diff(i) = abs(LogTarget(i) - LogTarget_ref(i))
73 20 : call report()
74 24 : call test%assert(assertion, SK_"The logPDFNF must be computed correctly for the given input scalar value of `shape` and `invScale = 2.`.")
75 : end do
76 :
77 : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
78 :
79 4 : call reset()
80 28 : Kappa = getLinSpace(0.1_RKC, 10._RKC, count = 5_IK)
81 28 : invOmega = getLinSpace(10._RKC, 0.1_RKC, count = 5_IK)
82 28 : LogTarget_ref = -log_gamma(Kappa(1)) + log(invOmega)
83 48 : LogTarget = getGenExpGammaLogPDFNF(Kappa(1), invOmega)
84 28 : diff = abs(LogTarget - LogTarget_ref)
85 :
86 24 : do i = 1_IK, size(Kappa, kind = IK)
87 20 : call report()
88 24 : call test%assert(assertion, SK_"The logPDFNF must be computed correctly for the given input scalar value of `shape` and vector `invScale`.")
89 : end do
90 :
91 : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
92 :
93 4 : call reset()
94 28 : Kappa = getLinSpace(0.1_RKC, 10._RKC, count = 5_IK)
95 28 : invOmega = getLinSpace(10._RKC, 0.1_RKC, count = 5_IK)
96 28 : LogTarget_ref = -log_gamma(Kappa) + log(invOmega)
97 48 : LogTarget = getGenExpGammaLogPDFNF(Kappa, invOmega)
98 28 : diff = abs(LogTarget - LogTarget_ref)
99 :
100 24 : do i = 1_IK, size(Kappa, kind = IK)
101 20 : call report()
102 24 : call test%assert(assertion, SK_"The logPDFNF must be computed correctly for the given input vector value of `shape` and `invScale`.")
103 : end do
104 :
105 : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
106 : #elif getGenExpGammaLogPDF_ENABLED || setGenExpGammaLogPDF_ENABLED
107 : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
108 :
109 : #if setGenExpGammaLogPDF_ENABLED
110 : real(RKC) :: kappa_current, invOmega_current, logSigma_current
111 : #endif
112 : real(RKC) , allocatable :: logPDFNF(:), Kappa(:), invOmega(:), LogSigma(:), Point(:), LogTarget(:), LogTarget_ref(:), diff(:)
113 :
114 8 : assertion = .true._LK
115 :
116 : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
117 :
118 8 : call reset()
119 :
120 : #if getGenExpGammaLogPDF_ENABLED || setGenExpGammaLogPDF_ENABLED
121 72 : Point = real([-10,-5,-1,0,2,4,8], kind = RKC)
122 : LogTarget_ref = [ -10.0000453999297624848515355915155600_RKC & ! LCOV_EXCL_LINE
123 : , -5.00673794699908546709663604842314809_RKC & ! LCOV_EXCL_LINE
124 : , -1.36787944117144232159552377016146087_RKC & ! LCOV_EXCL_LINE
125 : , -1.00000000000000000000000000000000000_RKC & ! LCOV_EXCL_LINE
126 : , -5.38905609893065022723042746057500802_RKC & ! LCOV_EXCL_LINE
127 : , -50.5981500331442390781102612028608809_RKC & ! LCOV_EXCL_LINE
128 : , -2972.95798704172827474359209945288863_RKC & ! LCOV_EXCL_LINE
129 72 : ]
130 : #endif
131 24 : allocate(LogTarget, diff, mold = LogTarget_ref)
132 :
133 64 : do i = 1_IK, size(Point, kind = IK)
134 : #if getGenExpGammaLogPDF_ENABLED
135 28 : LogTarget(i) = getGenExpGammaLogPDF(Point(i))
136 : #elif setGenExpGammaLogPDF_ENABLED
137 28 : call setGenExpGammaLogPDF(LogTarget(i), Point(i))
138 : #endif
139 56 : diff(i) = abs(LogTarget(i) - LogTarget_ref(i))
140 56 : assertion = assertion .and. diff(i) <= TOL
141 56 : call report()
142 64 : call test%assert(assertion, SK_"The `logPDF` must be computed correctly for a input scalar `x` with the default parameters.", int(__LINE__, IK))
143 : end do
144 :
145 : #if getGenExpGammaLogPDF_ENABLED
146 64 : LogTarget = getGenExpGammaLogPDF(Point)
147 : #elif setGenExpGammaLogPDF_ENABLED
148 32 : call setGenExpGammaLogPDF(LogTarget, Point)
149 : #endif
150 64 : do i = 1_IK, size(Point, kind = IK)
151 56 : diff(i) = abs(LogTarget(i) - LogTarget_ref(i))
152 56 : assertion = assertion .and. diff(i) <= TOL
153 56 : call report()
154 64 : call test%assert(assertion, SK_"The `logPDF` must be computed correctly for a input vector `x` with the default parameters.", int(__LINE__, IK))
155 : end do
156 :
157 : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
158 :
159 8 : call reset()
160 :
161 : #if getGenExpGammaLogPDF_ENABLED || setGenExpGammaLogPDF_ENABLED
162 24 : Kappa = [5._RKC]
163 32 : logPDFNF = getGenExpGammaLogPDFNF(Kappa)
164 72 : Point = real([-10,-5,-1,0,2,4,8], kind = RKC)
165 : LogTarget_ref = [ -53.17809923027770810449847719281262070_RKC & ! LCOV_EXCL_LINE
166 : , -28.18479177734703108674357764972020190_RKC & ! LCOV_EXCL_LINE
167 : , -8.545933271519387941242465371458516020_RKC & ! LCOV_EXCL_LINE
168 : , -4.178053830347945619646941601297055340_RKC & ! LCOV_EXCL_LINE
169 : , -0.567109929278595846877369061872063355_RKC & ! LCOV_EXCL_LINE
170 : , -37.77620386349218469775720280415793240_RKC & ! LCOV_EXCL_LINE
171 : , -2944.136040872076220363239041054185630_RKC & ! LCOV_EXCL_LINE
172 72 : ]
173 : #endif
174 24 : allocate(LogTarget, diff, mold = LogTarget_ref)
175 :
176 64 : do i = 1_IK, size(Point, kind = IK)
177 : #if getGenExpGammaLogPDF_ENABLED
178 112 : LogTarget(i:i) = getGenExpGammaLogPDF(Point(i), Kappa)
179 : #elif setGenExpGammaLogPDF_ENABLED
180 56 : call setGenExpGammaLogPDF(LogTarget(i:i), Point(i), logPDFNF, Kappa)
181 : #endif
182 56 : diff(i) = abs(LogTarget(i) - LogTarget_ref(i))
183 56 : assertion = assertion .and. diff(i) <= TOL
184 56 : call report()
185 64 : call test%assert(assertion, SK_"The `logPDF` must be computed correctly for a input scalar `x` with `shape = [5]`.", int(__LINE__, IK))
186 : end do
187 :
188 : #if getGenExpGammaLogPDF_ENABLED
189 64 : LogTarget = getGenExpGammaLogPDF(Point, Kappa(1))
190 : #elif setGenExpGammaLogPDF_ENABLED
191 32 : call setGenExpGammaLogPDF(LogTarget, Point, logPDFNF(1), Kappa(1))
192 : #endif
193 64 : do i = 1_IK, size(Point, kind = IK)
194 56 : diff(i) = abs(LogTarget(i) - LogTarget_ref(i))
195 56 : assertion = assertion .and. diff(i) <= TOL
196 56 : call report()
197 64 : call test%assert(assertion, SK_"The `logPDF` must be computed correctly for a input vector `x` with `shape = [5]`.", int(__LINE__, IK))
198 : end do
199 :
200 : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
201 :
202 8 : call reset()
203 :
204 : #if getGenExpGammaLogPDF_ENABLED || setGenExpGammaLogPDF_ENABLED
205 24 : Kappa = [5._RKC]
206 24 : invOmega = [1._RKC]
207 24 : LogSigma = [0._RKC]
208 32 : logPDFNF = getGenExpGammaLogPDFNF(Kappa)
209 72 : Point = real([-10,-5,-1,0,2,4,8], kind = RKC)
210 : LogTarget_ref = [ -53.17809923027770810449847719281262070_RKC & ! LCOV_EXCL_LINE
211 : , -28.18479177734703108674357764972020190_RKC & ! LCOV_EXCL_LINE
212 : , -8.545933271519387941242465371458516020_RKC & ! LCOV_EXCL_LINE
213 : , -4.178053830347945619646941601297055340_RKC & ! LCOV_EXCL_LINE
214 : , -0.567109929278595846877369061872063355_RKC & ! LCOV_EXCL_LINE
215 : , -37.77620386349218469775720280415793240_RKC & ! LCOV_EXCL_LINE
216 : , -2944.136040872076220363239041054185630_RKC & ! LCOV_EXCL_LINE
217 72 : ]
218 : #endif
219 24 : allocate(LogTarget, diff, mold = LogTarget_ref)
220 :
221 64 : do i = 1_IK, size(Point, kind = IK)
222 : #if getGenExpGammaLogPDF_ENABLED
223 112 : LogTarget(i:i) = getGenExpGammaLogPDF(Point(i), Kappa, invOmega(1), LogSigma)
224 : #elif setGenExpGammaLogPDF_ENABLED
225 56 : call setGenExpGammaLogPDF(LogTarget(i:i), Point(i), logPDFNF, Kappa, invOmega(1), LogSigma)
226 : #endif
227 56 : diff(i) = abs(LogTarget(i) - LogTarget_ref(i))
228 56 : assertion = assertion .and. diff(i) <= TOL
229 56 : call report()
230 64 : call test%assert(assertion, SK_"The `logPDF` must be computed correctly for a input scalar `x` with `shape, invScale, loc = [5], [1], [0]`.", int(__LINE__, IK))
231 : end do
232 :
233 : #if getGenExpGammaLogPDF_ENABLED
234 64 : LogTarget = getGenExpGammaLogPDF(Point, Kappa(1), invOmega(1), LogSigma(1))
235 : #elif setGenExpGammaLogPDF_ENABLED
236 32 : call setGenExpGammaLogPDF(LogTarget, Point, logPDFNF(1), Kappa(1), invOmega(1), LogSigma(1))
237 : #endif
238 64 : do i = 1_IK, size(Point, kind = IK)
239 56 : diff(i) = abs(LogTarget(i) - LogTarget_ref(i))
240 56 : assertion = assertion .and. diff(i) <= TOL
241 56 : call report()
242 64 : call test%assert(assertion, SK_"The `logPDF` must be computed correctly for a input vector `x` with `shape, invScale, loc = [5], [1], [0]`.", int(__LINE__, IK))
243 : end do
244 :
245 : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
246 :
247 8 : call reset()
248 :
249 : #if getGenExpGammaLogPDF_ENABLED || setGenExpGammaLogPDF_ENABLED
250 24 : Kappa = [5._RKC]
251 24 : invOmega = [1._RKC/7._RKC]
252 24 : LogSigma = [0._RKC]
253 32 : logPDFNF = getGenExpGammaLogPDFNF(Kappa, invOmega)
254 72 : Point = real([-10,-5,-1,0,2,4,8], kind = RKC)
255 : LogTarget_ref = [ -12.5064721587021775768864997445425634_RKC & ! LCOV_EXCL_LINE
256 : , -9.18493421038878347841123612554047209_RKC & ! LCOV_EXCL_LINE
257 : , -6.70512759343915483796951253560755200_RKC & ! LCOV_EXCL_LINE
258 : , -6.12396397940325892475229434474023509_RKC & ! LCOV_EXCL_LINE
259 : , -5.02610474827918033062690825274710576_RKC & ! LCOV_EXCL_LINE
260 : , -4.03761607469555673334531727846312397_RKC & ! LCOV_EXCL_LINE
261 : , -2.54539302868736732595888578628241702_RKC & ! LCOV_EXCL_LINE
262 72 : ]
263 : #endif
264 24 : allocate(LogTarget, diff, mold = LogTarget_ref)
265 :
266 64 : do i = 1_IK, size(Point, kind = IK)
267 : #if getGenExpGammaLogPDF_ENABLED
268 112 : LogTarget(i:i) = getGenExpGammaLogPDF(Point(i), Kappa, invOmega(1))
269 : #elif setGenExpGammaLogPDF_ENABLED
270 56 : call setGenExpGammaLogPDF(LogTarget(i:i), Point(i), logPDFNF, Kappa, invOmega(1))
271 : #endif
272 56 : diff(i) = abs(LogTarget(i) - LogTarget_ref(i))
273 56 : assertion = assertion .and. diff(i) <= TOL
274 56 : call report()
275 64 : call test%assert(assertion, SK_"The `logPDF` must be computed correctly for a input scalar `x` with `shape, invScale = [5], [7]`.", int(__LINE__, IK))
276 : end do
277 :
278 : #if getGenExpGammaLogPDF_ENABLED
279 64 : LogTarget = getGenExpGammaLogPDF(Point, Kappa(1), invOmega(1), LogSigma(1))
280 : #elif setGenExpGammaLogPDF_ENABLED
281 32 : call setGenExpGammaLogPDF(LogTarget, Point, logPDFNF(1), Kappa(1), invOmega(1), LogSigma(1))
282 : #endif
283 64 : do i = 1_IK, size(Point, kind = IK)
284 56 : diff(i) = abs(LogTarget(i) - LogTarget_ref(i))
285 56 : assertion = assertion .and. diff(i) <= TOL
286 56 : call report()
287 64 : call test%assert(assertion, SK_"The `logPDF` must be computed correctly for a input vector `x` with `shape, invScale = [5], [1/7]`.", int(__LINE__, IK))
288 : end do
289 :
290 : #if getGenExpGammaLogPDF_ENABLED
291 64 : LogTarget = getGenExpGammaLogPDF(Point, Kappa(1), invOmega(1), LogSigma(1))
292 : #elif setGenExpGammaLogPDF_ENABLED
293 32 : call setGenExpGammaLogPDF(LogTarget, Point, logPDFNF(1), Kappa(1), invOmega(1), LogSigma(1))
294 : #endif
295 64 : do i = 1_IK, size(Point, kind = IK)
296 56 : diff(i) = abs(LogTarget(i) - LogTarget_ref(i))
297 56 : assertion = assertion .and. diff(i) <= TOL
298 56 : call report()
299 64 : call test%assert(assertion, SK_"The `logPDF` must be computed correctly for a input vector `x` with `shape, invScale, loc = [5], [1/7], [0]`.", int(__LINE__, IK))
300 : end do
301 :
302 : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
303 :
304 8 : call reset()
305 :
306 : #if getGenExpGammaLogPDF_ENABLED || setGenExpGammaLogPDF_ENABLED
307 24 : Kappa = [0.5_RKC]
308 24 : invOmega = [8._RKC]
309 24 : LogSigma = [3._RKC]
310 32 : logPDFNF = getGenExpGammaLogPDFNF(Kappa, invOmega)
311 72 : Point = real([-10,-5,-1,0,2,4,8], kind = RKC)
312 128 : LogTarget_ref = getGenExpGammaLogPDF(Point - LogSigma(1), Kappa(1), invOmega(1))
313 : #endif
314 24 : allocate(LogTarget, diff, mold = LogTarget_ref)
315 :
316 64 : do i = 1_IK, size(Point, kind = IK)
317 : #if getGenExpGammaLogPDF_ENABLED
318 112 : LogTarget(i:i) = getGenExpGammaLogPDF(Point(i), Kappa, invOmega(1), LogSigma(1))
319 : #elif setGenExpGammaLogPDF_ENABLED
320 56 : call setGenExpGammaLogPDF(LogTarget(i:i), Point(i), logPDFNF, Kappa, invOmega(1), LogSigma(1))
321 : #endif
322 56 : diff(i) = abs(LogTarget(i) - LogTarget_ref(i))
323 56 : assertion = assertion .and. diff(i) <= TOL
324 56 : call report()
325 64 : call test%assert(assertion, SK_"The `logPDF` must be computed correctly for a input scalar `x` with `shape, invScale = [5], [7]`.", int(__LINE__, IK))
326 : end do
327 :
328 : #if getGenExpGammaLogPDF_ENABLED
329 64 : LogTarget = getGenExpGammaLogPDF(Point, Kappa(1), invOmega(1), LogSigma(1))
330 : #elif setGenExpGammaLogPDF_ENABLED
331 32 : call setGenExpGammaLogPDF(LogTarget, Point, logPDFNF(1), Kappa(1), invOmega(1), LogSigma(1))
332 : #endif
333 64 : do i = 1_IK, size(Point, kind = IK)
334 56 : diff(i) = abs(LogTarget(i) - LogTarget_ref(i))
335 56 : assertion = assertion .and. diff(i) <= TOL
336 56 : call report()
337 64 : call test%assert(assertion, SK_"The `logPDF` must be computed correctly for a input vector `x` with `shape, invScale = [5], [1/7]`.", int(__LINE__, IK))
338 : end do
339 :
340 : #if getGenExpGammaLogPDF_ENABLED
341 64 : LogTarget = getGenExpGammaLogPDF(Point, Kappa(1), invOmega(1), LogSigma(1))
342 : #elif setGenExpGammaLogPDF_ENABLED
343 32 : call setGenExpGammaLogPDF(LogTarget, Point, logPDFNF(1), Kappa(1), invOmega(1), LogSigma(1))
344 : #endif
345 64 : do i = 1_IK, size(Point, kind = IK)
346 56 : diff(i) = abs(LogTarget(i) - LogTarget_ref(i))
347 56 : assertion = assertion .and. diff(i) <= TOL
348 56 : call report()
349 64 : call test%assert(assertion, SK_"The `logPDF` must be computed correctly for a input vector `x` with `shape, invScale, loc = [5], [1/7], [0]`.", int(__LINE__, IK))
350 : end do
351 :
352 : #if setGenExpGammaLogPDF_ENABLED
353 4 : block
354 :
355 : use pm_val2str, only: getStr
356 : use pm_quadPack, only: isFailedQuad
357 : use pm_distUnif, only: setUnifRand
358 : use pm_distGenExpGamma, only: getGenExpGammaCDF
359 :
360 : real(RKC) :: lb, ub, integral_def, integral, abserr
361 4 : lb = -10._RKC
362 4 : ub = +10._RKC
363 :
364 4 : integral_def = getGenExpGammaCDF(ub) - getGenExpGammaCDF(lb)
365 4 : assertion = .not. isFailedQuad(getFunc1, lb, ub, integral, abserr)
366 4 : call test%assert(assertion, SK_"The integral of the PDF over its support must not fail.", int(__LINE__, IK))
367 4 : assertion = assertion .and. abs(integral - integral_def) <= abserr
368 12 : call test%assert(assertion, SK_"The integral of the PDF must equal unity. integral, abserr = "//getStr([integral, abserr]), int(__LINE__, IK))
369 :
370 4 : call setUnifRand(kappa_current, epsilon(0._RKC), 5._RKC)
371 4 : integral_def = getGenExpGammaCDF(ub, kappa = kappa_current) - getGenExpGammaCDF(lb, kappa = kappa_current)
372 4 : assertion = .not. isFailedQuad(getFunc2, lb, ub, integral, abserr)
373 4 : call test%assert(assertion, SK_"The integral of the PDF over its support must not fail.", int(__LINE__, IK))
374 4 : assertion = assertion .and. abs(integral - integral_def) <= abserr
375 16 : call test%assert(assertion, SK_"The integral of the PDF must equal unity. integral, abserr, kappa_current = "//getStr([integral, abserr, kappa_current]), int(__LINE__, IK))
376 :
377 4 : call setUnifRand(kappa_current, epsilon(0._RKC), 5._RKC)
378 4 : call setUnifRand(invOmega_current, epsilon(0._RKC), 5._RKC)
379 4 : integral_def = getGenExpGammaCDF(ub, kappa = kappa_current, invOmega = invOmega_current) - getGenExpGammaCDF(lb, kappa = kappa_current, invOmega = invOmega_current)
380 4 : assertion = .not. isFailedQuad(getFunc3, lb, ub, integral, abserr)
381 4 : call test%assert(assertion, SK_"The integral of the PDF over its support must not fail.", int(__LINE__, IK))
382 4 : assertion = assertion .and. abs(integral - integral_def) <= abserr
383 20 : call test%assert(assertion, SK_"The integral of the PDF must equal unity. integral, abserr, kappa_current, invOmega_current = "//getStr([integral, abserr, kappa_current, invOmega_current]), int(__LINE__, IK))
384 :
385 4 : call setUnifRand(kappa_current, epsilon(0._RKC), 5._RKC)
386 4 : call setUnifRand(invOmega_current, epsilon(0._RKC), 5._RKC)
387 4 : call setUnifRand(logSigma_current, -10._RKC, 10._RKC)
388 4 : integral_def = getGenExpGammaCDF(ub, kappa_current, invOmega_current, logSigma_current) - getGenExpGammaCDF(lb, kappa_current, invOmega_current, logSigma_current)
389 4 : assertion = .not. isFailedQuad(getFunc4, lb, ub, integral, abserr)
390 4 : call test%assert(assertion, SK_"The integral of the PDF over its support must not fail.", int(__LINE__, IK))
391 4 : assertion = assertion .and. abs(integral - integral_def) <= abserr
392 24 : call test%assert(assertion, SK_"The integral of the PDF must equal unity. integral, abserr, kappa_current, invOmega_current, logSigma_current = "//getStr([integral, abserr, kappa_current, invOmega_current, logSigma_current]), int(__LINE__, IK))
393 :
394 : end block
395 : #endif
396 :
397 : #else
398 : !%%%%%%%%%%%%%%%%%%%%%%%%
399 : #error "Unrecognized interface."
400 : !%%%%%%%%%%%%%%%%%%%%%%%%
401 : #endif
402 :
403 : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
404 :
405 : contains
406 :
407 : #if setGenExpGammaLogPDF_ENABLED
408 :
409 : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
410 :
411 1344 : function getFunc1(x) result(func)
412 : real(RKC) , intent(in) :: x
413 : real(RKC) :: func
414 1344 : call setGenExpGammaLogPDF(func, x)
415 1344 : func = exp(func)
416 1344 : end function
417 :
418 : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
419 :
420 1512 : function getFunc2(x) result(func)
421 : real(RKC) , intent(in) :: x
422 : real(RKC) :: func
423 1512 : call setGenExpGammaLogPDF(func, x, getGenExpGammaLogPDFNF(kappa_current), kappa_current)
424 1512 : func = exp(func)
425 1512 : end function
426 :
427 : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
428 :
429 1722 : function getFunc3(x) result(func)
430 : real(RKC) , intent(in) :: x
431 : real(RKC) :: func
432 1722 : call setGenExpGammaLogPDF(func, x, getGenExpGammaLogPDFNF(kappa_current, invOmega_current), kappa_current, invOmega_current)
433 1722 : func = exp(func)
434 1722 : end function
435 :
436 : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
437 :
438 1722 : function getFunc4(x) result(func)
439 : real(RKC) , intent(in) :: x
440 : real(RKC) :: func
441 1722 : call setGenExpGammaLogPDF(func, x, getGenExpGammaLogPDFNF(kappa_current, invOmega_current), kappa_current, invOmega_current, logSigma_current)
442 1722 : func = exp(func)
443 1722 : end function
444 :
445 : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
446 : #endif
447 56 : subroutine reset()
448 56 : if (allocated(diff)) deallocate(diff)
449 56 : if (allocated(LogTarget)) deallocate(LogTarget)
450 56 : end subroutine
451 :
452 : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
453 :
454 772 : subroutine report()
455 772 : if (test%traceable .and. .not. assertion) then
456 0 : assertion = assertion .and. diff(i) <= TOL
457 : ! LCOV_EXCL_START
458 : write(test%disp%unit,"(*(g0,:,', '))")
459 : write(test%disp%unit,"(*(g0,:,', '))") "Kappa ", Kappa
460 : write(test%disp%unit,"(*(g0,:,', '))") "invOmega ", invOmega
461 : write(test%disp%unit,"(*(g0,:,', '))") "LogTarget_ref ", LogTarget_ref
462 : write(test%disp%unit,"(*(g0,:,', '))") "LogTarget ", LogTarget
463 : write(test%disp%unit,"(*(g0,:,', '))") "diff ", diff
464 : write(test%disp%unit,"(*(g0,:,', '))") "TOL ", TOL
465 : write(test%disp%unit,"(*(g0,:,', '))")
466 : ! LCOV_EXCL_STOP
467 : end if
468 772 : end subroutine
469 :
470 : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|