ParaMonte Fortran 2.0.0
Parallel Monte Carlo and Machine Learning Library
See the latest version documentation.
test_pm_mathCumPropExp.F90
Go to the documentation of this file.
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
22
23!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
24
26
27 use pm_mathCumPropExp ! LCOV_EXCL_LINE
28 use pm_err, only: err_type
29 use pm_test, only: test_type, LK
30 use pm_kind, only: LK
31 implicit none
32
33 private
34 public :: setTest
35 type(test_type) :: test
36
37!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
38
39 interface
40
41#if RK5_ENABLED
42 module function test_getCumPropExpSel_RK5() result(assertion); logical(LK) :: assertion; end function
43#endif
44#if RK4_ENABLED
45 module function test_getCumPropExpSel_RK4() result(assertion); logical(LK) :: assertion; end function
46#endif
47#if RK3_ENABLED
48 module function test_getCumPropExpSel_RK3() result(assertion); logical(LK) :: assertion; end function
49#endif
50#if RK2_ENABLED
51 module function test_getCumPropExpSel_RK2() result(assertion); logical(LK) :: assertion; end function
52#endif
53#if RK1_ENABLED
54 module function test_getCumPropExpSel_RK1() result(assertion); logical(LK) :: assertion; end function
55#endif
56
57 end interface
58
59!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
60
61 interface
62
63#if RK5_ENABLED
64 module function test_getCumPropExpSeq_RK5() result(assertion); logical(LK) :: assertion; end function
65#endif
66#if RK4_ENABLED
67 module function test_getCumPropExpSeq_RK4() result(assertion); logical(LK) :: assertion; end function
68#endif
69#if RK3_ENABLED
70 module function test_getCumPropExpSeq_RK3() result(assertion); logical(LK) :: assertion; end function
71#endif
72#if RK2_ENABLED
73 module function test_getCumPropExpSeq_RK2() result(assertion); logical(LK) :: assertion; end function
74#endif
75#if RK1_ENABLED
76 module function test_getCumPropExpSeq_RK1() result(assertion); logical(LK) :: assertion; end function
77#endif
78
79 end interface
80
81!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
82
83 interface
84
85#if RK5_ENABLED
86 module function test_setCumPropExpSel_RK5() result(assertion); logical(LK) :: assertion; end function
87#endif
88#if RK4_ENABLED
89 module function test_setCumPropExpSel_RK4() result(assertion); logical(LK) :: assertion; end function
90#endif
91#if RK3_ENABLED
92 module function test_setCumPropExpSel_RK3() result(assertion); logical(LK) :: assertion; end function
93#endif
94#if RK2_ENABLED
95 module function test_setCumPropExpSel_RK2() result(assertion); logical(LK) :: assertion; end function
96#endif
97#if RK1_ENABLED
98 module function test_setCumPropExpSel_RK1() result(assertion); logical(LK) :: assertion; end function
99#endif
100
101 end interface
102
103!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
104
105 interface
106
107#if RK5_ENABLED
108 module function test_setCumPropExpSeq_RK5() result(assertion); logical(LK) :: assertion; end function
109#endif
110#if RK4_ENABLED
111 module function test_setCumPropExpSeq_RK4() result(assertion); logical(LK) :: assertion; end function
112#endif
113#if RK3_ENABLED
114 module function test_setCumPropExpSeq_RK3() result(assertion); logical(LK) :: assertion; end function
115#endif
116#if RK2_ENABLED
117 module function test_setCumPropExpSeq_RK2() result(assertion); logical(LK) :: assertion; end function
118#endif
119#if RK1_ENABLED
120 module function test_setCumPropExpSeq_RK1() result(assertion); logical(LK) :: assertion; end function
121#endif
122
123 end interface
124
125!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
126
127contains
128
129!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
130
131 subroutine setTest()
132
134
135 !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
136
137#if RK5_ENABLED
138 call test%run(test_getCumPropExpSel_RK5, SK_"test_getCumPropExpSel_RK5")
139#endif
140#if RK4_ENABLED
141 call test%run(test_getCumPropExpSel_RK4, SK_"test_getCumPropExpSel_RK4")
142#endif
143#if RK3_ENABLED
144 call test%run(test_getCumPropExpSel_RK3, SK_"test_getCumPropExpSel_RK3")
145#endif
146#if RK2_ENABLED
147 call test%run(test_getCumPropExpSel_RK2, SK_"test_getCumPropExpSel_RK2")
148#endif
149#if RK1_ENABLED
150 call test%run(test_getCumPropExpSel_RK1, SK_"test_getCumPropExpSel_RK1")
151#endif
152
153 !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
154
155#if RK5_ENABLED
156 call test%run(test_getCumPropExpSeq_RK5, SK_"test_getCumPropExpSeq_RK5")
157#endif
158#if RK4_ENABLED
159 call test%run(test_getCumPropExpSeq_RK4, SK_"test_getCumPropExpSeq_RK4")
160#endif
161#if RK3_ENABLED
162 call test%run(test_getCumPropExpSeq_RK3, SK_"test_getCumPropExpSeq_RK3")
163#endif
164#if RK2_ENABLED
165 call test%run(test_getCumPropExpSeq_RK2, SK_"test_getCumPropExpSeq_RK2")
166#endif
167#if RK1_ENABLED
168 call test%run(test_getCumPropExpSeq_RK1, SK_"test_getCumPropExpSeq_RK1")
169#endif
170
171 !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
172
173#if RK5_ENABLED
174 call test%run(test_setCumPropExpSel_RK5, SK_"test_setCumPropExpSel_RK5")
175#endif
176#if RK4_ENABLED
177 call test%run(test_setCumPropExpSel_RK4, SK_"test_setCumPropExpSel_RK4")
178#endif
179#if RK3_ENABLED
180 call test%run(test_setCumPropExpSel_RK3, SK_"test_setCumPropExpSel_RK3")
181#endif
182#if RK2_ENABLED
183 call test%run(test_setCumPropExpSel_RK2, SK_"test_setCumPropExpSel_RK2")
184#endif
185#if RK1_ENABLED
186 call test%run(test_setCumPropExpSel_RK1, SK_"test_setCumPropExpSel_RK1")
187#endif
188
189 !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
190
191#if RK5_ENABLED
192 call test%run(test_setCumPropExpSeq_RK5, SK_"test_setCumPropExpSeq_RK5")
193#endif
194#if RK4_ENABLED
195 call test%run(test_setCumPropExpSeq_RK4, SK_"test_setCumPropExpSeq_RK4")
196#endif
197#if RK3_ENABLED
198 call test%run(test_setCumPropExpSeq_RK3, SK_"test_setCumPropExpSeq_RK3")
199#endif
200#if RK2_ENABLED
201 call test%run(test_setCumPropExpSeq_RK2, SK_"test_setCumPropExpSeq_RK2")
202#endif
203#if RK1_ENABLED
204 call test%run(test_setCumPropExpSeq_RK1, SK_"test_setCumPropExpSeq_RK1")
205#endif
206
207 !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
208
209 call test%run(test_setCumPropExp_RK, SK_"test_setCumPropExp_RK")
210
211 call test%summarize()
212
213 end subroutine setTest
214
215!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
216
219 function test_setCumPropExp_RK() result(assertion)
220
221 use pm_kind, only: IK, RK
222 use pm_mathCumSum, only: getCumSum ! LCOV_EXCL_LINE
223 use pm_distUnif, only: getUnifRand ! LCOV_EXCL_LINE
224
225 logical(LK) :: assertion
226 real(RK) , parameter :: TOL = epsilon(1._RK) * 10._RK
227 real(RK) , allocatable :: Array(:)
228 real(RK) , allocatable :: cumPropExp_ref(:)
229 real(RK) , allocatable :: cumPropExp(:)
230 real(RK) , allocatable :: diff(:)
231 integer(IK) :: i
232
233 do i = 1, 200
234 Array = getUnifRand(minexponent(0._RK), maxexponent(0._RK), getUnifRand(1_IK, 10_IK))
235 cumPropExp_ref = getCumSum(exp(Array - maxval(Array)))
236 cumPropExp_ref = cumPropExp_ref / cumPropExp_ref(size(cumPropExp_ref))
237 cumPropExp = getCumPropExp_RK(Array, maxval(Array), size(Array, kind = IK))
238 diff = abs(cumPropExp - cumPropExp_ref)
239 assertion = all(diff < TOL)
240 call test%assert(assertion, desc = "The genLogCumProp_RK() must correctly compute CumSumProp for an input array of real of default kind.")
241 end do
242
243 end function
244
245!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
246
247end module test_pm_mathCumPropExp ! LCOV_EXCL_LINE
Generate and return a scalar or a contiguous array of rank 1 of length s1 of randomly uniformly distr...
Generate and return the cumulative sum of the input array, optionally in the backward direction and,...
This module contains classes and procedures for computing various statistical quantities related to t...
This module contains classes and procedures for reporting and handling errors.
Definition: pm_err.F90:52
character(*, SK), parameter MODULE_NAME
Definition: pm_err.F90:58
This module defines the relevant Fortran kind type-parameters frequently used in the ParaMonte librar...
Definition: pm_kind.F90:268
integer, parameter RK
The default real kind in the ParaMonte library: real64 in Fortran, c_double in C-Fortran Interoperati...
Definition: pm_kind.F90:543
integer, parameter LK
The default logical kind in the ParaMonte library: kind(.true.) in Fortran, kind(....
Definition: pm_kind.F90:541
integer, parameter IK
The default integer kind in the ParaMonte library: int32 in Fortran, c_int32_t in C-Fortran Interoper...
Definition: pm_kind.F90:540
This module contains the procedures and interfaces for computing the cumulative sum of the exponentia...
pure real(RKG) function, dimension(lenArray) getCumPropExp_RK(array, maxArray, lenArray)
[LEGACY code] Generate and return the normalized cumulative sum (i.e., Cumulative Density Function (...
This module contains the procedures and interfaces for computing the cumulative sum of an array.
This module contains a simple unit-testing framework for the Fortran libraries, including the ParaMon...
Definition: pm_test.F90:42
This module contains tests of the module pm_mathCumPropExp.
logical(LK) function test_setCumPropExp_RK()
Test the special legacy interface: genLogCumProp_RK()
This is the derived type for generating objects to gracefully and verbosely handle runtime unexpected...
Definition: pm_err.F90:157
This is the derived type test_type for generating objects that facilitate testing of a series of proc...
Definition: pm_test.F90:209