ParaMonte Fortran 2.0.0
Parallel Monte Carlo and Machine Learning Library
See the latest version documentation.
pm_sampleQuan::getQuan Interface Reference

Generate and return the approximate sample quantile for the given method at the specified probabilities. More...

Detailed Description

Generate and return the approximate sample quantile for the given method at the specified probabilities.

Parameters
[in]method: The input scalar constant that can be,
  1. The scalar constant neimean or a scalar object of type neimean_type implying the use of the average of the sample values of the two nearest neighbors of the input prob smaller and larger than it as the output quan.
  2. The scalar constant neinear or a scalar object of type neinear_type implying the use of the average of the sample value of the nearest neighbor of the input prob as the output quan.
    Note that the nearest neighbor in this case is measured by actual Euclidean distances of neighbors to the input prob.
  3. The scalar constant neiprev or a scalar object of type neiprev_type implying the use of the sample value of the largest abscissa in the input prob smaller than the input prob as the output quan.
  4. The scalar constant neinext or a scalar object of type neinext_type implying the use of the sample value of the smallest abscissa in the input prob larger than the input prob as the output quan.
  5. The scalar constant piwilin or a scalar object of type piwilin_type implying the use of the linear interpolation of the sample values of the two prob points that bracket prob as the output quan.
    The linear interpolation implemented in this constructor is based on the Lagrange classical formula for linear interpolation.
    Suppose an input query point \(x\) falls between two nodes \(x_i\) and \(x_{i+1}\) with the corresponding function values \(y_i\) and \(y_{i+1}\) and we wish to estimate the corresponding interpolated value \(y(x)\), which can be computed as,

    \begin{equation*} y(x) = \frac {x - x_{i+1}} {x_i - x_{i+1}} y_i + \frac {x - x_{i}} {x_{i+1} - x_{i}} y_{i+1} ~. \end{equation*}

Either piwilin or neinear for larger sample sizes can be reasonable choices.
[in]prob: The input scalar or contiguous vector of
  1. type real of kind any supported by the processor (e.g., RK, RK32, RK64, or RK128),
containing the (set of) probability(s) for which the corresponding quantiles must be computed.
[in]sample: The input contiguous vector of shape (1:nsam) or matrix of shape (1:ndim, 1:nsam) of the same type, kind, and size as prob, containing the sample based upon which the quantiles must be computed.
[in]dim: The input scalar of type integer of default kind IK, whose value represents the dimension of the input sample containing different nsam observations:
  1. If dim = 1, the input sample is assumed to have the shape (1:nsam, 1:ndim).
  2. If dim = 2, the input sample is assumed to have the shape (1:ndim, 1:nsam).
(optional. It must be present if and only if the input arguments the condition rank(sample) > 1 holds.)
[in]weight: The input contiguous vector of length nsam of,
  1. type integer of default kind IK, or
  2. type real of the same kind as the kind of prob,
containing the corresponding weights of individual nsam observations in the target sample.
(optional. default = getFilled(1, nsam).)
[in]weisum: The input scalar of the same type and kind as weight containing the quantity sum(weight).
(optional. It can be present if and only if the input argument weight is also present.)
Returns

quan : The output object of the same type and kind as prob, containing the sample quantiles corresponding to the input prob.

  1. If sample is a vector and prob is a scalar, then quan is a scalar.
  2. If sample is a vector and prob is a vector, then quan is a vector of size size(prob).
  3. If sample is a matrix and prob is a scalar, then quan is a vector of size size(sample, 3 - dim).
  4. If sample is a matrix and prob is a vector, then quan is a matrix of shape [size(prob), size(sample, 3 - dim)].


Possible calling interfaces

