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+5
12std = getUnifRand(1, 10, ndim)
13std
14+6.000000E+00, +9.000000E+00, +6.000000E+00, +7.000000E+00, +6.000000E+00
15call setResized(cov, [ndim, ndim])
16cor = getCovRand(1., ndim)
17cor
18+1.000000E+00, +9.891092E-01, +3.671026E-01, -3.147610E-01, +5.508389E-01
19+9.891092E-01, +1.000000E+00, +2.625513E-01, -1.737380E-01, +6.411951E-01
20+3.671026E-01, +2.625513E-01, +1.000000E+00, -6.506268E-01, -1.362509E-01
21-3.147610E-01, -1.737380E-01, -6.506268E-01, +1.000000E+00, +4.639086E-01
22+5.508389E-01, +6.411951E-01, -1.362509E-01, +4.639086E-01, +1.000000E+00
23cov = getCov(cor, uppDia, std) ! convert upper correlation matrix to full covariance matrix.
24cov
25+3.600000E+01, +5.341190E+01, +1.321569E+01, -1.321996E+01, +1.983020E+01
26+5.341190E+01, +8.100000E+01, +1.417777E+01, -1.094549E+01, +3.462453E+01
27+1.321569E+01, +1.417777E+01, +3.600000E+01, -2.732633E+01, -4.905034E+00
28-1.321996E+01, -1.094549E+01, -2.732633E+01, +4.900000E+01, +1.948416E+01
29+1.983020E+01, +3.462453E+01, -4.905034E+00, +1.948416E+01, +3.600000E+01
30cov = getCov(cor, lowDia, std) ! convert upper correlation matrix to full covariance matrix.
31cov
32+3.600000E+01, +5.341190E+01, +1.321569E+01, -1.321996E+01, +1.983020E+01
33+5.341190E+01, +8.100000E+01, +1.417777E+01, -1.094549E+01, +3.462453E+01
34+1.321569E+01, +1.417777E+01, +3.600000E+01, -2.732633E+01, -4.905034E+00
35-1.321996E+01, -1.094549E+01, -2.732633E+01, +4.900000E+01, +1.948416E+01
36+1.983020E+01, +3.462453E+01, -4.905034E+00, +1.948416E+01, +3.600000E+01
37getCor(getCov(cor, lowDia, std), lowDia) ! reconstruct the original correlation matrix.
38+1.000000E+00, +9.891092E-01, +3.671027E-01, -3.147610E-01, +5.508390E-01
39+9.891092E-01, +1.000000E+00, +2.625513E-01, -1.737380E-01, +6.411951E-01
40+3.671027E-01, +2.625513E-01, +1.000000E+00, -6.506269E-01, -1.362510E-01
41-3.147610E-01, -1.737380E-01, -6.506269E-01, +1.000000E+00, +4.639086E-01
42+5.508390E-01, +6.411951E-01, -1.362510E-01, +4.639086E-01, +1.000000E+00
43
44
45ndim = getUnifRand(1, 7)
46ndim
47+6
48std = getUnifRand(1, 10, ndim)
49std
50+3.000000E+00, +3.000000E+00, +9.000000E+00, +9.000000E+00, +2.000000E+00, +1.000000E+01
51call setResized(cov, [ndim, ndim])
52cor = getCovRand(1., ndim)
53cor
54+1.000000E+00, -5.903295E-01, -6.757442E-01, +2.854192E-01, -5.913720E-01, -2.565042E-01
55-5.903295E-01, +1.000000E+00, +2.447819E-01, +1.457454E-01, +7.583390E-01, +1.903602E-02
56-6.757442E-01, +2.447819E-01, +1.000000E+00, -4.168186E-01, +5.063804E-01, -1.243629E-01
57+2.854192E-01, +1.457454E-01, -4.168186E-01, +1.000000E+00, -4.532497E-01, +5.046430E-01
58-5.913720E-01, +7.583390E-01, +5.063804E-01, -4.532497E-01, +1.000000E+00, -2.784536E-01
59-2.565042E-01, +1.903602E-02, -1.243629E-01, +5.046430E-01, -2.784536E-01, +1.000000E+00
60cov = getCov(cor, uppDia, std) ! convert upper correlation matrix to full covariance matrix.
61cov
62+9.000000E+00, -5.312966E+00, -1.824509E+01, +7.706317E+00, -3.548232E+00, -7.695126E+00
63-5.312966E+00, +9.000000E+00, +6.609110E+00, +3.935125E+00, +4.550034E+00, +5.710807E-01
64-1.824509E+01, +6.609110E+00, +8.100000E+01, -3.376231E+01, +9.114848E+00, -1.119266E+01
65+7.706317E+00, +3.935125E+00, -3.376231E+01, +8.100000E+01, -8.158495E+00, +4.541787E+01
66-3.548232E+00, +4.550034E+00, +9.114848E+00, -8.158495E+00, +4.000000E+00, -5.569072E+00
67-7.695126E+00, +5.710807E-01, -1.119266E+01, +4.541787E+01, -5.569072E+00, +1.000000E+02
68cov = getCov(cor, lowDia, std) ! convert upper correlation matrix to full covariance matrix.
69cov
70+9.000000E+00, -5.312966E+00, -1.824509E+01, +7.706317E+00, -3.548232E+00, -7.695126E+00
71-5.312966E+00, +9.000000E+00, +6.609110E+00, +3.935125E+00, +4.550034E+00, +5.710807E-01
72-1.824509E+01, +6.609110E+00, +8.100000E+01, -3.376231E+01, +9.114848E+00, -1.119266E+01
73+7.706317E+00, +3.935125E+00, -3.376231E+01, +8.100000E+01, -8.158495E+00, +4.541787E+01
74-3.548232E+00, +4.550034E+00, +9.114848E+00, -8.158495E+00, +4.000000E+00, -5.569072E+00
75-7.695126E+00, +5.710807E-01, -1.119266E+01, +4.541787E+01, -5.569072E+00, +1.000000E+02
76getCor(getCov(cor, lowDia, std), lowDia) ! reconstruct the original correlation matrix.
77+1.000000E+00, -5.903296E-01, -6.757442E-01, +2.854192E-01, -5.913720E-01, -2.565042E-01
78-5.903296E-01, +1.000000E+00, +2.447819E-01, +1.457454E-01, +7.583390E-01, +1.903603E-02
79-6.757442E-01, +2.447819E-01, +1.000000E+00, -4.168186E-01, +5.063804E-01, -1.243629E-01
80+2.854192E-01, +1.457454E-01, -4.168186E-01, +1.000000E+00, -4.532497E-01, +5.046430E-01
81-5.913720E-01, +7.583390E-01, +5.063804E-01, -4.532497E-01, +1.000000E+00, -2.784536E-01
82-2.565042E-01, +1.903603E-02, -1.243629E-01, +5.046430E-01, -2.784536E-01, +1.000000E+00
83
84
85ndim = getUnifRand(1, 7)
86ndim
87+6
88std = getUnifRand(1, 10, ndim)
89std
90+7.000000E+00, +4.000000E+00, +2.000000E+00, +5.000000E+00, +5.000000E+00, +1.000000E+00
91call setResized(cov, [ndim, ndim])
92cor = getCovRand(1., ndim)
93cor
94+1.000000E+00, -7.550418E-01, +6.540549E-01, -4.530548E-01, +4.864781E-01, +4.320849E-01
95-7.550418E-01, +1.000000E+00, -3.967842E-01, +1.601340E-01, -7.208964E-01, -4.087623E-01
96+6.540549E-01, -3.967842E-01, +1.000000E+00, -4.134919E-01, +3.657568E-01, +4.992943E-01
97-4.530548E-01, +1.601340E-01, -4.134919E-01, +1.000000E+00, -4.011500E-01, -6.136380E-02
98+4.864781E-01, -7.208964E-01, +3.657568E-01, -4.011500E-01, +1.000000E+00, -6.830871E-02
99+4.320849E-01, -4.087623E-01, +4.992943E-01, -6.136380E-02, -6.830871E-02, +1.000000E+00
100cov = getCov(cor, uppDia, std) ! convert upper correlation matrix to full covariance matrix.
101cov
102+4.900000E+01, -2.114117E+01, +9.156769E+00, -1.585692E+01, +1.702674E+01, +3.024594E+00
103-2.114117E+01, +1.600000E+01, -3.174273E+00, +3.202681E+00, -1.441793E+01, -1.635049E+00
104+9.156769E+00, -3.174273E+00, +4.000000E+00, -4.134919E+00, +3.657568E+00, +9.985886E-01
105-1.585692E+01, +3.202681E+00, -4.134919E+00, +2.500000E+01, -1.002875E+01, -3.068190E-01
106+1.702674E+01, -1.441793E+01, +3.657568E+00, -1.002875E+01, +2.500000E+01, -3.415436E-01
107+3.024594E+00, -1.635049E+00, +9.985886E-01, -3.068190E-01, -3.415436E-01, +1.000000E+00
108cov = getCov(cor, lowDia, std) ! convert upper correlation matrix to full covariance matrix.
109cov
110+4.900000E+01, -2.114117E+01, +9.156769E+00, -1.585692E+01, +1.702674E+01, +3.024594E+00
111-2.114117E+01, +1.600000E+01, -3.174273E+00, +3.202681E+00, -1.441793E+01, -1.635049E+00
112+9.156769E+00, -3.174273E+00, +4.000000E+00, -4.134919E+00, +3.657568E+00, +9.985886E-01
113-1.585692E+01, +3.202681E+00, -4.134919E+00, +2.500000E+01, -1.002875E+01, -3.068190E-01
114+1.702674E+01, -1.441793E+01, +3.657568E+00, -1.002875E+01, +2.500000E+01, -3.415436E-01
115+3.024594E+00, -1.635049E+00, +9.985886E-01, -3.068190E-01, -3.415436E-01, +1.000000E+00
116getCor(getCov(cor, lowDia, std), lowDia) ! reconstruct the original correlation matrix.
117+1.000000E+00, -7.550418E-01, +6.540549E-01, -4.530548E-01, +4.864782E-01, +4.320849E-01
118-7.550418E-01, +1.000000E+00, -3.967842E-01, +1.601340E-01, -7.208964E-01, -4.087623E-01
119+6.540549E-01, -3.967842E-01, +1.000000E+00, -4.134919E-01, +3.657568E-01, +4.992943E-01
120-4.530548E-01, +1.601340E-01, -4.134919E-01, +1.000000E+00, -4.011500E-01, -6.136381E-02
121+4.864782E-01, -7.208964E-01, +3.657568E-01, -4.011500E-01, +1.000000E+00, -6.830871E-02
122+4.320849E-01, -4.087623E-01, +4.992943E-01, -6.136381E-02, -6.830871E-02, +1.000000E+00
123
124
125ndim = getUnifRand(1, 7)
126ndim
127+5
128std = getUnifRand(1, 10, ndim)
129std
130+1.000000E+00, +3.000000E+00, +1.000000E+00, +9.000000E+00, +6.000000E+00
131call setResized(cov, [ndim, ndim])
132cor = getCovRand(1., ndim)
133cor
134+1.000000E+00, -9.815785E-01, +9.779150E-01, -1.241162E-01, +8.468044E-01
135-9.815785E-01, +1.000000E+00, -9.700820E-01, +2.326918E-01, -8.871166E-01
136+9.779150E-01, -9.700820E-01, +1.000000E+00, -3.148893E-01, +9.276935E-01
137-1.241162E-01, +2.326918E-01, -3.148893E-01, +1.000000E+00, -6.096638E-01
138+8.468044E-01, -8.871166E-01, +9.276935E-01, -6.096638E-01, +1.000000E+00
139cov = getCov(cor, uppDia, std) ! convert upper correlation matrix to full covariance matrix.
140cov
141+1.000000E+00, -2.944736E+00, +9.779150E-01, -1.117046E+00, +5.080826E+00
142-2.944736E+00, +9.000000E+00, -2.910246E+00, +6.282679E+00, -1.596810E+01
143+9.779150E-01, -2.910246E+00, +1.000000E+00, -2.834003E+00, +5.566161E+00
144-1.117046E+00, +6.282679E+00, -2.834003E+00, +8.100000E+01, -3.292185E+01
145+5.080826E+00, -1.596810E+01, +5.566161E+00, -3.292185E+01, +3.600000E+01
146cov = getCov(cor, lowDia, std) ! convert upper correlation matrix to full covariance matrix.
147cov
148+1.000000E+00, -2.944736E+00, +9.779150E-01, -1.117046E+00, +5.080826E+00
149-2.944736E+00, +9.000000E+00, -2.910246E+00, +6.282679E+00, -1.596810E+01
150+9.779150E-01, -2.910246E+00, +1.000000E+00, -2.834003E+00, +5.566161E+00
151-1.117046E+00, +6.282679E+00, -2.834003E+00, +8.100000E+01, -3.292185E+01
152+5.080826E+00, -1.596810E+01, +5.566161E+00, -3.292185E+01, +3.600000E+01
153getCor(getCov(cor, lowDia, std), lowDia) ! reconstruct the original correlation matrix.
154+1.000000E+00, -9.815785E-01, +9.779150E-01, -1.241162E-01, +8.468044E-01
155-9.815785E-01, +1.000000E+00, -9.700820E-01, +2.326918E-01, -8.871166E-01
156+9.779150E-01, -9.700820E-01, +1.000000E+00, -3.148893E-01, +9.276935E-01
157-1.241162E-01, +2.326918E-01, -3.148893E-01, +1.000000E+00, -6.096638E-01
158+8.468044E-01, -8.871166E-01, +9.276935E-01, -6.096638E-01, +1.000000E+00
159
160
161ndim = getUnifRand(1, 7)
162ndim
163+4
164std = getUnifRand(1, 10, ndim)
165std
166+5.000000E+00, +7.000000E+00, +7.000000E+00, +8.000000E+00
167call setResized(cov, [ndim, ndim])
168cor = getCovRand(1., ndim)
169cor
170+1.000000E+00, +6.181051E-01, -4.229319E-01, +3.606492E-01
171+6.181051E-01, +1.000000E+00, -5.002312E-01, +3.857741E-01
172-4.229319E-01, -5.002312E-01, +1.000000E+00, +4.527903E-01
173+3.606492E-01, +3.857741E-01, +4.527903E-01, +1.000000E+00
174cov = getCov(cor, uppDia, std) ! convert upper correlation matrix to full covariance matrix.
175cov
176+2.500000E+01, +2.163368E+01, -1.480262E+01, +1.442597E+01
177+2.163368E+01, +4.900000E+01, -2.451133E+01, +2.160335E+01
178-1.480262E+01, -2.451133E+01, +4.900000E+01, +2.535625E+01
179+1.442597E+01, +2.160335E+01, +2.535625E+01, +6.400000E+01
180cov = getCov(cor, lowDia, std) ! convert upper correlation matrix to full covariance matrix.
181cov
182+2.500000E+01, +2.163368E+01, -1.480262E+01, +1.442597E+01
183+2.163368E+01, +4.900000E+01, -2.451133E+01, +2.160335E+01
184-1.480262E+01, -2.451133E+01, +4.900000E+01, +2.535625E+01
185+1.442597E+01, +2.160335E+01, +2.535625E+01, +6.400000E+01
186getCor(getCov(cor, lowDia, std), lowDia) ! reconstruct the original correlation matrix.
187+1.000000E+00, +6.181051E-01, -4.229319E-01, +3.606492E-01
188+6.181051E-01, +1.000000E+00, -5.002313E-01, +3.857742E-01
189-4.229319E-01, -5.002313E-01, +1.000000E+00, +4.527903E-01
190+3.606492E-01, +3.857742E-01, +4.527903E-01, +1.000000E+00
191
192
193ndim = getUnifRand(1, 7)
194ndim
195+6
196std = getUnifRand(1, 10, ndim)
197std
198+8.000000E+00, +8.000000E+00, +3.000000E+00, +1.000000E+00, +5.000000E+00, +8.000000E+00
199call setResized(cov, [ndim, ndim])
200cor = getCovRand(1., ndim)
201cor
202+1.000000E+00, -8.734986E-01, -6.900458E-01, +5.561408E-01, +1.351264E-01, -8.163971E-02
203-8.734986E-01, +1.000000E+00, +8.110426E-01, -2.170484E-01, -1.584250E-01, +3.240204E-01
204-6.900458E-01, +8.110426E-01, +1.000000E+00, -4.859434E-01, +1.363465E-01, -1.112393E-02
205+5.561408E-01, -2.170484E-01, -4.859434E-01, +1.000000E+00, -3.533417E-01, +6.472332E-01
206+1.351264E-01, -1.584250E-01, +1.363465E-01, -3.533417E-01, +1.000000E+00, -4.207928E-01
207-8.163971E-02, +3.240204E-01, -1.112393E-02, +6.472332E-01, -4.207928E-01, +1.000000E+00
208cov = getCov(cor, uppDia, std) ! convert upper correlation matrix to full covariance matrix.
209cov
210+6.400000E+01, -5.590391E+01, -1.656110E+01, +4.449126E+00, +5.405055E+00, -5.224941E+00
211-5.590391E+01, +6.400000E+01, +1.946502E+01, -1.736387E+00, -6.337001E+00, +2.073730E+01
212-1.656110E+01, +1.946502E+01, +9.000000E+00, -1.457830E+00, +2.045198E+00, -2.669742E-01
213+4.449126E+00, -1.736387E+00, -1.457830E+00, +1.000000E+00, -1.766709E+00, +5.177866E+00
214+5.405055E+00, -6.337001E+00, +2.045198E+00, -1.766709E+00, +2.500000E+01, -1.683171E+01
215-5.224941E+00, +2.073730E+01, -2.669742E-01, +5.177866E+00, -1.683171E+01, +6.400000E+01
216cov = getCov(cor, lowDia, std) ! convert upper correlation matrix to full covariance matrix.
217cov
218+6.400000E+01, -5.590391E+01, -1.656110E+01, +4.449126E+00, +5.405055E+00, -5.224941E+00
219-5.590391E+01, +6.400000E+01, +1.946502E+01, -1.736387E+00, -6.337001E+00, +2.073730E+01
220-1.656110E+01, +1.946502E+01, +9.000000E+00, -1.457830E+00, +2.045198E+00, -2.669742E-01
221+4.449126E+00, -1.736387E+00, -1.457830E+00, +1.000000E+00, -1.766709E+00, +5.177866E+00
222+5.405055E+00, -6.337001E+00, +2.045198E+00, -1.766709E+00, +2.500000E+01, -1.683171E+01
223-5.224941E+00, +2.073730E+01, -2.669742E-01, +5.177866E+00, -1.683171E+01, +6.400000E+01
224getCor(getCov(cor, lowDia, std), lowDia) ! reconstruct the original correlation matrix.
225+1.000000E+00, -8.734986E-01, -6.900458E-01, +5.561408E-01, +1.351264E-01, -8.163971E-02
226-8.734986E-01, +1.000000E+00, +8.110427E-01, -2.170484E-01, -1.584250E-01, +3.240204E-01
227-6.900458E-01, +8.110427E-01, +1.000000E+00, -4.859434E-01, +1.363465E-01, -1.112393E-02
228+5.561408E-01, -2.170484E-01, -4.859434E-01, +1.000000E+00, -3.533417E-01, +6.472332E-01
229+1.351264E-01, -1.584250E-01, +1.363465E-01, -3.533417E-01, +1.000000E+00, -4.207928E-01
230-8.163971E-02, +3.240204E-01, -1.112393E-02, +6.472332E-01, -4.207928E-01, +1.000000E+00
231
232
233ndim = getUnifRand(1, 7)
234ndim
235+1
236std = getUnifRand(1, 10, ndim)
237std
238+9.000000E+00
239call setResized(cov, [ndim, ndim])
240cor = getCovRand(1., ndim)
241cor
242+1.000000E+00
243cov = getCov(cor, uppDia, std) ! convert upper correlation matrix to full covariance matrix.
244cov
245+8.100000E+01
246cov = getCov(cor, lowDia, std) ! convert upper correlation matrix to full covariance matrix.
247cov
248+8.100000E+01
249getCor(getCov(cor, lowDia, std), lowDia) ! reconstruct the original correlation matrix.
250+1.000000E+00
251
252
253ndim = getUnifRand(1, 7)
254ndim
255+6
256std = getUnifRand(1, 10, ndim)
257std
258+7.000000E+00, +6.000000E+00, +5.000000E+00, +5.000000E+00, +7.000000E+00, +4.000000E+00
259call setResized(cov, [ndim, ndim])
260cor = getCovRand(1., ndim)
261cor
262+1.000000E+00, -8.708906E-01, -7.212316E-01, +7.850715E-01, -4.953624E-01, -5.063903E-01
263-8.708906E-01, +1.000000E+00, +9.407201E-01, -8.420515E-01, +4.640191E-01, +1.872781E-01
264-7.212316E-01, +9.407201E-01, +1.000000E+00, -6.266006E-01, +5.827245E-01, +7.379752E-02
265+7.850715E-01, -8.420515E-01, -6.266006E-01, +1.000000E+00, -7.926303E-02, -1.860915E-01
266-4.953624E-01, +4.640191E-01, +5.827245E-01, -7.926303E-02, +1.000000E+00, +4.321689E-01
267-5.063903E-01, +1.872781E-01, +7.379752E-02, -1.860915E-01, +4.321689E-01, +1.000000E+00
268cov = getCov(cor, uppDia, std) ! convert upper correlation matrix to full covariance matrix.
269cov
270+4.900000E+01, -3.657740E+01, -2.524311E+01, +2.747750E+01, -2.427276E+01, -1.417893E+01
271-3.657740E+01, +3.600000E+01, +2.822160E+01, -2.526155E+01, +1.948880E+01, +4.494675E+00
272-2.524311E+01, +2.822160E+01, +2.500000E+01, -1.566501E+01, +2.039536E+01, +1.475950E+00
273+2.747750E+01, -2.526155E+01, -1.566501E+01, +2.500000E+01, -2.774206E+00, -3.721830E+00
274-2.427276E+01, +1.948880E+01, +2.039536E+01, -2.774206E+00, +4.900000E+01, +1.210073E+01
275-1.417893E+01, +4.494675E+00, +1.475950E+00, -3.721830E+00, +1.210073E+01, +1.600000E+01
276cov = getCov(cor, lowDia, std) ! convert upper correlation matrix to full covariance matrix.
277cov
278+4.900000E+01, -3.657740E+01, -2.524311E+01, +2.747750E+01, -2.427276E+01, -1.417893E+01
279-3.657740E+01, +3.600000E+01, +2.822160E+01, -2.526155E+01, +1.948880E+01, +4.494675E+00
280-2.524311E+01, +2.822160E+01, +2.500000E+01, -1.566501E+01, +2.039536E+01, +1.475950E+00
281+2.747750E+01, -2.526155E+01, -1.566501E+01, +2.500000E+01, -2.774206E+00, -3.721830E+00
282-2.427276E+01, +1.948880E+01, +2.039536E+01, -2.774206E+00, +4.900000E+01, +1.210073E+01
283-1.417893E+01, +4.494675E+00, +1.475950E+00, -3.721830E+00, +1.210073E+01, +1.600000E+01
284getCor(getCov(cor, lowDia, std), lowDia) ! reconstruct the original correlation matrix.
285+1.000000E+00, -8.708907E-01, -7.212317E-01, +7.850716E-01, -4.953624E-01, -5.063903E-01
286-8.708907E-01, +1.000000E+00, +9.407201E-01, -8.420516E-01, +4.640192E-01, +1.872781E-01
287-7.212317E-01, +9.407201E-01, +1.000000E+00, -6.266006E-01, +5.827245E-01, +7.379752E-02
288+7.850716E-01, -8.420516E-01, -6.266006E-01, +1.000000E+00, -7.926304E-02, -1.860915E-01
289-4.953624E-01, +4.640192E-01, +5.827245E-01, -7.926304E-02, +1.000000E+00, +4.321689E-01
290-5.063903E-01, +1.872781E-01, +7.379752E-02, -1.860915E-01, +4.321689E-01, +1.000000E+00
291
292
293ndim = getUnifRand(1, 7)
294ndim
295+2
296std = getUnifRand(1, 10, ndim)
297std
298+1.000000E+01, +4.000000E+00
299call setResized(cov, [ndim, ndim])
300cor = getCovRand(1., ndim)
301cor
302+1.000000E+00, -4.872438E-01
303-4.872438E-01, +1.000000E+00
304cov = getCov(cor, uppDia, std) ! convert upper correlation matrix to full covariance matrix.
305cov
306+1.000000E+02, -1.948975E+01
307-1.948975E+01, +1.600000E+01
308cov = getCov(cor, lowDia, std) ! convert upper correlation matrix to full covariance matrix.
309cov
310+1.000000E+02, -1.948975E+01
311-1.948975E+01, +1.600000E+01
312getCor(getCov(cor, lowDia, std), lowDia) ! reconstruct the original correlation matrix.
313+1.000000E+00, -4.872437E-01
314-4.872437E-01, +1.000000E+00
315
316
317ndim = getUnifRand(1, 7)
318ndim
319+7
320std = getUnifRand(1, 10, ndim)
321std
322+8.000000E+00, +2.000000E+00, +3.000000E+00, +7.000000E+00, +1.000000E+00, +2.000000E+00, +3.000000E+00
323call setResized(cov, [ndim, ndim])
324cor = getCovRand(1., ndim)
325cor
326+1.000000E+00, -8.945295E-01, -6.121029E-01, +2.959809E-01, -4.762225E-01, +3.883915E-01, +4.625305E-01
327-8.945295E-01, +1.000000E+00, +4.337425E-01, -2.968968E-01, +2.600544E-01, -5.605094E-01, -5.916742E-01
328-6.121029E-01, +4.337425E-01, +1.000000E+00, +4.215247E-01, +1.057041E-01, -3.071637E-01, +1.984254E-02
329+2.959809E-01, -2.968968E-01, +4.215247E-01, +1.000000E+00, -2.349117E-01, -2.088761E-01, +4.009157E-01
330-4.762225E-01, +2.600544E-01, +1.057041E-01, -2.349117E-01, +1.000000E+00, +1.028427E-02, +2.777941E-01
331+3.883915E-01, -5.605094E-01, -3.071637E-01, -2.088761E-01, +1.028427E-02, +1.000000E+00, +2.129828E-01
332+4.625305E-01, -5.916742E-01, +1.984254E-02, +4.009157E-01, +2.777941E-01, +2.129828E-01, +1.000000E+00
333cov = getCov(cor, uppDia, std) ! convert upper correlation matrix to full covariance matrix.
334cov
335+6.400000E+01, -1.431247E+01, -1.469047E+01, +1.657493E+01, -3.809780E+00, +6.214263E+00, +1.110073E+01
336-1.431247E+01, +4.000000E+00, +2.602455E+00, -4.156555E+00, +5.201088E-01, -2.242038E+00, -3.550045E+00
337-1.469047E+01, +2.602455E+00, +9.000000E+00, +8.852019E+00, +3.171124E-01, -1.842982E+00, +1.785828E-01
338+1.657493E+01, -4.156555E+00, +8.852019E+00, +4.900000E+01, -1.644382E+00, -2.924265E+00, +8.419230E+00
339-3.809780E+00, +5.201088E-01, +3.171124E-01, -1.644382E+00, +1.000000E+00, +2.056853E-02, +8.333822E-01
340+6.214263E+00, -2.242038E+00, -1.842982E+00, -2.924265E+00, +2.056853E-02, +4.000000E+00, +1.277897E+00
341+1.110073E+01, -3.550045E+00, +1.785828E-01, +8.419230E+00, +8.333822E-01, +1.277897E+00, +9.000000E+00
342cov = getCov(cor, lowDia, std) ! convert upper correlation matrix to full covariance matrix.
343cov
344+6.400000E+01, -1.431247E+01, -1.469047E+01, +1.657493E+01, -3.809780E+00, +6.214263E+00, +1.110073E+01
345-1.431247E+01, +4.000000E+00, +2.602455E+00, -4.156555E+00, +5.201088E-01, -2.242038E+00, -3.550045E+00
346-1.469047E+01, +2.602455E+00, +9.000000E+00, +8.852019E+00, +3.171124E-01, -1.842982E+00, +1.785828E-01
347+1.657493E+01, -4.156555E+00, +8.852019E+00, +4.900000E+01, -1.644382E+00, -2.924265E+00, +8.419230E+00
348-3.809780E+00, +5.201088E-01, +3.171124E-01, -1.644382E+00, +1.000000E+00, +2.056853E-02, +8.333822E-01
349+6.214263E+00, -2.242038E+00, -1.842982E+00, -2.924265E+00, +2.056853E-02, +4.000000E+00, +1.277897E+00
350+1.110073E+01, -3.550045E+00, +1.785828E-01, +8.419230E+00, +8.333822E-01, +1.277897E+00, +9.000000E+00
351getCor(getCov(cor, lowDia, std), lowDia) ! reconstruct the original correlation matrix.
352+1.000000E+00, -8.945295E-01, -6.121029E-01, +2.959809E-01, -4.762225E-01, +3.883915E-01, +4.625305E-01
353-8.945295E-01, +1.000000E+00, +4.337425E-01, -2.968968E-01, +2.600544E-01, -5.605094E-01, -5.916742E-01
354-6.121029E-01, +4.337425E-01, +1.000000E+00, +4.215248E-01, +1.057041E-01, -3.071637E-01, +1.984254E-02
355+2.959809E-01, -2.968968E-01, +4.215248E-01, +1.000000E+00, -2.349117E-01, -2.088761E-01, +4.009157E-01
356-4.762225E-01, +2.600544E-01, +1.057041E-01, -2.349117E-01, +1.000000E+00, +1.028427E-02, +2.777941E-01
357+3.883915E-01, -5.605094E-01, -3.071637E-01, -2.088761E-01, +1.028427E-02, +1.000000E+00, +2.129828E-01
358+4.625305E-01, -5.916742E-01, +1.984254E-02, +4.009157E-01, +2.777941E-01, +2.129828E-01, +1.000000E+00
359
360
361!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
362!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
363!Compute the covariance matrix of a 2-D sample.
364!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
365!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
366
367ndim = 2; nsam = 10
368sample = reshape(getUnifRand(1, 20, ndim * nsam), shape = [ndim, nsam], order = [2, 1])
369sample
370+16.0000000, +14.0000000, +6.00000000, +18.0000000, +20.0000000, +20.0000000, +14.0000000, +13.0000000, +17.0000000, +7.00000000
371+5.00000000, +18.0000000, +5.00000000, +2.00000000, +12.0000000, +8.00000000, +11.0000000, +12.0000000, +13.0000000, +19.0000000
372
373'Compute the sample covariance along the second dimension.'
374
375cov = getCov(sample, dim = 2_IK)
376cov
377+21.2500000, -6.05000019
378-6.05000019, +27.8500004
379
380'Compute the sample covariance along the first dimension.'
381
382cov = getCov(transpose(sample), dim = 1_IK)
383cov
384+21.2500000, -6.05000019
385-6.05000019, +27.8500004
386
387'Compute the full sample covariance for a pair of time series.'
388
389cov = getCov(sample(1,:), sample(2,:))
390cov
391+21.2500000, -6.05000019
392-6.05000019, +27.8500004
393
394ndim = 2; nsam = 10
395sample = reshape(cmplx(getUnifRand(1, 20, ndim * nsam), -getUnifRand(1, 20, ndim * nsam), TKG), shape = [ndim, nsam], order = [2, 1])
396sample
397(+2.00000000, -17.0000000), (+19.0000000, -15.0000000), (+8.00000000, -17.0000000), (+9.00000000, -20.0000000), (+3.00000000, -5.00000000), (+2.00000000, -15.0000000), (+13.0000000, -20.0000000), (+9.00000000, -15.0000000), (+11.0000000, -7.00000000), (+11.0000000, -3.00000000)
398(+1.00000000, -13.0000000), (+15.0000000, -4.00000000), (+7.00000000, -15.0000000), (+19.0000000, -14.0000000), (+15.0000000, -10.0000000), (+2.00000000, -16.0000000), (+19.0000000, -1.00000000), (+9.00000000, -18.0000000), (+10.0000000, -12.0000000), (+10.0000000, -18.0000000)
399
400'Compute the sample covariance along the second dimension.'
401
402cov = getCov(sample, dim = 2_IK)
403cov
404(+59.8499947, +0.00000000), (+9.27000713, -16.4900036)
405(+9.27000713, +16.4900036), (+65.3000107, +0.00000000)
406
407'Compute the sample covariance along the first dimension.'
408
409cov = getCov(transpose(sample), dim = 1_IK)
410cov
411(+59.8500023, +0.00000000), (+9.27000713, -16.4900036)
412(+9.27000713, +16.4900036), (+65.3000107, +0.00000000)
413
414'Compute the full sample covariance for a pair of time series.'
415
416cov = getCov(sample(1,:), sample(2,:))
417cov
418(+59.8499947, +0.00000000), (+9.27000713, -16.4900036)
419(+9.27000713, +16.4900036), (+65.3000107, +0.00000000)
420
421
422!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
423!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
424!Compute the biased covariance matrix of a weighted 2-D sample.
425!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
426!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
427
428ndim = 2; nsam = 10
429sample = reshape(getUnifRand(1, 20, ndim * nsam), shape = [ndim, nsam], order = [2, 1])
430sample
431+10.0000000, +2.00000000, +17.0000000, +14.0000000, +20.0000000, +5.00000000, +19.0000000, +8.00000000, +12.0000000, +19.0000000
432+16.0000000, +9.00000000, +18.0000000, +1.00000000, +20.0000000, +5.00000000, +1.00000000, +14.0000000, +13.0000000, +1.00000000
433call setResized(mean, ndim)
434iweight = getUnifRand(1, 10, nsam) ! integer-valued weights.
435iweight
436+10, +5, +4, +9, +2, +4, +2, +7, +5, +10
437call setMean(mean, sample, 2_IK, iweight, iweisum)
438mean
439+12.2068968, +8.98275852
440iweisum
441+58
442rweight = iweight ! or real-valued weights.
443iweight
444+10, +5, +4, +9, +2, +4, +2, +7, +5, +10
445call setMean(mean, sample, 2_IK, rweight, rweisum)
446mean
447+12.2068968, +8.98275852
448rweisum
449+58.0000000
450
451!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
452!Compute the covariance matrix with integer weights.
453!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
454
455cov = getCov(sample, 2_IK, iweight)
456cov
457+29.2675381, -10.8240185
458-10.8240185, +46.8790131
459
460'Compute the sample covariance along the first dimension.'
461
462cov = getCov(transpose(sample), 1_IK, iweight)
463cov
464+29.2675362, -10.8240185
465-10.8240185, +46.8790131
466
467'Compute the full sample covariance for a pair of time series.'
468
469cov = getCov(sample(1,:), sample(2,:), weight = iweight)
470cov
471+29.2675381, -10.8240185
472-10.8240185, +46.8790131
473
474
475!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
476!Compute the covariance matrix with real weights.
477!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
478
479cov = getCov(sample, 2_IK, rweight)
480cov
481+29.2675381, -10.8240185
482-10.8240185, +46.8790131
483
484'Compute the sample covariance along the first dimension.'
485
486cov = getCov(transpose(sample), 1_IK, rweight)
487cov
488+29.2675362, -10.8240185
489-10.8240185, +46.8790131
490
491'Compute the full sample covariance for a pair of time series.'
492
493cov = getCov(sample(1,:), sample(2,:), weight = rweight)
494cov
495+29.2675381, -10.8240185
496-10.8240185, +46.8790131
497
498ndim = 2; nsam = 10
499sample = reshape(cmplx(getUnifRand(1, 20, ndim * nsam), -getUnifRand(1, 20, ndim * nsam), TKG), shape = [ndim, nsam], order = [2, 1])
500sample
501(+14.0000000, -8.00000000), (+11.0000000, -1.00000000), (+10.0000000, -16.0000000), (+16.0000000, -11.0000000), (+14.0000000, -4.00000000), (+6.00000000, -16.0000000), (+15.0000000, -9.00000000), (+15.0000000, -6.00000000), (+5.00000000, -6.00000000), (+16.0000000, -19.0000000)
502(+15.0000000, -16.0000000), (+14.0000000, -12.0000000), (+11.0000000, -2.00000000), (+12.0000000, -17.0000000), (+17.0000000, -6.00000000), (+9.00000000, -16.0000000), (+19.0000000, -16.0000000), (+5.00000000, -19.0000000), (+4.00000000, -14.0000000), (+16.0000000, -20.0000000)
503call setResized(mean, ndim)
504iweight = getUnifRand(1, 10, nsam) ! integer-valued weights.
505iweight
506+7, +4, +6, +6, +5, +8, +4, +4, +9, +1
507call setMean(mean, sample, 2_IK, iweight, iweisum)
508mean
509(+11.0555553, -9.31481457), (+11.1851854, -13.2962961)
510iweisum
511+54
512rweight = iweight ! or real-valued weights.
513iweight
514+7, +4, +6, +6, +5, +8, +4, +4, +9, +1
515call setMean(mean, sample, 2_IK, rweight, rweisum)
516mean
517(+11.0555553, -9.31481457), (+11.1851854, -13.2962961)
518rweisum
519+54.0000000
520
521!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
522!Compute the covariance matrix with integer weights.
523!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
524
525cov = getCov(sample, 2_IK, iweight)
526cov
527(+41.6755829, +0.00000000), (+11.5630989, +3.96776319)
528(+11.5630989, -3.96776319), (+49.4334717, +0.00000000)
529
530'Compute the sample covariance along the first dimension.'
531
532cov = getCov(transpose(sample), 1_IK, iweight)
533cov
534(+41.6755829, +0.00000000), (+11.5630989, +3.96776319)
535(+11.5630989, -3.96776319), (+49.4334717, +0.00000000)
536
537'Compute the full sample covariance for a pair of time series.'
538
539cov = getCov(sample(1,:), sample(2,:), weight = iweight)
540cov
541(+41.6755829, +0.00000000), (+11.5630989, +3.96776319)
542(+11.5630989, -3.96776319), (+49.4334717, +0.00000000)
543
544
545!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
546!Compute the covariance matrix with real weights.
547!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
548
549cov = getCov(sample, 2_IK, rweight)
550cov
551(+41.6755829, +0.00000000), (+11.5630989, +3.96776319)
552(+11.5630989, -3.96776319), (+49.4334717, +0.00000000)
553
554'Compute the sample covariance along the first dimension.'
555
556cov = getCov(transpose(sample), 1_IK, rweight)
557cov
558(+41.6755829, +0.00000000), (+11.5630989, +3.96776319)
559(+11.5630989, -3.96776319), (+49.4334717, +0.00000000)
560
561'Compute the full sample covariance for a pair of time series.'
562
563cov = getCov(sample(1,:), sample(2,:), weight = rweight)
564cov
565(+41.6755829, +0.00000000), (+11.5630989, +3.96776319)
566(+11.5630989, -3.96776319), (+49.4334717, +0.00000000)
567
568
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: