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

Return the covariance and mean of a sample that results from the merger of two separate (potentially weighted) non-singular \(A\) and singular \(B\) samples.
More...

Detailed Description

Return the covariance and mean of a sample that results from the merger of two separate (potentially weighted) non-singular \(A\) and singular \(B\) samples.

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

Note
The input and output variances of this generic interface are all biased variances.
A biased covariance 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 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),
containing the biased covariance of the first sample that must be merged with the second sample.
[in]meanA: The input object of the same type and kind as the input argument covA of size size(covA, 1), containing the mean of the first sample that must be merged with the mean of the second sample meanB.
[in]meanB: The input or input/output object of the same type and kind and rank as the input argument covA of size size(covA, 1), containing the mean of the second sample that must be merged with the mean of the first sample meanA.
If the input argument mean is missing, then meanB contains the updated mean of the merged sample on return.
Otherwise, the contents of meanB remain intact upon return.
[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 cov, and covA matrices must be accessed and/or manipulated.
  2. The constant uppDia, implying that only the upper-diagonal subset of the input cov, 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 setCovMeanUpdated(covA(1:ndim, 1:ndim), meanA(1:ndim), meanB(1:ndim), fracA, subset)
Return the covariance and mean of a sample that results from the merger of two separate (potentially ...
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(meanB) == shape(covA)) must hold for the corresponding input arguments.
The condition all(size(meanA) == 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
setCovMerged
setCovMeanUpdated
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 setCovMeanUpdated(covA, meanA, meanB, real(nsamA, TKG) / real(nsamA + nsamB, TKG), uppDia)")
72 call setCovMeanUpdated(covA, meanA, meanB, real(nsamA, TKG) / real(nsamA + nsamB, TKG), uppDia)
73 call disp%show("meanA")
74 call disp%show( meanA )
75 call disp%show("mean ! reference")
76 call disp%show( mean )
77 call disp%show("covA")
78 call disp%show( covA )
79 call disp%show("cov ! reference")
80 call disp%show( cov )
81 call disp%skip()
82 end do
83 end block
84
85end 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+4, +7
10sampleA = getUnifRand(-1., +1., ndim, nsamA) ! Generate a non-singular sample.
11sampleA
12-0.724493146, +0.862805367, +0.280618668E-1, +0.369733095, -0.501728892, +0.328645229, +0.795634508
13-0.548898220, +0.118338346, -0.560021996, +0.920188427, -0.690604806, +0.213442564, -0.856673717E-1
14+0.574165225, +0.832754016, +0.238830686, +0.662994981, -0.692979097E-1, -0.516011596, -0.466838717
15+0.452611089, +0.561205149E-1, +0.840897679, +0.115975618, -0.819746137, +0.600364923, +0.875329733
16covA = getCov(sampleA, dim)
17covA
18+0.315400332, +0.182511583, -0.228406377E-1, +0.105837122
19+0.182511583, +0.278316408, +0.501574650E-1, +0.293136500E-1
20-0.228406377E-1, +0.501574650E-1, +0.254739910, -0.654489994E-1
21+0.105837122, +0.293136500E-1, -0.654489994E-1, +0.297741622
22meanA = getMean(sampleA, dim)
23meanA
24+0.165522575, -0.904604420E-1, +0.179513842, +0.303079069
25sampleB = spread([(idim, idim = 1, ndim)], dim, nsamB) ! Generate a singular sample.
26sampleB
27+1.00000000, +1.00000000, +1.00000000, +1.00000000
28+2.00000000, +2.00000000, +2.00000000, +2.00000000
29+3.00000000, +3.00000000, +3.00000000, +3.00000000
30+4.00000000, +4.00000000, +4.00000000, +4.00000000
31meanB = getMean(sampleB, dim)
32meanB
33+1.00000000, +2.00000000, +3.00000000, +4.00000000
34sample = reshape([sampleA, sampleB], [ndim, nsamA + nsamB])
35sample
36-0.724493146, +0.862805367, +0.280618668E-1, +0.369733095, -0.501728892, +0.328645229, +0.795634508, +1.00000000, +1.00000000, +1.00000000, +1.00000000
37-0.548898220, +0.118338346, -0.560021996, +0.920188427, -0.690604806, +0.213442564, -0.856673717E-1, +2.00000000, +2.00000000, +2.00000000, +2.00000000
38+0.574165225, +0.832754016, +0.238830686, +0.662994981, -0.692979097E-1, -0.516011596, -0.466838717, +3.00000000, +3.00000000, +3.00000000, +3.00000000
39+0.452611089, +0.561205149E-1, +0.840897679, +0.115975618, -0.819746137, +0.600364923, +0.875329733, +4.00000000, +4.00000000, +4.00000000, +4.00000000
40cov = getCov(sample, dim)
41cov
42+0.361849010, +0.519816339, +0.530107141, +0.781234443
43+0.519816339, +1.18835557, +1.39630854, +1.80701363
44+0.530107141, +1.39630854, +2.00296640, +2.37123680
45+0.781234443, +1.80701363, +2.37123680, +3.35213614
46mean = getMean(sample, dim)
47mean
48+0.468968928, +0.669707000, +1.20514512, +1.64741397
49call setCovMeanUpdated(covA, meanA, meanB, real(nsamA, TKG) / real(nsamA + nsamB, TKG), uppDia)
50meanA
51+0.468968928, +0.669707000, +1.20514524, +1.64741397
52mean ! reference
53+0.468968928, +0.669707000, +1.20514512, +1.64741397
54covA
55+0.361848742, +0.519816279, +0.530107141, +0.781234503
56+0.182511583, +1.18835592, +1.39630866, +1.80701351
57-0.228406377E-1, +0.501574650E-1, +2.00296640, +2.37123632
58+0.105837122, +0.293136500E-1, -0.654489994E-1, +3.35213542
59cov ! reference
60+0.361849010, +0.519816339, +0.530107141, +0.781234443
61+0.519816339, +1.18835557, +1.39630854, +1.80701363
62+0.530107141, +1.39630854, +2.00296640, +2.37123680
63+0.781234443, +1.80701363, +2.37123680, +3.35213614
64
65
66dim = 2; ndim = getUnifRand(1, 5); nsamA = getUnifRand(ndim + 1_IK, ndim * 2_IK); nsamB = getUnifRand(1_IK, nsamA)
67[ndim, nsamA]
68+5, +8
69sampleA = getUnifRand(-1., +1., ndim, nsamA) ! Generate a non-singular sample.
70sampleA
71-0.541354060, +0.419566035, +0.680793524, +0.926667452, -0.500715017, +0.970036745, -0.584456444, +0.700276732
72+0.809617043E-1, +0.380273581, -0.224937916, -0.539620876, +0.715513945, +0.691724300, +0.996623039, +0.377838850
73-0.858645558, -0.212482333, -0.801915646, -0.115464687, +0.744967818, +0.422034860, +0.965401173, +0.711405754
74+0.522912860, +0.355256915, +0.801435471, +0.963045359, +0.592142463, -0.715792298, -0.446122050, +0.828020573E-1
75-0.460367441, +0.607446074, -0.645457745, +0.789445281, -0.641710758, -0.351844549, -0.921537280, +0.131766796
76covA = getCov(sampleA, dim)
77covA
78+0.409865320, -0.148019806, -0.660416484E-1, +0.923618674E-2, +0.224171653
79-0.148019806, +0.231452376, +0.235413015, -0.209389985, -0.149495393
80-0.660416484E-1, +0.235413015, +0.439820886, -0.217697114, -0.712807775E-1
81+0.923618674E-2, -0.209389985, -0.217697114, +0.307175368, +0.114255361
82+0.224171653, -0.149495393, -0.712807775E-1, +0.114255361, +0.343074262
83meanA = getMean(sampleA, dim)
84meanA
85+0.258851886, +0.309797078, +0.106912673, +0.269460112, -0.186532453
86sampleB = spread([(idim, idim = 1, ndim)], dim, nsamB) ! Generate a singular sample.
87sampleB
88+1.00000000, +1.00000000, +1.00000000
89+2.00000000, +2.00000000, +2.00000000
90+3.00000000, +3.00000000, +3.00000000
91+4.00000000, +4.00000000, +4.00000000
92+5.00000000, +5.00000000, +5.00000000
93meanB = getMean(sampleB, dim)
94meanB
95+1.00000000, +2.00000000, +3.00000000, +4.00000000, +5.00000000
96sample = reshape([sampleA, sampleB], [ndim, nsamA + nsamB])
97sample
98-0.541354060, +0.419566035, +0.680793524, +0.926667452, -0.500715017, +0.970036745, -0.584456444, +0.700276732, +1.00000000, +1.00000000, +1.00000000
99+0.809617043E-1, +0.380273581, -0.224937916, -0.539620876, +0.715513945, +0.691724300, +0.996623039, +0.377838850, +2.00000000, +2.00000000, +2.00000000
100-0.858645558, -0.212482333, -0.801915646, -0.115464687, +0.744967818, +0.422034860, +0.965401173, +0.711405754, +3.00000000, +3.00000000, +3.00000000
101+0.522912860, +0.355256915, +0.801435471, +0.963045359, +0.592142463, -0.715792298, -0.446122050, +0.828020573E-1, +4.00000000, +4.00000000, +4.00000000
102-0.460367441, +0.607446074, -0.645457745, +0.789445281, -0.641710758, -0.351844549, -0.921537280, +0.131766796, +5.00000000, +5.00000000, +5.00000000
103cov = getCov(sample, dim)
104cov
105+0.407035917, +0.140816733, +0.377266467, +0.555123508, +0.925477862
106+0.140816733, +0.734964192, +1.14110792, +1.09836817, +1.63004482
107+0.377266467, +1.14110792, +1.98002601, +1.98239088, +2.92437553
108+0.555123508, +1.09836817, +1.98239088, +2.98378277, +3.92082667
109+0.925477862, +1.63004482, +2.92437553, +3.92082667, +5.58506918
110mean = getMean(sample, dim)
111mean
112+0.460983217, +0.770761490, +0.895936489, +1.28688014, +1.22797644
113call setCovMeanUpdated(covA, meanA, meanB, real(nsamA, TKG) / real(nsamA + nsamB, TKG), uppDia)
114meanA
115+0.460983157, +0.770761490, +0.895936430, +1.28688002, +1.22797632
116mean ! reference
117+0.460983217, +0.770761490, +0.895936489, +1.28688014, +1.22797644
118covA
119+0.407036036, +0.140816793, +0.377266794, +0.555123627, +0.925477982
120-0.148019806, +0.734964192, +1.14110792, +1.09836793, +1.63004470
121-0.660416484E-1, +0.235413015, +1.98002601, +1.98239088, +2.92437577
122+0.923618674E-2, -0.209389985, -0.217697114, +2.98378253, +3.92082667
123+0.224171653, -0.149495393, -0.712807775E-1, +0.114255361, +5.58506870
124cov ! reference
125+0.407035917, +0.140816733, +0.377266467, +0.555123508, +0.925477862
126+0.140816733, +0.734964192, +1.14110792, +1.09836817, +1.63004482
127+0.377266467, +1.14110792, +1.98002601, +1.98239088, +2.92437553
128+0.555123508, +1.09836817, +1.98239088, +2.98378277, +3.92082667
129+0.925477862, +1.63004482, +2.92437553, +3.92082667, +5.58506918
130
131
132dim = 2; ndim = getUnifRand(1, 5); nsamA = getUnifRand(ndim + 1_IK, ndim * 2_IK); nsamB = getUnifRand(1_IK, nsamA)
133[ndim, nsamA]
134+3, +4
135sampleA = getUnifRand(-1., +1., ndim, nsamA) ! Generate a non-singular sample.
136sampleA
137-0.184733868E-1, +0.307175398, +0.402213335, +0.220773578
138-0.233609915, +0.995969057, -0.790747404, -0.717688680
139+0.841259956E-2, +0.153938770, -0.875600576E-1, +0.368371487
140covA = getCov(sampleA, dim)
141covA
142+0.243550949E-1, +0.951104797E-3, -0.194174796E-2
143+0.951104797E-3, +0.511932194, +0.971830264E-2
144-0.194174796E-2, +0.971830264E-2, +0.295084789E-1
145meanA = getMean(sampleA, dim)
146meanA
147+0.227922231, -0.186519235, +0.110790700
148sampleB = spread([(idim, idim = 1, ndim)], dim, nsamB) ! Generate a singular sample.
149sampleB
150+1.00000000, +1.00000000
151+2.00000000, +2.00000000
152+3.00000000, +3.00000000
153meanB = getMean(sampleB, dim)
154meanB
155+1.00000000, +2.00000000, +3.00000000
156sample = reshape([sampleA, sampleB], [ndim, nsamA + nsamB])
157sample
158-0.184733868E-1, +0.307175398, +0.402213335, +0.220773578, +1.00000000, +1.00000000
159-0.233609915, +0.995969057, -0.790747404, -0.717688680, +2.00000000, +2.00000000
160+0.841259956E-2, +0.153938770, -0.875600576E-1, +0.368371487, +3.00000000, +3.00000000
161cov = getCov(sample, dim)
162cov
163+0.148704290, +0.375781387, +0.494415283
164+0.375781387, +1.40370309, +1.41032600
165+0.494415283, +1.41032600, +1.87467945
166mean = getMean(sample, dim)
167mean
168+0.485281467, +0.542320490, +1.07386053
169call setCovMeanUpdated(covA, meanA, meanB, real(nsamA, TKG) / real(nsamA + nsamB, TKG), uppDia)
170meanA
171+0.485281467, +0.542320490, +1.07386041
172mean ! reference
173+0.485281467, +0.542320490, +1.07386053
174covA
175+0.148704320, +0.375781357, +0.494415343
176+0.951104797E-3, +1.40370274, +1.41032577
177-0.194174796E-2, +0.971830264E-2, +1.87467897
178cov ! reference
179+0.148704290, +0.375781387, +0.494415283
180+0.375781387, +1.40370309, +1.41032600
181+0.494415283, +1.41032600, +1.87467945
182
183
184dim = 2; ndim = getUnifRand(1, 5); nsamA = getUnifRand(ndim + 1_IK, ndim * 2_IK); nsamB = getUnifRand(1_IK, nsamA)
185[ndim, nsamA]
186+1, +2
187sampleA = getUnifRand(-1., +1., ndim, nsamA) ! Generate a non-singular sample.
188sampleA
189+0.178900599, -0.138574839
190covA = getCov(sampleA, dim)
191covA
192+0.251976643E-1
193meanA = getMean(sampleA, dim)
194meanA
195+0.201628804E-1
196sampleB = spread([(idim, idim = 1, ndim)], dim, nsamB) ! Generate a singular sample.
197sampleB
198+1.00000000, +1.00000000
199meanB = getMean(sampleB, dim)
200meanB
201+1.00000000
202sample = reshape([sampleA, sampleB], [ndim, nsamA + nsamB])
203sample
204+0.178900599, -0.138574839, +1.00000000, +1.00000000
205cov = getCov(sample, dim)
206cov
207+0.252619058
208mean = getMean(sample, dim)
209mean
210+0.510081410
211call setCovMeanUpdated(covA, meanA, meanB, real(nsamA, TKG) / real(nsamA + nsamB, TKG), uppDia)
212meanA
213+0.510081410
214mean ! reference
215+0.510081410
216covA
217+0.252619028
218cov ! reference
219+0.252619058
220
221
222dim = 2; ndim = getUnifRand(1, 5); nsamA = getUnifRand(ndim + 1_IK, ndim * 2_IK); nsamB = getUnifRand(1_IK, nsamA)
223[ndim, nsamA]
224+1, +2
225sampleA = getUnifRand(-1., +1., ndim, nsamA) ! Generate a non-singular sample.
226sampleA
227-0.242768884, -0.332967758
228covA = getCov(sampleA, dim)
229covA
230+0.203395914E-2
231meanA = getMean(sampleA, dim)
232meanA
233-0.287868321
234sampleB = spread([(idim, idim = 1, ndim)], dim, nsamB) ! Generate a singular sample.
235sampleB
236+1.00000000, +1.00000000
237meanB = getMean(sampleB, dim)
238meanB
239+1.00000000
240sample = reshape([sampleA, sampleB], [ndim, nsamA + nsamB])
241sample
242-0.242768884, -0.332967758, +1.00000000, +1.00000000
243cov = getCov(sample, dim)
244cov
245+0.415668130
246mean = getMean(sample, dim)
247mean
248+0.356065840
249call setCovMeanUpdated(covA, meanA, meanB, real(nsamA, TKG) / real(nsamA + nsamB, TKG), uppDia)
250meanA
251+0.356065840
252mean ! reference
253+0.356065840
254covA
255+0.415668130
256cov ! reference
257+0.415668130
258
259
260dim = 2; ndim = getUnifRand(1, 5); nsamA = getUnifRand(ndim + 1_IK, ndim * 2_IK); nsamB = getUnifRand(1_IK, nsamA)
261[ndim, nsamA]
262+4, +6
263sampleA = getUnifRand(-1., +1., ndim, nsamA) ! Generate a non-singular sample.
264sampleA
265-0.985509992, +0.418117881, +0.898956418, -0.158331871, -0.125674844, -0.941638589
266-0.135289431E-1, -0.975535393, +0.110741377, -0.305778027, +0.788400888, +0.811418533
267-0.274427295, +0.295702815, +0.839575291, -0.233001947, -0.254423618, -0.376750946
268+0.581861615, +0.278476119, +0.826095939, +0.642797232, -0.434192777, +0.879514217
269covA = getCov(sampleA, dim)
270covA
271+0.458081901, -0.174631238, +0.261994123, -0.293862130E-1
272-0.174631238, +0.384798110, -0.104432218, -0.342513546E-1
273+0.261994123, -0.104432218, +0.188099623, +0.411855355E-1
274-0.293862130E-1, -0.342513546E-1, +0.411855355E-1, +0.198463306
275meanA = getMean(sampleA, dim)
276meanA
277-0.149013504, +0.692864060E-1, -0.554283499E-3, +0.462425411
278sampleB = spread([(idim, idim = 1, ndim)], dim, nsamB) ! Generate a singular sample.
279sampleB
280+1.00000000, +1.00000000
281+2.00000000, +2.00000000
282+3.00000000, +3.00000000
283+4.00000000, +4.00000000
284meanB = getMean(sampleB, dim)
285meanB
286+1.00000000, +2.00000000, +3.00000000, +4.00000000
287sample = reshape([sampleA, sampleB], [ndim, nsamA + nsamB])
288sample
289-0.985509992, +0.418117881, +0.898956418, -0.158331871, -0.125674844, -0.941638589, +1.00000000, +1.00000000
290-0.135289431E-1, -0.975535393, +0.110741377, -0.305778027, +0.788400888, +0.811418533, +2.00000000, +2.00000000
291-0.274427295, +0.295702815, +0.839575291, -0.233001947, -0.254423618, -0.376750946, +3.00000000, +3.00000000
292+0.581861615, +0.278476119, +0.826095939, +0.642797232, -0.434192777, +0.879514217, +4.00000000, +4.00000000
293cov = getCov(sample, dim)
294cov
295+0.591105103, +0.284979582, +0.842935205, +0.740095496
296+0.284979582, +0.987533927, +1.00790286, +1.25494456
297+0.842935205, +1.00790286, +1.82919848, +2.02114296
298+0.740095496, +1.25494456, +2.02114296, +2.49530411
299mean = getMean(sample, dim)
300mean
301+0.138239875, +0.551964819, +0.749584317, +1.34681904
302call setCovMeanUpdated(covA, meanA, meanB, real(nsamA, TKG) / real(nsamA + nsamB, TKG), uppDia)
303meanA
304+0.138239875, +0.551964819, +0.749584258, +1.34681904
305mean ! reference
306+0.138239875, +0.551964819, +0.749584317, +1.34681904
307covA
308+0.591104925, +0.284979582, +0.842935145, +0.740095556
309-0.174631238, +0.987533927, +1.00790286, +1.25494456
310+0.261994123, -0.104432218, +1.82919836, +2.02114248
311-0.293862130E-1, -0.342513546E-1, +0.411855355E-1, +2.49530387
312cov ! reference
313+0.591105103, +0.284979582, +0.842935205, +0.740095496
314+0.284979582, +0.987533927, +1.00790286, +1.25494456
315+0.842935205, +1.00790286, +1.82919848, +2.02114296
316+0.740095496, +1.25494456, +2.02114296, +2.49530411
317
318
319dim = 2; ndim = getUnifRand(1, 5); nsamA = getUnifRand(ndim + 1_IK, ndim * 2_IK); nsamB = getUnifRand(1_IK, nsamA)
320[ndim, nsamA]
321+1, +2
322sampleA = getUnifRand(-1., +1., ndim, nsamA) ! Generate a non-singular sample.
323sampleA
324-0.553773165, -0.192247510
325covA = getCov(sampleA, dim)
326covA
327+0.326751992E-1
328meanA = getMean(sampleA, dim)
329meanA
330-0.373010337
331sampleB = spread([(idim, idim = 1, ndim)], dim, nsamB) ! Generate a singular sample.
332sampleB
333+1.00000000
334meanB = getMean(sampleB, dim)
335meanB
336+1.00000000
337sample = reshape([sampleA, sampleB], [ndim, nsamA + nsamB])
338sample
339-0.553773165, -0.192247510, +1.00000000
340cov = getCov(sample, dim)
341cov
342+0.440707296
343mean = getMean(sample, dim)
344mean
345+0.846597776E-1
346call setCovMeanUpdated(covA, meanA, meanB, real(nsamA, TKG) / real(nsamA + nsamB, TKG), uppDia)
347meanA
348+0.846597552E-1
349mean ! reference
350+0.846597776E-1
351covA
352+0.440707356
353cov ! reference
354+0.440707296
355
356
357dim = 2; ndim = getUnifRand(1, 5); nsamA = getUnifRand(ndim + 1_IK, ndim * 2_IK); nsamB = getUnifRand(1_IK, nsamA)
358[ndim, nsamA]
359+2, +3
360sampleA = getUnifRand(-1., +1., ndim, nsamA) ! Generate a non-singular sample.
361sampleA
362+0.995398641, +0.349297881, +0.108977675
363-0.540418625, -0.535397530, -0.226763487E-1
364covA = getCov(sampleA, dim)
365covA
366+0.140104651, -0.650443360E-1
367-0.650443360E-1, +0.589961484E-1
368meanA = getMean(sampleA, dim)
369meanA
370+0.484558076, -0.366164178
371sampleB = spread([(idim, idim = 1, ndim)], dim, nsamB) ! Generate a singular sample.
372sampleB
373+1.00000000, +1.00000000
374+2.00000000, +2.00000000
375meanB = getMean(sampleB, dim)
376meanB
377+1.00000000, +2.00000000
378sample = reshape([sampleA, sampleB], [ndim, nsamA + nsamB])
379sample
380+0.995398641, +0.349297881, +0.108977675, +1.00000000, +1.00000000
381-0.540418625, -0.535397530, -0.226763487E-1, +2.00000000, +2.00000000
382cov = getCov(sample, dim)
383cov
384+0.147826120, +0.253682226
385+0.253682226, +1.37909341
386mean = getMean(sample, dim)
387mean
388+0.690734863, +0.580301464
389call setCovMeanUpdated(covA, meanA, meanB, real(nsamA, TKG) / real(nsamA + nsamB, TKG), uppDia)
390meanA
391+0.690734863, +0.580301404
392mean ! reference
393+0.690734863, +0.580301464
394covA
395+0.147826076, +0.253682196
396-0.650443360E-1, +1.37909353
397cov ! reference
398+0.147826120, +0.253682226
399+0.253682226, +1.37909341
400
401
402dim = 2; ndim = getUnifRand(1, 5); nsamA = getUnifRand(ndim + 1_IK, ndim * 2_IK); nsamB = getUnifRand(1_IK, nsamA)
403[ndim, nsamA]
404+5, +10
405sampleA = getUnifRand(-1., +1., ndim, nsamA) ! Generate a non-singular sample.
406sampleA
407-0.386622190, -0.219056726, -0.277997851, +0.398256302, -0.695959330E-1, -0.429108620, -0.244629979, +0.299552083, +0.569471359, -0.212445974
408+0.581753969, -0.300965667, -0.131580114, -0.969779491E-2, +0.959468484, -0.142873168, +0.926055193, +0.746746063E-1, -0.585629821, +0.263986111
409-0.561352372, -0.569215298, +0.965556860, +0.999942899, +0.131845474E-3, -0.823703647, +0.388041854, +0.790804863, +0.562757969, +0.683697701
410-0.625701904, -0.511930585, -0.749570489, -0.787944913, -0.747785211, +0.928250551, +0.204727173, +0.281444788E-1, -0.268698573, +0.819108486
411+0.105562210E-1, +0.352396727, +0.780585408, -0.182500601, +0.202603698, -0.715684056, -0.835976243, +0.744940758, +0.966921568, +0.204016805
412covA = getCov(sampleA, dim)
413covA
414+0.110859863, -0.631932840E-1, +0.128158838, -0.564257018E-1, +0.944412276E-1
415-0.631932840E-1, +0.239583775, -0.303308964E-1, -0.108631132E-1, -0.138498098
416+0.128158838, -0.303308964E-1, +0.421615213, -0.706196055E-1, +0.153028190
417-0.564257018E-1, -0.108631132E-1, -0.706196055E-1, +0.375007421, -0.142555088
418+0.944412276E-1, -0.138498098, +0.153028190, -0.142555088, +0.331708431
419meanA = getMean(sampleA, dim)
420meanA
421-0.572177544E-1, +0.163519189, +0.243666276, -0.171140105, +0.152786031
422sampleB = spread([(idim, idim = 1, ndim)], dim, nsamB) ! Generate a singular sample.
423sampleB
424+1.00000000, +1.00000000, +1.00000000, +1.00000000, +1.00000000, +1.00000000, +1.00000000
425+2.00000000, +2.00000000, +2.00000000, +2.00000000, +2.00000000, +2.00000000, +2.00000000
426+3.00000000, +3.00000000, +3.00000000, +3.00000000, +3.00000000, +3.00000000, +3.00000000
427+4.00000000, +4.00000000, +4.00000000, +4.00000000, +4.00000000, +4.00000000, +4.00000000
428+5.00000000, +5.00000000, +5.00000000, +5.00000000, +5.00000000, +5.00000000, +5.00000000
429meanB = getMean(sampleB, dim)
430meanB
431+1.00000000, +2.00000000, +3.00000024, +4.00000000, +5.00000000
432sample = reshape([sampleA, sampleB], [ndim, nsamA + nsamB])
433sample
434-0.386622190, -0.219056726, -0.277997851, +0.398256302, -0.695959330E-1, -0.429108620, -0.244629979, +0.299552083, +0.569471359, -0.212445974, +1.00000000, +1.00000000, +1.00000000, +1.00000000, +1.00000000, +1.00000000, +1.00000000
435+0.581753969, -0.300965667, -0.131580114, -0.969779491E-2, +0.959468484, -0.142873168, +0.926055193, +0.746746063E-1, -0.585629821, +0.263986111, +2.00000000, +2.00000000, +2.00000000, +2.00000000, +2.00000000, +2.00000000, +2.00000000
436-0.561352372, -0.569215298, +0.965556860, +0.999942899, +0.131845474E-3, -0.823703647, +0.388041854, +0.790804863, +0.562757969, +0.683697701, +3.00000000, +3.00000000, +3.00000000, +3.00000000, +3.00000000, +3.00000000, +3.00000000
437-0.625701904, -0.511930585, -0.749570489, -0.787944913, -0.747785211, +0.928250551, +0.204727173, +0.281444788E-1, -0.268698573, +0.819108486, +4.00000000, +4.00000000, +4.00000000, +4.00000000, +4.00000000, +4.00000000, +4.00000000
438+0.105562210E-1, +0.352396727, +0.780585408, -0.182500601, +0.202603698, -0.715684056, -0.835976243, +0.744940758, +0.966921568, +0.204016805, +5.00000000, +5.00000000, +5.00000000, +5.00000000, +5.00000000, +5.00000000, +5.00000000
439cov = getCov(sample, dim)
440cov
441+0.335937053, +0.433101594, +0.781211734, +1.03492677, +1.29679608
442+0.433101594, +0.957839429, +1.20823705, +1.84902620, +2.07467961
443+0.781211734, +1.20823705, +2.08820391, +2.74321342, +3.32613277
444+1.03492677, +1.84902620, +2.74321342, +4.43474054, +4.81333637
445+1.29679608, +2.07467961, +3.32613277, +4.81333637, +5.88606834
446mean = getMean(sample, dim)
447mean
448+0.378107220, +0.919717193, +1.37862718, +1.54638815, +2.14869785
449call setCovMeanUpdated(covA, meanA, meanB, real(nsamA, TKG) / real(nsamA + nsamB, TKG), uppDia)
450meanA
451+0.378107190, +0.919717133, +1.37862718, +1.54638803, +2.14869738
452mean ! reference
453+0.378107220, +0.919717193, +1.37862718, +1.54638815, +2.14869785
454covA
455+0.335937113, +0.433101565, +0.781211674, +1.03492689, +1.29679668
456-0.631932840E-1, +0.957839370, +1.20823729, +1.84902620, +2.07467937
457+0.128158838, -0.303308964E-1, +2.08820415, +2.74321318, +3.32613373
458-0.564257018E-1, -0.108631132E-1, -0.706196055E-1, +4.43474054, +4.81333637
459+0.944412276E-1, -0.138498098, +0.153028190, -0.142555088, +5.88606977
460cov ! reference
461+0.335937053, +0.433101594, +0.781211734, +1.03492677, +1.29679608
462+0.433101594, +0.957839429, +1.20823705, +1.84902620, +2.07467961
463+0.781211734, +1.20823705, +2.08820391, +2.74321342, +3.32613277
464+1.03492677, +1.84902620, +2.74321342, +4.43474054, +4.81333637
465+1.29679608, +2.07467961, +3.32613277, +4.81333637, +5.88606834
466
467
468dim = 2; ndim = getUnifRand(1, 5); nsamA = getUnifRand(ndim + 1_IK, ndim * 2_IK); nsamB = getUnifRand(1_IK, nsamA)
469[ndim, nsamA]
470+2, +4
471sampleA = getUnifRand(-1., +1., ndim, nsamA) ! Generate a non-singular sample.
472sampleA
473-0.416366339, -0.981516719, +0.352468729, +0.313314080
474-0.747122169, +0.351686478, +0.366575718, +0.905455470
475covA = getCov(sampleA, dim)
476covA
477+0.306285799, +0.134806946
478+0.134806946, +0.360999346
479meanA = getMean(sampleA, dim)
480meanA
481-0.183025062, +0.219148874
482sampleB = spread([(idim, idim = 1, ndim)], dim, nsamB) ! Generate a singular sample.
483sampleB
484+1.00000000
485+2.00000000
486meanB = getMean(sampleB, dim)
487meanB
488+1.00000000, +2.00000000
489sample = reshape([sampleA, sampleB], [ndim, nsamA + nsamB])
490sample
491-0.416366339, -0.981516719, +0.352468729, +0.313314080, +1.00000000
492-0.747122169, +0.351686478, +0.366575718, +0.905455470, +2.00000000
493cov = getCov(sample, dim)
494cov
495+0.468956381, +0.444932222
496+0.444932222, +0.796228409
497mean = getMean(sample, dim)
498mean
499+0.535799526E-1, +0.575319111
500call setCovMeanUpdated(covA, meanA, meanB, real(nsamA, TKG) / real(nsamA + nsamB, TKG), uppDia)
501meanA
502+0.535799414E-1, +0.575319052
503mean ! reference
504+0.535799526E-1, +0.575319111
505covA
506+0.468956381, +0.444932222
507+0.134806946, +0.796228409
508cov ! reference
509+0.468956381, +0.444932222
510+0.444932222, +0.796228409
511
512
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 at Austin

Definition at line 8922 of file pm_sampleCov.F90.


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