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

Return the covAariance resulting from the merger of two separate (potentially weighted) non-singular and singular samples \(A\) and \(B\).
More...

Detailed Description

Return the covAariance resulting from the merger of two separate (potentially weighted) non-singular and singular samples \(A\) and \(B\).

See the documentation of pm_sampleCov for more information and definition online updating of sample covAariance.

Note
The input and output variances of this generic interface are all biased variances.
A biased covAariance can be readily unbiased by multiplying it with the appropriate bias-correction factors detailed in the documentation of pm_sampleCov.
Parameters
[in]covA: The input/output contiguous 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),

On input, it must contain the biased covAariance of the initial non-singular sample \(A\) that must be merged with the second singular sample \(B\).

Parameters
[in]meanDiff: The input object of the same type and kind as the input argument covA of size size(covA, 1), containing the difference of mean of the two non-singular and singular samples meanDiff = meanA - meanB.
The subtraction order is immaterial.
[in]fracA: The input scalar of type real of the same kind as covA, containing the ratio of the sum of the weights of all points in sample \(A\) to sum of weights of all points in the merged sample.
If the sample is unweighted, then fracA is simply size(sampleA) / (size(sampleA) + size(sampleB)).
[in]subset: The input scalar constant that can be:
  1. The constant lowDia, implying that only the lower-diagonal subset of the input covA, and covA matrices must be accessed and/or manipulated.
  2. The constant uppDia, implying that only the upper-diagonal subset of the input covA, and covA matrices must be accessed and/or manipulated.
This input argument is merely serves to resolve the different procedures of this generic interface from each other at compile-time.


Possible calling interfaces

call setCovUpdated(covA(1:ndim, 1:ndim), meanDiff(1:ndim), fracA, subset)
Return the covAariance resulting from the merger of two separate (potentially weighted) non-singular ...
This module contains classes and procedures for computing the properties related to the covariance ma...
Warning
The condition 0 < fracA .and. fracA < 1 must hold for the corresponding input arguments.
The condition all(size(meanDiff) == shape(covA)) must hold for the corresponding input arguments.
These conditions are verified only if the library is built with the preprocessor macro CHECK_ENABLED=1.
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.
See also
getCor
setCor
getCov
setCov
getVar
setVar
getMean
setMean
getCovMerged
setCovUpdated
setCovMeanMerged
getVarCorrection
getMeanMerged
setMeanMerged
getVarMerged
setVarMerged


Example usage

1program example
2
3 use pm_kind, only: SK, IK
4 use pm_kind, only: TKG => RKS ! All other real types are also supported.
5 use pm_sampleCov, only: getCov
6 use pm_sampleMean, only: getMean
7 use pm_sampleCov, only: uppDia, lowDia
10 use pm_arrayResize, only: setResized
11 use pm_distUnif, only: getUnifRand
12 use pm_arrayRange, only: getRange
13 use pm_io, only: display_type
14
15 implicit none
16
17 integer(IK) :: isam, ndim
18 integer(IK) , allocatable :: iweight(:)
19 integer(IK) :: dim, idim, nsamA, nsamB, itry, ntry = 10
20 type(display_type) :: disp
21 disp = display_type(file = "main.out.F90")
22
23 call disp%skip()
24 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
25 call disp%show("!Compute the biased merged covariance of a multivariate sample.")
26 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
27 call disp%skip()
28
29 block
30 real(TKG), allocatable :: cov(:,:), covA(:,:)
31 real(TKG), allocatable :: mean(:), meanA(:), meanB(:)
32 real(TKG), allocatable :: sample(:,:), sampleA(:,:), sampleB(:,:)
33 do itry = 1, ntry
34 call disp%skip()
35 call disp%show("dim = 2; ndim = getUnifRand(1, 5); nsamA = getUnifRand(ndim + 1_IK, ndim * 2_IK); nsamB = getUnifRand(1_IK, nsamA)")
36 dim = 2; ndim = getUnifRand(1, 5); nsamA = getUnifRand(ndim + 1_IK, ndim * 2_IK); nsamB = getUnifRand(1_IK, nsamA)
37 call disp%show("[ndim, nsamA]")
38 call disp%show( [ndim, nsamA] )
39 call disp%show("sampleA = getUnifRand(-1., +1., ndim, nsamA) ! Generate a non-singular sample.")
40 sampleA = getUnifRand(-1., +1., ndim, nsamA)
41 call disp%show("sampleA")
42 call disp%show( sampleA )
43 call disp%show("covA = getCov(sampleA, dim)")
44 covA = getCov(sampleA, dim)
45 call disp%show("covA")
46 call disp%show( covA )
47 call disp%show("meanA = getMean(sampleA, dim)")
48 meanA = getMean(sampleA, dim)
49 call disp%show("meanA")
50 call disp%show( meanA )
51 call disp%show("sampleB = spread([(idim, idim = 1, ndim)], dim, nsamB) ! Generate a singular sample.")
52 sampleB = spread([(idim, idim = 1, ndim)], dim, nsamB)
53 call disp%show("sampleB")
54 call disp%show( sampleB )
55 call disp%show("meanB = getMean(sampleB, dim)")
56 meanB = getMean(sampleB, dim)
57 call disp%show("meanB")
58 call disp%show( meanB )
59 call disp%show("sample = reshape([sampleA, sampleB], [ndim, nsamA + nsamB])")
60 sample = reshape([sampleA, sampleB], [ndim, nsamA + nsamB])
61 call disp%show("sample")
62 call disp%show( sample )
63 call disp%show("cov = getCov(sample, dim)")
64 cov = getCov(sample, dim)
65 call disp%show("cov")
66 call disp%show( cov )
67 call disp%show("mean = getMean(sample, dim)")
68 mean = getMean(sample, dim)
69 call disp%show("mean")
70 call disp%show( mean )
71 call disp%show("call setCovUpdated(covA, meanA - meanB, real(nsamA, TKG) / real(nsamA + nsamB, TKG), uppDia)")
72 call setCovUpdated(covA, meanA - meanB, real(nsamA, TKG) / real(nsamA + nsamB, TKG), uppDia)
73 call disp%show("covA")
74 call disp%show( covA )
75 call disp%show("cov ! reference")
76 call disp%show( cov )
77 call disp%skip()
78 end do
79 end block
80
81end program example
Generate minimally-spaced character, integer, real sequences or sequences at fixed intervals of size ...
Resize (shrink or expand) an input allocatable array of rank 1..3 to arbitrary new lower and upper bo...
Allocate or resize (shrink or expand) an input allocatable scalar string or array of rank 1....
Generate and return a scalar or a contiguous array of rank 1 of length s1 of randomly uniformly distr...
This is a generic method of the derived type display_type with pass attribute.
Definition: pm_io.F90:11726
This is a generic method of the derived type display_type with pass attribute.
Definition: pm_io.F90:11508
Generate and return the (optionally unbiased) covariance matrix of a pair of (potentially weighted) t...
Generate and return the (weighted) mean of an input sample of nsam observations with ndim = 1 or 2 at...
This module contains procedures and generic interfaces for generating ranges of discrete character,...
This module contains procedures and generic interfaces for resizing allocatable arrays of various typ...
This module contains procedures and generic interfaces for resizing allocatable arrays of various typ...
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 IK
The default integer kind in the ParaMonte library: int32 in Fortran, c_int32_t in C-Fortran Interoper...
Definition: pm_kind.F90:540
integer, parameter SK
The default character kind in the ParaMonte library: kind("a") in Fortran, c_char in C-Fortran Intero...
Definition: pm_kind.F90:539
integer, parameter RKS
The single-precision real kind in Fortran mode. On most platforms, this is an 32-bit real kind.
Definition: pm_kind.F90:567
This module contains classes and procedures for computing the first moment (i.e., the statistical mea...
Generate and return an object of type display_type.
Definition: pm_io.F90:10282

Example Unix compile command via Intel ifort compiler
1#!/usr/bin/env sh
2rm main.exe
3ifort -fpp -standard-semantics -O3 -Wl,-rpath,../../../lib -I../../../inc main.F90 ../../../lib/libparamonte* -o main.exe
4./main.exe

Example Windows Batch compile command via Intel ifort compiler
1del main.exe
2set PATH=..\..\..\lib;%PATH%
3ifort /fpp /standard-semantics /O3 /I:..\..\..\include main.F90 ..\..\..\lib\libparamonte*.lib /exe:main.exe
4main.exe

Example Unix / MinGW compile command via GNU gfortran compiler
1#!/usr/bin/env sh
2rm main.exe
3gfortran -cpp -ffree-line-length-none -O3 -Wl,-rpath,../../../lib -I../../../inc main.F90 ../../../lib/libparamonte* -o main.exe
4./main.exe

Example output
1
2!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3!Compute the biased merged covariance of a multivariate sample.
4!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5
6
7dim = 2; ndim = getUnifRand(1, 5); nsamA = getUnifRand(ndim + 1_IK, ndim * 2_IK); nsamB = getUnifRand(1_IK, nsamA)
8[ndim, nsamA]
9+5, +6
10sampleA = getUnifRand(-1., +1., ndim, nsamA) ! Generate a non-singular sample.
11sampleA
12-0.678403735, -0.435983777, -0.610186219, +0.178292394, -0.249370694, -0.437976122
13-0.828455687E-1, +0.666078925, -0.291938543, -0.534110427, -0.837818384E-1, -0.969791412
14-0.149039149, +0.745225430, +0.421300530, +0.795945764, +0.681076050E-1, -0.217056155
15+0.201816082, -0.331631660, +0.930408120, +0.959064007, -0.384520054, -0.317964673
16+0.230368733, -0.358304739, -0.400052905, -0.398969650E-1, -0.135749340, +0.697605252
17covA = getCov(sampleA, dim)
18covA
19+0.794869959E-1, -0.313763395E-1, +0.597938225E-1, +0.399414301E-1, -0.616697967E-2
20-0.313763395E-1, +0.248072907, +0.875064731E-1, -0.754146203E-1, -0.131017536
21+0.597938225E-1, +0.875064731E-1, +0.163099676, +0.104613125, -0.110107049
22+0.399414301E-1, -0.754146203E-1, +0.104613125, +0.333143502, -0.689519942E-1
23-0.616697967E-2, -0.131017536, -0.110107049, -0.689519942E-1, +0.141360179
24meanA = getMean(sampleA, dim)
25meanA
26-0.372271389, -0.216064811, +0.277414024, +0.176195309, -0.100499392E-2
27sampleB = spread([(idim, idim = 1, ndim)], dim, nsamB) ! Generate a singular sample.
28sampleB
29+1.00000000, +1.00000000, +1.00000000, +1.00000000, +1.00000000
30+2.00000000, +2.00000000, +2.00000000, +2.00000000, +2.00000000
31+3.00000000, +3.00000000, +3.00000000, +3.00000000, +3.00000000
32+4.00000000, +4.00000000, +4.00000000, +4.00000000, +4.00000000
33+5.00000000, +5.00000000, +5.00000000, +5.00000000, +5.00000000
34meanB = getMean(sampleB, dim)
35meanB
36+1.00000000, +2.00000000, +3.00000000, +4.00000000, +5.00000000
37sample = reshape([sampleA, sampleB], [ndim, nsamA + nsamB])
38sample
39-0.678403735, -0.435983777, -0.610186219, +0.178292394, -0.249370694, -0.437976122, +1.00000000, +1.00000000, +1.00000000, +1.00000000, +1.00000000
40-0.828455687E-1, +0.666078925, -0.291938543, -0.534110427, -0.837818384E-1, -0.969791412, +2.00000000, +2.00000000, +2.00000000, +2.00000000, +2.00000000
41-0.149039149, +0.745225430, +0.421300530, +0.795945764, +0.681076050E-1, -0.217056155, +3.00000000, +3.00000000, +3.00000000, +3.00000000, +3.00000000
42+0.201816082, -0.331631660, +0.930408120, +0.959064007, -0.384520054, -0.317964673, +4.00000000, +4.00000000, +4.00000000, +4.00000000, +4.00000000
43+0.230368733, -0.358304739, -0.400052905, -0.398969650E-1, -0.135749340, +0.697605252, +5.00000000, +5.00000000, +5.00000000, +5.00000000, +5.00000000
44cov = getCov(sample, dim)
45cov
46+0.510247946, +0.736863077, +0.958927035, +1.32276881, +1.69814098
47+0.736863077, +1.35290182, +1.54362178, +2.05980635, +2.67627597
48+0.958927035, +1.54362178, +1.92676675, +2.63821149, +3.31572604
49+1.32276881, +2.05980635, +2.63821149, +3.80687547, +4.70359612
50+1.69814098, +2.67627597, +3.31572604, +4.70359612, +6.27794456
51mean = getMean(sample, dim)
52mean
53+0.251488358, +0.791237414, +1.51495314, +1.91428828, +2.27217913
54call setCovUpdated(covA, meanA - meanB, real(nsamA, TKG) / real(nsamA + nsamB, TKG), uppDia)
55covA
56+0.510248005, +0.736863136, +0.958927274, +1.32276905, +1.69814098
57-0.313763395E-1, +1.35290194, +1.54362178, +2.05980682, +2.67627597
58+0.597938225E-1, +0.875064731E-1, +1.92676699, +2.63821125, +3.31572652
59+0.399414301E-1, -0.754146203E-1, +0.104613125, +3.80687523, +4.70359659
60-0.616697967E-2, -0.131017536, -0.110107049, -0.689519942E-1, +6.27794504
61cov ! reference
62+0.510247946, +0.736863077, +0.958927035, +1.32276881, +1.69814098
63+0.736863077, +1.35290182, +1.54362178, +2.05980635, +2.67627597
64+0.958927035, +1.54362178, +1.92676675, +2.63821149, +3.31572604
65+1.32276881, +2.05980635, +2.63821149, +3.80687547, +4.70359612
66+1.69814098, +2.67627597, +3.31572604, +4.70359612, +6.27794456
67
68
69dim = 2; ndim = getUnifRand(1, 5); nsamA = getUnifRand(ndim + 1_IK, ndim * 2_IK); nsamB = getUnifRand(1_IK, nsamA)
70[ndim, nsamA]
71+4, +7
72sampleA = getUnifRand(-1., +1., ndim, nsamA) ! Generate a non-singular sample.
73sampleA
74+0.368643761, +0.192456126, -0.798490286, -0.401340246, -0.397512913E-1, +0.830801725E-1, +0.118317723
75-0.654027939, -0.658138275, -0.410542607, +0.242659688, -0.160286427, +0.781846762, -0.493915081E-1
76-0.269494534, +0.569403529, +0.402458549, +0.794622183, -0.794650793, +0.460416913, -0.607789993
77+0.707683206, +0.285599470, -0.443557262, +0.765340328E-1, +0.797566533, -0.259109735E-1, +0.397417545
78covA = getCov(sampleA, dim)
79covA
80+0.137366295, -0.191047713E-1, -0.848977268E-1, +0.110690445
81-0.191047713E-1, +0.229999080, +0.597787425E-1, -0.550020449E-1
82-0.848977268E-1, +0.597787425E-1, +0.337015539, -0.167913094
83+0.110690445, -0.550020449E-1, -0.167913094, +0.159892499
84meanA = getMean(sampleA, dim)
85meanA
86-0.681548640E-1, -0.129697189, +0.792808384E-1, +0.256476104
87sampleB = spread([(idim, idim = 1, ndim)], dim, nsamB) ! Generate a singular sample.
88sampleB
89+1.00000000, +1.00000000
90+2.00000000, +2.00000000
91+3.00000000, +3.00000000
92+4.00000000, +4.00000000
93meanB = getMean(sampleB, dim)
94meanB
95+1.00000000, +2.00000000, +3.00000000, +4.00000000
96sample = reshape([sampleA, sampleB], [ndim, nsamA + nsamB])
97sample
98+0.368643761, +0.192456126, -0.798490286, -0.401340246, -0.397512913E-1, +0.830801725E-1, +0.118317723, +1.00000000, +1.00000000
99-0.654027939, -0.658138275, -0.410542607, +0.242659688, -0.160286427, +0.781846762, -0.493915081E-1, +2.00000000, +2.00000000
100-0.269494534, +0.569403529, +0.402458549, +0.794622183, -0.794650793, +0.460416913, -0.607789993, +3.00000000, +3.00000000
101+0.707683206, +0.285599470, -0.443557262, +0.765340328E-1, +0.797566533, -0.259109735E-1, +0.397417545, +4.00000000, +4.00000000
102cov = getCov(sample, dim)
103cov
104+0.304042548, +0.378324062, +0.473189741, +0.777219594
105+0.378324062, +0.962820828, +1.12159908, +1.33519614
106+0.473189741, +1.12159908, +1.73654795, +1.75919056
107+0.777219594, +1.33519614, +1.75919056, +2.54652905
108mean = getMean(sample, dim)
109mean
110+0.169212893, +0.343568861, +0.728329539, +1.08837020
111call setCovUpdated(covA, meanA - meanB, real(nsamA, TKG) / real(nsamA + nsamB, TKG), uppDia)
112covA
113+0.304042488, +0.378323972, +0.473189652, +0.777219474
114-0.191047713E-1, +0.962820649, +1.12159896, +1.33519590
115-0.848977268E-1, +0.597787425E-1, +1.73654795, +1.75919008
116+0.110690445, -0.550020449E-1, -0.167913094, +2.54652834
117cov ! reference
118+0.304042548, +0.378324062, +0.473189741, +0.777219594
119+0.378324062, +0.962820828, +1.12159908, +1.33519614
120+0.473189741, +1.12159908, +1.73654795, +1.75919056
121+0.777219594, +1.33519614, +1.75919056, +2.54652905
122
123
124dim = 2; ndim = getUnifRand(1, 5); nsamA = getUnifRand(ndim + 1_IK, ndim * 2_IK); nsamB = getUnifRand(1_IK, nsamA)
125[ndim, nsamA]
126+5, +7
127sampleA = getUnifRand(-1., +1., ndim, nsamA) ! Generate a non-singular sample.
128sampleA
129-0.148767114, -0.908918262, -0.767965078, +0.877235532, +0.564850569E-1, -0.938119769, -0.231353998
130-0.875314116, -0.197059751, +0.250890970, -0.371153355E-1, +0.764985919, +0.892132521, -0.494159222
131+0.906487942, +0.112674117, -0.912119269, -0.408276320, -0.518396378, +0.231902361, -0.724831939
132+0.154561877, -0.514539719, -0.104609251, +0.887235761, +0.657966971, -0.255117416E-1, +0.427653313
133+0.254720211, -0.483943462, +0.927181125, +0.269582748, -0.283031702, -0.156413913, -0.975247145
134covA = getCov(sampleA, dim)
135covA
136+0.362472266, -0.722380280E-1, -0.515168346E-1, +0.243163228, +0.215872880E-1
137-0.722380280E-1, +0.354484916, -0.114825733, +0.159579441E-1, +0.343334191E-1
138-0.515168346E-1, -0.114825733, +0.347835004, -0.805198848E-1, -0.655661337E-2
139+0.243163228, +0.159579441E-1, -0.805198848E-1, +0.198449776, -0.105737178E-1
140+0.215872880E-1, +0.343334191E-1, -0.655661337E-2, -0.105737178E-1, +0.322648436
141meanA = getMean(sampleA, dim)
142meanA
143-0.294486254, +0.434801430E-1, -0.187508509, +0.211822465, -0.638788790E-1
144sampleB = spread([(idim, idim = 1, ndim)], dim, nsamB) ! Generate a singular sample.
145sampleB
146+1.00000000, +1.00000000, +1.00000000, +1.00000000, +1.00000000, +1.00000000, +1.00000000
147+2.00000000, +2.00000000, +2.00000000, +2.00000000, +2.00000000, +2.00000000, +2.00000000
148+3.00000000, +3.00000000, +3.00000000, +3.00000000, +3.00000000, +3.00000000, +3.00000000
149+4.00000000, +4.00000000, +4.00000000, +4.00000000, +4.00000000, +4.00000000, +4.00000000
150+5.00000000, +5.00000000, +5.00000000, +5.00000000, +5.00000000, +5.00000000, +5.00000000
151meanB = getMean(sampleB, dim)
152meanB
153+1.00000000, +2.00000000, +3.00000024, +4.00000000, +5.00000000
154sample = reshape([sampleA, sampleB], [ndim, nsamA + nsamB])
155sample
156-0.148767114, -0.908918262, -0.767965078, +0.877235532, +0.564850569E-1, -0.938119769, -0.231353998, +1.00000000, +1.00000000, +1.00000000, +1.00000000, +1.00000000, +1.00000000, +1.00000000
157-0.875314116, -0.197059751, +0.250890970, -0.371153355E-1, +0.764985919, +0.892132521, -0.494159222, +2.00000000, +2.00000000, +2.00000000, +2.00000000, +2.00000000, +2.00000000, +2.00000000
158+0.906487942, +0.112674117, -0.912119269, -0.408276320, -0.518396378, +0.231902361, -0.724831939, +3.00000000, +3.00000000, +3.00000000, +3.00000000, +3.00000000, +3.00000000, +3.00000000
159+0.154561877, -0.514539719, -0.104609251, +0.887235761, +0.657966971, -0.255117416E-1, +0.427653313, +4.00000000, +4.00000000, +4.00000000, +4.00000000, +4.00000000, +4.00000000, +4.00000000
160+0.254720211, -0.483943462, +0.927181125, +0.269582748, -0.283031702, -0.156413913, -0.975247145, +5.00000000, +5.00000000, +5.00000000, +5.00000000, +5.00000000, +5.00000000, +5.00000000
161cov = getCov(sample, dim)
162cov
163+0.600159883, +0.597052932, +1.00578809, +1.34751749, +1.64957440
164+0.597052932, +1.13423491, +1.50169301, +1.86089003, +2.49406219
165+1.00578809, +1.50169301, +2.71397066, +2.97845244, +4.03201103
166+1.34751749, +1.86089003, +2.97845244, +3.68679667, +4.79043150
167+1.64957440, +2.49406219, +4.03201103, +4.79043150, +6.57204390
168mean = getMean(sample, dim)
169mean
170+0.352756888, +1.02174020, +1.40624583, +2.10591125, +2.46806073
171call setCovUpdated(covA, meanA - meanB, real(nsamA, TKG) / real(nsamA + nsamB, TKG), uppDia)
172covA
173+0.600159824, +0.597053051, +1.00578821, +1.34751749, +1.64957416
174-0.722380280E-1, +1.13423491, +1.50169325, +1.86089003, +2.49406147
175-0.515168346E-1, -0.114825733, +2.71397066, +2.97845244, +4.03201151
176+0.243163228, +0.159579441E-1, -0.805198848E-1, +3.68679690, +4.79043150
177+0.215872880E-1, +0.343334191E-1, -0.655661337E-2, -0.105737178E-1, +6.57204151
178cov ! reference
179+0.600159883, +0.597052932, +1.00578809, +1.34751749, +1.64957440
180+0.597052932, +1.13423491, +1.50169301, +1.86089003, +2.49406219
181+1.00578809, +1.50169301, +2.71397066, +2.97845244, +4.03201103
182+1.34751749, +1.86089003, +2.97845244, +3.68679667, +4.79043150
183+1.64957440, +2.49406219, +4.03201103, +4.79043150, +6.57204390
184
185
186dim = 2; ndim = getUnifRand(1, 5); nsamA = getUnifRand(ndim + 1_IK, ndim * 2_IK); nsamB = getUnifRand(1_IK, nsamA)
187[ndim, nsamA]
188+3, +6
189sampleA = getUnifRand(-1., +1., ndim, nsamA) ! Generate a non-singular sample.
190sampleA
191-0.977409482, +0.149205327, -0.850092649, +0.654974461, -0.896157503, +0.508450985
192+0.959184885, -0.663272858, +0.692103386, +0.123913288E-1, -0.932570219, +0.468411088
193-0.560616016, +0.898816586E-1, +0.624711752, -0.228697896, -0.742463827, -0.309799910E-1
194covA = getCov(sampleA, dim)
195covA
196+0.476504564, -0.694521293E-1, +0.551094636E-1
197-0.694521293E-1, +0.480049372, +0.976455808E-1
198+0.551094636E-1, +0.976455808E-1, +0.199541897
199meanA = getMean(sampleA, dim)
200meanA
201-0.235171482, +0.893746018E-1, -0.141360730
202sampleB = spread([(idim, idim = 1, ndim)], dim, nsamB) ! Generate a singular sample.
203sampleB
204+1.00000000, +1.00000000, +1.00000000
205+2.00000000, +2.00000000, +2.00000000
206+3.00000000, +3.00000000, +3.00000000
207meanB = getMean(sampleB, dim)
208meanB
209+1.00000000, +2.00000000, +3.00000000
210sample = reshape([sampleA, sampleB], [ndim, nsamA + nsamB])
211sample
212-0.977409482, +0.149205327, -0.850092649, +0.654974461, -0.896157503, +0.508450985, +1.00000000, +1.00000000, +1.00000000
213+0.959184885, -0.663272858, +0.692103386, +0.123913288E-1, -0.932570219, +0.468411088, +2.00000000, +2.00000000, +2.00000000
214-0.560616016, +0.898816586E-1, +0.624711752, -0.228697896, -0.742463827, -0.309799910E-1, +3.00000000, +3.00000000, +3.00000000
215cov = getCov(sample, dim)
216cov
217+0.656702876, +0.478131920, +0.898988307
218+0.478131920, +1.13125277, +1.39886665
219+0.898988307, +1.39886665, +2.32594919
220mean = getMean(sample, dim)
221mean
222+0.176552355, +0.726249754, +0.905759513
223call setCovUpdated(covA, meanA - meanB, real(nsamA, TKG) / real(nsamA + nsamB, TKG), uppDia)
224covA
225+0.656702697, +0.478131890, +0.898988307
226-0.694521293E-1, +1.13125277, +1.39886665
227+0.551094636E-1, +0.976455808E-1, +2.32594967
228cov ! reference
229+0.656702876, +0.478131920, +0.898988307
230+0.478131920, +1.13125277, +1.39886665
231+0.898988307, +1.39886665, +2.32594919
232
233
234dim = 2; ndim = getUnifRand(1, 5); nsamA = getUnifRand(ndim + 1_IK, ndim * 2_IK); nsamB = getUnifRand(1_IK, nsamA)
235[ndim, nsamA]
236+1, +2
237sampleA = getUnifRand(-1., +1., ndim, nsamA) ! Generate a non-singular sample.
238sampleA
239+0.989915133E-1, +0.492268920
240covA = getCov(sampleA, dim)
241covA
242+0.386667810E-1
243meanA = getMean(sampleA, dim)
244meanA
245+0.295630217
246sampleB = spread([(idim, idim = 1, ndim)], dim, nsamB) ! Generate a singular sample.
247sampleB
248+1.00000000, +1.00000000
249meanB = getMean(sampleB, dim)
250meanB
251+1.00000000
252sample = reshape([sampleA, sampleB], [ndim, nsamA + nsamB])
253sample
254+0.989915133E-1, +0.492268920, +1.00000000, +1.00000000
255cov = getCov(sample, dim)
256cov
257+0.143367589
258mean = getMean(sample, dim)
259mean
260+0.647815108
261call setCovUpdated(covA, meanA - meanB, real(nsamA, TKG) / real(nsamA + nsamB, TKG), uppDia)
262covA
263+0.143367589
264cov ! reference
265+0.143367589
266
267
268dim = 2; ndim = getUnifRand(1, 5); nsamA = getUnifRand(ndim + 1_IK, ndim * 2_IK); nsamB = getUnifRand(1_IK, nsamA)
269[ndim, nsamA]
270+5, +10
271sampleA = getUnifRand(-1., +1., ndim, nsamA) ! Generate a non-singular sample.
272sampleA
273+0.242099404, -0.812963367, -0.910529971, +0.989816546, -0.113401413E-1, -0.980651736, +0.998832822, -0.259596705, +0.375204921, +0.836794019
274-0.737822294, +0.188988805, -0.430051088, +0.675435185, +0.879404545, +0.226621270, -0.194710135, -0.499482870, -0.113875866, +0.503795505
275+0.213539124, +0.156482100, +0.290858984, -0.960152507, -0.389784694, +0.554591060, +0.600591063, +0.854776263, +0.639061928E-1, -0.653483868E-1
276+0.807485938, +0.845973253, -0.737810373, -0.411867023, -0.998105884, +0.528955460E-1, -0.759599566, -0.557564497, -0.217288256, +0.266754031
277+0.534258485, -0.294958711, -0.324164629E-1, -0.608785033, -0.474806666, -0.626298904, +0.311079502, +0.144816995, -0.394211888, -0.271849036
278covA = getCov(sampleA, dim)
279covA
280+0.537431896, +0.786378756E-1, -0.154458657, -0.661031976E-1, +0.393480174E-1
281+0.786378756E-1, +0.257530600, -0.176851779, -0.591849796E-1, -0.154626653
282-0.154458657, -0.176851779, +0.246169001, +0.165440142E-1, +0.100999571
283-0.661031976E-1, -0.591849796E-1, +0.165440142E-1, +0.379484385, +0.300609600E-1
284+0.393480174E-1, -0.154626653, +0.100999571, +0.300609600E-1, +0.141534612
285meanA = getMean(sampleA, dim)
286meanA
287+0.467665792E-1, +0.498303063E-1, +0.131945923, -0.170912683, -0.171317175
288sampleB = spread([(idim, idim = 1, ndim)], dim, nsamB) ! Generate a singular sample.
289sampleB
290+1.00000000, +1.00000000
291+2.00000000, +2.00000000
292+3.00000000, +3.00000000
293+4.00000000, +4.00000000
294+5.00000000, +5.00000000
295meanB = getMean(sampleB, dim)
296meanB
297+1.00000000, +2.00000000, +3.00000000, +4.00000000, +5.00000000
298sample = reshape([sampleA, sampleB], [ndim, nsamA + nsamB])
299sample
300+0.242099404, -0.812963367, -0.910529971, +0.989816546, -0.113401413E-1, -0.980651736, +0.998832822, -0.259596705, +0.375204921, +0.836794019, +1.00000000, +1.00000000
301-0.737822294, +0.188988805, -0.430051088, +0.675435185, +0.879404545, +0.226621270, -0.194710135, -0.499482870, -0.113875866, +0.503795505, +2.00000000, +2.00000000
302+0.213539124, +0.156482100, +0.290858984, -0.960152507, -0.389784694, +0.554591060, +0.600591063, +0.854776263, +0.639061928E-1, -0.653483868E-1, +3.00000000, +3.00000000
303+0.807485938, +0.845973253, -0.737810373, -0.411867023, -0.998105884, +0.528955460E-1, -0.759599566, -0.557564497, -0.217288256, +0.266754031, +4.00000000, +4.00000000
304+0.534258485, -0.294958711, -0.324164629E-1, -0.608785033, -0.474806666, -0.626298904, +0.311079502, +0.144816995, -0.394211888, -0.271849036, +5.00000000, +5.00000000
305cov = getCov(sample, dim)
306cov
307+0.574061871, +0.323721409, +0.250996262, +0.497115850, +0.717438936
308+0.323721409, +0.742825747, +0.629455745, +1.08039951, +1.27183139
309+0.250996262, +0.629455745, +1.34760404, +1.67523146, +2.14411306
310+0.497115850, +1.08039951, +1.67523146, +2.73241949, +3.02076101
311+0.717438936, +1.27183139, +2.14411306, +3.02076101, +3.83218455
312mean = getMean(sample, dim)
313mean
314+0.205638811, +0.374858588, +0.609954953, +0.524239421, +0.690569043
315call setCovUpdated(covA, meanA - meanB, real(nsamA, TKG) / real(nsamA + nsamB, TKG), uppDia)
316covA
317+0.574061871, +0.323721409, +0.250996292, +0.497115880, +0.717438996
318+0.786378756E-1, +0.742825806, +0.629455805, +1.08039975, +1.27183139
319-0.154458657, -0.176851779, +1.34760404, +1.67523170, +2.14411330
320-0.661031976E-1, -0.591849796E-1, +0.165440142E-1, +2.73241949, +3.02076101
321+0.393480174E-1, -0.154626653, +0.100999571, +0.300609600E-1, +3.83218479
322cov ! reference
323+0.574061871, +0.323721409, +0.250996262, +0.497115850, +0.717438936
324+0.323721409, +0.742825747, +0.629455745, +1.08039951, +1.27183139
325+0.250996262, +0.629455745, +1.34760404, +1.67523146, +2.14411306
326+0.497115850, +1.08039951, +1.67523146, +2.73241949, +3.02076101
327+0.717438936, +1.27183139, +2.14411306, +3.02076101, +3.83218455
328
329
330dim = 2; ndim = getUnifRand(1, 5); nsamA = getUnifRand(ndim + 1_IK, ndim * 2_IK); nsamB = getUnifRand(1_IK, nsamA)
331[ndim, nsamA]
332+4, +6
333sampleA = getUnifRand(-1., +1., ndim, nsamA) ! Generate a non-singular sample.
334sampleA
335-0.646743774E-1, -0.895692229, +0.928888083, -0.936853051, +0.883156657, +0.473411322
336-0.341555595, +0.536874771, +0.981539130, -0.429799914, -0.968770623, -0.545197606
337+0.222136736, -0.429530144E-1, +0.373711228, +0.489082098, -0.306901455, +0.389834285
338-0.284952283, +0.328786612, -0.259376764, +0.342698097, +0.746292830, -0.184359074
339covA = getCov(sampleA, dim)
340covA
341+0.587656140, -0.347400978E-1, -0.410391018E-1, -0.518041179E-1
342-0.347400978E-1, +0.448462248, +0.477061346E-1, -0.110405348
343-0.410391018E-1, +0.477061346E-1, +0.775511041E-1, -0.728078410E-1
344-0.518041179E-1, -0.110405348, -0.728078410E-1, +0.147636205
345meanA = getMean(sampleA, dim)
346meanA
347+0.647060722E-1, -0.127818316, +0.187484980, +0.114848241
348sampleB = spread([(idim, idim = 1, ndim)], dim, nsamB) ! Generate a singular sample.
349sampleB
350+1.00000000, +1.00000000, +1.00000000, +1.00000000
351+2.00000000, +2.00000000, +2.00000000, +2.00000000
352+3.00000000, +3.00000000, +3.00000000, +3.00000000
353+4.00000000, +4.00000000, +4.00000000, +4.00000000
354meanB = getMean(sampleB, dim)
355meanB
356+1.00000000, +2.00000000, +3.00000000, +4.00000000
357sample = reshape([sampleA, sampleB], [ndim, nsamA + nsamB])
358sample
359-0.646743774E-1, -0.895692229, +0.928888083, -0.936853051, +0.883156657, +0.473411322, +1.00000000, +1.00000000, +1.00000000, +1.00000000
360-0.341555595, +0.536874771, +0.981539130, -0.429799914, -0.968770623, -0.545197606, +2.00000000, +2.00000000, +2.00000000, +2.00000000
361+0.222136736, -0.429530144E-1, +0.373711228, +0.489082098, -0.306901455, +0.389834285, +3.00000000, +3.00000000, +3.00000000, +3.00000000
362-0.284952283, +0.328786612, -0.259376764, +0.342698097, +0.746292830, -0.184359074, +4.00000000, +4.00000000, +4.00000000, +4.00000000
363cov = getCov(sample, dim)
364cov
365+0.562539577, +0.456788450, +0.606703222, +0.841019630
366+0.456788450, +1.35570371, +1.46490860, +1.91781235
367+0.606703222, +1.46490860, +1.94498825, +2.57880640
368+0.841019630, +1.91781235, +2.57880640, +3.71123862
369mean = getMean(sample, dim)
370mean
371+0.438823670, +0.723309040, +1.31249106, +1.66890895
372call setCovUpdated(covA, meanA - meanB, real(nsamA, TKG) / real(nsamA + nsamB, TKG), uppDia)
373covA
374+0.562539577, +0.456788450, +0.606703281, +0.841019630
375-0.347400978E-1, +1.35570383, +1.46490872, +1.91781211
376-0.410391018E-1, +0.477061346E-1, +1.94498849, +2.57880664
377-0.518041179E-1, -0.110405348, -0.728078410E-1, +3.71123886
378cov ! reference
379+0.562539577, +0.456788450, +0.606703222, +0.841019630
380+0.456788450, +1.35570371, +1.46490860, +1.91781235
381+0.606703222, +1.46490860, +1.94498825, +2.57880640
382+0.841019630, +1.91781235, +2.57880640, +3.71123862
383
384
385dim = 2; ndim = getUnifRand(1, 5); nsamA = getUnifRand(ndim + 1_IK, ndim * 2_IK); nsamB = getUnifRand(1_IK, nsamA)
386[ndim, nsamA]
387+5, +10
388sampleA = getUnifRand(-1., +1., ndim, nsamA) ! Generate a non-singular sample.
389sampleA
390+0.546100616, +0.815762639, +0.808750272, -0.674964428, +0.480329394, +0.375563502, +0.455841899, +0.695978999, -0.864295959, -0.494003773
391+0.209347248, -0.438059688, +0.698264718, +0.219759226, -0.790010929, +0.675023437, +0.748577476, +0.186113477, +0.433472991, +0.826915622
392-0.715224147, -0.872349977, +0.711754441, -0.973014832E-1, +0.393944860, -0.741891026, +0.255285025, -0.643513203, -0.433871269, -0.868891239
393+0.134205818E-1, +0.246544838, +0.623852015, -0.773234963, +0.454962730, -0.779368043, -0.861263871, -0.580057502, +0.254970789, -0.392792344
394+0.112079859, -0.631906033, +0.981932878, +0.250630140, -0.478811264, -0.816925526, -0.329329491, +0.443502426, +0.442672968, -0.200255394
395covA = getCov(sampleA, dim)
396covA
397+0.366820902, -0.859026238E-1, +0.568520129E-1, +0.722692460E-1, -0.442662053E-1
398-0.859026238E-1, +0.255109966, -0.105070015E-1, -0.119543865, +0.792833343E-1
399+0.568520129E-1, -0.105070015E-1, +0.300944299, +0.896055251E-1, +0.110730253
400+0.722692460E-1, -0.119543865, +0.896055251E-1, +0.283851922, +0.860655904E-1
401-0.442662053E-1, +0.792833343E-1, +0.110730253, +0.860655904E-1, +0.287159026
402meanA = getMean(sampleA, dim)
403meanA
404+0.214506343, +0.276940346, -0.301205814, -0.179296583, -0.226409435E-1
405sampleB = spread([(idim, idim = 1, ndim)], dim, nsamB) ! Generate a singular sample.
406sampleB
407+1.00000000, +1.00000000, +1.00000000, +1.00000000, +1.00000000, +1.00000000, +1.00000000, +1.00000000, +1.00000000
408+2.00000000, +2.00000000, +2.00000000, +2.00000000, +2.00000000, +2.00000000, +2.00000000, +2.00000000, +2.00000000
409+3.00000000, +3.00000000, +3.00000000, +3.00000000, +3.00000000, +3.00000000, +3.00000000, +3.00000000, +3.00000000
410+4.00000000, +4.00000000, +4.00000000, +4.00000000, +4.00000000, +4.00000000, +4.00000000, +4.00000000, +4.00000000
411+5.00000000, +5.00000000, +5.00000000, +5.00000000, +5.00000000, +5.00000000, +5.00000000, +5.00000000, +5.00000000
412meanB = getMean(sampleB, dim)
413meanB
414+1.00000000, +2.00000000, +3.00000000, +4.00000000, +5.00000000
415sample = reshape([sampleA, sampleB], [ndim, nsamA + nsamB])
416sample
417+0.546100616, +0.815762639, +0.808750272, -0.674964428, +0.480329394, +0.375563502, +0.455841899, +0.695978999, -0.864295959, -0.494003773, +1.00000000, +1.00000000, +1.00000000, +1.00000000, +1.00000000, +1.00000000, +1.00000000, +1.00000000, +1.00000000
418+0.209347248, -0.438059688, +0.698264718, +0.219759226, -0.790010929, +0.675023437, +0.748577476, +0.186113477, +0.433472991, +0.826915622, +2.00000000, +2.00000000, +2.00000000, +2.00000000, +2.00000000, +2.00000000, +2.00000000, +2.00000000, +2.00000000
419-0.715224147, -0.872349977, +0.711754441, -0.973014832E-1, +0.393944860, -0.741891026, +0.255285025, -0.643513203, -0.433871269, -0.868891239, +3.00000000, +3.00000000, +3.00000000, +3.00000000, +3.00000000, +3.00000000, +3.00000000, +3.00000000, +3.00000000
420+0.134205818E-1, +0.246544838, +0.623852015, -0.773234963, +0.454962730, -0.779368043, -0.861263871, -0.580057502, +0.254970789, -0.392792344, +4.00000000, +4.00000000, +4.00000000, +4.00000000, +4.00000000, +4.00000000, +4.00000000, +4.00000000, +4.00000000
421+0.112079859, -0.631906033, +0.981932878, +0.250630140, -0.478811264, -0.816925526, -0.329329491, +0.443502426, +0.442672968, -0.200255394, +5.00000000, +5.00000000, +5.00000000, +5.00000000, +5.00000000, +5.00000000, +5.00000000, +5.00000000, +5.00000000
422cov = getCov(sample, dim)
423cov
424+0.346886426, +0.292213887, +0.676395476, +0.856465697, +0.960283101
425+0.292213887, +0.874446094, +1.41257393, +1.73238933, +2.19931221
426+0.676395476, +1.41257393, +2.87533450, +3.48678470, +4.19198942
427+0.856465697, +1.73238933, +3.48678470, +4.50393057, +5.27853823
428+0.960283101, +2.19931221, +4.19198942, +5.27853823, +6.44039917
429mean = getMean(sample, dim)
430mean
431+0.586582303, +1.09312654, +1.26252329, +1.80037034, +2.35650468
432call setCovUpdated(covA, meanA - meanB, real(nsamA, TKG) / real(nsamA + nsamB, TKG), uppDia)
433covA
434+0.346886456, +0.292213917, +0.676395416, +0.856465816, +0.960283041
435-0.859026238E-1, +0.874445975, +1.41257453, +1.73238957, +2.19931221
436+0.568520129E-1, -0.105070015E-1, +2.87533498, +3.48678613, +4.19198990
437+0.722692460E-1, -0.119543865, +0.896055251E-1, +4.50392962, +5.27853727
438-0.442662053E-1, +0.792833343E-1, +0.110730253, +0.860655904E-1, +6.44039774
439cov ! reference
440+0.346886426, +0.292213887, +0.676395476, +0.856465697, +0.960283101
441+0.292213887, +0.874446094, +1.41257393, +1.73238933, +2.19931221
442+0.676395476, +1.41257393, +2.87533450, +3.48678470, +4.19198942
443+0.856465697, +1.73238933, +3.48678470, +4.50393057, +5.27853823
444+0.960283101, +2.19931221, +4.19198942, +5.27853823, +6.44039917
445
446
447dim = 2; ndim = getUnifRand(1, 5); nsamA = getUnifRand(ndim + 1_IK, ndim * 2_IK); nsamB = getUnifRand(1_IK, nsamA)
448[ndim, nsamA]
449+2, +3
450sampleA = getUnifRand(-1., +1., ndim, nsamA) ! Generate a non-singular sample.
451sampleA
452-0.864516497, +0.310994983, -0.682423353
453-0.979835033, -0.349213600, +0.151518583
454covA = getCov(sampleA, dim)
455covA
456+0.266873926, +0.499864444E-1
457+0.499864444E-1, +0.214264080
458meanA = getMean(sampleA, dim)
459meanA
460-0.411981642, -0.392510027
461sampleB = spread([(idim, idim = 1, ndim)], dim, nsamB) ! Generate a singular sample.
462sampleB
463+1.00000000, +1.00000000, +1.00000000
464+2.00000000, +2.00000000, +2.00000000
465meanB = getMean(sampleB, dim)
466meanB
467+1.00000000, +2.00000000
468sample = reshape([sampleA, sampleB], [ndim, nsamA + nsamB])
469sample
470-0.864516497, +0.310994983, -0.682423353, +1.00000000, +1.00000000, +1.00000000
471-0.979835033, -0.349213600, +0.151518583, +2.00000000, +2.00000000, +2.00000000
472cov = getCov(sample, dim)
473cov
474+0.631859779, +0.869538307
475+0.869538307, +1.53815818
476mean = getMean(sample, dim)
477mean
478+0.294009209, +0.803744972
479call setCovUpdated(covA, meanA - meanB, real(nsamA, TKG) / real(nsamA + nsamB, TKG), uppDia)
480covA
481+0.631859958, +0.869538248
482+0.499864444E-1, +1.53815806
483cov ! reference
484+0.631859779, +0.869538307
485+0.869538307, +1.53815818
486
487
488dim = 2; ndim = getUnifRand(1, 5); nsamA = getUnifRand(ndim + 1_IK, ndim * 2_IK); nsamB = getUnifRand(1_IK, nsamA)
489[ndim, nsamA]
490+1, +2
491sampleA = getUnifRand(-1., +1., ndim, nsamA) ! Generate a non-singular sample.
492sampleA
493+0.857347250E-1, -0.264907002
494covA = getCov(sampleA, dim)
495covA
496+0.307374056E-1
497meanA = getMean(sampleA, dim)
498meanA
499-0.895861387E-1
500sampleB = spread([(idim, idim = 1, ndim)], dim, nsamB) ! Generate a singular sample.
501sampleB
502+1.00000000
503meanB = getMean(sampleB, dim)
504meanB
505+1.00000000
506sample = reshape([sampleA, sampleB], [ndim, nsamA + nsamB])
507sample
508+0.857347250E-1, -0.264907002, +1.00000000
509cov = getCov(sample, dim)
510cov
511+0.284313381
512mean = getMean(sample, dim)
513mean
514+0.273609251
515call setCovUpdated(covA, meanA - meanB, real(nsamA, TKG) / real(nsamA + nsamB, TKG), uppDia)
516covA
517+0.284313351
518cov ! reference
519+0.284313381
520
521
Test:
test_pm_sampleCov


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:
Amir Shahmoradi, April 21, 2017, 1:54 AM, Institute for Computational Engineering and Sciences (ICES), The University of Texas Austin

Definition at line 8553 of file pm_sampleCov.F90.


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