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: TKG => RKS ! all processor kinds are supported.
31 real(TKG), 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: TKG => RKS ! all processor kinds are supported.
76 real(TKG), 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: TKG => RKS ! all processor kinds are supported.
119 real(TKG), allocatable :: sample(:), prob(:), quan(:)
120 real(TKG), 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._TKG, size(sample, 1, IK))))")
125 rweight = exp(getNormLogPDF(getFilled(0._TKG, 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: TKG => RKS ! all processor kinds are supported.
169 real(TKG), 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: TKG => RKS ! all processor kinds are supported.
229 real(TKG), 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: TKG => RKS ! all processor kinds are supported.
295 real(TKG), 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: TKG => RKS ! all processor kinds are supported.
365 real(TKG), allocatable :: sample(:,:), prob(:), quan1(:), quan2(:,:)
366 real(TKG), 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+7, +4, +7, +3, +8, +9, +6
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, +3.00000000, +4.00000000, +7.00000000, +10.0000000
47quan = getQuan(neinext, prob, sample, iweight)
48quan
49+0.00000000, +1.00000000, +4.00000000, +7.00000000, +10.0000000, +10.0000000
50quan = getQuan(neiprev, prob, sample, iweight)
51quan
52+0.00000000, +1.00000000, +3.00000000, +4.00000000, +7.00000000, +10.0000000
53quan = getQuan(piwilin, prob, sample, iweight, sum(iweight))
54quan
55-1.75000000, +1.00000000, +3.12500024, +5.33333349, +7.79999924, +10.0000000
56do iprob = 1, size(prob)
57 quan(iprob) = getQuan(piwilin, prob(iprob), sample, iweight)
58end do
59quan
60-1.75000000, +1.00000000, +3.12500024, +5.33333349, +7.79999924, +10.0000000
61
62
63sample = [10, 7, 4, 3, 2, 1, 0]
64rweight = exp(getNormLogPDF(getFilled(0._TKG, 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, +10, +8
98sample = getPoisRand(getFilled(10., ndim, nsam))
99sample
100+6.00000000, +6.00000000, +10.0000000, +11.0000000, +9.00000000, +9.00000000, +9.00000000, +8.00000000, +9.00000000, +9.00000000
101prob = getLinSpace(0., 1., nprob)
102prob
103+0.00000000, +0.142857149, +0.285714298, +0.428571463, +0.571428597, +0.714285731, +0.857142925, +1.00000000
104quan2 = getQuan(neimean, prob, sample, dim)
105quan2
106+6.00000000
107+6.00000000
108+7.00000000
109+9.00000000
110+9.00000000
111+9.00000000
112+9.50000000
113+11.0000000
114quan2 = getQuan(neinear, prob, sample, dim)
115quan2
116+6.00000000
117+6.00000000
118+8.00000000
119+9.00000000
120+9.00000000
121+9.00000000
122+10.0000000
123+11.0000000
124quan2 = getQuan(neinext, prob, sample, dim)
125quan2
126+6.00000000
127+6.00000000
128+8.00000000
129+9.00000000
130+9.00000000
131+9.00000000
132+10.0000000
133+11.0000000
134quan2 = getQuan(neiprev, prob, sample, dim)
135quan2
136+6.00000000
137+6.00000000
138+6.00000000
139+9.00000000
140+9.00000000
141+9.00000000
142+9.00000000
143+11.0000000
144quan2 = getQuan(piwilin, prob, sample, dim)
145quan2
146+6.00000000
147+6.00000000
148+7.71428585
149+9.00000000
150+9.00000095
151+9.00000000
152+9.57142925
153+11.0000000
154quan1 = getQuan(neimean, prob(nprob/2), sample, dim)
155quan1
156+9.00000000
157quan1 = getQuan(neinear, prob(nprob/2), sample, dim)
158quan1
159+9.00000000
160quan1 = getQuan(neinext, prob(nprob/2), sample, dim)
161quan1
162+9.00000000
163quan1 = getQuan(neiprev, prob(nprob/2), sample, dim)
164quan1
165+9.00000000
166quan1 = getQuan(piwilin, prob(nprob/2), sample, dim)
167quan1
168+9.00000000
169
170
171dim = 1; ndim = getUnifRand(1, 3); nsam = getUnifRand(5, 10); nprob = getUnifRand(3, 9)
172[ndim, nsam, nprob]
173+3, +10, +3
174sample = getPoisRand(getFilled(10., nsam, ndim))
175sample
176+15.0000000, +12.0000000, +7.00000000
177+13.0000000, +10.0000000, +12.0000000
178+9.00000000, +10.0000000, +9.00000000
179+10.0000000, +9.00000000, +9.00000000
180+10.0000000, +10.0000000, +7.00000000
181+12.0000000, +14.0000000, +15.0000000
182+8.00000000, +10.0000000, +11.0000000
183+9.00000000, +11.0000000, +10.0000000
184+10.0000000, +6.00000000, +9.00000000
185+4.00000000, +6.00000000, +6.00000000
186prob = getLinSpace(0., 1., nprob)
187prob
188+0.00000000, +0.500000000, +1.00000000
189quan2 = getQuan(neimean, prob, sample, dim)
190quan2
191+4.00000000, +6.00000000, +6.00000000
192+10.0000000, +10.0000000, +9.00000000
193+15.0000000, +14.0000000, +15.0000000
194quan2 = getQuan(neinear, prob, sample, dim)
195quan2
196+4.00000000, +6.00000000, +6.00000000
197+10.0000000, +10.0000000, +9.00000000
198+15.0000000, +14.0000000, +15.0000000
199quan2 = getQuan(neinext, prob, sample, dim)
200quan2
201+4.00000000, +6.00000000, +6.00000000
202+10.0000000, +10.0000000, +9.00000000
203+15.0000000, +14.0000000, +15.0000000
204quan2 = getQuan(neiprev, prob, sample, dim)
205quan2
206+4.00000000, +6.00000000, +6.00000000
207+10.0000000, +10.0000000, +9.00000000
208+15.0000000, +14.0000000, +15.0000000
209quan2 = getQuan(piwilin, prob, sample, dim)
210quan2
211+0.00000000, +6.00000000, +5.00000000
212+10.0000000, +10.0000000, +9.00000000
213+15.0000000, +14.0000000, +15.0000000
214quan1 = getQuan(neimean, prob(nprob/2), sample, dim)
215quan1
216+4.00000000, +6.00000000, +6.00000000
217quan1 = getQuan(neinear, prob(nprob/2), sample, dim)
218quan1
219+4.00000000, +6.00000000, +6.00000000
220quan1 = getQuan(neinext, prob(nprob/2), sample, dim)
221quan1
222+4.00000000, +6.00000000, +6.00000000
223quan1 = getQuan(neiprev, prob(nprob/2), sample, dim)
224quan1
225+4.00000000, +6.00000000, +6.00000000
226quan1 = getQuan(piwilin, prob(nprob/2), sample, dim)
227quan1
228+0.00000000, +6.00000000, +5.00000000
229
230
231!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
232!2D frequency/reliability-weighted sample quantile.
233!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
234
235
236dim = 2; ndim = getUnifRand(1, 3); nsam = getUnifRand(5, 10); nprob = getUnifRand(3, 9)
237[ndim, nsam, nprob]
238+1, +5, +8
239sample = getPoisRand(getFilled(10., ndim, nsam))
240sample
241+15.0000000, +10.0000000, +10.0000000, +8.00000000, +7.00000000
242iweight = getUnifRand(1, 9, nsam)
243iweight
244+8, +7, +6, +2, +5
245prob = getLinSpace(0., 1., nprob)
246prob
247+0.00000000, +0.142857149, +0.285714298, +0.428571463, +0.571428597, +0.714285731, +0.857142925, +1.00000000
248quan2 = getQuan(neimean, prob, sample, dim, iweight)
249quan2
250+7.00000000
251+7.00000000
252+7.00000000
253+7.50000000
254+9.00000000
255+9.00000000
256+12.5000000
257+15.0000000
258quan2 = getQuan(neinear, prob, sample, dim, iweight)
259quan2
260+7.00000000
261+7.00000000
262+7.00000000
263+8.00000000
264+8.00000000
265+10.0000000
266+10.0000000
267+15.0000000
268quan2 = getQuan(neinext, prob, sample, dim, iweight)
269quan2
270+7.00000000
271+7.00000000
272+7.00000000
273+8.00000000
274+10.0000000
275+10.0000000
276+15.0000000
277+15.0000000
278quan2 = getQuan(neiprev, prob, sample, dim, iweight)
279quan2
280+7.00000000
281+7.00000000
282+7.00000000
283+7.00000000
284+8.00000000
285+8.00000000
286+10.0000000
287+15.0000000
288quan2 = getQuan(piwilin, prob, sample, dim, iweight)
289quan2
290+5.85714340
291+6.42857170
292+7.00000000
293+7.57142878
294+8.33333397
295+9.66666794
296+11.0000010
297+15.0000000
298quan1 = getQuan(neimean, prob(nprob/2), sample, dim, iweight)
299quan1
300+7.50000000
301quan1 = getQuan(neinear, prob(nprob/2), sample, dim, iweight)
302quan1
303+8.00000000
304quan1 = getQuan(neinext, prob(nprob/2), sample, dim, iweight)
305quan1
306+8.00000000
307quan1 = getQuan(neiprev, prob(nprob/2), sample, dim, iweight)
308quan1
309+7.00000000
310quan1 = getQuan(piwilin, prob(nprob/2), sample, dim, iweight)
311quan1
312+7.57142878
313
314
315!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
316!2D frequency/reliability-weighted sample quantile.
317!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
318
319
320dim = 2; ndim = getUnifRand(1, 3); nsam = getUnifRand(5, 10); nprob = getUnifRand(3, 9)
321[ndim, nsam, nprob]
322+1, +7, +3
323sample = getPoisRand(getFilled(10., ndim, nsam))
324sample
325+4.00000000, +7.00000000, +10.0000000, +12.0000000, +9.00000000, +20.0000000, +12.0000000
326rweight = getUnifRand(1, 9, nsam)
327rweight
328+4.00000000, +7.00000000, +7.00000000, +8.00000000, +6.00000000, +7.00000000, +7.00000000
329prob = getLinSpace(0., 1., nprob)
330prob
331+0.00000000, +0.500000000, +1.00000000
332quan2 = getQuan(neimean, prob, sample, dim, rweight)
333quan2
334+4.00000000
335+9.50000000
336+20.0000000
337quan2 = getQuan(neinear, prob, sample, dim, rweight)
338quan2
339+4.00000000
340+10.0000000
341+20.0000000
342quan2 = getQuan(neinext, prob, sample, dim, rweight)
343quan2
344+4.00000000
345+10.0000000
346+20.0000000
347quan2 = getQuan(neiprev, prob, sample, dim, rweight)
348quan2
349+4.00000000
350+9.00000000
351+20.0000000
352quan2 = getQuan(piwilin, prob, sample, dim, rweight)
353quan2
354+2.28571463
355+9.62500000
356+20.0000000
357quan1 = getQuan(neimean, prob(nprob/2), sample, dim, rweight)
358quan1
359+4.00000000
360quan1 = getQuan(neinear, prob(nprob/2), sample, dim, rweight)
361quan1
362+4.00000000
363quan1 = getQuan(neinext, prob(nprob/2), sample, dim, rweight)
364quan1
365+4.00000000
366quan1 = getQuan(neiprev, prob(nprob/2), sample, dim, rweight)
367quan1
368+4.00000000
369quan1 = getQuan(piwilin, prob(nprob/2), sample, dim, rweight)
370quan1
371+2.28571463
372
373
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: