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, +1.00000000), (+9.00000000, +7.00000000), (+3.00000000, +5.00000000), (+1.00000000, +3.00000000), (+7.00000000, +9.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+6.52446842, +3.83352661, +1.77059317, +8.38501263, +8.95649338
59+5.00342083, +7.77162886, +4.97027016, +1.27960253, +7.32357645
60+3.90767574, +4.08084774, +5.77870083, +1.82107782, +5.74156380
61+8.22197819, +7.56458569, +3.83126736, +6.85559607, +3.62764645
62call setResized(var, 1_IK)
63var(1) = getVar(sample)
64var(1)
65+5.12359524
66var(1) = getVar(sample, correction = fweight)
67var(1)
68+5.39325857
69var(1) = getVar(sample, correction = rweight)
70var(1)
71+5.39325857
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+4.97601366, +4.45858145, +4.38417006, +3.08473539, +3.36357975
79var = getVar(sample, dim, correction = rweight)
80var
81+4.97601366, +4.45858145, +4.38417006, +3.08473539, +3.36357975
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+8.88743401, +6.12243223, +7.31469440, +0.990785539
89var = getVar(sample, dim, correction = rweight)
90var
91+8.88743401, +6.12243223, +7.31469440, +0.990785539
92
93
94sample = cmplx(getUnifRand(-9, 9, 4_IK, 5_IK), -getUnifRand(-9, 9, 4_IK, 5_IK), TKG)
95sample
96(-8.00000000, +6.00000000), (-7.00000000, +2.00000000), (+4.00000000, -1.00000000), (+0.00000000, +2.00000000), (+2.00000000, -3.00000000)
97(-2.00000000, +0.00000000), (+9.00000000, -4.00000000), (+7.00000000, +7.00000000), (+0.00000000, -7.00000000), (+1.00000000, +6.00000000)
98(+3.00000000, -8.00000000), (-5.00000000, +6.00000000), (+8.00000000, +4.00000000), (+8.00000000, -8.00000000), (+4.00000000, +7.00000000)
99(-2.00000000, +2.00000000), (-1.00000000, +5.00000000), (-4.00000000, +3.00000000), (+1.00000000, +6.00000000), (+5.00000000, +1.00000000)
100call setResized(var, 1_IK)
101var(1) = getVar(sample)
102var(1)
103+47.0374985
104var(1) = getVar(sample, correction = fweight)
105var(1)
106+49.5131569
107var(1) = getVar(sample, correction = rweight)
108var(1)
109+49.5131569
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(-1.00000000, +3.00000000), (+3.00000000, +1.00000000), (-2.00000000, +6.00000000), (+5.00000000, +1.00000000), (-8.00000000, -7.00000000)
116(+8.00000000, -2.00000000), (-3.00000000, +8.00000000), (+1.00000000, +3.00000000), (+5.00000000, +3.00000000), (-5.00000000, -2.00000000)
117(+7.00000000, -3.00000000), (-5.00000000, +8.00000000), (-2.00000000, -9.00000000), (-6.00000000, -7.00000000), (+9.00000000, +4.00000000)
118(-8.00000000, -5.00000000), (+3.00000000, +8.00000000), (-3.00000000, +0.00000000), (+6.00000000, -3.00000000), (+2.00000000, +3.00000000)
119var = getVar(sample, dim)
120var
121+50.9375000, +21.9375000, +33.7500000, +39.0000000, +62.5000000
122var = getVar(sample, dim, correction = fweight)
123var
124+53.6184235, +23.0921059, +35.5263176, +41.0526314, +65.7894745
125var = getVar(sample, dim, correction = rweight)
126var
127+53.6184235, +23.0921059, +35.5263176, +41.0526314, +65.7894745
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(+4.00000000, +6.00000000), (-9.00000000, +5.00000000), (-1.00000000, +0.00000000), (-2.00000000, -1.00000000), (+5.00000000, +3.00000000)
134(+9.00000000, +8.00000000), (-8.00000000, -2.00000000), (-1.00000000, -4.00000000), (+8.00000000, -9.00000000), (+7.00000000, +3.00000000)
135(-4.00000000, +0.00000000), (+2.00000000, +8.00000000), (-7.00000000, -8.00000000), (-6.00000000, +3.00000000), (-5.00000000, +7.00000000)
136(-2.00000000, +0.00000000), (+3.00000000, -3.00000000), (+9.00000000, -4.00000000), (-7.00000000, +7.00000000), (-3.00000000, +2.00000000)
137var = getVar(sample, dim)
138var
139+32.4799995, +76.9599991, +43.2000008, +45.8400002
140var = getVar(sample, dim, correction = fweight)
141var
142+34.1894760, +81.0105286, +45.4736862, +48.2526321
143var = getVar(sample, dim, correction = rweight)
144var
145+34.1894760, +81.0105286, +45.4736862, +48.2526321
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+4.92118597, +3.93205404, +2.04195070, +1.08013439, +8.42021465
186+6.33719110, +4.58371544, +3.42720079, +5.51021671, +4.78841782
187+6.35301495, +5.05011415, +7.05587339, +5.93136883, +3.38336372
188+7.58829355, +5.07982922, +3.44624376, +7.93914604, +1.88381815
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.70261192
196var(1) = getVar(sample, weight = weight, correction = fweight)
197var(1)
198+4.75011301
199var(1) = getVar(sample, weight = weight, correction = rweight)
200var(1)
201+5.01232052
202
203dim ! The observations axis.
204+1
205sample = getUnifRand(1._TKG, 9._TKG, 4_IK, 5_IK)
206sample
207+4.29987097, +4.51889372, +2.49617767, +4.28629637, +4.84596252
208+1.13063669, +6.40167713, +1.41440201, +4.65148449, +1.05075884
209+2.81298780, +5.53477764, +3.52329731, +1.20692921, +8.21473789
210+8.45940113, +8.63117886, +5.85738850, +7.98474264, +4.74142790
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+9.65500069, +2.24928784, +2.94472671, +8.61085415, +6.13436651
217var = getVar(sample, dim, weight = weight, correction = fweight)
218var
219+10.1631594, +2.36767149, +3.09971237, +9.06405735, +6.45722818
220var = getVar(sample, dim, weight = weight, correction = rweight)
221var
222+14.6042023, +3.40228391, +4.45420837, +13.0248203, +9.27887344
223
224dim ! The observations axis.
225+2
226sample = getUnifRand(1._TKG, 9._TKG, 4_IK, 5_IK)
227sample
228+5.95939255, +8.73706532, +5.65549803, +2.86419582, +1.95827341
229+6.32004738, +4.42536259, +2.82742453, +8.56602859, +3.90013361
230+6.40244722, +6.10307646, +3.61640501, +8.00912476, +6.62316418
231+1.59151077, +2.09931469, +5.49416971, +3.51770878, +7.18769121
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+5.25076151, +5.02641058, +2.29942298, +3.86122894
238var = getVar(sample, dim, weight = weight, correction = fweight)
239var
240+5.46954298, +5.23584414, +2.39523220, +4.02211332
241var = getVar(sample, dim, weight = weight, correction = rweight)
242var
243+7.13418674, +6.82936192, +3.12421584, +5.24623489
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.670200706, +0.245780528, +0.691632628E-1
254+0.741564631, +0.370370686, +0.645985901
255+0.567170262, +0.154305458, +0.208736062
256slice(:,:,2) =
257+0.954846084, +0.512954772, +0.562396646E-1
258+0.101873875, +0.967078269, +0.719123542
259+0.322870612E-1, +0.252239347, +0.973619521
260slice(:,:,3) =
261+0.739393175, +0.216321886, +0.134367526
262+0.837722719, +0.347896039, +0.566112757
263+0.416002929, +0.695480704, +0.562496781E-1
264samptr(1:product(shape(sample))) => sample
265var = getVar(samptr)
266var
267+0.931585357E-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: