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

Generate and return the variance of the input sample of type complex or real of shape (nsam) or (ndim, nsam) or (nsam, ndim) where ndim is the number of data dimensions (the number of data attributes) and nsam is the number of data points.
More...

Detailed Description

Generate and return the variance of the input sample of type complex or real of shape (nsam) or (ndim, nsam) or (nsam, ndim) where ndim is the number of data dimensions (the number of data attributes) and nsam is the number of data points.

See the documentation of the parent module pm_sampleVar for algorithmic details and variance definitions.

Parameters
[in]sample: The input contiguous array of shape (nsam), (ndim, nsam), or (nsam, ndim) of,
  1. type complex of kind any supported by the processor (e.g., CK, CK32, CK64, or CK128),
  2. type real of kind any supported by the processor (e.g., RK, RK32, RK64, or RK128),
containing the sample comprised of nsam observations each with ndim attributes.
If sample is a matrix, then the direction along which variance is computed is dictated by the input argument dim.
[in]dim: The input scalar integer of default kind IK representing the dimension (1 or 2) of the input sample along which the mean must be computed.
  1. If dim = 1, the input sample of rank 2 is assumed to have the shape (nsam, ndim).
  2. If dim = 2, the input sample of rank 2 is assumed to have the shape (ndim, nsam).
The input dim must always be 1 or missing for an input sample of rank 1.
(optional. If missing, the variance of the whole input sample is computed.)
[in]weight: The contiguous vector of length nsam of,
  1. type integer of default kind IK, or
  2. type real of the same kind as the input sample,
containing the corresponding weights of individual nsam observations in sample.
(optional. default = getFilled(1, size(sample, dim)) if dim is present, or getFilled(1, size(sample)) if dim is missing.)
[in]correction: The input scalar object that can be the following:
  1. The constant fweight or an object of type fweight implying a bias correction based on the assumption of frequency weights for the sample observations, even if the weight argument is missing.
    This is the most popular type of correction, also known as the Bessel correction.
  2. The constant rweight or an object of type rweight_type implying a bias correction based on the assumption of reliability weights for the sample observations.
(optional. If missing, no bias-correction will be applied to the output var.)
Returns
var : The output object of type real of the same kind as the input sample of rank rank(sample) - 1, representing its variance:
  1. If sample is a vector, the output var is a scalar.
  2. If sample is a matrix, the output var is an allocatable vector of size ndim = size(sample, dim).


Possible calling interfaces

use pm_sampleVar, only: getVar
var = getVar(sample(:), weight = weight(1 : size(sample)), correction = correction)
var = getVar(sample(:,:), weight = weight(1 : size(sample)), correction = correction)
var = getVar(sample(:), weight = weight(1 : size(sample, dim)), correction = correction)
var(:) = getVar(sample(:,:), dim, weight = weight(1 : size(sample, dim)), correction = correction)
Generate and return the variance of the input sample of type complex or real of shape (nsam) or (ndim...
This module contains classes and procedures for computing the properties related to the covariance ma...
Warning
This generic interface is merely a flexible wrapper around the generic subroutine interface setVar.
As such, all conditions and warnings associated with setVar equally hold for this generic interface.
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.
Note
Note the effects of bias-correction in computing the variance become noticeable only for very sample sample sizes (i.e., when nsam is small).
For a one-dimensional sample, one can also use the concise Fortran syntax to achieve the same goal as with the interface var = getVar(sample(:), mean, correction) with integer weight:
mean = sum(sample) / size(sample)
var = sum((sample-mean)**2) / (size(sample) - 1)
But the above concise version will be likely slightly slower as it potentially involves more loops.
For a two or higher-dimensional sample, if the variance is to be computed for the entire sample (as opposed to computing it along a particular dimension), simply pass reshape(sample, shape = size(sample)) to the appropriate getVar interface.
Alternatively, a 1D pointer of the same size as the multidimensional sample can be passed to the procedure.
See also
getMean
setMean
getShifted
setShifted
getVar
setVar


Example usage

1program example
2
3 use pm_kind, only: SK, IK, LK
4 use pm_kind, only: TKG => RKS ! All other real types are also supported.
5 use pm_io, only: display_type
6 use pm_sampleVar, only: getVar
9 use pm_sampleCov, only: fweight, rweight
10 use pm_sampleShift, only: getShifted
11 use pm_arrayResize, only: setResized
12 use pm_distUnif, only: getUnifRand
13 use pm_sampleMean, only: getMean
14
15 implicit none
16
17 integer(IK) :: dim
18 type(display_type) :: disp
19 disp = display_type(file = "main.out.F90")
20
21 call disp%skip()
22 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
23 call disp%show("!Compute the variance of a 1-D array.")
24 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
25 call disp%skip()
26
27 block
28 real(TKG) :: var
29 real(TKG), allocatable :: sample(:)
30 call disp%show("sample = getLinSpace(1._TKG, 9._TKG, 5_IK)")
31 sample = getLinSpace(1._TKG, 9._TKG, 5_IK)
32 call disp%show("sample")
33 call disp%show( sample )
34 call disp%show("var = getVar(sample)")
35 var = getVar(sample)
36 call disp%show("var")
37 call disp%show( var )
38 call disp%show("var = getVar(sample, correction = fweight)")
39 var = getVar(sample, correction = fweight)
40 call disp%show("var")
41 call disp%show( var )
42 call disp%show("var = getVar(sample, correction = rweight)")
43 var = getVar(sample, correction = rweight)
44 call disp%show("var")
45 call disp%show( var )
46 call disp%show("var = getVar(sample, dim = 1_IK)")
47 var = getVar(sample, dim = 1_IK)
48 call disp%show("var")
49 call disp%show( var )
50 call disp%show("var = getVar(sample, dim = 1_IK, correction = fweight)")
51 var = getVar(sample, dim = 1_IK, correction = fweight)
52 call disp%show("var")
53 call disp%show( var )
54 call disp%show("var = getVar(sample, dim = 1_IK, correction = rweight)")
55 var = getVar(sample, dim = 1_IK, correction = rweight)
56 call disp%show("var")
57 call disp%show( var )
58 call disp%skip()
59 end block
60
61 block
62 real(TKG) :: var
63 complex(TKG) , allocatable :: sample(:)
64 call disp%show("sample = cmplx(getShuffled(getLinSpace(1., 9., 5_IK)), getShuffled(getLinSpace(1., 9., 5_IK)), TKG)")
65 sample = cmplx(getShuffled(getLinSpace(1., 9., 5_IK)), getShuffled(getLinSpace(1., 9., 5_IK)), TKG)
66 call disp%show("sample")
67 call disp%show( sample )
68 call disp%show("var = getVar(sample)")
69 var = getVar(sample)
70 call disp%show("var")
71 call disp%show( var )
72 call disp%show("var = getVar(sample, correction = fweight)")
73 var = getVar(sample, correction = fweight)
74 call disp%show("var")
75 call disp%show( var )
76 call disp%show("var = getVar(sample, correction = rweight)")
77 var = getVar(sample, correction = rweight)
78 call disp%show("var")
79 call disp%show( var )
80 call disp%show("var = getVar(sample, dim = 1_IK)")
81 var = getVar(sample, dim = 1_IK)
82 call disp%show("var")
83 call disp%show( var )
84 call disp%show("var = getVar(sample, dim = 1_IK, correction = fweight)")
85 var = getVar(sample, dim = 1_IK, correction = fweight)
86 call disp%show("var")
87 call disp%show( var )
88 call disp%show("var = getVar(sample, dim = 1_IK, correction = rweight)")
89 var = getVar(sample, dim = 1_IK, correction = rweight)
90 call disp%show("var")
91 call disp%show( var )
92 call disp%skip()
93 end block
94
95 call disp%skip()
96 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
97 call disp%show("!Compute the variance of a 2-D array.")
98 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
99 call disp%skip()
100
101 block
102 real(TKG), allocatable :: var(:), sample(:,:)
103 call disp%skip()
104 call disp%show("sample = getUnifRand(1._TKG, 9._TKG, 4_IK, 5_IK)")
105 sample = getUnifRand(1._TKG, 9._TKG, 4_IK, 5_IK)
106 call disp%show("sample")
107 call disp%show( sample )
108 call disp%show("call setResized(var, 1_IK)")
109 call setResized(var, 1_IK)
110 call disp%show("var(1) = getVar(sample)")
111 var(1) = getVar(sample)
112 call disp%show("var(1)")
113 call disp%show( var(1) )
114 call disp%show("var(1) = getVar(sample, correction = fweight)")
115 var(1) = getVar(sample, correction = fweight)
116 call disp%show("var(1)")
117 call disp%show( var(1) )
118 call disp%show("var(1) = getVar(sample, correction = rweight)")
119 var(1) = getVar(sample, correction = rweight)
120 call disp%show("var(1)")
121 call disp%show( var(1) )
122 call disp%skip()
123 do dim = 1, 2
124 call disp%show("dim ! The observations axis.")
125 call disp%show( dim )
126 call disp%show("sample = getUnifRand(1._TKG, 9._TKG, 4_IK, 5_IK)")
127 sample = getUnifRand(1._TKG, 9._TKG, 4_IK, 5_IK)
128 call disp%show("var = getVar(sample, dim, correction = fweight)")
129 var = getVar(sample, dim, correction = fweight)
130 call disp%show("var")
131 call disp%show( var )
132 call disp%show("var = getVar(sample, dim, correction = rweight)")
133 var = getVar(sample, dim, correction = rweight)
134 call disp%show("var")
135 call disp%show( var )
136 call disp%skip()
137 end do
138 end block
139
140 block
141 real(TKG), allocatable :: var(:)
142 complex(TKG), allocatable :: sample(:,:)
143 call disp%skip()
144 call disp%show("sample = cmplx(getUnifRand(-9, 9, 4_IK, 5_IK), -getUnifRand(-9, 9, 4_IK, 5_IK), TKG)")
145 sample = cmplx(getUnifRand(-9, 9, 4_IK, 5_IK), -getUnifRand(-9, 9, 4_IK, 5_IK), TKG)
146 call disp%show("sample")
147 call disp%show( sample )
148 call disp%show("call setResized(var, 1_IK)")
149 call setResized(var, 1_IK)
150 call disp%show("var(1) = getVar(sample)")
151 var(1) = getVar(sample)
152 call disp%show("var(1)")
153 call disp%show( var(1) )
154 call disp%show("var(1) = getVar(sample, correction = fweight)")
155 var(1) = getVar(sample, correction = fweight)
156 call disp%show("var(1)")
157 call disp%show( var(1) )
158 call disp%show("var(1) = getVar(sample, correction = rweight)")
159 var(1) = getVar(sample, correction = rweight)
160 call disp%show("var(1)")
161 call disp%show( var(1) )
162 call disp%skip()
163 do dim = 1, 2
164 call disp%show("dim ! The observations axis.")
165 call disp%show( dim )
166 call disp%show("sample = cmplx(getUnifRand(-9, 9, 4_IK, 5_IK), -getUnifRand(-9, 9, 4_IK, 5_IK), TKG)")
167 sample = cmplx(getUnifRand(-9, 9, 4_IK, 5_IK), -getUnifRand(-9, 9, 4_IK, 5_IK), TKG)
168 call disp%show("sample")
169 call disp%show( sample )
170 call disp%show("var = getVar(sample, dim)")
171 var = getVar(sample, dim)
172 call disp%show("var")
173 call disp%show( var )
174 call disp%show("var = getVar(sample, dim, correction = fweight)")
175 var = getVar(sample, dim, correction = fweight)
176 call disp%show("var")
177 call disp%show( var )
178 call disp%show("var = getVar(sample, dim, correction = rweight)")
179 var = getVar(sample, dim, correction = rweight)
180 call disp%show("var")
181 call disp%show( var )
182 call disp%skip()
183 end do
184 end block
185
186 call disp%skip()
187 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
188 call disp%show("!Compute the variance of a 1-D weighted array.")
189 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
190 call disp%skip()
191
192 block
193 real(TKG) :: var
194 real(TKG), allocatable :: sample(:)
195 real(TKG) , allocatable :: weight(:)
196 call disp%show("sample = getLinSpace(1._TKG, 9._TKG, 5_IK)")
197 sample = getLinSpace(1._TKG, 9._TKG, 5_IK)
198 call disp%show("sample")
199 call disp%show( sample )
200 call disp%show("weight = getLinSpace(1._TKG, 9._TKG, size(sample, 1, IK))")
201 weight = getLinSpace(1._TKG, 9._TKG, size(sample, 1, IK))
202 call disp%show("weight")
203 call disp%show( weight )
204 call disp%show("var = getVar(sample, weight = weight)")
205 var = getVar(sample, weight = weight)
206 call disp%show("var")
207 call disp%show( var )
208 call disp%show("var = getVar(sample, weight = weight, correction = fweight)")
209 var = getVar(sample, weight = weight, correction = fweight)
210 call disp%show("var")
211 call disp%show( var )
212 call disp%show("var = getVar(sample, weight = weight, correction = rweight)")
213 var = getVar(sample, weight = weight, correction = rweight)
214 call disp%show("var")
215 call disp%show( var )
216 call disp%show("var = getVar(sample, dim = 1_IK, weight = weight)")
217 var = getVar(sample, dim = 1_IK, weight = weight)
218 call disp%show("var")
219 call disp%show( var )
220 call disp%show("var = getVar(sample, dim = 1_IK, weight = weight, correction = fweight)")
221 var = getVar(sample, dim = 1_IK, weight = weight, correction = fweight)
222 call disp%show("var")
223 call disp%show( var )
224 call disp%show("var = getVar(sample, dim = 1_IK, weight = weight, correction = rweight)")
225 var = getVar(sample, dim = 1_IK, weight = weight, correction = rweight)
226 call disp%show("var")
227 call disp%show( var )
228 call disp%skip()
229 end block
230
231 call disp%skip()
232 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
233 call disp%show("!Compute the variance of a 2-D weighted array.")
234 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
235 call disp%skip()
236
237 block
238 real(TKG), allocatable :: var(:), sample(:,:)
239 real(TKG), allocatable :: weight(:)
240 call disp%skip()
241 call disp%show("sample = getUnifRand(1._TKG, 9._TKG, 4_IK, 5_IK)")
242 sample = getUnifRand(1._TKG, 9._TKG, 4_IK, 5_IK)
243 call disp%show("sample")
244 call disp%show( sample )
245 call disp%show("weight = getLinSpace(1._TKG, 9._TKG, size(sample, kind = IK))")
246 weight = getLinSpace(1._TKG, 9._TKG, size(sample, kind = IK))
247 call disp%show("weight")
248 call disp%show( weight )
249 call disp%show("call setResized(var, 1_IK)")
250 call setResized(var, 1_IK)
251 call disp%show("var(1) = getVar(sample, weight = weight)")
252 var(1) = getVar(sample, weight = weight)
253 call disp%show("var(1)")
254 call disp%show( var(1) )
255 call disp%show("var(1) = getVar(sample, weight = weight, correction = fweight)")
256 var(1) = getVar(sample, weight = weight, correction = fweight)
257 call disp%show("var(1)")
258 call disp%show( var(1) )
259 call disp%show("var(1) = getVar(sample, weight = weight, correction = rweight)")
260 var(1) = getVar(sample, weight = weight, correction = rweight)
261 call disp%show("var(1)")
262 call disp%show( var(1) )
263 call disp%skip()
264 do dim = 1, 2
265 call disp%show("dim ! The observations axis.")
266 call disp%show( dim )
267 call disp%show("sample = getUnifRand(1._TKG, 9._TKG, 4_IK, 5_IK)")
268 sample = getUnifRand(1._TKG, 9._TKG, 4_IK, 5_IK)
269 call disp%show("sample")
270 call disp%show( sample )
271 call disp%show("weight = getLinSpace(1._TKG, 9._TKG, size(sample, dim, IK))")
272 weight = getLinSpace(1._TKG, 9._TKG, size(sample, dim, IK))
273 call disp%show("weight")
274 call disp%show( weight )
275 call disp%show("var = getVar(sample, dim, weight = weight)")
276 var = getVar(sample, dim, weight = weight)
277 call disp%show("var")
278 call disp%show( var )
279 call disp%show("var = getVar(sample, dim, weight = weight, correction = fweight)")
280 var = getVar(sample, dim, weight = weight, correction = fweight)
281 call disp%show("var")
282 call disp%show( var )
283 call disp%show("var = getVar(sample, dim, weight = weight, correction = rweight)")
284 var = getVar(sample, dim, weight = weight, correction = rweight)
285 call disp%show("var")
286 call disp%show( var )
287 call disp%skip()
288 end do
289 end block
290
291 call disp%skip()
292 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
293 call disp%show("!Compute the variance of a multidimensional array by reshaping the array.")
294 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
295 call disp%skip()
296
297 block
298 real(TKG), allocatable :: var
299 real(TKG), allocatable, target :: sample(:,:,:)
300 real(TKG), pointer :: samptr(:)
301 call disp%show("sample = getUnifRand(0., 1., 3_IK, 3_IK, 3_IK)")
302 sample = getUnifRand(0., 1., 3_IK, 3_IK, 3_IK)
303 call disp%show("sample")
304 call disp%show( sample )
305 call disp%show("samptr(1:product(shape(sample))) => sample")
306 samptr(1:product(shape(sample))) => sample
307 call disp%show("var = getVar(samptr)")
308 var = getVar(samptr)
309 call disp%show("var")
310 call disp%show( var )
311 call disp%show("nullify(samptr)")
312 nullify(samptr)
313 call disp%skip()
314 end block
315
316end program example
Allocate or resize (shrink or expand) an input allocatable scalar string or array of rank 1....
Perform an unbiased random shuffling of the input array, known as the Knuth or Fisher-Yates shuffle,...
Generate count evenly spaced points over the interval [x1, x2] if x1 < x2, or [x2,...
Generate and return a scalar or a contiguous array of rank 1 of length s1 of randomly uniformly distr...
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
Generate and return the (weighted) mean of an input sample of nsam observations with ndim = 1 or 2 at...
Generate a sample of shape (nsam), or (ndim, nsam) or (nsam, ndim) that is shifted by the specified i...
This module contains procedures and generic interfaces for resizing allocatable arrays of various typ...
This module contains procedures and generic interfaces for shuffling arrays of various types.
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 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
This module contains classes and procedures for computing the properties related to the covariance ma...
This module contains classes and procedures for computing the first moment (i.e., the statistical mea...
This module contains classes and procedures for shifting univariate or multivariate samples by arbitr...
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!Compute the variance of a 1-D array.
4!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5
6sample = getLinSpace(1._TKG, 9._TKG, 5_IK)
7sample
8+1.00000000, +3.00000000, +5.00000000, +7.00000000, +9.00000000
9var = getVar(sample)
10var
11+8.00000000
12var = getVar(sample, correction = fweight)
13var
14+10.0000000
15var = getVar(sample, correction = rweight)
16var
17+10.0000000
18var = getVar(sample, dim = 1_IK)
19var
20+8.00000000
21var = getVar(sample, dim = 1_IK, correction = fweight)
22var
23+10.0000000
24var = getVar(sample, dim = 1_IK, correction = rweight)
25var
26+10.0000000
27
28sample = cmplx(getShuffled(getLinSpace(1., 9., 5_IK)), getShuffled(getLinSpace(1., 9., 5_IK)), TKG)
29sample
30(+5.00000000, +5.00000000), (+3.00000000, +1.00000000), (+9.00000000, +3.00000000), (+1.00000000, +9.00000000), (+7.00000000, +7.00000000)
31var = getVar(sample)
32var
33+16.0000000
34var = getVar(sample, correction = fweight)
35var
36+20.0000000
37var = getVar(sample, correction = rweight)
38var
39+20.0000000
40var = getVar(sample, dim = 1_IK)
41var
42+16.0000000
43var = getVar(sample, dim = 1_IK, correction = fweight)
44var
45+20.0000000
46var = getVar(sample, dim = 1_IK, correction = rweight)
47var
48+20.0000000
49
50
51!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
52!Compute the variance of a 2-D array.
53!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
54
55
56sample = getUnifRand(1._TKG, 9._TKG, 4_IK, 5_IK)
57sample
58+8.46121979, +2.88154745, +8.14079189, +4.04352474, +6.89574957
59+2.75623846, +3.50739288, +3.63932037, +5.67869186, +7.74653864
60+6.32414484, +3.41867828, +5.80312395, +2.09699774, +3.31619024
61+7.81285095, +5.76273727, +1.54534245, +8.01425076, +4.72753334
62call setResized(var, 1_IK)
63var(1) = getVar(sample)
64var(1)
65+4.66890812
66var(1) = getVar(sample, correction = fweight)
67var(1)
68+4.91464043
69var(1) = getVar(sample, correction = rweight)
70var(1)
71+4.91464043
72
73dim ! The observations axis.
74+1
75sample = getUnifRand(1._TKG, 9._TKG, 4_IK, 5_IK)
76var = getVar(sample, dim, correction = fweight)
77var
78+10.7168875, +5.29745150, +1.59614623, +7.69147253, +7.22516012
79var = getVar(sample, dim, correction = rweight)
80var
81+10.7168875, +5.29745150, +1.59614623, +7.69147253, +7.22516012
82
83dim ! The observations axis.
84+2
85sample = getUnifRand(1._TKG, 9._TKG, 4_IK, 5_IK)
86var = getVar(sample, dim, correction = fweight)
87var
88+5.05653095, +3.55342412, +6.45670557, +6.92159510
89var = getVar(sample, dim, correction = rweight)
90var
91+5.05653095, +3.55342412, +6.45670557, +6.92159510
92
93
94sample = cmplx(getUnifRand(-9, 9, 4_IK, 5_IK), -getUnifRand(-9, 9, 4_IK, 5_IK), TKG)
95sample
96(-5.00000000, -6.00000000), (+6.00000000, -7.00000000), (+7.00000000, -1.00000000), (+0.00000000, -2.00000000), (-2.00000000, -5.00000000)
97(+9.00000000, +5.00000000), (-1.00000000, +3.00000000), (+9.00000000, +2.00000000), (+1.00000000, -2.00000000), (+4.00000000, -1.00000000)
98(-1.00000000, -1.00000000), (-3.00000000, +8.00000000), (-2.00000000, -3.00000000), (-9.00000000, +3.00000000), (+1.00000000, +7.00000000)
99(-8.00000000, -1.00000000), (+0.00000000, +9.00000000), (+6.00000000, +5.00000000), (-6.00000000, +9.00000000), (+9.00000000, +9.00000000)
100call setResized(var, 1_IK)
101var(1) = getVar(sample)
102var(1)
103+55.3350029
104var(1) = getVar(sample, correction = fweight)
105var(1)
106+58.2473717
107var(1) = getVar(sample, correction = rweight)
108var(1)
109+58.2473717
110
111dim ! The observations axis.
112+1
113sample = cmplx(getUnifRand(-9, 9, 4_IK, 5_IK), -getUnifRand(-9, 9, 4_IK, 5_IK), TKG)
114sample
115(-8.00000000, -4.00000000), (-7.00000000, -7.00000000), (-2.00000000, +5.00000000), (-4.00000000, +5.00000000), (+8.00000000, -9.00000000)
116(-1.00000000, -6.00000000), (+1.00000000, +4.00000000), (-2.00000000, -7.00000000), (-1.00000000, +0.00000000), (+8.00000000, +4.00000000)
117(-4.00000000, -8.00000000), (-1.00000000, +1.00000000), (+7.00000000, +5.00000000), (+2.00000000, -4.00000000), (+7.00000000, +6.00000000)
118(-7.00000000, +3.00000000), (+4.00000000, -7.00000000), (+0.00000000, +5.00000000), (-9.00000000, -2.00000000), (+3.00000000, -3.00000000)
119var = getVar(sample, dim)
120var
121+24.6875000, +39.8750000, +40.6875000, +27.6875000, +39.5000000
122var = getVar(sample, dim, correction = fweight)
123var
124+25.9868431, +41.9736862, +42.8289490, +29.1447372, +41.5789490
125var = getVar(sample, dim, correction = rweight)
126var
127+25.9868431, +41.9736862, +42.8289490, +29.1447372, +41.5789490
128
129dim ! The observations axis.
130+2
131sample = cmplx(getUnifRand(-9, 9, 4_IK, 5_IK), -getUnifRand(-9, 9, 4_IK, 5_IK), TKG)
132sample
133(-9.00000000, -7.00000000), (-5.00000000, -7.00000000), (+9.00000000, -3.00000000), (-2.00000000, +4.00000000), (+4.00000000, -9.00000000)
134(+7.00000000, -2.00000000), (+7.00000000, +1.00000000), (+8.00000000, -3.00000000), (-6.00000000, +9.00000000), (-3.00000000, +7.00000000)
135(+0.00000000, +1.00000000), (+2.00000000, -8.00000000), (+0.00000000, +7.00000000), (+4.00000000, -2.00000000), (+1.00000000, -5.00000000)
136(-4.00000000, -2.00000000), (-1.00000000, -8.00000000), (-9.00000000, -8.00000000), (+3.00000000, +9.00000000), (-8.00000000, -9.00000000)
137var = getVar(sample, dim)
138var
139+62.4799995, +57.6800041, +28.8799953, +65.5999985
140var = getVar(sample, dim, correction = fweight)
141var
142+65.7684250, +60.7157974, +30.3999958, +69.0526352
143var = getVar(sample, dim, correction = rweight)
144var
145+65.7684250, +60.7157974, +30.3999958, +69.0526352
146
147
148!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
149!Compute the variance of a 1-D weighted array.
150!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
151
152sample = getLinSpace(1._TKG, 9._TKG, 5_IK)
153sample
154+1.00000000, +3.00000000, +5.00000000, +7.00000000, +9.00000000
155weight = getLinSpace(1._TKG, 9._TKG, size(sample, 1, IK))
156weight
157+1.00000000, +3.00000000, +5.00000000, +7.00000000, +9.00000000
158var = getVar(sample, weight = weight)
159var
160+5.44000006
161var = getVar(sample, weight = weight, correction = fweight)
162var
163+5.66666651
164var = getVar(sample, weight = weight, correction = rweight)
165var
166+7.39130449
167var = getVar(sample, dim = 1_IK, weight = weight)
168var
169+5.44000006
170var = getVar(sample, dim = 1_IK, weight = weight, correction = fweight)
171var
172+5.66666651
173var = getVar(sample, dim = 1_IK, weight = weight, correction = rweight)
174var
175+7.39130449
176
177
178!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
179!Compute the variance of a 2-D weighted array.
180!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
181
182
183sample = getUnifRand(1._TKG, 9._TKG, 4_IK, 5_IK)
184sample
185+1.66025639, +7.30356741, +3.77517033, +8.43390274, +5.07321405
186+1.27086878, +5.52604342, +5.72993326, +2.41723633, +3.23205423
187+7.18606520, +7.31867552, +5.05243540, +7.03428316, +7.15761232
188+8.16402435, +3.55640984, +3.90907669, +1.88557053, +4.73296118
189weight = getLinSpace(1._TKG, 9._TKG, size(sample, kind = IK))
190weight
191+1.00000000, +1.42105269, +1.84210527, +2.26315784, +2.68421054, +3.10526323, +3.52631569, +3.94736838, +4.36842108, +4.78947353, +5.21052647, +5.63157892, +6.05263138, +6.47368431, +6.89473677, +7.31578970, +7.73684216, +8.15789413, +8.57894707, +9.00000000
192call setResized(var, 1_IK)
193var(1) = getVar(sample, weight = weight)
194var(1)
195+4.00580359
196var(1) = getVar(sample, weight = weight, correction = fweight)
197var(1)
198+4.04626608
199var(1) = getVar(sample, weight = weight, correction = rweight)
200var(1)
201+4.26962137
202
203dim ! The observations axis.
204+1
205sample = getUnifRand(1._TKG, 9._TKG, 4_IK, 5_IK)
206sample
207+6.44592428, +2.60194921, +8.35702324, +5.78197050, +7.79200220
208+7.76933098, +1.72515774, +8.31732082, +4.61817598, +7.87490940
209+1.01469517, +7.60194731, +2.17010546, +6.15357304, +8.82890320
210+8.67280197, +6.08868027, +3.15658522, +6.96983576, +7.84637260
211weight = getLinSpace(1._TKG, 9._TKG, size(sample, dim, IK))
212weight
213+1.00000000, +3.66666675, +6.33333349, +9.00000000
214var = getVar(sample, dim, weight = weight)
215var
216+11.6679602, +4.57861280, +5.74431419, +0.734408319, +0.207621455
217var = getVar(sample, dim, weight = weight, correction = fweight)
218var
219+12.2820635, +4.81959248, +6.04664660, +0.773061395, +0.218548909
220var = getVar(sample, dim, weight = weight, correction = rweight)
221var
222+17.6490135, +6.92563248, +8.68887806, +1.11086965, +0.314049244
223
224dim ! The observations axis.
225+2
226sample = getUnifRand(1._TKG, 9._TKG, 4_IK, 5_IK)
227sample
228+7.70591974, +1.84098530, +6.65535021, +7.79736185, +4.78858471
229+2.16351271, +4.52038765, +7.79764414, +2.13297844, +6.85165071
230+3.24853897, +3.12180233, +5.27173328, +7.09050941, +3.96719503
231+8.81959057, +1.70425415, +5.06731319, +6.36379337, +1.68238258
232weight = getLinSpace(1._TKG, 9._TKG, size(sample, dim, IK))
233weight
234+1.00000000, +3.00000000, +5.00000000, +7.00000000, +9.00000000
235var = getVar(sample, dim, weight = weight)
236var
237+3.65673018, +5.38696194, +2.16769910, +5.28587389
238var = getVar(sample, dim, weight = weight, correction = fweight)
239var
240+3.80909371, +5.61141825, +2.25801992, +5.50611830
241var = getVar(sample, dim, weight = weight, correction = rweight)
242var
243+4.96838331, +7.31924152, +2.94524336, +7.18189383
244
245
246!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
247!Compute the variance of a multidimensional array by reshaping the array.
248!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
249
250sample = getUnifRand(0., 1., 3_IK, 3_IK, 3_IK)
251sample
252slice(:,:,1) =
253+0.971357822E-1, +0.744138360, +0.615796089
254+0.220432758, +0.139037549, +0.873998165
255+0.342322826, +0.796147406, +0.862752497
256slice(:,:,2) =
257+0.875705302, +0.241637230E-3, +0.340877771
258+0.763631761, +0.269887805, +0.234624743
259+0.502892256, +0.506789804, +0.113740087
260slice(:,:,3) =
261+0.158408821, +0.676580548, +0.288008809
262+0.155710757, +0.449842870, +0.940518022
263+0.327032804E-2, +0.397980869, +0.583401799
264samptr(1:product(shape(sample))) => sample
265var = getVar(samptr)
266var
267+0.840605125E-1
268nullify(samptr)
269
270
Test:
test_pm_sampleVar
Todo:
Very Low Priority: The functionality of this interface can be expanded in the future to include the computation of the variance of higher dimensional input sample and whole sample input arrays of arbitrary shape.


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:
Fatemeh Bagheri, Monday 02:15 AM, September 27, 2021, Dallas, TX

Definition at line 715 of file pm_sampleVar.F90.


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