! 1D sample
quan = getQuan(method, prob, sample(1:nsam))
quan = getQuan(method, prob, sample(1:nsam), weight(1:nsam), weisum = weisum)
quan(1:nprob) = getQuan(method, prob(1:nprob), sample(1:nsam))
quan(1:nprob) = getQuan(method, prob(1:nprob), sample(1:nsam), weight(1:nsam), weisum = weisum)
! 2D sample
quan(1:size(sample, 3 - dim)) = getQuan(method, prob, sample(:,:), dim)
quan(1:size(sample, 3 - dim)) = getQuan(method, prob, sample(:,:), dim, weight(1:nsam), weisum = weisum)
quan(1:nprob, 1:size(sample, 3 - dim)) = getQuan(method, prob(1:nprob), sample(:,:), dim)
quan(1:nprob, 1:size(sample, 3 - dim)) = getQuan(method, prob(1:nprob), sample(:,:), dim, weight(1:nsam), weisum = weisum)
Generate and return the approximate sample quantile for the given method at the specified probabiliti...
This module contains procedures and data types for computing sample quantile.
Warning
The condition size(weight) == size(sample, dim) must hold for the corresponding input arguments.
The condition all([0 <= prob .and. prob <= 1]) must hold for the corresponding input arguments.
The condition 0 < dim .and. dim < 3 must hold for the corresponding input arguments.
The condition all(0 <= weight) must hold for the corresponding input arguments.
These conditions are verified only if the library is built with the preprocessor macro CHECK_ENABLED=1.
The pure procedure(s) documented herein become impure when the ParaMonte library is compiled with preprocessor macro CHECK_ENABLED=1.
By default, these procedures are pure in release build and impure in debug and testing builds.
Developer Remark:
A subroutine equivalent of this functional interface was deemed unnecessary.
Internally, the functional interface requires two internal runtime allocatable arrays to sort the input sample and store the sample ECDF.
For intensive repeated calculations, these allocation actions and copies can be avoided by explicitly implementing this generic interface as the following for a 1D sample.
type_of(sample) :: ecdf(size(sample))
call setECDF(ecdf, weight, weisum)
call setSorted(sample)
call setExtrap(method, ecdf, sample, prob, quan)
Sort the input scalar string or contiguous vector in ascending order, or return the sorted indices of...
Generate and return the approximate polynomial interpolation/extrapolation value of the input specifi...
Compute and return the Empirical Cumulative Distribution Function (ECDF) of a univariate (optionally ...
This module contains procedures and generic interfaces for various sorting tasks.
This module contains procedures and data types for interpolation of finite samples of data.
This module contains classes and procedures for computing the Empirical Cumulative Distribution Funct...
See also
pm_polation
pm_sampleECDF
pm_sampleQuan
pm_arraySort


Example usage

1program example
2
3 use pm_kind, only: SK, IK, LK
6 use pm_distNorm, only: getNormRand
9 use pm_distPois, only: getPoisRand
10 use pm_distUnif, only: getUnifRand
11 use pm_arrayFill, only: getFilled
12 use pm_io, only: getErrTableWrite
13 use pm_io, only: display_type
14
15 implicit none
16
17 integer(IK) :: iprob, ndim, nsam, itry, ntry = 5
18 integer(IK), allocatable :: iweight(:)
19 type(display_type) :: disp
20
21 disp = display_type(file = "main.out.F90")
22
23 call disp%skip()
24 call disp%show("!%%%%%%%%%%%%%%%%%%%")
25 call disp%show("!1D sample quantile.")
26 call disp%show("!%%%%%%%%%%%%%%%%%%%")
27 call disp%skip()
28
29 block
30 use pm_kind, only: TKC => RKS ! all processor kinds are supported.
31 real(TKC), allocatable :: sample(:), prob(:), quan(:)
32 call disp%skip()
33 call disp%show("sample = [10, 7, 4, 3, 2, 1, 0]")
34 sample = [10, 7, 4, 3, 2, 1, 0]
35 call disp%show("prob = [0., .25, .5, .75, .9, 1.]")
36 prob = [0., .25, .5, .75, .9, 1.]
37 call disp%show("quan = getQuan(neimean, prob, sample)")
38 quan = getQuan(neimean, prob, sample)
39 call disp%show("quan")
40 call disp%show( quan )
41 call disp%show("quan = getQuan(neinear, prob, sample)")
42 quan = getQuan(neinear, prob, sample)
43 call disp%show("quan")
44 call disp%show( quan )
45 call disp%show("quan = getQuan(neinext, prob, sample)")
46 quan = getQuan(neinext, prob, sample)
47 call disp%show("quan")
48 call disp%show( quan )
49 call disp%show("quan = getQuan(neiprev, prob, sample)")
50 quan = getQuan(neiprev, prob, sample)
51 call disp%show("quan")
52 call disp%show( quan )
53 call disp%show("quan = getQuan(piwilin, prob, sample)")
54 quan = getQuan(piwilin, prob, sample)
55 call disp%show("quan")
56 call disp%show( quan )
57 call disp%show("do iprob = 1, size(prob)")
58 call disp%show(" quan(iprob) = getQuan(piwilin, prob(iprob), sample)")
59 call disp%show("end do")
60 do iprob = 1, size(prob)
61 quan(iprob) = getQuan(piwilin, prob(iprob), sample)
62 end do
63 call disp%show("quan")
64 call disp%show( quan )
65 call disp%skip()
66 end block
67
68 call disp%skip()
69 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
70 call disp%show("!1D frequency/reliability-weighted sample quantile.")
71 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
72 call disp%skip()
73
74 block
75 use pm_kind, only: TKC => RKS ! all processor kinds are supported.
76 real(TKC), allocatable :: sample(:), prob(:), quan(:)
77 call disp%skip()
78 call disp%show("sample = [10, 7, 4, 3, 2, 1, 0]")
79 sample = [10, 7, 4, 3, 2, 1, 0]
80 call disp%show("iweight = getUnifRand(1, 9, size(sample, 1, IK))")
81 iweight = getUnifRand(1, 9, size(sample, 1, IK))
82 call disp%show("iweight")
83 call disp%show( iweight )
84 call disp%show("prob = [0., .25, .5, .75, .9, 1.]")
85 prob = [0., .25, .5, .75, .9, 1.]
86 call disp%show("quan = getQuan(neimean, prob, sample)")
87 quan = getQuan(neimean, prob, sample)
88 call disp%show("quan")
89 call disp%show( quan )
90 call disp%show("quan = getQuan(neinear, prob, sample, iweight)")
91 quan = getQuan(neinear, prob, sample, iweight)
92 call disp%show("quan")
93 call disp%show( quan )
94 call disp%show("quan = getQuan(neinext, prob, sample, iweight)")
95 quan = getQuan(neinext, prob, sample, iweight)
96 call disp%show("quan")
97 call disp%show( quan )
98 call disp%show("quan = getQuan(neiprev, prob, sample, iweight)")
99 quan = getQuan(neiprev, prob, sample, iweight)
100 call disp%show("quan")
101 call disp%show( quan )
102 call disp%show("quan = getQuan(piwilin, prob, sample, iweight, sum(iweight))")
103 quan = getQuan(piwilin, prob, sample, iweight, sum(iweight))
104 call disp%show("quan")
105 call disp%show( quan )
106 call disp%show("do iprob = 1, size(prob)")
107 call disp%show(" quan(iprob) = getQuan(piwilin, prob(iprob), sample, iweight)")
108 call disp%show("end do")
109 do iprob = 1, size(prob)
110 quan(iprob) = getQuan(piwilin, prob(iprob), sample, iweight)
111 end do
112 call disp%show("quan")
113 call disp%show( quan )
114 call disp%skip()
115 end block
116
117 block
118 use pm_kind, only: TKC => RKS ! all processor kinds are supported.
119 real(TKC), allocatable :: sample(:), prob(:), quan(:)
120 real(TKC), allocatable :: rweight(:)
121 call disp%skip()
122 call disp%show("sample = [10, 7, 4, 3, 2, 1, 0]")
123 sample = [10, 7, 4, 3, 2, 1, 0]
124 call disp%show("rweight = exp(getNormLogPDF(getFilled(0._TKC, size(sample, 1, IK))))")
125 rweight = exp(getNormLogPDF(getFilled(0._TKC, size(sample, 1, IK))))
126 call disp%show("rweight")
127 call disp%show( rweight )
128 call disp%show("prob = [0., .25, .5, .75, .9, 1.]")
129 prob = [0., .25, .5, .75, .9, 1.]
130 call disp%show("quan = getQuan(neimean, prob, sample)")
131 quan = getQuan(neimean, prob, sample)
132 call disp%show("quan")
133 call disp%show( quan )
134 call disp%show("quan = getQuan(neinear, prob, sample, rweight)")
135 quan = getQuan(neinear, prob, sample, rweight)
136 call disp%show("quan")
137 call disp%show( quan )
138 call disp%show("quan = getQuan(neinext, prob, sample, rweight)")
139 quan = getQuan(neinext, prob, sample, rweight)
140 call disp%show("quan")
141 call disp%show( quan )
142 call disp%show("quan = getQuan(neiprev, prob, sample, rweight)")
143 quan = getQuan(neiprev, prob, sample, rweight)
144 call disp%show("quan")
145 call disp%show( quan )
146 call disp%show("quan = getQuan(piwilin, prob, sample, rweight, sum(rweight))")
147 quan = getQuan(piwilin, prob, sample, rweight, sum(rweight))
148 call disp%show("quan")
149 call disp%show( quan )
150 call disp%show("do iprob = 1, size(prob)")
151 call disp%show(" quan(iprob) = getQuan(piwilin, prob(iprob), sample, rweight)")
152 call disp%show("end do")
153 do iprob = 1, size(prob)
154 quan(iprob) = getQuan(piwilin, prob(iprob), sample, rweight)
155 end do
156 call disp%show("quan")
157 call disp%show( quan )
158 call disp%skip()
159 end block
160
161 call disp%skip()
162 call disp%show("!%%%%%%%%%%%%%%%%%%%")
163 call disp%show("!2D sample quantile.")
164 call disp%show("!%%%%%%%%%%%%%%%%%%%")
165 call disp%skip()
166
167 block
168 use pm_kind, only: TKC => RKS ! all processor kinds are supported.
169 real(TKC), allocatable :: sample(:,:), prob(:), quan1(:), quan2(:,:)
170 integer(IK) :: nsam, nprob, dim
171 call disp%skip()
172 call disp%show("dim = 2; ndim = getUnifRand(1, 3); nsam = getUnifRand(5, 10); nprob = getUnifRand(3, 9)")
173 dim = 2; ndim = getUnifRand(1, 3); nsam = getUnifRand(5, 10); nprob = getUnifRand(3, 9)
174 call disp%show("[ndim, nsam, nprob]")
175 call disp%show( [ndim, nsam, nprob] )
176 call disp%show("sample = getPoisRand(getFilled(10., ndim, nsam))")
177 sample = getPoisRand(getFilled(10., ndim, nsam))
178 call disp%show("sample")
179 call disp%show( sample )
180 call disp%show("prob = getLinSpace(0., 1., nprob)")
181 prob = getLinSpace(0., 1., nprob)
182 call disp%show("prob")
183 call disp%show( prob )
184 call disp%show("quan2 = getQuan(neimean, prob, sample, dim)")
185 quan2 = getQuan(neimean, prob, sample, dim)
186 call disp%show("quan2")
187 call disp%show( quan2 )
188 call disp%show("quan2 = getQuan(neinear, prob, sample, dim)")
189 quan2 = getQuan(neinear, prob, sample, dim)
190 call disp%show("quan2")
191 call disp%show( quan2 )
192 call disp%show("quan2 = getQuan(neinext, prob, sample, dim)")
193 quan2 = getQuan(neinext, prob, sample, dim)
194 call disp%show("quan2")
195 call disp%show( quan2 )
196 call disp%show("quan2 = getQuan(neiprev, prob, sample, dim)")
197 quan2 = getQuan(neiprev, prob, sample, dim)
198 call disp%show("quan2")
199 call disp%show( quan2 )
200 call disp%show("quan2 = getQuan(piwilin, prob, sample, dim)")
201 quan2 = getQuan(piwilin, prob, sample, dim)
202 call disp%show("quan2")
203 call disp%show( quan2 )
204 call disp%show("quan1 = getQuan(neimean, prob(nprob/2), sample, dim)")
205 quan1 = getQuan(neimean, prob(nprob/2), sample, dim)
206 call disp%show("quan1")
207 call disp%show( quan1 )
208 call disp%show("quan1 = getQuan(neinear, prob(nprob/2), sample, dim)")
209 quan1 = getQuan(neinear, prob(nprob/2), sample, dim)
210 call disp%show("quan1")
211 call disp%show( quan1 )
212 call disp%show("quan1 = getQuan(neinext, prob(nprob/2), sample, dim)")
213 quan1 = getQuan(neinext, prob(nprob/2), sample, dim)
214 call disp%show("quan1")
215 call disp%show( quan1 )
216 call disp%show("quan1 = getQuan(neiprev, prob(nprob/2), sample, dim)")
217 quan1 = getQuan(neiprev, prob(nprob/2), sample, dim)
218 call disp%show("quan1")
219 call disp%show( quan1 )
220 call disp%show("quan1 = getQuan(piwilin, prob(nprob/2), sample, dim)")
221 quan1 = getQuan(piwilin, prob(nprob/2), sample, dim)
222 call disp%show("quan1")
223 call disp%show( quan1 )
224 call disp%skip()
225 end block
226
227 block
228 use pm_kind, only: TKC => RKS ! all processor kinds are supported.
229 real(TKC), allocatable :: sample(:,:), prob(:), quan1(:), quan2(:,:)
230 integer(IK) :: nsam, nprob, dim
231 call disp%skip()
232 call disp%show("dim = 1; ndim = getUnifRand(1, 3); nsam = getUnifRand(5, 10); nprob = getUnifRand(3, 9)")
233 dim = 1; ndim = getUnifRand(1, 3); nsam = getUnifRand(5, 10); nprob = getUnifRand(3, 9)
234 call disp%show("[ndim, nsam, nprob]")
235 call disp%show( [ndim, nsam, nprob] )
236 call disp%show("sample = getPoisRand(getFilled(10., nsam, ndim))")
237 sample = getPoisRand(getFilled(10., nsam, ndim))
238 call disp%show("sample")
239 call disp%show( sample )
240 call disp%show("prob = getLinSpace(0., 1., nprob)")
241 prob = getLinSpace(0., 1., nprob)
242 call disp%show("prob")
243 call disp%show( prob )
244 call disp%show("quan2 = getQuan(neimean, prob, sample, dim)")
245 quan2 = getQuan(neimean, prob, sample, dim)
246 call disp%show("quan2")
247 call disp%show( quan2 )
248 call disp%show("quan2 = getQuan(neinear, prob, sample, dim)")
249 quan2 = getQuan(neinear, prob, sample, dim)
250 call disp%show("quan2")
251 call disp%show( quan2 )
252 call disp%show("quan2 = getQuan(neinext, prob, sample, dim)")
253 quan2 = getQuan(neinext, prob, sample, dim)
254 call disp%show("quan2")
255 call disp%show( quan2 )
256 call disp%show("quan2 = getQuan(neiprev, prob, sample, dim)")
257 quan2 = getQuan(neiprev, prob, sample, dim)
258 call disp%show("quan2")
259 call disp%show( quan2 )
260 call disp%show("quan2 = getQuan(piwilin, prob, sample, dim)")
261 quan2 = getQuan(piwilin, prob, sample, dim)
262 call disp%show("quan2")
263 call disp%show( quan2 )
264 call disp%show("quan1 = getQuan(neimean, prob(nprob/2), sample, dim)")
265 quan1 = getQuan(neimean, prob(nprob/2), sample, dim)
266 call disp%show("quan1")
267 call disp%show( quan1 )
268 call disp%show("quan1 = getQuan(neinear, prob(nprob/2), sample, dim)")
269 quan1 = getQuan(neinear, prob(nprob/2), sample, dim)
270 call disp%show("quan1")
271 call disp%show( quan1 )
272 call disp%show("quan1 = getQuan(neinext, prob(nprob/2), sample, dim)")
273 quan1 = getQuan(neinext, prob(nprob/2), sample, dim)
274 call disp%show("quan1")
275 call disp%show( quan1 )
276 call disp%show("quan1 = getQuan(neiprev, prob(nprob/2), sample, dim)")
277 quan1 = getQuan(neiprev, prob(nprob/2), sample, dim)
278 call disp%show("quan1")
279 call disp%show( quan1 )
280 call disp%show("quan1 = getQuan(piwilin, prob(nprob/2), sample, dim)")
281 quan1 = getQuan(piwilin, prob(nprob/2), sample, dim)
282 call disp%show("quan1")
283 call disp%show( quan1 )
284 call disp%skip()
285 end block
286
287 call disp%skip()
288 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
289 call disp%show("!2D frequency/reliability-weighted sample quantile.")
290 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
291 call disp%skip()
292
293 block
294 use pm_kind, only: TKC => RKS ! all processor kinds are supported.
295 real(TKC), allocatable :: sample(:,:), prob(:), quan1(:), quan2(:,:)
296 integer(IK) :: nsam, nprob, dim
297 call disp%skip()
298 call disp%show("dim = 2; ndim = getUnifRand(1, 3); nsam = getUnifRand(5, 10); nprob = getUnifRand(3, 9)")
299 dim = 2; ndim = getUnifRand(1, 3); nsam = getUnifRand(5, 10); nprob = getUnifRand(3, 9)
300 call disp%show("[ndim, nsam, nprob]")
301 call disp%show( [ndim, nsam, nprob] )
302 call disp%show("sample = getPoisRand(getFilled(10., ndim, nsam))")
303 sample = getPoisRand(getFilled(10., ndim, nsam))
304 call disp%show("sample")
305 call disp%show( sample )
306 call disp%show("iweight = getUnifRand(1, 9, nsam)")
307 iweight = getUnifRand(1, 9, nsam)
308 call disp%show("iweight")
309 call disp%show( iweight )
310 call disp%show("prob = getLinSpace(0., 1., nprob)")
311 prob = getLinSpace(0., 1., nprob)
312 call disp%show("prob")
313 call disp%show( prob )
314 call disp%show("quan2 = getQuan(neimean, prob, sample, dim, iweight)")
315 quan2 = getQuan(neimean, prob, sample, dim, iweight)
316 call disp%show("quan2")
317 call disp%show( quan2 )
318 call disp%show("quan2 = getQuan(neinear, prob, sample, dim, iweight)")
319 quan2 = getQuan(neinear, prob, sample, dim, iweight)
320 call disp%show("quan2")
321 call disp%show( quan2 )
322 call disp%show("quan2 = getQuan(neinext, prob, sample, dim, iweight)")
323 quan2 = getQuan(neinext, prob, sample, dim, iweight)
324 call disp%show("quan2")
325 call disp%show( quan2 )
326 call disp%show("quan2 = getQuan(neiprev, prob, sample, dim, iweight)")
327 quan2 = getQuan(neiprev, prob, sample, dim, iweight)
328 call disp%show("quan2")
329 call disp%show( quan2 )
330 call disp%show("quan2 = getQuan(piwilin, prob, sample, dim, iweight)")
331 quan2 = getQuan(piwilin, prob, sample, dim, iweight)
332 call disp%show("quan2")
333 call disp%show( quan2 )
334 call disp%show("quan1 = getQuan(neimean, prob(nprob/2), sample, dim, iweight)")
335 quan1 = getQuan(neimean, prob(nprob/2), sample, dim, iweight)
336 call disp%show("quan1")
337 call disp%show( quan1 )
338 call disp%show("quan1 = getQuan(neinear, prob(nprob/2), sample, dim, iweight)")
339 quan1 = getQuan(neinear, prob(nprob/2), sample, dim, iweight)
340 call disp%show("quan1")
341 call disp%show( quan1 )
342 call disp%show("quan1 = getQuan(neinext, prob(nprob/2), sample, dim, iweight)")
343 quan1 = getQuan(neinext, prob(nprob/2), sample, dim, iweight)
344 call disp%show("quan1")
345 call disp%show( quan1 )
346 call disp%show("quan1 = getQuan(neiprev, prob(nprob/2), sample, dim, iweight)")
347 quan1 = getQuan(neiprev, prob(nprob/2), sample, dim, iweight)
348 call disp%show("quan1")
349 call disp%show( quan1 )
350 call disp%show("quan1 = getQuan(piwilin, prob(nprob/2), sample, dim, iweight)")
351 quan1 = getQuan(piwilin, prob(nprob/2), sample, dim, iweight)
352 call disp%show("quan1")
353 call disp%show( quan1 )
354 call disp%skip()
355 end block
356
357 call disp%skip()
358 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
359 call disp%show("!2D frequency/reliability-weighted sample quantile.")
360 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
361 call disp%skip()
362
363 block
364 use pm_kind, only: TKC => RKS ! all processor kinds are supported.
365 real(TKC), allocatable :: sample(:,:), prob(:), quan1(:), quan2(:,:)
366 real(TKC), allocatable :: rweight(:)
367 integer(IK) :: nsam, nprob, dim
368 call disp%skip()
369 call disp%show("dim = 2; ndim = getUnifRand(1, 3); nsam = getUnifRand(5, 10); nprob = getUnifRand(3, 9)")
370 dim = 2; ndim = getUnifRand(1, 3); nsam = getUnifRand(5, 10); nprob = getUnifRand(3, 9)
371 call disp%show("[ndim, nsam, nprob]")
372 call disp%show( [ndim, nsam, nprob] )
373 call disp%show("sample = getPoisRand(getFilled(10., ndim, nsam))")
374 sample = getPoisRand(getFilled(10., ndim, nsam))
375 call disp%show("sample")
376 call disp%show( sample )
377 call disp%show("rweight = getUnifRand(1, 9, nsam)")
378 rweight = getUnifRand(1, 9, nsam)
379 call disp%show("rweight")
380 call disp%show( rweight )
381 call disp%show("prob = getLinSpace(0., 1., nprob)")
382 prob = getLinSpace(0., 1., nprob)
383 call disp%show("prob")
384 call disp%show( prob )
385 call disp%show("quan2 = getQuan(neimean, prob, sample, dim, rweight)")
386 quan2 = getQuan(neimean, prob, sample, dim, rweight)
387 call disp%show("quan2")
388 call disp%show( quan2 )
389 call disp%show("quan2 = getQuan(neinear, prob, sample, dim, rweight)")
390 quan2 = getQuan(neinear, prob, sample, dim, rweight)
391 call disp%show("quan2")
392 call disp%show( quan2 )
393 call disp%show("quan2 = getQuan(neinext, prob, sample, dim, rweight)")
394 quan2 = getQuan(neinext, prob, sample, dim, rweight)
395 call disp%show("quan2")
396 call disp%show( quan2 )
397 call disp%show("quan2 = getQuan(neiprev, prob, sample, dim, rweight)")
398 quan2 = getQuan(neiprev, prob, sample, dim, rweight)
399 call disp%show("quan2")
400 call disp%show( quan2 )
401 call disp%show("quan2 = getQuan(piwilin, prob, sample, dim, rweight)")
402 quan2 = getQuan(piwilin, prob, sample, dim, rweight)
403 call disp%show("quan2")
404 call disp%show( quan2 )
405 call disp%show("quan1 = getQuan(neimean, prob(nprob/2), sample, dim, rweight)")
406 quan1 = getQuan(neimean, prob(nprob/2), sample, dim, rweight)
407 call disp%show("quan1")
408 call disp%show( quan1 )
409 call disp%show("quan1 = getQuan(neinear, prob(nprob/2), sample, dim, rweight)")
410 quan1 = getQuan(neinear, prob(nprob/2), sample, dim, rweight)
411 call disp%show("quan1")
412 call disp%show( quan1 )
413 call disp%show("quan1 = getQuan(neinext, prob(nprob/2), sample, dim, rweight)")
414 quan1 = getQuan(neinext, prob(nprob/2), sample, dim, rweight)
415 call disp%show("quan1")
416 call disp%show( quan1 )
417 call disp%show("quan1 = getQuan(neiprev, prob(nprob/2), sample, dim, rweight)")
418 quan1 = getQuan(neiprev, prob(nprob/2), sample, dim, rweight)
419 call disp%show("quan1")
420 call disp%show( quan1 )
421 call disp%show("quan1 = getQuan(piwilin, prob(nprob/2), sample, dim, rweight)")
422 quan1 = getQuan(piwilin, prob(nprob/2), sample, dim, rweight)
423 call disp%show("quan1")
424 call disp%show( quan1 )
425 call disp%skip()
426 end block
427
428end program example
Generate and return an array of the specified rank and shape of arbitrary intrinsic type and kind wit...
Generate count evenly spaced points over the interval [x1, x2] if x1 < x2, or [x2,...
Generate the natural logarithm of probability density function (PDF) of the univariate Normal distrib...
Generate and return a scalar or array of arbitrary rank of random values from the univariate Normal d...
Generate and return the natural logarithm of the Probability Mass Function (PMF) of the Poisson distr...
Generate and return a scalar (or array of arbitrary rank of) random value(s) from the Poisson distrib...
Generate and return a scalar or a contiguous array of rank 1 of length s1 of randomly uniformly distr...
Generate and return the iostat code resulting from writing the input table of rank 1 or 2 to the spec...
Definition: pm_io.F90:5940
This is a generic method of the derived type display_type with pass attribute.
Definition: pm_io.F90:11726
This is a generic method of the derived type display_type with pass attribute.
Definition: pm_io.F90:11508
This module contains procedures and generic interfaces for convenient allocation and filling of array...
This module contains procedures and generic interfaces for generating arrays with linear or logarithm...
This module contains classes and procedures for computing various statistical quantities related to t...
This module contains classes and procedures for computing various statistical quantities related to t...
This module contains classes and procedures for computing various statistical quantities related to t...
This module contains classes and procedures for input/output (IO) or generic display operations on st...
Definition: pm_io.F90:252
type(display_type) disp
This is a scalar module variable an object of type display_type for general display.
Definition: pm_io.F90:11393
This module defines the relevant Fortran kind type-parameters frequently used in the ParaMonte librar...
Definition: pm_kind.F90:268
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
integer, parameter SK
The default character kind in the ParaMonte library: kind("a") in Fortran, c_char in C-Fortran Intero...
Definition: pm_kind.F90:539
integer, parameter RKS
The single-precision real kind in Fortran mode. On most platforms, this is an 32-bit real kind.
Definition: pm_kind.F90:567
type(piwilin_type), parameter piwilin
type(neiprev_type), parameter neiprev
type(neinext_type), parameter neinext
type(neinear_type), parameter neinear
type(neimean_type), parameter neimean
Generate and return an object of type display_type.
Definition: pm_io.F90:10282

Example Unix compile command via Intel ifort compiler
1#!/usr/bin/env sh
2rm main.exe
3ifort -fpp -standard-semantics -O3 -Wl,-rpath,../../../lib -I../../../inc main.F90 ../../../lib/libparamonte* -o main.exe
4./main.exe

Example Windows Batch compile command via Intel ifort compiler
1del main.exe
2set PATH=..\..\..\lib;%PATH%
3ifort /fpp /standard-semantics /O3 /I:..\..\..\include main.F90 ..\..\..\lib\libparamonte*.lib /exe:main.exe
4main.exe

Example Unix / MinGW compile command via GNU gfortran compiler
1#!/usr/bin/env sh
2rm main.exe
3gfortran -cpp -ffree-line-length-none -O3 -Wl,-rpath,../../../lib -I../../../inc main.F90 ../../../lib/libparamonte* -o main.exe
4./main.exe

Example output
1
2!%%%%%%%%%%%%%%%%%%%
3!1D sample quantile.
4!%%%%%%%%%%%%%%%%%%%
5
6
7sample = [10, 7, 4, 3, 2, 1, 0]
8prob = [0., .25, .5, .75, .9, 1.]
9quan = getQuan(neimean, prob, sample)
10quan
11+0.00000000, +0.500000000, +2.50000000, +5.50000000, +8.50000000, +10.0000000
12quan = getQuan(neinear, prob, sample)
13quan
14+0.00000000, +1.00000000, +2.00000000, +4.00000000, +7.00000000, +10.0000000
15quan = getQuan(neinext, prob, sample)
16quan
17+0.00000000, +1.00000000, +3.00000000, +7.00000000, +10.0000000, +10.0000000
18quan = getQuan(neiprev, prob, sample)
19quan
20+0.00000000, +0.00000000, +2.00000000, +4.00000000, +7.00000000, +10.0000000
21quan = getQuan(piwilin, prob, sample)
22quan
23-1.00000000, +0.749999881, +2.50000000, +4.75000000, +7.89999962, +10.0000000
24do iprob = 1, size(prob)
25 quan(iprob) = getQuan(piwilin, prob(iprob), sample)
26end do
27quan
28-1.00000000, +0.749999881, +2.50000000, +4.75000000, +7.89999962, +10.0000000
29
30
31!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
32!1D frequency/reliability-weighted sample quantile.
33!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
34
35
36sample = [10, 7, 4, 3, 2, 1, 0]
37iweight = getUnifRand(1, 9, size(sample, 1, IK))
38iweight
39+6, +3, +6, +3, +6, +5, +3
40prob = [0., .25, .5, .75, .9, 1.]
41quan = getQuan(neimean, prob, sample)
42quan
43+0.00000000, +0.500000000, +2.50000000, +5.50000000, +8.50000000, +10.0000000
44quan = getQuan(neinear, prob, sample, iweight)
45quan
46+0.00000000, +1.00000000, +2.00000000, +4.00000000, +7.00000000, +10.0000000
47quan = getQuan(neinext, prob, sample, iweight)
48quan
49+0.00000000, +1.00000000, +3.00000000, +4.00000000, +7.00000000, +10.0000000
50quan = getQuan(neiprev, prob, sample, iweight)
51quan
52+0.00000000, +0.00000000, +2.00000000, +4.00000000, +4.00000000, +10.0000000
53quan = getQuan(piwilin, prob, sample, iweight, sum(iweight))
54quan
55-2.00000000, +0.666666687, +2.33333349, +4.00000000, +6.87999964, +10.0000000
56do iprob = 1, size(prob)
57 quan(iprob) = getQuan(piwilin, prob(iprob), sample, iweight)
58end do
59quan
60-2.00000000, +0.666666687, +2.33333349, +4.00000000, +6.87999964, +10.0000000
61
62
63sample = [10, 7, 4, 3, 2, 1, 0]
64rweight = exp(getNormLogPDF(getFilled(0._TKC, size(sample, 1, IK))))
65rweight
66+0.398942292, +0.398942292, +0.398942292, +0.398942292, +0.398942292, +0.398942292, +0.398942292
67prob = [0., .25, .5, .75, .9, 1.]
68quan = getQuan(neimean, prob, sample)
69quan
70+0.00000000, +0.500000000, +2.50000000, +5.50000000, +8.50000000, +10.0000000
71quan = getQuan(neinear, prob, sample, rweight)
72quan
73+0.00000000, +1.00000000, +2.00000000, +4.00000000, +7.00000000, +10.0000000
74quan = getQuan(neinext, prob, sample, rweight)
75quan
76+0.00000000, +1.00000000, +3.00000000, +7.00000000, +10.0000000, +10.0000000
77quan = getQuan(neiprev, prob, sample, rweight)
78quan
79+0.00000000, +0.00000000, +2.00000000, +4.00000000, +7.00000000, +10.0000000
80quan = getQuan(piwilin, prob, sample, rweight, sum(rweight))
81quan
82-1.00000000, +0.749999881, +2.50000000, +4.75000000, +7.89999962, +10.0000000
83do iprob = 1, size(prob)
84 quan(iprob) = getQuan(piwilin, prob(iprob), sample, rweight)
85end do
86quan
87-1.00000000, +0.749999881, +2.50000000, +4.75000000, +7.89999962, +10.0000000
88
89
90!%%%%%%%%%%%%%%%%%%%
91!2D sample quantile.
92!%%%%%%%%%%%%%%%%%%%
93
94
95dim = 2; ndim = getUnifRand(1, 3); nsam = getUnifRand(5, 10); nprob = getUnifRand(3, 9)
96[ndim, nsam, nprob]
97+1, +9, +9
98sample = getPoisRand(getFilled(10., ndim, nsam))
99sample
100+12.0000000, +10.0000000, +13.0000000, +8.00000000, +12.0000000, +9.00000000, +10.0000000, +3.00000000, +8.00000000
101prob = getLinSpace(0., 1., nprob)
102prob
103+0.00000000, +0.125000000, +0.250000000, +0.375000000, +0.500000000, +0.625000000, +0.750000000, +0.875000000, +1.00000000
104quan2 = getQuan(neimean, prob, sample, dim)
105quan2
106+3.00000000
107+5.50000000
108+8.00000000
109+8.50000000
110+9.50000000
111+10.0000000
112+11.0000000
113+12.0000000
114+13.0000000
115quan2 = getQuan(neinear, prob, sample, dim)
116quan2
117+3.00000000
118+3.00000000
119+8.00000000
120+8.00000000
121+9.00000000
122+10.0000000
123+12.0000000
124+12.0000000
125+13.0000000
126quan2 = getQuan(neinext, prob, sample, dim)
127quan2
128+3.00000000
129+8.00000000
130+8.00000000
131+9.00000000
132+10.0000000
133+10.0000000
134+12.0000000
135+12.0000000
136+13.0000000
137quan2 = getQuan(neiprev, prob, sample, dim)
138quan2
139+3.00000000
140+3.00000000
141+8.00000000
142+8.00000000
143+9.00000000
144+10.0000000
145+10.0000000
146+12.0000000
147+13.0000000
148quan2 = getQuan(piwilin, prob, sample, dim)
149quan2
150-2.00000000
151+3.62500000
152+7.99999952
153+8.37500000
154+9.50000000
155+10.0000000
156+11.5000000
157+12.0000010
158+13.0000000
159quan1 = getQuan(neimean, prob(nprob/2), sample, dim)
160quan1
161+8.50000000
162quan1 = getQuan(neinear, prob(nprob/2), sample, dim)
163quan1
164+8.00000000
165quan1 = getQuan(neinext, prob(nprob/2), sample, dim)
166quan1
167+9.00000000
168quan1 = getQuan(neiprev, prob(nprob/2), sample, dim)
169quan1
170+8.00000000
171quan1 = getQuan(piwilin, prob(nprob/2), sample, dim)
172quan1
173+8.37500000
174
175
176dim = 1; ndim = getUnifRand(1, 3); nsam = getUnifRand(5, 10); nprob = getUnifRand(3, 9)
177[ndim, nsam, nprob]
178+3, +10, +8
179sample = getPoisRand(getFilled(10., nsam, ndim))
180sample
181+15.0000000, +12.0000000, +17.0000000
182+12.0000000, +14.0000000, +2.00000000
183+11.0000000, +10.0000000, +11.0000000
184+8.00000000, +11.0000000, +7.00000000
185+14.0000000, +19.0000000, +9.00000000
186+8.00000000, +11.0000000, +5.00000000
187+12.0000000, +5.00000000, +8.00000000
188+13.0000000, +16.0000000, +10.0000000
189+10.0000000, +12.0000000, +7.00000000
190+8.00000000, +15.0000000, +6.00000000
191prob = getLinSpace(0., 1., nprob)
192prob
193+0.00000000, +0.142857149, +0.285714298, +0.428571463, +0.571428597, +0.714285731, +0.857142925, +1.00000000
194quan2 = getQuan(neimean, prob, sample, dim)
195quan2
196+8.00000000, +5.00000000, +2.00000000
197+8.00000000, +7.50000000, +3.50000000
198+8.00000000, +10.5000000, +5.50000000
199+10.5000000, +11.5000000, +7.00000000
200+11.5000000, +12.0000000, +7.50000000
201+12.5000000, +14.5000000, +9.50000000
202+13.5000000, +15.5000000, +10.5000000
203+15.0000000, +19.0000000, +17.0000000
204quan2 = getQuan(neinear, prob, sample, dim)
205quan2
206+8.00000000, +5.00000000, +2.00000000
207+8.00000000, +5.00000000, +2.00000000
208+8.00000000, +11.0000000, +6.00000000
209+10.0000000, +11.0000000, +7.00000000
210+12.0000000, +12.0000000, +8.00000000
211+12.0000000, +14.0000000, +9.00000000
212+14.0000000, +16.0000000, +11.0000000
213+15.0000000, +19.0000000, +17.0000000
214quan2 = getQuan(neinext, prob, sample, dim)
215quan2
216+8.00000000, +5.00000000, +2.00000000
217+8.00000000, +10.0000000, +5.00000000
218+8.00000000, +11.0000000, +6.00000000
219+11.0000000, +12.0000000, +7.00000000
220+12.0000000, +12.0000000, +8.00000000
221+13.0000000, +15.0000000, +10.0000000
222+14.0000000, +16.0000000, +11.0000000
223+15.0000000, +19.0000000, +17.0000000
224quan2 = getQuan(neiprev, prob, sample, dim)
225quan2
226+8.00000000, +5.00000000, +2.00000000
227+8.00000000, +5.00000000, +2.00000000
228+8.00000000, +10.0000000, +5.00000000
229+10.0000000, +11.0000000, +7.00000000
230+11.0000000, +12.0000000, +7.00000000
231+12.0000000, +14.0000000, +9.00000000
232+13.0000000, +15.0000000, +10.0000000
233+15.0000000, +19.0000000, +17.0000000
234quan2 = getQuan(piwilin, prob, sample, dim)
235quan2
236+8.00000000, +0.00000000, -1.00000000
237+8.00000000, +7.14285755, +3.28571439
238+8.00000000, +10.8571434, +5.85714245
239+10.2857151, +11.2857151, +7.00000000
240+11.7142868, +12.0000010, +7.71428633
241+12.1428576, +14.1428566, +9.14285755
242+13.5714283, +15.5714283, +10.5714293
243+15.0000000, +19.0000000, +17.0000000
244quan1 = getQuan(neimean, prob(nprob/2), sample, dim)
245quan1
246+10.5000000, +11.5000000, +7.00000000
247quan1 = getQuan(neinear, prob(nprob/2), sample, dim)
248quan1
249+10.0000000, +11.0000000, +7.00000000
250quan1 = getQuan(neinext, prob(nprob/2), sample, dim)
251quan1
252+11.0000000, +12.0000000, +7.00000000
253quan1 = getQuan(neiprev, prob(nprob/2), sample, dim)
254quan1
255+10.0000000, +11.0000000, +7.00000000
256quan1 = getQuan(piwilin, prob(nprob/2), sample, dim)
257quan1
258+10.2857151, +11.2857151, +7.00000000
259
260
261!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
262!2D frequency/reliability-weighted sample quantile.
263!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
264
265
266dim = 2; ndim = getUnifRand(1, 3); nsam = getUnifRand(5, 10); nprob = getUnifRand(3, 9)
267[ndim, nsam, nprob]
268+1, +5, +4
269sample = getPoisRand(getFilled(10., ndim, nsam))
270sample
271+13.0000000, +14.0000000, +15.0000000, +11.0000000, +10.0000000
272iweight = getUnifRand(1, 9, nsam)
273iweight
274+7, +2, +5, +8, +6
275prob = getLinSpace(0., 1., nprob)
276prob
277+0.00000000, +0.333333343, +0.666666687, +1.00000000
278quan2 = getQuan(neimean, prob, sample, dim, iweight)
279quan2
280+10.0000000
281+12.0000000
282+13.5000000
283+15.0000000
284quan2 = getQuan(neinear, prob, sample, dim, iweight)
285quan2
286+10.0000000
287+11.0000000
288+14.0000000
289+15.0000000
290quan2 = getQuan(neinext, prob, sample, dim, iweight)
291quan2
292+10.0000000
293+13.0000000
294+14.0000000
295+15.0000000
296quan2 = getQuan(neiprev, prob, sample, dim, iweight)
297quan2
298+10.0000000
299+11.0000000
300+13.0000000
301+15.0000000
302quan2 = getQuan(piwilin, prob, sample, dim, iweight)
303quan2
304+6.50000000
305+11.1333332
306+13.5833340
307+15.0000000
308quan1 = getQuan(neimean, prob(nprob/2), sample, dim, iweight)
309quan1
310+12.0000000
311quan1 = getQuan(neinear, prob(nprob/2), sample, dim, iweight)
312quan1
313+11.0000000
314quan1 = getQuan(neinext, prob(nprob/2), sample, dim, iweight)
315quan1
316+13.0000000
317quan1 = getQuan(neiprev, prob(nprob/2), sample, dim, iweight)
318quan1
319+11.0000000
320quan1 = getQuan(piwilin, prob(nprob/2), sample, dim, iweight)
321quan1
322+11.1333332
323
324
325!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
326!2D frequency/reliability-weighted sample quantile.
327!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
328
329
330dim = 2; ndim = getUnifRand(1, 3); nsam = getUnifRand(5, 10); nprob = getUnifRand(3, 9)
331[ndim, nsam, nprob]
332+1, +7, +5
333sample = getPoisRand(getFilled(10., ndim, nsam))
334sample
335+11.0000000, +8.00000000, +10.0000000, +14.0000000, +11.0000000, +10.0000000, +9.00000000
336rweight = getUnifRand(1, 9, nsam)
337rweight
338+6.00000000, +3.00000000, +4.00000000, +2.00000000, +6.00000000, +8.00000000, +3.00000000
339prob = getLinSpace(0., 1., nprob)
340prob
341+0.00000000, +0.250000000, +0.500000000, +0.750000000, +1.00000000
342quan2 = getQuan(neimean, prob, sample, dim, rweight)
343quan2
344+8.00000000
345+8.50000000
346+10.5000000
347+11.0000000
348+14.0000000
349quan2 = getQuan(neinear, prob, sample, dim, rweight)
350quan2
351+8.00000000
352+9.00000000
353+10.0000000
354+11.0000000
355+14.0000000
356quan2 = getQuan(neinext, prob, sample, dim, rweight)
357quan2
358+8.00000000
359+9.00000000
360+11.0000000
361+11.0000000
362+14.0000000
363quan2 = getQuan(neiprev, prob, sample, dim, rweight)
364quan2
365+8.00000000
366+8.00000000
367+10.0000000
368+11.0000000
369+14.0000000
370quan2 = getQuan(piwilin, prob, sample, dim, rweight)
371quan2
372+6.00000000
373+8.66666698
374+10.1666670
375+11.0000000
376+14.0000000
377quan1 = getQuan(neimean, prob(nprob/2), sample, dim, rweight)
378quan1
379+8.50000000
380quan1 = getQuan(neinear, prob(nprob/2), sample, dim, rweight)
381quan1
382+9.00000000
383quan1 = getQuan(neinext, prob(nprob/2), sample, dim, rweight)
384quan1
385+9.00000000
386quan1 = getQuan(neiprev, prob(nprob/2), sample, dim, rweight)
387quan1
388+8.00000000
389quan1 = getQuan(piwilin, prob(nprob/2), sample, dim, rweight)
390quan1
391+8.66666698
392
393
Test:
test_pm_sampleQuan


Final Remarks


If you believe this algorithm or its documentation can be improved, we appreciate your contribution and help to edit this page's documentation and source file on GitHub.
For details on the naming abbreviations, see this page.
For details on the naming conventions, see this page.
This software is distributed under the MIT license with additional terms outlined below.

  1. If you use any parts or concepts from this library to any extent, please acknowledge the usage by citing the relevant publications of the ParaMonte library.
  2. If you regenerate any parts/ideas from this library in a programming environment other than those currently supported by this ParaMonte library (i.e., other than C, C++, Fortran, MATLAB, Python, R), please also ask the end users to cite this original ParaMonte library.

This software is available to the public under a highly permissive license.
Help us justify its continued development and maintenance by acknowledging its benefit to society, distributing it, and contributing to it.

Author:
Amir Shahmoradi, Thursday 2:45 AM, August 19, 2021, Dallas, TX

Definition at line 207 of file pm_sampleQuan.F90.


The documentation for this interface was generated from the following file: