2%> This is the base
class for generating objects containing
3%> information about autocorrelation of the input data and
4%> tools
for visualizing it.<br>
7%> This is convenience
class for easy computation
8%> of autocorrelation and its storage all in one place.<br>
9%> The primary advantage of
this class over the MATLAB
10%> intrinsic functions is in the ability of
this class
11%> to compute the result
for input dataframe table and
12%>
return the results always in MATLAB ``table`` format.<br>
15%> See the documentation of the
class constructor
21%> \JoshuaOsborne, May 21 2024, 4:06 AM, University of Texas at Arlington<br>
22%> \FatemehBagheri, May 20 2024, 1:25 PM, NASA Goddard Space Flight Center (GSFC), Washington, D.C.<br>
23%> \AmirShahmoradi, May 16 2016, 9:03 AM, Oden Institute
for Computational Engineering and Sciences (ICES), UT Austin<br>
26 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
28 properties(Access =
public)
32 %> A scalar
object of
class [pm.container.DataFrame](@ref
DataFrame) containing
33 %> (a refernece to) the user-specified data whose covariance must be computed.<br>
39 %> The positive scalar MATLAB whole number representing the
40 %> number of lags
for which the autocorrelation must be computed.<br>
41 %> This argument is directly passed to the corresponding argument
42 %> of the MATLAB intrinsic ``autocorr()`` in the MATLAB Econometrics Toolbox.<br>
48 %> The positive scalar MATLAB
double representing the
49 %> number of standard deviations to be used in computing the
50 %> lower and upper significance levels of the autocorrelation.<br>
51 %> This argument is directly passed to the corresponding argument
52 %> of the MATLAB intrinsic ``autocorr()`` in the MATLAB Econometrics Toolbox.<br>
58 %> The MATLAB ``table`` of rank ``2`` serving as a convenient
59 %> storage component each column of
which corresponds to the
60 %> absolute ``numstd``-significance bound
for the corresponding
61 %> computed autocorrelations of the input data (that is optionally
62 %> stored in the ``val`` component of the parent
object).<br>
63 %> The values represent the ``numstd``-sigma standard
64 %> errors on the computed autocorrelations.<br>
65 %> Any autocorrelation value bound within these limits can be
66 %> considered random fluctuations at ``numstd``-sigma confidence level.<br>
67 %> This component is automatically populated when constructing
68 %> an
object of
class [pm.stats.AutoCorr](@ref
AutoCorr).<br>
69 %> It must be populated manually at all other times.<br>
75 %> The MATLAB ``table`` of rank ``2`` serving as a
76 %> convenient storage component
for the autocorrelation.<br>
77 %> This component is automatically populated when constructing
78 %> an
object of
class [pm.stats.AutoCorr](@ref
AutoCorr).<br>
79 %> It must be populated manually at all other times.<br>
82 %> The first column of ``val`` always contains the set
83 %> of lags
for which the autocorrelation is computed.<br>
89 %> The scalar MATLAB ``
struct`` containing the set of
90 %> predefined visualizations
for the output data.<br>
95 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
97 methods(Access =
public)
100 %> Return an
object of
class [pm.stats.AutoCorr](@ref
AutoCorr).<br>
101 %> This is the constructor of the [pm.stats.AutoCorr](@ref
AutoCorr)
class.<br>
103 %> \param[in] dfref : The input MATLAB matrix or table of rank ``2``
104 %> containing the data as ``ncol`` columns of ``nrow``
105 %> observations whose autocorrelation must be computed.<br>
106 %> Ideally, the user would want to pass a reference
107 %> to a dataframe (e.g., as a function handle ``@()df``)
108 %> so that the data remains dynamically up-to-date.<br>
109 %> (**optional**. If missing, the autocorrelation will not be computed.)
110 %> \param[in] numlag : The input scalar MATLAB positive whole number representing the number
111 %> of lags
for which the autocorrelation must be computed.<br>
112 %> This argument is directly passed to the corresponding argument
113 %> of the MATLAB intrinsic ``autocorr()`` in the MATLAB Econometrics Toolbox.<br>
114 %> \param[in] numstd : The input positive scalar MATLAB
double representing the
115 %> number of standard deviations to be used in computing the
116 %> lower and upper significance levels of the autocorrelation.<br>
117 %> This argument is directly passed to the corresponding argument
118 %> of the MATLAB intrinsic ``autocorr()`` in the MATLAB Econometrics Toolbox.<br>
119 %> (**optional**,
default = ``1``)
122 %> ``self`` : The output
object of
class [pm.stats.AutoCorr](@ref
AutoCorr).<br>
128 %> acf = pm.stats.AutoCorr([])
129 %> acf = pm.stats.AutoCorr(dfref)
130 %> acf = pm.stats.AutoCorr(dfref, numlag)
131 %> acf = pm.stats.AutoCorr(dfref, [], numstd)
132 %> acf = pm.stats.AutoCorr(dfref, numlag, numstd)
137 %> \include{lineno} example/stats/
AutoCorr/main.m
140 %> \image html example/stats/
AutoCorr/
AutoCorr.unifrnd.plot.line.png width=700
142 %> \image html example/stats/
AutoCorr/
AutoCorr.unifrnd.tile.line.png width=700
144 %> \image html example/stats/
AutoCorr/
AutoCorr.unifrnd.cascade.line.1.png width=700
146 %> \image html example/stats/
AutoCorr/
AutoCorr.unifrnd.cascade.line.2.png width=700
148 %> \image html example/stats/
AutoCorr/
AutoCorr.unifrnd.cascade.line.3.png width=700
150 %> \image html example/stats/
AutoCorr/
AutoCorr.unifrnd.cascade.line.4.png width=700
155 %> \JoshuaOsborne, May 21 2024, 4:10 AM, University of Texas at Arlington<br>
156 %> \FatemehBagheri, May 20 2024, 1:25 PM, NASA Goddard Space Flight Center (GSFC), Washington, D.C.<br>
157 %> \AmirShahmoradi, May 16 2016, 9:03 AM, Oden Institute
for Computational Engineering and Sciences (ICES), UT Austin<br>
158 function self =
AutoCorr(dfref, numlag, numstd)
170 self.numstd = numstd;
172 [self.val, self.bnd] = self.get(dfref, numlag, numstd);
179 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
182 %> Return the autocorrelation of the input
183 %> data from a lag of ``0`` to ``numlag``.<br>
186 %> This is a dynamic method of the [pm.stats.AutoCorr](@ref
AutoCorr)
class.<br>
187 %> This method automatically stores any input information
188 %> in the corresponding components of the parent
object.<br>
189 %> However, any components of the parent
object
190 %> corresponding to the output of
this method
191 %> must be set explicitly manually.<br>
193 %> \param[inout] self : The input/output parent
object of
class [pm.stats.AutoCorr](@ref
AutoCorr)
194 %>
which is **implicitly** passed to
this dynamic method (not by the user).<br>
195 %> \param[in] dfref : The input MATLAB matrix or table of rank ``2``
196 %> containing the data as ``ncol`` columns of ``nrow``
197 %> observations whose autocorrelation must be computed.<br>
198 %> Ideally, the user would want to pass a reference
199 %> to a dataframe (e.g., as a function handle ``@()df``)
200 %> so that the data remains dynamically up-to-date.<br>
201 %> (**optional**. If missing, the contents of the corresponding
202 %> internal component of the parent
object will be used.)
203 %> \param[in] numlag : The input positive scalar MATLAB integer representing the
204 %> number of lags to be used in computing the autocorrelation.<br>
205 %> The
default value will be used
if the input ``numlag``
206 %> is unspecified or empty ``[]``.<br>
207 %> (**optional**,
default = ``size(dfref.copy(), 1) - 1``)
208 %> \param[in] numstd : The input positive scalar MATLAB
double representing the
209 %> number of standard deviations to be used in computing the
210 %> lower and upper significance levels of the autocorrelation.<br>
211 %> This argument is directly passed to the corresponding argument
212 %> of the MATLAB intrinsic ``autocorr()`` in the MATLAB Econometrics Toolbox.<br>
213 %> The
default value will be used
if the input ``numstd`` is empty ``[]``.<br>
214 %> (**optional**,
default = ``1``)
217 %> ``val`` : The output MATLAB ``table`` of size ``numlag + 1``
218 %> containing the autocorrelation from lag ``0`` to ``numlag``.<br>
219 %> The first column of ``val`` always contains the set of ``numlag + 1``
220 %> autocorrelation lags from ``0`` to ``numlag``.<br>
221 %> ``bnd`` : The output MATLAB ``table`` of ``size(dfref.copy(), 2)`` rows by one column
222 %> containing the absolute ``numstd``-significance level of the
223 %> computed autocorrelations. Any autocorrelation value whose
224 %> magnitude is smaller than the corresponding ``bnd`` element
225 %> can be considered insignificant and mere fluctuation.<br>
230 %> acf = pm.stats.AutoCorr()
231 %> [acf.val, acf.bnd] = acf.get(dfref)
232 %> [acf.val, acf.bnd] = acf.get(dfref, [])
233 %> [acf.val, acf.bnd] = acf.get(dfref, numlag)
234 %> [acf.val, acf.bnd] = acf.get(dfref, [], numstd)
235 %> [acf.val, acf.bnd] = acf.get(dfref, numlag, numstd)
240 %> See the documentation of the
class constructor
246 %> \JoshuaOsborne, May 21 2024, 4:14 AM, University of Texas at Arlington<br>
247 %> \FatemehBagheri, May 20 2024, 1:25 PM, NASA Goddard Space Flight Center (GSFC), Washington, D.C.<br>
248 %> \AmirShahmoradi, May 16 2016, 9:03 AM, Oden Institute
for Computational Engineering and Sciences (ICES), UT Austin<br>
249 function [val, bnd] = get(self, dfref, numlag, numstd)
252 %%%% Define the data.
260 self.dfref = pm.container.DataFrame(dfref);
263 dfcopy = self.dfref.copy();
268 help(
"pm.stats.AutoCorr");
270 +
"A non-mepty ``dfref`` attribute or input argument is required for computing the autocorrelation." + newline ...
276 %%%% Define the number of lags.
284 self.numlag = numlag;
285 elseif isempty(self.numlag)
286 self.numlag = size(data, 1) - 1;
290 %%%% Define the number of standard deviations for the bounds.
298 self.numstd = numstd;
299 elseif isempty(self.numstd)
304 %%%% Compute the ACF.
307 bnd = zeros(size(data, 2), 1);
308 val = zeros(self.numlag + 1, size(data, 2) + 1);
312 for icol = 1 : size(data, 2)
313 [val(:, icol + 1), val(:, 1), bounds] = autocorr(data(:, icol), "numlags", self.numlag);
314 bnd(icol) =
abs(bounds(1)) * self.numstd;
316 val = array2table(val);
320 %val = NaN(numlag, size(data, 2));
321 warning ( newline ...
322 +
string(me.identifier) + " : " +
string(me.message) + newline ...
323 + "skipping the autocorrelation computation..." + newline ...
330 val.Properties.VariableNames = ["Lag", "ACF(" +
string(dfcopy.Properties.VariableNames) + ")"];
334 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
338 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
340 methods(Access = public, Hidden)
342 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
345 %> Set up the visualization tools of the autocorrelation.<br>
348 %> This is a dynamic ``Hidden`` method of the [pm.stats.
AutoCorr](@ref
AutoCorr) class.<br>
349 %> This method is inaccessible to the end users of the ParaMonte MATLAB library.<br>
351 %> \param[inout] self : The **implicitly-passed** input argument representing the parent
object of the method.<br>
352 %> \param[in] val : The input (reference of function handle returning a) MATLAB matrix or table of rank ``2``
353 %> containing the computed autocorrelation to be visualized.<br>
354 %> Ideally, the user would want to pass a reference to a dataframe (e.g., as a function handle ``@()df``)
355 %> so that the data remains dynamically up-to-date.<br>
356 %> (**optional**. If missing, the contents of the corresponding ``var`` attribute of the parent
object will be used.)
361 %> acf = pm.stats.AutoCorr(dfref, method)
362 %> acf.setvis(); % This method is automatically called within the
object constructor.
369 %> \FatemehBagheri, May 20 2024, 1:25 PM, NASA Goddard Space Flight Center (GSFC), Washington, D.C.<br>
370 %> \AmirShahmoradi, May 16 2016, 9:03 AM, Oden Institute
for Computational Engineering and Sciences (ICES), UT Austin<br>
371 function setvis(self, val)
379 self.vis.plot =
struct();
380 self.vis.plot.line = pm.vis.PlotLine( @()self.val ...
381 ,
"colx", 1,
"coly", 2 : size(self.val, 2) ...
382 ,
"legend", {
"enabled",
true} ...,
"labels", self.val.Properties.VariableNames(2:end)} ...
383 ,
"ylabel", {
"txt",
"Autocorrelation Function (ACF)"} ...
384 ,
"xlabel", {
"txt",
"Autocorrelation Lag"} ...
385 ,
"colormap", {
"enabled",
false} ...
386 ,
"axes", {
"xscale",
"log"} ...
387 ,
"ylim", [-1, 1] ...
390 self.vis.tile =
struct();
391 self.vis.tile.line = pm.vis.TileLine( @()self.val ...
392 ,
"colx", 1,
"coly", 2 : size(self.val, 2) ...
393 ,
"ylabel", {
"txt",
"Autocorrelation Function (ACF)"} ...
394 ,
"xlabel", {
"txt",
"Autocorrelation Lag"} ...
395 ,
"colormap", {
"enabled",
false} ...
396 ,
"legend", {
"enabled",
true} ...
397 ,
"axes", {
"xscale",
"log"} ...
398 ,
"tiledlayout", {
"TileSpacing",
"tight"} ...
399 ,
"ylim", [-1, 1] ...
402 self.vis.cascade =
struct();
403 self.vis.cascade.line = pm.vis.CascadeLine ( @()self.val ...
404 ,
"colx", 1,
"coly", 2 : size(self.val, 2) ...
405 ,
"ylabel", {
"txt",
"Autocorrelation Function (ACF)"} ...
406 ,
"xlabel", {
"txt",
"Autocorrelation Lag"} ...
407 ,
"colormap", {
"enabled",
false} ...
408 ,
"legend", {
"enabled",
true} ...
409 ,
"axes", {
"xscale",
"log"} ...
410 ,
"ylim", [-1, 1] ...
415 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
419 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function abs(in path, in style)
Return the Get absolute canonical path of a file or folder.
This is the base class for generating objects containing information about autocorrelation of the inp...
function setvis(in self, in val)
Set up the visualization tools of the autocorrelation.
function AutoCorr(in dfref, in numlag, in numstd)
Return an object of class pm.stats.AutoCorr. This is the constructor of the pm.stats....
function get(in self, in dfref, in numlag, in numstd)
Return the autocorrelation of the input data from a lag of 0 to numlag.
This is the abstract class for generating instances of objects that can contain basic attributes requ...
This is the base class for generating subclass of MATLAB handle superclass whose annoying methods are...
function which(in vendor)
Return the a MATLAB string containing the path to the first mpiexec executable binary found in system...