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

Generate and return a random upper and lower Cholesky factorization.
More...

Detailed Description

Generate and return a random upper and lower Cholesky factorization.

See the documentation of pm_distChol for details.
See also setCholRand for generating only the upper or lower subset of the Cholesky factor.

Parameters
[in]mold: The input scalar 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),
whose type and kind determines the type and kind of the output rand.
The value of mold is ignored entirely within the algorithm.
[in]ndim: The input positive scalar of type integer of default kind IK, representing the rank of the matrix (the number of dimensions) of shape (ndim, ndim).
[in]subset: The input scalar constant that can be any of the following:
  1. the constant uppDia or an object of type uppDia_type implying that the upper-diagonal triangular block of the argument rand must be used while the lower subset is not referenced.
  2. the constant lowDia or an object of type lowDia_type implying that the lower-diagonal triangular block of the argument rand must be used while the upper subset is not referenced.
This argument is merely a convenience to differentiate the different procedure functionalities within this generic interface.
Beware that the oppsite subset will not be set to zero explicitly and it is the user's responsibility to ensure it.
The generic interface getCholRand can be used to generate random Cholesky factors whose complementary subset elements are all set to zero.
Returns
rand : The output matrix of shape (1:ndim, 1:ndim) of the same type and kind as the input argument mold, containing an upper or lower Cholesky factorization as specified by the input subset.


Possible calling interfaces

rand(1:ndim, 1:ndim) = getCholRand(mold, ndim, subset)
Generate and return a random upper and lower Cholesky factorization.
This module contains classes and procedures for generating random upper or lower Cholesky factor tria...
Definition: pm_distChol.F90:43
See also
getCovRand
setCovRand
getCholRand
setCholRand


Example usage

1program example
2
3 use pm_kind, only: SK, IK, LK
4 use pm_io, only: display_type
5 use pm_container, only: csp_type
6 use pm_distUnif, only: getUnifRand
8 use pm_distChol, only: getCholRand, uppDia, lowDia, subset_type
9
10 implicit none
11
12 integer(IK) :: isub, itry, ndim
13
14 type(csp_type) :: subset(2)
15
16 type(display_type) :: disp
17 disp = display_type(file = "main.out.F90")
18
19 subset = [csp_type(uppDia), csp_type(lowDia)]
20 do isub = 1, size(subset)
21
22 block
23 use pm_kind, only: TKG => RKS ! all real kinds are supported.
24 real(TKG), allocatable :: rand(:,:), cov(:,:)
25 real(TKG) :: mold
26 do itry = 1, 5
27 call disp%skip()
28 call disp%show("ndim = getUnifRand(2, 5)")
29 ndim = getUnifRand(2, 5)
30 call disp%show("[same_type_as(subset(isub)%val, uppDia), same_type_as(subset(isub)%val, lowDia)]")
31 call disp%show( [same_type_as(subset(isub)%val, uppDia), same_type_as(subset(isub)%val, lowDia)] )
32 call disp%show("rand = getCholRand(mold, ndim, subset(isub)%val)")
33 rand = getCholRand(mold, ndim, subset(isub)%val)
34 call disp%show("rand")
35 call disp%show( rand )
36 call disp%show("cov = matmul(rand, transpose(rand))")
37 cov = matmul(rand, transpose(rand))
38 call disp%show("isMatClass(cov, posdefmat)")
39 call disp%show( isMatClass(cov, posdefmat) )
40 call disp%skip()
41 end do
42 end block
43
44 block
45 use pm_kind, only: TKG => CKS ! all complex kinds are supported.
46 complex(TKG), allocatable :: rand(:,:), cov(:,:)
47 complex(TKG) :: mold
48 do itry = 1, 5
49 call disp%skip()
50 call disp%show("ndim = getUnifRand(2, 5)")
51 ndim = getUnifRand(2, 5)
52 call disp%show("[same_type_as(subset(isub)%val, uppDia), same_type_as(subset(isub)%val, lowDia)]")
53 call disp%show( [same_type_as(subset(isub)%val, uppDia), same_type_as(subset(isub)%val, lowDia)] )
54 call disp%show("rand = getCholRand(mold, ndim, subset(isub)%val)")
55 rand = getCholRand(mold, ndim, subset(isub)%val)
56 call disp%show("rand")
57 call disp%show( rand )
58 call disp%show("cov = matmul(rand, conjg(transpose(rand)))")
59 cov = matmul(rand, conjg(transpose(rand)))
60 call disp%show("isMatClass(cov, posdefmat)")
61 call disp%show( isMatClass(cov, posdefmat) )
62 call disp%skip()
63 end do
64 end block
65
66 end do
67
68end program example
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 .true. if and only if the input matrix is of the specified input class.
This module contains the derived types for generating allocatable containers of scalar,...
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 CKS
The single-precision complex kind in Fortran mode. On most platforms, this is a 32-bit real kind.
Definition: pm_kind.F90:570
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 abstract and concrete derived types that are required for compile-time resolutio...
type(posdefmat_type), parameter posdefmat
This is a scalar parameter object of type hermitian_type that is exclusively used to signify the Herm...
This is the csp_type type for generating instances of container of scalar unlimited polymorphic objec...
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
2ndim = getUnifRand(2, 5)
3[same_type_as(subset(isub)%val, uppDia), same_type_as(subset(isub)%val, lowDia)]
4T, F
5rand = getCholRand(mold, ndim, subset(isub)%val)
6rand
7+1.00000000, +0.999980330
8+0.00000000, +0.627283892E-2
9cov = matmul(rand, transpose(rand))
11T
12
13
14ndim = getUnifRand(2, 5)
15[same_type_as(subset(isub)%val, uppDia), same_type_as(subset(isub)%val, lowDia)]
16T, F
17rand = getCholRand(mold, ndim, subset(isub)%val)
18rand
19+1.00000000, +0.486679018
20+0.00000000, +0.873580813
21cov = matmul(rand, transpose(rand))
23T
24
25
26ndim = getUnifRand(2, 5)
27[same_type_as(subset(isub)%val, uppDia), same_type_as(subset(isub)%val, lowDia)]
28T, F
29rand = getCholRand(mold, ndim, subset(isub)%val)
30rand
31+0.999999940, +0.948251069, -0.638649762, +0.752539873, +0.112472862
32+0.00000000, +0.317521393, -0.753969848, -0.528783381, -0.374730885
33+0.00000000, +0.00000000, +0.153804898, +0.328769594, +0.180891007
34+0.00000000, +0.00000000, +0.00000000, +0.214435145, +0.288898736
35+0.00000000, +0.00000000, +0.00000000, +0.00000000, +0.854834855
36cov = matmul(rand, transpose(rand))
38T
39
40
41ndim = getUnifRand(2, 5)
42[same_type_as(subset(isub)%val, uppDia), same_type_as(subset(isub)%val, lowDia)]
43T, F
44rand = getCholRand(mold, ndim, subset(isub)%val)
45rand
46+1.00000000, +0.683479846, +0.429321676
47+0.00000000, +0.729969323, -0.687118888
48+0.00000000, +0.00000000, +0.586131811
49cov = matmul(rand, transpose(rand))
51T
52
53
54ndim = getUnifRand(2, 5)
55[same_type_as(subset(isub)%val, uppDia), same_type_as(subset(isub)%val, lowDia)]
56T, F
57rand = getCholRand(mold, ndim, subset(isub)%val)
58rand
59+1.00000000, -0.208362281, +0.350319833, +0.372993857, -0.796791613
60+0.00000000, +0.978051722, +0.933816254, -0.696913421, +0.520424962
61+0.00000000, +0.00000000, +0.725479946E-1, +0.487141728, -0.178081349
62+0.00000000, +0.00000000, +0.00000000, +0.371322185, -0.460583270E-1
63+0.00000000, +0.00000000, +0.00000000, +0.00000000, +0.245859027
64cov = matmul(rand, transpose(rand))
66T
67
68
69ndim = getUnifRand(2, 5)
70[same_type_as(subset(isub)%val, uppDia), same_type_as(subset(isub)%val, lowDia)]
71T, F
72rand = getCholRand(mold, ndim, subset(isub)%val)
73rand
74(+1.00000000, +0.00000000), (-0.696427166, -0.153193638), (+0.604950309, -0.401363343)
75(+0.00000000, +0.00000000), (+0.701085627, +0.00000000), (+0.515467882, -0.441972882)
76(+0.00000000, +0.00000000), (+0.00000000, +0.00000000), (+0.109066740, +0.00000000)
77cov = matmul(rand, conjg(transpose(rand)))
79T
80
81
82ndim = getUnifRand(2, 5)
83[same_type_as(subset(isub)%val, uppDia), same_type_as(subset(isub)%val, lowDia)]
84T, F
85rand = getCholRand(mold, ndim, subset(isub)%val)
86rand
87(+0.999999940, +0.00000000), (-0.814798534, -0.564739704), (-0.445493579, -0.682549834)
88(+0.00000000, +0.00000000), (+0.131043822, +0.00000000), (-0.170492291, +0.256871045)
89(+0.00000000, +0.00000000), (+0.00000000, +0.00000000), (+0.490520924, +0.00000000)
90cov = matmul(rand, conjg(transpose(rand)))
92T
93
94
95ndim = getUnifRand(2, 5)
96[same_type_as(subset(isub)%val, uppDia), same_type_as(subset(isub)%val, lowDia)]
97T, F
98rand = getCholRand(mold, ndim, subset(isub)%val)
99rand
100(+1.00000000, +0.00000000), (+0.252333522, +0.284540087), (+0.505015373, +0.750738680E-1), (+0.466432720, -0.357902765)
101(+0.00000000, +0.00000000), (+0.924859345, +0.00000000), (+0.229453012, +0.610010564), (+0.507515609, +0.244659126)
102(+0.00000000, +0.00000000), (+0.00000000, +0.00000000), (+0.560858250, +0.00000000), (-0.209694147, +0.540583134)
103(+0.00000000, +0.00000000), (+0.00000000, +0.00000000), (+0.00000000, +0.00000000), (+0.267231241E-1, +0.00000000)
104cov = matmul(rand, conjg(transpose(rand)))
106T
107
108
109ndim = getUnifRand(2, 5)
110[same_type_as(subset(isub)%val, uppDia), same_type_as(subset(isub)%val, lowDia)]
111T, F
112rand = getCholRand(mold, ndim, subset(isub)%val)
113rand
114(+1.00000000, +0.00000000), (-0.567369163, +0.677293225E-3), (-0.596424758, -0.248483270)
115(+0.00000000, +0.00000000), (+0.823463321, +0.00000000), (-0.262918830, -0.173736691)
116(+0.00000000, +0.00000000), (+0.00000000, +0.00000000), (+0.695142329, +0.00000000)
117cov = matmul(rand, conjg(transpose(rand)))
119T
120
121
122ndim = getUnifRand(2, 5)
123[same_type_as(subset(isub)%val, uppDia), same_type_as(subset(isub)%val, lowDia)]
124T, F
125rand = getCholRand(mold, ndim, subset(isub)%val)
126rand
127(+0.999999940, +0.00000000), (-0.754440963, +0.634528279), (-0.856003463, -0.363812804), (-0.509728849, -0.400169566E-1)
128(+0.00000000, +0.00000000), (+0.167907178, +0.00000000), (-0.238472015, +0.227033287), (-0.534852505, -0.488764077)
129(+0.00000000, +0.00000000), (+0.00000000, +0.00000000), (+0.162742957, +0.00000000), (-0.239155278, -0.180429414)
130(+0.00000000, +0.00000000), (+0.00000000, +0.00000000), (+0.00000000, +0.00000000), (+0.351948112, +0.00000000)
131cov = matmul(rand, conjg(transpose(rand)))
133T
134
135
136ndim = getUnifRand(2, 5)
137[same_type_as(subset(isub)%val, uppDia), same_type_as(subset(isub)%val, lowDia)]
138F, T
139rand = getCholRand(mold, ndim, subset(isub)%val)
140rand
141+1.00000000, +0.00000000, +0.00000000, +0.00000000, +0.00000000
142+0.980282724, +0.197600275, +0.00000000, +0.00000000, +0.00000000
143-0.908162773, +0.180209935, +0.377842426, +0.00000000, +0.00000000
144-0.815407559E-1, -0.460282028, +0.292683821E-1, +0.883535445, +0.00000000
145-0.552618802, -0.425505310, +0.257496834E-1, -0.421366304, +0.579089880
146cov = matmul(rand, transpose(rand))
148T
149
150
151ndim = getUnifRand(2, 5)
152[same_type_as(subset(isub)%val, uppDia), same_type_as(subset(isub)%val, lowDia)]
153F, T
154rand = getCholRand(mold, ndim, subset(isub)%val)
155rand
156+1.00000000, +0.00000000, +0.00000000, +0.00000000
157-0.880598128, +0.473863810, +0.00000000, +0.00000000
158+0.288508415, +0.154566169, +0.944919109, +0.00000000
159-0.450525552, -0.442106992, -0.186803147, +0.752776682
160cov = matmul(rand, transpose(rand))
162T
163
164
165ndim = getUnifRand(2, 5)
166[same_type_as(subset(isub)%val, uppDia), same_type_as(subset(isub)%val, lowDia)]
167F, T
168rand = getCholRand(mold, ndim, subset(isub)%val)
169rand
170+1.00000000, +0.00000000, +0.00000000, +0.00000000, +0.00000000
171+0.729097605, +0.684409857, +0.00000000, +0.00000000, +0.00000000
172-0.144098550, -0.989551783, +0.477859052E-2, +0.00000000, +0.00000000
173-0.484757096, -0.387064070, +0.617888629, +0.483120561, +0.00000000
174+0.569720805, -0.377417922, +0.310855716, -0.615052938, +0.240940735
175cov = matmul(rand, transpose(rand))
177T
178
179
180ndim = getUnifRand(2, 5)
181[same_type_as(subset(isub)%val, uppDia), same_type_as(subset(isub)%val, lowDia)]
182F, T
183rand = getCholRand(mold, ndim, subset(isub)%val)
184rand
185+0.999999940, +0.00000000, +0.00000000
186-0.997409284, +0.719356835E-1, +0.00000000
187-0.688432395, -0.119444856E-2, +0.725299478
188cov = matmul(rand, transpose(rand))
190T
191
192
193ndim = getUnifRand(2, 5)
194[same_type_as(subset(isub)%val, uppDia), same_type_as(subset(isub)%val, lowDia)]
195F, T
196rand = getCholRand(mold, ndim, subset(isub)%val)
197rand
198+1.00000000, +0.00000000
199-0.676224520E-2, +0.999977171
200cov = matmul(rand, transpose(rand))
202T
203
204
205ndim = getUnifRand(2, 5)
206[same_type_as(subset(isub)%val, uppDia), same_type_as(subset(isub)%val, lowDia)]
207F, T
208rand = getCholRand(mold, ndim, subset(isub)%val)
209rand
210(+1.00000000, +0.00000000), (+0.00000000, +0.00000000), (+0.00000000, +0.00000000)
211(+0.278139442, -0.922443509), (+0.267836601, +0.00000000), (+0.00000000, +0.00000000)
212(-0.335017473, -0.695173919), (+0.441735148, -0.748096928E-1), (+0.451408982, +0.00000000)
213cov = matmul(rand, conjg(transpose(rand)))
215T
216
217
218ndim = getUnifRand(2, 5)
219[same_type_as(subset(isub)%val, uppDia), same_type_as(subset(isub)%val, lowDia)]
220F, T
221rand = getCholRand(mold, ndim, subset(isub)%val)
222rand
223(+1.00000000, +0.00000000), (+0.00000000, +0.00000000)
224(-0.794135094, +0.324585319), (+0.513803363, +0.00000000)
225cov = matmul(rand, conjg(transpose(rand)))
227T
228
229
230ndim = getUnifRand(2, 5)
231[same_type_as(subset(isub)%val, uppDia), same_type_as(subset(isub)%val, lowDia)]
232F, T
233rand = getCholRand(mold, ndim, subset(isub)%val)
234rand
235(+1.00000000, +0.00000000), (+0.00000000, +0.00000000), (+0.00000000, +0.00000000), (+0.00000000, +0.00000000), (+0.00000000, +0.00000000)
236(+0.369813383, +0.655070901), (+0.658878028, +0.00000000), (+0.00000000, +0.00000000), (+0.00000000, +0.00000000), (+0.00000000, +0.00000000)
237(+0.266635299, -0.450432628), (-0.299397439, +0.220581830), (+0.766629517, +0.00000000), (+0.00000000, +0.00000000), (+0.00000000, +0.00000000)
238(+0.374578834, -0.500194788), (-0.346734524, -0.364071816), (+0.995573103E-1, +0.434140116), (+0.397911370, +0.00000000), (+0.00000000, +0.00000000)
239(+0.518814027, -0.127440065), (+0.113355033, -0.380458713), (+0.239206612, +0.511375606), (+0.463626385, -0.248699132E-1), (+0.150665060, +0.00000000)
240cov = matmul(rand, conjg(transpose(rand)))
242T
243
244
245ndim = getUnifRand(2, 5)
246[same_type_as(subset(isub)%val, uppDia), same_type_as(subset(isub)%val, lowDia)]
247F, T
248rand = getCholRand(mold, ndim, subset(isub)%val)
249rand
250(+1.00000000, +0.00000000), (+0.00000000, +0.00000000), (+0.00000000, +0.00000000), (+0.00000000, +0.00000000)
251(-0.807609379, -0.369952396E-1), (+0.588556111, +0.00000000), (+0.00000000, +0.00000000), (+0.00000000, +0.00000000)
252(-0.486296564, -0.804358244), (-0.751082450E-1, +0.330539227), (+0.403223410E-1, +0.00000000), (+0.00000000, +0.00000000)
253(+0.230936900, -0.443333030), (+0.559189856, +0.463470697), (+0.476008654E-1, -0.332982719), (+0.330881119, +0.00000000)
254cov = matmul(rand, conjg(transpose(rand)))
256T
257
258
259ndim = getUnifRand(2, 5)
260[same_type_as(subset(isub)%val, uppDia), same_type_as(subset(isub)%val, lowDia)]
261F, T
262rand = getCholRand(mold, ndim, subset(isub)%val)
263rand
264(+1.00000000, +0.00000000), (+0.00000000, +0.00000000), (+0.00000000, +0.00000000), (+0.00000000, +0.00000000)
265(-0.738734245, -0.340231776), (+0.581819534, +0.00000000), (+0.00000000, +0.00000000), (+0.00000000, +0.00000000)
266(-0.330684155, +0.502738416), (+0.273282290, +0.633378625), (+0.402554810, +0.00000000), (+0.00000000, +0.00000000)
267(-0.369890213, +0.337053239), (-0.370498240, -0.404159755), (-0.477574974, +0.294691801), (+0.366116375, +0.00000000)
268cov = matmul(rand, conjg(transpose(rand)))
270T
271
272
Test:
test_pm_distChol


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, Monday March 6, 2017, 3:22 pm, Institute for Computational Engineering and Sciences (ICES), The University of Texas at Austin.

Definition at line 115 of file pm_distChol.F90.


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