ParaMonte MATLAB 3.0.0
Parallel Monte Carlo and Machine Learning Library
See the latest version documentation.
getRand.m
Go to the documentation of this file.
1%> \brief
2%> Return a (set of) multivariate Uniform random vector(s),
3%> from within a hyper-ellipsoidal domain.<br>
4%>
5%> \details
6%> The returned random vectors are uniformly distributed
7%> within the hyper-ellipsoidal domain of the Uniform distribution.<br>
8%>
9%> \param[in] mean : The input vector of MATLAB ``real``,
10%> representing the mean of a Multivariate Uniform
11%> distribution in ``size(mean)`` dimensional space.<br>
12%> (**optional**. default = ``[]``. It must be present if ``cholow`` is missing.)
13%> \param[in] cholow : The input square matrix of MATLAB ``real``,
14%> representing the lower-triangle of the Cholesky
15%> factorization of the Gramian matrix of the target
16%> Multivariate Uniform distribution in ``numel(mean)`` dimensional space.<br>
17%> This argument can be obtained by passing the Gramian matrix ``gramian``
18%> of the distribution to the MATLAB intrinsic function ``chol(gramian, "lower")``.<br>
19%> (**optional**. default = ``[]``. It must be present if ``mean`` is missing.)
20%> \param[in] s1 : The input vector of MATLAB ``real``,
21%> representing the mean of a Multivariate Uniform
22%> distribution in ``size(mean)`` dimensional space.<br>
23%> (**optional**. default = ``1``)
24%>
25%> \return
26%> ``rand`` : The output vector of MATLAB ``real`` of
27%> shape ``(numel(mean), 1)`` containing a random vector
28%> from the specified Multivariate Uniform distribution.<br>
29%>
30%> \interface{getRand}
31%> \code{.m}
32%>
33%> rand = pm.stats.dist.mvu.getRand(mean)
34%> rand = pm.stats.dist.mvu.getRand([], cholow)
35%> rand = pm.stats.dist.mvu.getRand(mean, cholow)
36%> rand = pm.stats.dist.mvu.getRand([], cholow, s1)
37%> rand = pm.stats.dist.mvu.getRand(mean, cholow, s1)
38%>
39%> \endcode
40%>
41%> \example{getRand}
42%>
43%> \example{getRand}
44%> \include{lineno} example/stats/dist/mvu/getRand/main.m
45%> \vis{getRand}
46%> \image html example/stats/dist/mvu/getRand/mvu.getRand.hist1.png width=700
47%> \image html example/stats/dist/mvu/getRand/mvu.getRand.hist2.png width=700
48%> \image html example/stats/dist/mvu/getRand/mvu.getRand.scatter1.png width=700
49%>
50%> \final{getRand}
51%>
52%> \author
53%> \JoshuaOsborne, May 21 2024, 4:03 AM, University of Texas at Arlington<br>
54%> \FatemehBagheri, May 20 2024, 1:25 PM, NASA Goddard Space Flight Center (GSFC), Washington, D.C.<br>
55%> \AmirShahmoradi, May 16 2016, 9:03 AM, Oden Institute for Computational Engineering and Sciences (ICES), UT Austin<br>
56function rand = getRand(mean, cholow, s1)
57 if nargin < 3
58 s1 = 1;
59 end
60 if 1 < nargin
61 if ~isempty(cholow)
62 ndiminv = 1 / size(cholow, 1);
63 rand = randn(size(cholow, 1), s1);
64 for irand = 1 : s1
65 rand(:, irand) = cholow * rand(:, irand) * (unifrnd(0, 1)^ndiminv / norm(rand(:, irand)));
66 end
67 else
68 ndiminv = 1 / numel(mean);
69 rand = randn(numel(mean), s1);
70 for irand = 1 : s1
71 rand(:, irand) = rand(:, irand) * (unifrnd(0, 1)^ndiminv / norm(rand(:, irand)));
72 end
73 end
74 else
75 ndiminv = 1 / numel(mean);
76 rand = randn(numel(mean), s1);
77 for irand = 1 : s1
78 rand(:, irand) = rand(:, irand) * (unifrnd(0, 1)^ndiminv / norm(rand(:, irand)));
79 end
80 end
81 if ~isempty(mean)
82 rand = bsxfun(@plus, mean(:), rand);
83 end
84end
function getRand(in ndim, in scale)
Generate and return a random positive-definite (correlation or covariance) matrix using the Gram meth...