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

Generate and return the (optionally unbiased) covariance matrix of a pair of (potentially weighted) time series x(1:nsam) and y(1:nsam) or of an input (potentially weighted) array of shape (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 (optionally unbiased) covariance matrix of a pair of (potentially weighted) time series x(1:nsam) and y(1:nsam) or of an input (potentially weighted) array of shape (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.

This generic interface performs one of the following computational tasks:

  1. compute the covariance matrix corresponding to an input correlation matrix and vector of standard deviations in arbitrary ndim dimensions.
  2. compute the sample covariance matrix of a random sample of nsam observations in arbitrary ndim dimensional space.
  3. compute the sample covariance matrix of a pair of nsam observations in two separated data vectors x and y.

See the documentation of the parent module pm_sampleCov for algorithmic details and sample covariance matrix definition.

Parameters
[in]cor: The input positive semi-definite square matrix of shape (1:ndim, 1:ndim) of the same type and kind as the input cov, representing the correlation matrix based upon which the output covariance matrix cov is to be computed.
(optional. It must be present if and only if the input arguments std and subsetr are present and the rest are missing.)
[in]subsetr: The input scalar constant argument that can be any of the following:
  1. The constant lowDia, implying that only the lower-diagonal subset of the input correlation matrix must be used.
  2. The constant uppDia, implying that only the upper-diagonal subset of the input correlation matrix must be used.
This input argument is merely serves to resolve the different procedures of this generic interface from each other at compile-time.
Although the allowed subset constants imply the use of the diagonal elements, they are by definition assumed to be 1 and therefore are not referenced in the algorithm. (optional. If missing, only the upper triangle will be used. It must be present if and only if the input arguments cor is present.)
[in]std: The input positive vector of shape (1:ndim) of type real of the same kind as the input cov, containing the standard deviations of the ndim data attributes based upon which the output covariance matrix cov is to be computed.
(optional. It must be present if and only if the input argument cor is present.)
[in]x: The input contiguous vector of shape (nsam) of the same type and kind as the output cov, containing the first attribute x of the observational sample, where nsam is the number of observations in the sample.
(optional. It must be present if and only if the input argument y is present and sample is missing.)
[in]y: The input contiguous vector of shape (nsam) of the same type and kind as the output cov, containing the second attribute x of the observational sample, where nsam is the number of observations in the sample.
(optional. It must be present if and only if the input argument x is present and sample is missing.)
[in]sample: The input contiguous array of shape (ndim, nsam) or (nsam, ndim) of the same type and kind as the output cov, containing the sample comprised of nsam observations each with ndim attributes.
If sample is a matrix, then the direction along which the covariance matrix is computed is dictated by the input argument dim.
(optional. It must be present if and only if the input argument dim is present and x and y are missing.)
[in]dim: The input scalar integer of default kind IK indicating the dimension of sample along which the covariance matrix must be computed.
  1. If dim = 1, the input sample is assumed to have the shape (nsam, ndim).
  2. If dim = 2, the input sample is assumed to have the shape (ndim, nsam).
(optional. It must be present if and only if the input argument sample is present.)
[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 output cov,
containing the corresponding weights of individual nsam observations in sample.
(optional. default = getFilled(1, nsam). It can be present only if the input arguments cor, subsetr, and std are 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 cov.
It can be present only if the input arguments cor, subsetr, and std are missing.)
Returns
cov : The output positive semi-definite square matrix of shape (1:ndim, 1: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 computed covariance matrix.
When the input arguments x and y are present, then ndim == 2 holds by definition and the output covariance is of the form,

\begin{equation} \ms{cov} = \begin{bmatrix} \sigma_{xx} && \sigma_{yx} \\ \sigma_{xy} && \sigma_{yy} \end{bmatrix} \end{equation}


Possible calling interfaces

use pm_sampleCov, only: getCov
! correlation matrix to covariance matrix.
cov(1:ndim, 1:ndim) = getCov(cor(1:ndim, 1:ndim), subsetr, std(1:ndim))
! XY time series covariance matrix.
cov(1:2, 1:2) = getCov(x(1:nsam), y(1:nsam) , correction = correction) ! full covariance matrix.
cov(1:2, 1:2) = getCov(x(1:nsam), y(1:nsam), weight(1:nsam), correction = correction) ! full covariance matrix.
! sample covariance matrix.
cov(1:ndim, 1:ndim) = getCov(sample(:,:), dim , correction = correction) ! full covariance matrix.
cov(1:ndim, 1:ndim) = getCov(sample(:,:), dim, weight(1:nsam), correction = correction) ! full covariance matrix.
!
Generate and return the (optionally unbiased) covariance matrix of a pair of (potentially weighted) t...
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 setCov.
As such, all conditions and warnings associated with setCov 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 covariance become noticeable only for very sample sample sizes (i.e., when nsam is small).
See also
getCor
setCor
getCov
setCov
getVar
setVar
getMean
setMean
getCovMerged
setCovMerged
setCovMeanMerged
getVarCorrection
getMeanMerged
setMeanMerged
getVarMerged
setVarMerged


Example usage

1program example
2
3 use pm_kind, only: SK, IK, LK
4 use pm_sampleMean, only: getMean
5 use pm_sampleMean, only: setMean
9 use pm_distUnif, only: getUnifRand
10 use pm_arrayFill, only: getFilled
11 use pm_sampleCov, only: uppDia
12 use pm_sampleCov, only: lowDia
13 use pm_sampleCov, only: getCov
14 use pm_sampleCor, only: getCor
15 use pm_io, only: display_type
16 use pm_io, only: getFormat
17
18 implicit none
19
20 integer(IK) :: itry, ntry = 10
21 type(display_type) :: disp
22 character(:), allocatable :: format
23 disp = display_type(file = "main.out.F90")
24
25 call disp%skip()
26 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
27 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
28 call disp%show("!Convert correlation matrix and standard deviation to covariance matrix.")
29 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
30 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
31 call disp%skip()
32
33 block
34 use pm_kind, only: TKG => RKS ! All other real types are also supported.
35 use pm_matrixCopy, only: setMatCopy, rdpack
36 use pm_distCov, only: getCovRand
37 integer(IK) :: ndim
38 real(TKG), allocatable :: cov(:,:), cor(:,:), std(:)
39 format = getFormat(mold = [0._TKG], ed = SK_"es", signed = .true._LK)
40 do itry = 1, ntry
41 call disp%skip()
42 call disp%show("ndim = getUnifRand(1, 7)")
43 ndim = getUnifRand(1, 7)
44 call disp%show("ndim")
45 call disp%show( ndim )
46 call disp%show("std = getUnifRand(1, 10, ndim)")
47 std = getUnifRand(1, 10, ndim)
48 call disp%show("std")
49 call disp%show( std , format = format )
50 call disp%show("call setResized(cov, [ndim, ndim])")
51 call setResized(cov, [ndim, ndim])
52 call disp%show("cor = getCovRand(1., ndim)")
53 cor = getCovRand(1., ndim)
54 call disp%show("cor")
55 call disp%show( cor , format = format )
56 call disp%show("cov = getCov(cor, uppDia, std) ! convert upper correlation matrix to full covariance matrix.")
57 cov = getCov(cor, uppDia, std)
58 call disp%show("cov")
59 call disp%show( cov , format = format )
60 call disp%show("cov = getCov(cor, lowDia, std) ! convert upper correlation matrix to full covariance matrix.")
61 cov = getCov(cor, lowDia, std)
62 call disp%show("cov")
63 call disp%show( cov , format = format )
64 call disp%show("getCor(getCov(cor, lowDia, std), lowDia) ! reconstruct the original correlation matrix.")
65 call disp%show( getCor(getCov(cor, lowDia, std), lowDia) , format = format )
66 call disp%skip()
67 end do
68 end block
69
70 call disp%skip()
71 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
72 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
73 call disp%show("!Compute the covariance matrix of a 2-D sample.")
74 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
75 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
76 call disp%skip()
77
78 block
79 use pm_kind, only: TKG => RKS ! All other real types are also supported.
80 real(TKG), allocatable :: sample(:,:), cov(:,:), mean(:)
81 integer(IK) :: ndim, nsam
82 call disp%show("ndim = 2; nsam = 10")
83 ndim = 2; nsam = 10
84 call disp%show("sample = reshape(getUnifRand(1, 20, ndim * nsam), shape = [ndim, nsam], order = [2, 1])")
85 sample = reshape(getUnifRand(1, 20, ndim * nsam), shape = [ndim, nsam], order = [2, 1])
86 call disp%show("sample")
87 call disp%show( sample )
88 call disp%skip()
89 call disp%show("Compute the sample covariance along the second dimension.", deliml = SK_'''')
90 call disp%skip()
91 call disp%show("cov = getCov(sample, dim = 2_IK)")
92 cov = getCov(sample, dim = 2_IK)
93 call disp%show("cov")
94 call disp%show( cov )
95 call disp%skip()
96 call disp%show("Compute the sample covariance along the first dimension.", deliml = SK_'''')
97 call disp%skip()
98 call disp%show("cov = getCov(transpose(sample), dim = 1_IK)")
99 cov = getCov(transpose(sample), dim = 1_IK)
100 call disp%show("cov")
101 call disp%show( cov )
102 call disp%skip()
103 call disp%show("Compute the full sample covariance for a pair of time series.", deliml = SK_'''')
104 call disp%skip()
105 call disp%show("cov = getCov(sample(1,:), sample(2,:))")
106 cov = getCov(sample(1,:), sample(2,:))
107 call disp%show("cov")
108 call disp%show( cov )
109 call disp%skip()
110 end block
111
112 block
113 use pm_kind, only: TKG => RKS ! All other real types are also supported.
114 complex(TKG), allocatable :: sample(:,:), cov(:,:), mean(:)
115 integer(IK) :: ndim, nsam
116 call disp%show("ndim = 2; nsam = 10")
117 ndim = 2; nsam = 10
118 call disp%show("sample = reshape(cmplx(getUnifRand(1, 20, ndim * nsam), -getUnifRand(1, 20, ndim * nsam), TKG), shape = [ndim, nsam], order = [2, 1])")
119 sample = reshape(cmplx(getUnifRand(1, 20, ndim * nsam), -getUnifRand(1, 20, ndim * nsam), TKG), shape = [ndim, nsam], order = [2, 1])
120 call disp%show("sample")
121 call disp%show( sample )
122 call disp%skip()
123 call disp%show("Compute the sample covariance along the second dimension.", deliml = SK_'''')
124 call disp%skip()
125 call disp%show("cov = getCov(sample, dim = 2_IK)")
126 cov = getCov(sample, dim = 2_IK)
127 call disp%show("cov")
128 call disp%show( cov )
129 call disp%skip()
130 call disp%show("Compute the sample covariance along the first dimension.", deliml = SK_'''')
131 call disp%skip()
132 call disp%show("cov = getCov(transpose(sample), dim = 1_IK)")
133 cov = getCov(transpose(sample), dim = 1_IK)
134 call disp%show("cov")
135 call disp%show( cov )
136 call disp%skip()
137 call disp%show("Compute the full sample covariance for a pair of time series.", deliml = SK_'''')
138 call disp%skip()
139 call disp%show("cov = getCov(sample(1,:), sample(2,:))")
140 cov = getCov(sample(1,:), sample(2,:))
141 call disp%show("cov")
142 call disp%show( cov )
143 call disp%skip()
144 end block
145
146 call disp%skip()
147 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
148 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
149 call disp%show("!Compute the biased covariance matrix of a weighted 2-D sample.")
150 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
151 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
152 call disp%skip()
153
154 block
155 use pm_kind, only: TKG => RKS ! All other real types are also supported.
156 real(TKG) :: rweisum
157 integer(IK) :: iweisum
158 real(TKG), allocatable :: rweight(:)
159 integer(IK), allocatable :: iweight(:)
160 real(TKG), allocatable :: sample(:,:), cov(:,:), mean(:)
161 integer(IK) :: ndim, nsam
162 call disp%show("ndim = 2; nsam = 10")
163 ndim = 2; nsam = 10
164 call disp%show("sample = reshape(getUnifRand(1, 20, ndim * nsam), shape = [ndim, nsam], order = [2, 1])")
165 sample = reshape(getUnifRand(1, 20, ndim * nsam), shape = [ndim, nsam], order = [2, 1])
166 call disp%show("sample")
167 call disp%show( sample )
168 call disp%show("call setResized(mean, ndim)")
169 call setResized(mean, ndim)
170 call disp%show("iweight = getUnifRand(1, 10, nsam) ! integer-valued weights.")
171 iweight = getUnifRand(1, 10, nsam) ! integer-valued weights.
172 call disp%show("iweight")
173 call disp%show( iweight )
174 call disp%show("call setMean(mean, sample, 2_IK, iweight, iweisum)")
175 call setMean(mean, sample, 2_IK, iweight, iweisum)
176 call disp%show("mean")
177 call disp%show( mean )
178 call disp%show("iweisum")
179 call disp%show( iweisum )
180 call disp%show("rweight = iweight ! or real-valued weights.")
181 rweight = iweight ! or real-valued weights.
182 call disp%show("iweight")
183 call disp%show( iweight )
184 call disp%show("call setMean(mean, sample, 2_IK, rweight, rweisum)")
185 call setMean(mean, sample, 2_IK, rweight, rweisum)
186 call disp%show("mean")
187 call disp%show( mean )
188 call disp%show("rweisum")
189 call disp%show( rweisum )
190
191 call disp%skip()
192 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
193 call disp%show("!Compute the covariance matrix with integer weights.")
194 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
195 call disp%skip()
196
197 call disp%show("cov = getCov(sample, 2_IK, iweight)")
198 cov = getCov(sample, 2_IK, iweight)
199 call disp%show("cov")
200 call disp%show( cov )
201 call disp%skip()
202 call disp%show("Compute the sample covariance along the first dimension.", deliml = SK_'''')
203 call disp%skip()
204 call disp%show("cov = getCov(transpose(sample), 1_IK, iweight)")
205 cov = getCov(transpose(sample), 1_IK, iweight)
206 call disp%show("cov")
207 call disp%show( cov )
208 call disp%skip()
209 call disp%show("Compute the full sample covariance for a pair of time series.", deliml = SK_'''')
210 call disp%skip()
211 call disp%show("cov = getCov(sample(1,:), sample(2,:), weight = iweight)")
212 cov = getCov(sample(1,:), sample(2,:), weight = iweight)
213 call disp%show("cov")
214 call disp%show( cov )
215 call disp%skip()
216
217 call disp%skip()
218 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
219 call disp%show("!Compute the covariance matrix with real weights.")
220 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
221 call disp%skip()
222
223 call disp%show("cov = getCov(sample, 2_IK, rweight)")
224 cov = getCov(sample, 2_IK, rweight)
225 call disp%show("cov")
226 call disp%show( cov )
227 call disp%skip()
228 call disp%show("Compute the sample covariance along the first dimension.", deliml = SK_'''')
229 call disp%skip()
230 call disp%show("cov = getCov(transpose(sample), 1_IK, rweight)")
231 cov = getCov(transpose(sample), 1_IK, rweight)
232 call disp%show("cov")
233 call disp%show( cov )
234 call disp%skip()
235 call disp%show("Compute the full sample covariance for a pair of time series.", deliml = SK_'''')
236 call disp%skip()
237 call disp%show("cov = getCov(sample(1,:), sample(2,:), weight = rweight)")
238 cov = getCov(sample(1,:), sample(2,:), weight = rweight)
239 call disp%show("cov")
240 call disp%show( cov )
241 call disp%skip()
242 end block
243
244 block
245 use pm_kind, only: TKG => RKS ! All other real types are also supported.
246 real(TKG) :: rweisum
247 integer(IK) :: iweisum
248 real(TKG), allocatable :: rweight(:)
249 integer(IK), allocatable :: iweight(:)
250 complex(TKG), allocatable :: sample(:,:), cov(:,:), mean(:)
251 integer(IK) :: ndim, nsam
252 call disp%show("ndim = 2; nsam = 10")
253 ndim = 2; nsam = 10
254 call disp%show("sample = reshape(cmplx(getUnifRand(1, 20, ndim * nsam), -getUnifRand(1, 20, ndim * nsam), TKG), shape = [ndim, nsam], order = [2, 1])")
255 sample = reshape(cmplx(getUnifRand(1, 20, ndim * nsam), -getUnifRand(1, 20, ndim * nsam), TKG), shape = [ndim, nsam], order = [2, 1])
256 call disp%show("sample")
257 call disp%show( sample )
258 call disp%show("call setResized(mean, ndim)")
259 call setResized(mean, ndim)
260 call disp%show("iweight = getUnifRand(1, 10, nsam) ! integer-valued weights.")
261 iweight = getUnifRand(1, 10, nsam) ! integer-valued weights.
262 call disp%show("iweight")
263 call disp%show( iweight )
264 call disp%show("call setMean(mean, sample, 2_IK, iweight, iweisum)")
265 call setMean(mean, sample, 2_IK, iweight, iweisum)
266 call disp%show("mean")
267 call disp%show( mean )
268 call disp%show("iweisum")
269 call disp%show( iweisum )
270 call disp%show("rweight = iweight ! or real-valued weights.")
271 rweight = iweight ! or real-valued weights.
272 call disp%show("iweight")
273 call disp%show( iweight )
274 call disp%show("call setMean(mean, sample, 2_IK, rweight, rweisum)")
275 call setMean(mean, sample, 2_IK, rweight, rweisum)
276 call disp%show("mean")
277 call disp%show( mean )
278 call disp%show("rweisum")
279 call disp%show( rweisum )
280
281 call disp%skip()
282 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
283 call disp%show("!Compute the covariance matrix with integer weights.")
284 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
285 call disp%skip()
286
287 call disp%show("cov = getCov(sample, 2_IK, iweight)")
288 cov = getCov(sample, 2_IK, iweight)
289 call disp%show("cov")
290 call disp%show( cov )
291 call disp%skip()
292 call disp%show("Compute the sample covariance along the first dimension.", deliml = SK_'''')
293 call disp%skip()
294 call disp%show("cov = getCov(transpose(sample), 1_IK, iweight)")
295 cov = getCov(transpose(sample), 1_IK, iweight)
296 call disp%show("cov")
297 call disp%show( cov )
298 call disp%skip()
299 call disp%show("Compute the full sample covariance for a pair of time series.", deliml = SK_'''')
300 call disp%skip()
301 call disp%show("cov = getCov(sample(1,:), sample(2,:), weight = iweight)")
302 cov = getCov(sample(1,:), sample(2,:), weight = iweight)
303 call disp%show("cov")
304 call disp%show( cov )
305 call disp%skip()
306
307 call disp%skip()
308 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
309 call disp%show("!Compute the covariance matrix with real weights.")
310 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
311 call disp%skip()
312
313 call disp%show("cov = getCov(sample, 2_IK, rweight)")
314 cov = getCov(sample, 2_IK, rweight)
315 call disp%show("cov")
316 call disp%show( cov )
317 call disp%skip()
318 call disp%show("Compute the sample covariance along the first dimension.", deliml = SK_'''')
319 call disp%skip()
320 call disp%show("cov = getCov(transpose(sample), 1_IK, rweight)")
321 cov = getCov(transpose(sample), 1_IK, rweight)
322 call disp%show("cov")
323 call disp%show( cov )
324 call disp%skip()
325 call disp%show("Compute the full sample covariance for a pair of time series.", deliml = SK_'''')
326 call disp%skip()
327 call disp%show("cov = getCov(sample(1,:), sample(2,:), weight = rweight)")
328 cov = getCov(sample(1,:), sample(2,:), weight = rweight)
329 call disp%show("cov")
330 call disp%show( cov )
331 call disp%skip()
332 end block
333
334end program example
Generate and return an array of the specified rank and shape of arbitrary intrinsic type and kind wit...
Allocate or resize (shrink or expand) an input allocatable scalar string or array of rank 1....
Generate count evenly spaced points over the interval [x1, x2] if x1 < x2, or [x2,...
Generate and return a random positive-definite (correlation or covariance) matrix using the Gram meth...
Definition: pm_distCov.F90:394
Generate and return a scalar or a contiguous array of rank 1 of length s1 of randomly uniformly distr...
Generate and return a generic or type/kind-specific IO format with the requested specifications that ...
Definition: pm_io.F90:18485
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
Copy a desired subset of the input source matrix of arbitrary shape (:) or (:,:) to the target subset...
Generate and return the (Pearson) correlation coefficient or matrix of a pair of (weighted) time seri...
Generate and return the (weighted) mean of an input sample of nsam observations with ndim = 1 or 2 at...
Return the (weighted) mean of a pair of time series or of an input sample of nsam observations with n...
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 convenient allocation and filling of array...
This module contains procedures and generic interfaces for resizing allocatable arrays of various typ...
This module contains procedures and generic interfaces for generating arrays with linear or logarithm...
This module contains classes and procedures for generating random matrices distributed on the space o...
Definition: pm_distCov.F90:72
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 procedures and generic interfaces relevant to copying (diagonal or upper/lower t...
This module contains classes and procedures for computing properties related to the correlation matri...
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!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4!Convert correlation matrix and standard deviation to covariance matrix.
5!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7
8
9ndim = getUnifRand(1, 7)
10ndim
11+2
12std = getUnifRand(1, 10, ndim)
13std
14+1.000000E+00, +2.000000E+00
15call setResized(cov, [ndim, ndim])
16cor = getCovRand(1., ndim)
17cor
18+1.000000E+00, -8.156881E-01
19-8.156881E-01, +1.000000E+00
20cov = getCov(cor, uppDia, std) ! convert upper correlation matrix to full covariance matrix.
21cov
22+1.000000E+00, -1.631376E+00
23-1.631376E+00, +4.000000E+00
24cov = getCov(cor, lowDia, std) ! convert upper correlation matrix to full covariance matrix.
25cov
26+1.000000E+00, -1.631376E+00
27-1.631376E+00, +4.000000E+00
28getCor(getCov(cor, lowDia, std), lowDia) ! reconstruct the original correlation matrix.
29+1.000000E+00, -8.156881E-01
30-8.156881E-01, +1.000000E+00
31
32
33ndim = getUnifRand(1, 7)
34ndim
35+1
36std = getUnifRand(1, 10, ndim)
37std
38+1.000000E+00
39call setResized(cov, [ndim, ndim])
40cor = getCovRand(1., ndim)
41cor
42+1.000000E+00
43cov = getCov(cor, uppDia, std) ! convert upper correlation matrix to full covariance matrix.
44cov
45+1.000000E+00
46cov = getCov(cor, lowDia, std) ! convert upper correlation matrix to full covariance matrix.
47cov
48+1.000000E+00
49getCor(getCov(cor, lowDia, std), lowDia) ! reconstruct the original correlation matrix.
50+1.000000E+00
51
52
53ndim = getUnifRand(1, 7)
54ndim
55+3
56std = getUnifRand(1, 10, ndim)
57std
58+9.000000E+00, +3.000000E+00, +1.000000E+01
59call setResized(cov, [ndim, ndim])
60cor = getCovRand(1., ndim)
61cor
62+1.000000E+00, +5.890449E-01, -4.425062E-01
63+5.890449E-01, +1.000000E+00, -3.070235E-01
64-4.425062E-01, -3.070235E-01, +1.000000E+00
65cov = getCov(cor, uppDia, std) ! convert upper correlation matrix to full covariance matrix.
66cov
67+8.100000E+01, +1.590421E+01, -3.982556E+01
68+1.590421E+01, +9.000000E+00, -9.210706E+00
69-3.982556E+01, -9.210706E+00, +1.000000E+02
70cov = getCov(cor, lowDia, std) ! convert upper correlation matrix to full covariance matrix.
71cov
72+8.100000E+01, +1.590421E+01, -3.982556E+01
73+1.590421E+01, +9.000000E+00, -9.210706E+00
74-3.982556E+01, -9.210706E+00, +1.000000E+02
75getCor(getCov(cor, lowDia, std), lowDia) ! reconstruct the original correlation matrix.
76+1.000000E+00, +5.890449E-01, -4.425062E-01
77+5.890449E-01, +1.000000E+00, -3.070236E-01
78-4.425062E-01, -3.070236E-01, +1.000000E+00
79
80
81ndim = getUnifRand(1, 7)
82ndim
83+4
84std = getUnifRand(1, 10, ndim)
85std
86+7.000000E+00, +5.000000E+00, +6.000000E+00, +3.000000E+00
87call setResized(cov, [ndim, ndim])
88cor = getCovRand(1., ndim)
89cor
90+1.000000E+00, +5.257127E-01, +5.521179E-01, +5.841199E-01
91+5.257127E-01, +1.000000E+00, +9.974027E-01, +9.890235E-01
92+5.521179E-01, +9.974027E-01, +1.000000E+00, +9.968132E-01
93+5.841199E-01, +9.890235E-01, +9.968132E-01, +1.000000E+00
94cov = getCov(cor, uppDia, std) ! convert upper correlation matrix to full covariance matrix.
95cov
96+4.900000E+01, +1.839995E+01, +2.318895E+01, +1.226652E+01
97+1.839995E+01, +2.500000E+01, +2.992208E+01, +1.483535E+01
98+2.318895E+01, +2.992208E+01, +3.600000E+01, +1.794264E+01
99+1.226652E+01, +1.483535E+01, +1.794264E+01, +9.000000E+00
100cov = getCov(cor, lowDia, std) ! convert upper correlation matrix to full covariance matrix.
101cov
102+4.900000E+01, +1.839995E+01, +2.318895E+01, +1.226652E+01
103+1.839995E+01, +2.500000E+01, +2.992208E+01, +1.483535E+01
104+2.318895E+01, +2.992208E+01, +3.600000E+01, +1.794264E+01
105+1.226652E+01, +1.483535E+01, +1.794264E+01, +9.000000E+00
106getCor(getCov(cor, lowDia, std), lowDia) ! reconstruct the original correlation matrix.
107+1.000000E+00, +5.257128E-01, +5.521179E-01, +5.841199E-01
108+5.257128E-01, +1.000000E+00, +9.974027E-01, +9.890236E-01
109+5.521179E-01, +9.974027E-01, +1.000000E+00, +9.968133E-01
110+5.841199E-01, +9.890236E-01, +9.968133E-01, +1.000000E+00
111
112
113ndim = getUnifRand(1, 7)
114ndim
115+3
116std = getUnifRand(1, 10, ndim)
117std
118+2.000000E+00, +4.000000E+00, +3.000000E+00
119call setResized(cov, [ndim, ndim])
120cor = getCovRand(1., ndim)
121cor
122+1.000000E+00, -6.935921E-01, +6.501193E-01
123-6.935921E-01, +1.000000E+00, +9.479794E-02
124+6.501193E-01, +9.479794E-02, +1.000000E+00
125cov = getCov(cor, uppDia, std) ! convert upper correlation matrix to full covariance matrix.
126cov
127+4.000000E+00, -5.548737E+00, +3.900716E+00
128-5.548737E+00, +1.600000E+01, +1.137575E+00
129+3.900716E+00, +1.137575E+00, +9.000000E+00
130cov = getCov(cor, lowDia, std) ! convert upper correlation matrix to full covariance matrix.
131cov
132+4.000000E+00, -5.548737E+00, +3.900716E+00
133-5.548737E+00, +1.600000E+01, +1.137575E+00
134+3.900716E+00, +1.137575E+00, +9.000000E+00
135getCor(getCov(cor, lowDia, std), lowDia) ! reconstruct the original correlation matrix.
136+1.000000E+00, -6.935921E-01, +6.501193E-01
137-6.935921E-01, +1.000000E+00, +9.479794E-02
138+6.501193E-01, +9.479794E-02, +1.000000E+00
139
140
141ndim = getUnifRand(1, 7)
142ndim
143+3
144std = getUnifRand(1, 10, ndim)
145std
146+6.000000E+00, +4.000000E+00, +3.000000E+00
147call setResized(cov, [ndim, ndim])
148cor = getCovRand(1., ndim)
149cor
150+1.000000E+00, -8.367915E-01, +2.911324E-01
151-8.367915E-01, +1.000000E+00, +5.950055E-02
152+2.911324E-01, +5.950055E-02, +1.000000E+00
153cov = getCov(cor, uppDia, std) ! convert upper correlation matrix to full covariance matrix.
154cov
155+3.600000E+01, -2.008299E+01, +5.240384E+00
156-2.008299E+01, +1.600000E+01, +7.140065E-01
157+5.240384E+00, +7.140065E-01, +9.000000E+00
158cov = getCov(cor, lowDia, std) ! convert upper correlation matrix to full covariance matrix.
159cov
160+3.600000E+01, -2.008299E+01, +5.240384E+00
161-2.008299E+01, +1.600000E+01, +7.140065E-01
162+5.240384E+00, +7.140065E-01, +9.000000E+00
163getCor(getCov(cor, lowDia, std), lowDia) ! reconstruct the original correlation matrix.
164+1.000000E+00, -8.367915E-01, +2.911325E-01
165-8.367915E-01, +1.000000E+00, +5.950055E-02
166+2.911325E-01, +5.950055E-02, +1.000000E+00
167
168
169ndim = getUnifRand(1, 7)
170ndim
171+2
172std = getUnifRand(1, 10, ndim)
173std
174+8.000000E+00, +4.000000E+00
175call setResized(cov, [ndim, ndim])
176cor = getCovRand(1., ndim)
177cor
178+1.000000E+00, +9.357148E-01
179+9.357148E-01, +1.000000E+00
180cov = getCov(cor, uppDia, std) ! convert upper correlation matrix to full covariance matrix.
181cov
182+6.400000E+01, +2.994287E+01
183+2.994287E+01, +1.600000E+01
184cov = getCov(cor, lowDia, std) ! convert upper correlation matrix to full covariance matrix.
185cov
186+6.400000E+01, +2.994287E+01
187+2.994287E+01, +1.600000E+01
188getCor(getCov(cor, lowDia, std), lowDia) ! reconstruct the original correlation matrix.
189+1.000000E+00, +9.357148E-01
190+9.357148E-01, +1.000000E+00
191
192
193ndim = getUnifRand(1, 7)
194ndim
195+1
196std = getUnifRand(1, 10, ndim)
197std
198+2.000000E+00
199call setResized(cov, [ndim, ndim])
200cor = getCovRand(1., ndim)
201cor
202+1.000000E+00
203cov = getCov(cor, uppDia, std) ! convert upper correlation matrix to full covariance matrix.
204cov
205+4.000000E+00
206cov = getCov(cor, lowDia, std) ! convert upper correlation matrix to full covariance matrix.
207cov
208+4.000000E+00
209getCor(getCov(cor, lowDia, std), lowDia) ! reconstruct the original correlation matrix.
210+1.000000E+00
211
212
213ndim = getUnifRand(1, 7)
214ndim
215+5
216std = getUnifRand(1, 10, ndim)
217std
218+2.000000E+00, +8.000000E+00, +1.000000E+00, +7.000000E+00, +8.000000E+00
219call setResized(cov, [ndim, ndim])
220cor = getCovRand(1., ndim)
221cor
222+1.000000E+00, +2.335250E-01, +2.207616E-01, -1.086629E-01, +1.843638E-01
223+2.335250E-01, +1.000000E+00, +9.317105E-01, +4.592218E-02, -1.676614E-01
224+2.207616E-01, +9.317105E-01, +1.000000E+00, -1.802482E-01, +5.627710E-02
225-1.086629E-01, +4.592218E-02, -1.802482E-01, +1.000000E+00, -5.366302E-01
226+1.843638E-01, -1.676614E-01, +5.627710E-02, -5.366302E-01, +1.000000E+00
227cov = getCov(cor, uppDia, std) ! convert upper correlation matrix to full covariance matrix.
228cov
229+4.000000E+00, +3.736401E+00, +4.415232E-01, -1.521281E+00, +2.949821E+00
230+3.736401E+00, +6.400000E+01, +7.453684E+00, +2.571642E+00, -1.073033E+01
231+4.415232E-01, +7.453684E+00, +1.000000E+00, -1.261738E+00, +4.502168E-01
232-1.521281E+00, +2.571642E+00, -1.261738E+00, +4.900000E+01, -3.005129E+01
233+2.949821E+00, -1.073033E+01, +4.502168E-01, -3.005129E+01, +6.400000E+01
234cov = getCov(cor, lowDia, std) ! convert upper correlation matrix to full covariance matrix.
235cov
236+4.000000E+00, +3.736401E+00, +4.415232E-01, -1.521281E+00, +2.949821E+00
237+3.736401E+00, +6.400000E+01, +7.453684E+00, +2.571642E+00, -1.073033E+01
238+4.415232E-01, +7.453684E+00, +1.000000E+00, -1.261738E+00, +4.502168E-01
239-1.521281E+00, +2.571642E+00, -1.261738E+00, +4.900000E+01, -3.005129E+01
240+2.949821E+00, -1.073033E+01, +4.502168E-01, -3.005129E+01, +6.400000E+01
241getCor(getCov(cor, lowDia, std), lowDia) ! reconstruct the original correlation matrix.
242+1.000000E+00, +2.335250E-01, +2.207616E-01, -1.086629E-01, +1.843638E-01
243+2.335250E-01, +1.000000E+00, +9.317105E-01, +4.592218E-02, -1.676614E-01
244+2.207616E-01, +9.317105E-01, +1.000000E+00, -1.802482E-01, +5.627710E-02
245-1.086629E-01, +4.592218E-02, -1.802482E-01, +1.000000E+00, -5.366302E-01
246+1.843638E-01, -1.676614E-01, +5.627710E-02, -5.366302E-01, +1.000000E+00
247
248
249ndim = getUnifRand(1, 7)
250ndim
251+6
252std = getUnifRand(1, 10, ndim)
253std
254+5.000000E+00, +6.000000E+00, +1.000000E+01, +7.000000E+00, +6.000000E+00, +6.000000E+00
255call setResized(cov, [ndim, ndim])
256cor = getCovRand(1., ndim)
257cor
258+1.000000E+00, -8.360406E-01, +7.955736E-01, +3.998902E-01, -7.772763E-03, -3.233274E-01
259-8.360406E-01, +1.000000E+00, -3.329079E-01, -6.350493E-01, +9.336077E-02, +1.734658E-01
260+7.955736E-01, -3.329079E-01, +1.000000E+00, -5.028822E-03, +1.046380E-01, -3.565818E-01
261+3.998902E-01, -6.350493E-01, -5.028822E-03, +1.000000E+00, -3.005168E-02, +5.875157E-01
262-7.772763E-03, +9.336077E-02, +1.046380E-01, -3.005168E-02, +1.000000E+00, -2.089017E-01
263-3.233274E-01, +1.734658E-01, -3.565818E-01, +5.875157E-01, -2.089017E-01, +1.000000E+00
264cov = getCov(cor, uppDia, std) ! convert upper correlation matrix to full covariance matrix.
265cov
266+2.500000E+01, -2.508122E+01, +3.977868E+01, +1.399616E+01, -2.331829E-01, -9.699822E+00
267-2.508122E+01, +3.600000E+01, -1.997448E+01, -2.667207E+01, +3.360988E+00, +6.244770E+00
268+3.977868E+01, -1.997448E+01, +1.000000E+02, -3.520176E-01, +6.278280E+00, -2.139491E+01
269+1.399616E+01, -2.667207E+01, -3.520176E-01, +4.900000E+01, -1.262171E+00, +2.467566E+01
270-2.331829E-01, +3.360988E+00, +6.278280E+00, -1.262171E+00, +3.600000E+01, -7.520463E+00
271-9.699822E+00, +6.244770E+00, -2.139491E+01, +2.467566E+01, -7.520463E+00, +3.600000E+01
272cov = getCov(cor, lowDia, std) ! convert upper correlation matrix to full covariance matrix.
273cov
274+2.500000E+01, -2.508122E+01, +3.977868E+01, +1.399616E+01, -2.331829E-01, -9.699822E+00
275-2.508122E+01, +3.600000E+01, -1.997448E+01, -2.667207E+01, +3.360988E+00, +6.244770E+00
276+3.977868E+01, -1.997448E+01, +1.000000E+02, -3.520176E-01, +6.278280E+00, -2.139491E+01
277+1.399616E+01, -2.667207E+01, -3.520176E-01, +4.900000E+01, -1.262171E+00, +2.467566E+01
278-2.331829E-01, +3.360988E+00, +6.278280E+00, -1.262171E+00, +3.600000E+01, -7.520463E+00
279-9.699822E+00, +6.244770E+00, -2.139491E+01, +2.467566E+01, -7.520463E+00, +3.600000E+01
280getCor(getCov(cor, lowDia, std), lowDia) ! reconstruct the original correlation matrix.
281+1.000000E+00, -8.360406E-01, +7.955737E-01, +3.998902E-01, -7.772763E-03, -3.233274E-01
282-8.360406E-01, +1.000000E+00, -3.329079E-01, -6.350494E-01, +9.336078E-02, +1.734658E-01
283+7.955737E-01, -3.329079E-01, +1.000000E+00, -5.028823E-03, +1.046380E-01, -3.565818E-01
284+3.998902E-01, -6.350494E-01, -5.028823E-03, +1.000000E+00, -3.005168E-02, +5.875158E-01
285-7.772763E-03, +9.336078E-02, +1.046380E-01, -3.005168E-02, +1.000000E+00, -2.089018E-01
286-3.233274E-01, +1.734658E-01, -3.565818E-01, +5.875158E-01, -2.089018E-01, +1.000000E+00
287
288
289!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
290!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
291!Compute the covariance matrix of a 2-D sample.
292!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
293!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
294
295ndim = 2; nsam = 10
296sample = reshape(getUnifRand(1, 20, ndim * nsam), shape = [ndim, nsam], order = [2, 1])
297sample
298+3.00000000, +9.00000000, +6.00000000, +9.00000000, +7.00000000, +11.0000000, +11.0000000, +14.0000000, +6.00000000, +19.0000000
299+3.00000000, +2.00000000, +1.00000000, +7.00000000, +3.00000000, +3.00000000, +12.0000000, +17.0000000, +17.0000000, +9.00000000
300
301'Compute the sample covariance along the second dimension.'
302
303cov = getCov(sample, dim = 2_IK)
304cov
305+18.8500004, +9.00000000
306+9.00000000, +33.6399994
307
308'Compute the sample covariance along the first dimension.'
309
310cov = getCov(transpose(sample), dim = 1_IK)
311cov
312+18.8500004, +9.00000000
313+9.00000000, +33.6399994
314
315'Compute the full sample covariance for a pair of time series.'
316
317cov = getCov(sample(1,:), sample(2,:))
318cov
319+18.8500004, +9.00000000
320+9.00000000, +33.6399994
321
322ndim = 2; nsam = 10
323sample = reshape(cmplx(getUnifRand(1, 20, ndim * nsam), -getUnifRand(1, 20, ndim * nsam), TKG), shape = [ndim, nsam], order = [2, 1])
324sample
325(+11.0000000, -14.0000000), (+6.00000000, -17.0000000), (+13.0000000, -11.0000000), (+20.0000000, -3.00000000), (+9.00000000, -6.00000000), (+17.0000000, -20.0000000), (+17.0000000, -17.0000000), (+1.00000000, -12.0000000), (+20.0000000, -8.00000000), (+1.00000000, -17.0000000)
326(+18.0000000, -5.00000000), (+11.0000000, -14.0000000), (+18.0000000, -19.0000000), (+6.00000000, -7.00000000), (+10.0000000, -4.00000000), (+16.0000000, -4.00000000), (+16.0000000, -20.0000000), (+15.0000000, -7.00000000), (+15.0000000, -9.00000000), (+16.0000000, -15.0000000)
327
328'Compute the sample covariance along the second dimension.'
329
330cov = getCov(sample, dim = 2_IK)
331cov
332(+73.9000015, +0.00000000), (+5.45000029, -14.0500002)
333(+5.45000029, +14.0500002), (+47.1300011, +0.00000000)
334
335'Compute the sample covariance along the first dimension.'
336
337cov = getCov(transpose(sample), dim = 1_IK)
338cov
339(+73.9000015, +0.00000000), (+5.45000029, -14.0500002)
340(+5.45000029, +14.0500002), (+47.1300011, +0.00000000)
341
342'Compute the full sample covariance for a pair of time series.'
343
344cov = getCov(sample(1,:), sample(2,:))
345cov
346(+73.9000015, +0.00000000), (+5.45000029, -14.0500002)
347(+5.45000029, +14.0500002), (+47.1300011, +0.00000000)
348
349
350!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
351!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
352!Compute the biased covariance matrix of a weighted 2-D sample.
353!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
354!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
355
356ndim = 2; nsam = 10
357sample = reshape(getUnifRand(1, 20, ndim * nsam), shape = [ndim, nsam], order = [2, 1])
358sample
359+10.0000000, +4.00000000, +14.0000000, +15.0000000, +15.0000000, +8.00000000, +18.0000000, +4.00000000, +18.0000000, +7.00000000
360+15.0000000, +19.0000000, +2.00000000, +3.00000000, +19.0000000, +7.00000000, +9.00000000, +12.0000000, +7.00000000, +13.0000000
361call setResized(mean, ndim)
362iweight = getUnifRand(1, 10, nsam) ! integer-valued weights.
363iweight
364+4, +9, +2, +5, +5, +7, +7, +7, +1, +5
365call setMean(mean, sample, 2_IK, iweight, iweisum)
366mean
367+9.94230843, +11.7884617
368iweisum
369+52
370rweight = iweight ! or real-valued weights.
371iweight
372+4, +9, +2, +5, +5, +7, +7, +7, +1, +5
373call setMean(mean, sample, 2_IK, rweight, rweisum)
374mean
375+9.94230843, +11.7884617
376rweisum
377+52.0000000
378
379!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
380!Compute the covariance matrix with integer weights.
381!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
382
383cov = getCov(sample, 2_IK, iweight)
384cov
385+27.7466717, -12.7237434
386-12.7237434, +30.6283302
387
388'Compute the sample covariance along the first dimension.'
389
390cov = getCov(transpose(sample), 1_IK, iweight)
391cov
392+27.7466717, -12.7237434
393-12.7237434, +30.6283302
394
395'Compute the full sample covariance for a pair of time series.'
396
397cov = getCov(sample(1,:), sample(2,:), weight = iweight)
398cov
399+27.7466717, -12.7237434
400-12.7237434, +30.6283302
401
402
403!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
404!Compute the covariance matrix with real weights.
405!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
406
407cov = getCov(sample, 2_IK, rweight)
408cov
409+27.7466717, -12.7237434
410-12.7237434, +30.6283302
411
412'Compute the sample covariance along the first dimension.'
413
414cov = getCov(transpose(sample), 1_IK, rweight)
415cov
416+27.7466717, -12.7237434
417-12.7237434, +30.6283302
418
419'Compute the full sample covariance for a pair of time series.'
420
421cov = getCov(sample(1,:), sample(2,:), weight = rweight)
422cov
423+27.7466717, -12.7237434
424-12.7237434, +30.6283302
425
426ndim = 2; nsam = 10
427sample = reshape(cmplx(getUnifRand(1, 20, ndim * nsam), -getUnifRand(1, 20, ndim * nsam), TKG), shape = [ndim, nsam], order = [2, 1])
428sample
429(+3.00000000, -17.0000000), (+8.00000000, -11.0000000), (+8.00000000, -1.00000000), (+13.0000000, -10.0000000), (+20.0000000, -16.0000000), (+7.00000000, -14.0000000), (+16.0000000, -9.00000000), (+19.0000000, -15.0000000), (+1.00000000, -1.00000000), (+2.00000000, -1.00000000)
430(+7.00000000, -6.00000000), (+5.00000000, -1.00000000), (+7.00000000, -12.0000000), (+4.00000000, -15.0000000), (+16.0000000, -20.0000000), (+8.00000000, -4.00000000), (+10.0000000, -13.0000000), (+17.0000000, -17.0000000), (+13.0000000, -3.00000000), (+6.00000000, -19.0000000)
431call setResized(mean, ndim)
432iweight = getUnifRand(1, 10, nsam) ! integer-valued weights.
433iweight
434+8, +10, +9, +6, +7, +6, +9, +1, +8, +6
435call setMean(mean, sample, 2_IK, iweight, iweisum)
436mean
437(+8.84285736, -8.87142849), (+8.57142830, -9.88571453)
438iweisum
439+70
440rweight = iweight ! or real-valued weights.
441iweight
442+8, +10, +9, +6, +7, +6, +9, +1, +8, +6
443call setMean(mean, sample, 2_IK, rweight, rweisum)
444mean
445(+8.84285736, -8.87142849), (+8.57142830, -9.88571453)
446rweisum
447+70.0000000
448
449!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
450!Compute the covariance matrix with integer weights.
451!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
452
453cov = getCov(sample, 2_IK, iweight)
454cov
455(+73.9587708, +0.00000000), (+5.86081553, +20.0371437)
456(+5.86081553, -20.0371437), (+57.3746948, +0.00000000)
457
458'Compute the sample covariance along the first dimension.'
459
460cov = getCov(transpose(sample), 1_IK, iweight)
461cov
462(+73.9587784, +0.00000000), (+5.86081553, +20.0371437)
463(+5.86081553, -20.0371437), (+57.3746948, +0.00000000)
464
465'Compute the full sample covariance for a pair of time series.'
466
467cov = getCov(sample(1,:), sample(2,:), weight = iweight)
468cov
469(+73.9587708, +0.00000000), (+5.86081553, +20.0371437)
470(+5.86081553, -20.0371437), (+57.3746948, +0.00000000)
471
472
473!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
474!Compute the covariance matrix with real weights.
475!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
476
477cov = getCov(sample, 2_IK, rweight)
478cov
479(+73.9587708, +0.00000000), (+5.86081553, +20.0371437)
480(+5.86081553, -20.0371437), (+57.3746948, +0.00000000)
481
482'Compute the sample covariance along the first dimension.'
483
484cov = getCov(transpose(sample), 1_IK, rweight)
485cov
486(+73.9587784, +0.00000000), (+5.86081553, +20.0371437)
487(+5.86081553, -20.0371437), (+57.3746948, +0.00000000)
488
489'Compute the full sample covariance for a pair of time series.'
490
491cov = getCov(sample(1,:), sample(2,:), weight = rweight)
492cov
493(+73.9587708, +0.00000000), (+5.86081553, +20.0371437)
494(+5.86081553, -20.0371437), (+57.3746948, +0.00000000)
495
496
Test:
test_pm_sampleCov
Bug:

Status: Unresolved
Source: Intel Classic Fortran Compiler ifort version 2021.8
Description: Intel ifort (possibly only with heap memory allocation) yields a segfault error in OpenMP parallel code at pm_sampleCov@routines.inc.F90:238.
The root cause of the segmentation fault was determined to be due to the use of do concurrent construct in the implementation.

Remedy (as of ParaMonte Library version 2.0.0): For now, all do concurrent statements are converted back to normal do loops.


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 344 of file pm_sampleCov.F90.


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