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(+3.00000000, +5.00000000), (+9.00000000, +1.00000000), (+7.00000000, +3.00000000), (+1.00000000, +7.00000000), (+5.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+4.12921572, +3.23392248, +8.71532631, +3.57250690, +2.84240818
59+4.19472408, +6.35930729, +2.11785364, +7.29621410, +5.26567125
60+4.05614471, +5.43257189, +3.42744541, +7.79892588, +6.00786209
61+7.65003061, +4.55825949, +1.56357431, +6.27047348, +4.27746677
62call setResized(var, 1_IK)
63var(1) = getVar(sample)
64var(1)
65+3.70040131
66var(1) = getVar(sample, correction = fweight)
67var(1)
68+3.89515948
69var(1) = getVar(sample, correction = rweight)
70var(1)
71+3.89515948
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+2.82083201, +1.53922629, +1.86118722, +5.26235390, +1.55820251
79var = getVar(sample, dim, correction = rweight)
80var
81+2.82083201, +1.53922629, +1.86118722, +5.26235390, +1.55820251
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+6.67883015, +2.03104091, +6.25487471, +3.24131751
89var = getVar(sample, dim, correction = rweight)
90var
91+6.67883015, +2.03104091, +6.25487471, +3.24131751
92
93
94sample = cmplx(getUnifRand(-9, 9, 4_IK, 5_IK), -getUnifRand(-9, 9, 4_IK, 5_IK), TKG)
95sample
96(-8.00000000, +0.00000000), (-2.00000000, -1.00000000), (+5.00000000, -1.00000000), (-9.00000000, +3.00000000), (+5.00000000, -8.00000000)
97(-6.00000000, -4.00000000), (-8.00000000, -9.00000000), (+6.00000000, -1.00000000), (+6.00000000, -4.00000000), (-4.00000000, +9.00000000)
98(+8.00000000, +7.00000000), (-6.00000000, +0.00000000), (+0.00000000, -5.00000000), (-1.00000000, +7.00000000), (-8.00000000, +2.00000000)
99(+5.00000000, -1.00000000), (-1.00000000, +9.00000000), (-6.00000000, -9.00000000), (-8.00000000, -2.00000000), (-3.00000000, -9.00000000)
100call setResized(var, 1_IK)
101var(1) = getVar(sample)
102var(1)
103+62.8149948
104var(1) = getVar(sample, correction = fweight)
105var(1)
106+66.1210480
107var(1) = getVar(sample, correction = rweight)
108var(1)
109+66.1210480
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(+9.00000000, -2.00000000), (+0.00000000, +1.00000000), (+0.00000000, -1.00000000), (-1.00000000, -2.00000000), (-4.00000000, -7.00000000)
116(+9.00000000, -6.00000000), (+7.00000000, -1.00000000), (+8.00000000, -7.00000000), (-1.00000000, +9.00000000), (-8.00000000, +6.00000000)
117(+8.00000000, +1.00000000), (+0.00000000, +4.00000000), (+2.00000000, -2.00000000), (+5.00000000, +2.00000000), (-9.00000000, +4.00000000)
118(-2.00000000, -3.00000000), (+3.00000000, +2.00000000), (+7.00000000, -4.00000000), (-4.00000000, +5.00000000), (+8.00000000, +1.00000000)
119var = getVar(sample, dim)
120var
121+27.7500000, +11.5000000, +16.4375000, +26.9375000, +70.1875000
122var = getVar(sample, dim, correction = fweight)
123var
124+29.2105274, +12.1052637, +17.3026314, +28.3552647, +73.8815842
125var = getVar(sample, dim, correction = rweight)
126var
127+29.2105274, +12.1052637, +17.3026314, +28.3552647, +73.8815842
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(+6.00000000, +8.00000000), (-7.00000000, -6.00000000), (-3.00000000, +8.00000000), (-1.00000000, +4.00000000), (-6.00000000, -7.00000000)
134(-5.00000000, -1.00000000), (+8.00000000, +1.00000000), (+4.00000000, -8.00000000), (-7.00000000, +9.00000000), (+3.00000000, +1.00000000)
135(+0.00000000, -7.00000000), (+7.00000000, -2.00000000), (-9.00000000, +7.00000000), (-8.00000000, +9.00000000), (-7.00000000, -3.00000000)
136(-2.00000000, +4.00000000), (+3.00000000, +3.00000000), (+3.00000000, +0.00000000), (+4.00000000, -6.00000000), (-3.00000000, -5.00000000)
137var = getVar(sample, dim)
138var
139+65.2000046, +61.6800003, +74.7999954, +24.9599991
140var = getVar(sample, dim, correction = fweight)
141var
142+68.6315842, +64.9263153, +78.7368393, +26.2736835
143var = getVar(sample, dim, correction = rweight)
144var
145+68.6315842, +64.9263153, +78.7368393, +26.2736835
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+5.29397678, +8.18918991, +5.16748524, +1.78410721, +6.57217121
186+4.60676575, +4.71704817, +7.21647358, +1.79534006, +3.11167288
187+2.63811302, +6.37841988, +1.21801853, +7.49396276, +3.56025982
188+7.52323580, +1.41013336, +5.17097330, +5.33743143, +3.31437349
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.37727976
196var(1) = getVar(sample, weight = weight, correction = fweight)
197var(1)
198+4.42149448
199var(1) = getVar(sample, weight = weight, correction = rweight)
200var(1)
201+4.66556215
202
203dim ! The observations axis.
204+1
205sample = getUnifRand(1._TKG, 9._TKG, 4_IK, 5_IK)
206sample
207+4.13911772, +7.03946257, +6.58551216, +7.89993811, +1.55608797
208+5.14891863, +6.02331781, +6.29733372, +3.76061153, +5.93542957
209+5.75712729, +8.68555546, +8.83969498, +2.90211916, +3.90573359
210+1.15081072, +8.26825047, +1.65203571, +3.76794291, +2.01402998
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+4.61553717, +0.938402474, +10.1462450, +1.08631825, +2.28568125
217var = getVar(sample, dim, weight = weight, correction = fweight)
218var
219+4.85846043, +0.987792134, +10.6802588, +1.14349294, +2.40598035
220var = getVar(sample, dim, weight = weight, correction = rweight)
221var
222+6.98148441, +1.41943228, +15.3472605, +1.64317036, +3.45733285
223
224dim ! The observations axis.
225+2
226sample = getUnifRand(1._TKG, 9._TKG, 4_IK, 5_IK)
227sample
228+5.18609095, +8.10227489, +6.44532299, +7.53516436, +7.00741339
229+5.34240055, +7.22200584, +4.45973253, +4.11605692, +6.00306177
230+5.69385910, +2.93198252, +4.05808020, +3.92866802, +2.51374769
231+2.02472973, +7.68335056, +8.90037918, +8.49943066, +7.49475288
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+0.408896327, +1.15480363, +0.684372485, +1.74474633
238var = getVar(sample, dim, weight = weight, correction = fweight)
239var
240+0.425933659, +1.20292044, +0.712888002, +1.81744397
241var = getVar(sample, dim, weight = weight, correction = rweight)
242var
243+0.555565655, +1.56902659, +0.929853916, +2.37057924
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.617693782, +0.712800622, +0.181455374
254+0.776526690, +0.269264579, +0.435956359
255+0.718100905, +0.579773188E-1, +0.238781571
256slice(:,:,2) =
257+0.118698955, +0.217659235, +0.782679617
258+0.395786285, +0.500491679, +0.579881847
259+0.114023924, +0.361837864, +0.494825244E-1
260slice(:,:,3) =
261+0.939588785, +0.498580039, +0.832240283
262+0.485584497, +0.497074604, +0.565555096E-1
263+0.709281743, +0.924800754, +0.784395993
264samptr(1:product(shape(sample))) => sample
265var = getVar(samptr)
266var
267+0.773779824E-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: