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+8, +6, +8, +9, +1, +6, +5
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, +0.00000000, +2.00000000, +4.00000000, +7.00000000, +10.0000000
47quan = getQuan(neinext, prob, sample, iweight)
48quan
49+0.00000000, +1.00000000, +2.00000000, +7.00000000, +10.0000000, +10.0000000
50quan = getQuan(neiprev, prob, sample, iweight)
51quan
52+0.00000000, +0.00000000, +1.00000000, +4.00000000, +7.00000000, +10.0000000
53quan = getQuan(piwilin, prob, sample, iweight, sum(iweight))
54quan
55-1.33333325, +0.458333313, +1.93749988, +4.12500000, +7.41999960, +10.0000000
56do iprob = 1, size(prob)
57 quan(iprob) = getQuan(piwilin, prob(iprob), sample, iweight)
58end do
59quan
60-1.33333325, +0.458333313, +1.93749988, +4.12500000, +7.41999960, +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, +5, +3
98sample = getPoisRand(getFilled(10., ndim, nsam))
99sample
100+12.0000000, +10.0000000, +11.0000000, +10.0000000, +12.0000000
101prob = getLinSpace(0., 1., nprob)
102prob
103+0.00000000, +0.500000000, +1.00000000
104quan2 = getQuan(neimean, prob, sample, dim)
105quan2
106+10.0000000
107+10.5000000
108+12.0000000
109quan2 = getQuan(neinear, prob, sample, dim)
110quan2
111+10.0000000
112+10.0000000
113+12.0000000
114quan2 = getQuan(neinext, prob, sample, dim)
115quan2
116+10.0000000
117+11.0000000
118+12.0000000
119quan2 = getQuan(neiprev, prob, sample, dim)
120quan2
121+10.0000000
122+10.0000000
123+12.0000000
124quan2 = getQuan(piwilin, prob, sample, dim)
125quan2
126+10.0000000
127+10.5000000
128+12.0000000
129quan1 = getQuan(neimean, prob(nprob/2), sample, dim)
130quan1
131+10.0000000
132quan1 = getQuan(neinear, prob(nprob/2), sample, dim)
133quan1
134+10.0000000
135quan1 = getQuan(neinext, prob(nprob/2), sample, dim)
136quan1
137+10.0000000
138quan1 = getQuan(neiprev, prob(nprob/2), sample, dim)
139quan1
140+10.0000000
141quan1 = getQuan(piwilin, prob(nprob/2), sample, dim)
142quan1
143+10.0000000
144
145
146dim = 1; ndim = getUnifRand(1, 3); nsam = getUnifRand(5, 10); nprob = getUnifRand(3, 9)
147[ndim, nsam, nprob]
148+2, +9, +6
149sample = getPoisRand(getFilled(10., nsam, ndim))
150sample
151+15.0000000, +9.00000000
152+12.0000000, +13.0000000
153+12.0000000, +11.0000000
154+11.0000000, +10.0000000
155+10.0000000, +11.0000000
156+11.0000000, +8.00000000
157+13.0000000, +10.0000000
158+8.00000000, +7.00000000
159+10.0000000, +9.00000000
160prob = getLinSpace(0., 1., nprob)
161prob
162+0.00000000, +0.200000003, +0.400000006, +0.600000024, +0.800000012, +1.00000000
163quan2 = getQuan(neimean, prob, sample, dim)
164quan2
165+8.00000000, +7.00000000
166+9.00000000, +7.50000000
167+10.5000000, +9.00000000
168+11.5000000, +10.0000000
169+12.5000000, +11.0000000
170+15.0000000, +13.0000000
171quan2 = getQuan(neinear, prob, sample, dim)
172quan2
173+8.00000000, +7.00000000
174+10.0000000, +8.00000000
175+11.0000000, +9.00000000
176+11.0000000, +10.0000000
177+12.0000000, +11.0000000
178+15.0000000, +13.0000000
179quan2 = getQuan(neinext, prob, sample, dim)
180quan2
181+8.00000000, +7.00000000
182+10.0000000, +8.00000000
183+11.0000000, +9.00000000
184+12.0000000, +10.0000000
185+13.0000000, +11.0000000
186+15.0000000, +13.0000000
187quan2 = getQuan(neiprev, prob, sample, dim)
188quan2
189+8.00000000, +7.00000000
190+8.00000000, +7.00000000
191+10.0000000, +9.00000000
192+11.0000000, +10.0000000
193+12.0000000, +11.0000000
194+15.0000000, +13.0000000
195quan2 = getQuan(piwilin, prob, sample, dim)
196quan2
197+6.00000000, +6.00000000
198+9.60000038, +7.80000019
199+10.6000004, +9.00000000
200+11.3999996, +10.0000000
201+12.2000008, +11.0000000
202+15.0000000, +13.0000000
203quan1 = getQuan(neimean, prob(nprob/2), sample, dim)
204quan1
205+10.5000000, +9.00000000
206quan1 = getQuan(neinear, prob(nprob/2), sample, dim)
207quan1
208+11.0000000, +9.00000000
209quan1 = getQuan(neinext, prob(nprob/2), sample, dim)
210quan1
211+11.0000000, +9.00000000
212quan1 = getQuan(neiprev, prob(nprob/2), sample, dim)
213quan1
214+10.0000000, +9.00000000
215quan1 = getQuan(piwilin, prob(nprob/2), sample, dim)
216quan1
217+10.6000004, +9.00000000
218
219
220!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
221!2D frequency/reliability-weighted sample quantile.
222!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
223
224
225dim = 2; ndim = getUnifRand(1, 3); nsam = getUnifRand(5, 10); nprob = getUnifRand(3, 9)
226[ndim, nsam, nprob]
227+1, +7, +6
228sample = getPoisRand(getFilled(10., ndim, nsam))
229sample
230+7.00000000, +7.00000000, +9.00000000, +11.0000000, +8.00000000, +5.00000000, +12.0000000
231iweight = getUnifRand(1, 9, nsam)
232iweight
233+9, +4, +6, +1, +3, +6, +9
234prob = getLinSpace(0., 1., nprob)
235prob
236+0.00000000, +0.200000003, +0.400000006, +0.600000024, +0.800000012, +1.00000000
237quan2 = getQuan(neimean, prob, sample, dim, iweight)
238quan2
239+5.00000000
240+5.00000000
241+7.00000000
242+8.50000000
243+11.5000000
244+12.0000000
245quan2 = getQuan(neinear, prob, sample, dim, iweight)
246quan2
247+5.00000000
248+5.00000000
249+7.00000000
250+9.00000000
251+11.0000000
252+12.0000000
253quan2 = getQuan(neinext, prob, sample, dim, iweight)
254quan2
255+5.00000000
256+5.00000000
257+7.00000000
258+9.00000000
259+12.0000000
260+12.0000000
261quan2 = getQuan(neiprev, prob, sample, dim, iweight)
262quan2
263+5.00000000
264+5.00000000
265+7.00000000
266+8.00000000
267+11.0000000
268+12.0000000
269quan2 = getQuan(piwilin, prob, sample, dim, iweight)
270quan2
271+0.500000000
272+4.29999971
273+7.00000000
274+8.93333340
275+11.1555557
276+12.0000000
277quan1 = getQuan(neimean, prob(nprob/2), sample, dim, iweight)
278quan1
279+7.00000000
280quan1 = getQuan(neinear, prob(nprob/2), sample, dim, iweight)
281quan1
282+7.00000000
283quan1 = getQuan(neinext, prob(nprob/2), sample, dim, iweight)
284quan1
285+7.00000000
286quan1 = getQuan(neiprev, prob(nprob/2), sample, dim, iweight)
287quan1
288+7.00000000
289quan1 = getQuan(piwilin, prob(nprob/2), sample, dim, iweight)
290quan1
291+7.00000000
292
293
294!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
295!2D frequency/reliability-weighted sample quantile.
296!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
297
298
299dim = 2; ndim = getUnifRand(1, 3); nsam = getUnifRand(5, 10); nprob = getUnifRand(3, 9)
300[ndim, nsam, nprob]
301+3, +8, +3
302sample = getPoisRand(getFilled(10., ndim, nsam))
303sample
304+6.00000000, +11.0000000, +11.0000000, +11.0000000, +12.0000000, +7.00000000, +5.00000000, +10.0000000
305+12.0000000, +8.00000000, +9.00000000, +8.00000000, +7.00000000, +7.00000000, +6.00000000, +14.0000000
306+19.0000000, +10.0000000, +14.0000000, +9.00000000, +7.00000000, +16.0000000, +12.0000000, +6.00000000
307rweight = getUnifRand(1, 9, nsam)
308rweight
309+2.00000000, +4.00000000, +1.00000000, +9.00000000, +1.00000000, +1.00000000, +7.00000000, +7.00000000
310prob = getLinSpace(0., 1., nprob)
311prob
312+0.00000000, +0.500000000, +1.00000000
313quan2 = getQuan(neimean, prob, sample, dim, rweight)
314quan2
315+5.00000000, +6.00000000, +6.00000000
316+10.0000000, +8.00000000, +10.0000000
317+12.0000000, +14.0000000, +19.0000000
318quan2 = getQuan(neinear, prob, sample, dim, rweight)
319quan2
320+5.00000000, +6.00000000, +6.00000000
321+10.0000000, +8.00000000, +10.0000000
322+12.0000000, +14.0000000, +19.0000000
323quan2 = getQuan(neinext, prob, sample, dim, rweight)
324quan2
325+5.00000000, +6.00000000, +6.00000000
326+10.0000000, +8.00000000, +10.0000000
327+12.0000000, +14.0000000, +19.0000000
328quan2 = getQuan(neiprev, prob, sample, dim, rweight)
329quan2
330+5.00000000, +6.00000000, +6.00000000
331+10.0000000, +8.00000000, +10.0000000
332+12.0000000, +14.0000000, +19.0000000
333quan2 = getQuan(piwilin, prob, sample, dim, rweight)
334quan2
335+4.50000000, +5.50000000, +5.50000000
336+10.0000000, +8.00000000, +10.0000000
337+12.0000000, +14.0000000, +19.0000000
338quan1 = getQuan(neimean, prob(nprob/2), sample, dim, rweight)
339quan1
340+5.00000000, +6.00000000, +6.00000000
341quan1 = getQuan(neinear, prob(nprob/2), sample, dim, rweight)
342quan1
343+5.00000000, +6.00000000, +6.00000000
344quan1 = getQuan(neinext, prob(nprob/2), sample, dim, rweight)
345quan1
346+5.00000000, +6.00000000, +6.00000000
347quan1 = getQuan(neiprev, prob(nprob/2), sample, dim, rweight)
348quan1
349+5.00000000, +6.00000000, +6.00000000
350quan1 = getQuan(piwilin, prob(nprob/2), sample, dim, rweight)
351quan1
352+4.50000000, +5.50000000, +5.50000000
353
354
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: