ParaMonte MATLAB 3.0.0
Parallel Monte Carlo and Machine Learning Library
See the latest version documentation.
Cov Class Reference

This is the base class for generating objects with methods and storage components for computing and storing and visualizing the covariance matrix of an input data.
More...

Inheritance diagram for Cov:
Collaboration diagram for Cov:

Public Member Functions

function Cov (in dfref, in method)
 Return an object of class pm.stats.Cov.
More...
 
function get (in self, in dfref, in method)
 Return the covariance matrix of the input data.
More...
 
function setvis (in self, in val)
 Set up the visualization tools of the covariance matrix.
More...
 

Data Fields

Property dfref
 
Property method
 
Property val
 
Property vis
 

Detailed Description

This is the base class for generating objects with methods and storage components for computing and storing and visualizing the covariance matrix of an input data.

This is merely a convenience class for easy computation of covariance and its storage all in one place.
The primary advantage of this class over the MATLAB intrinsic functions is in the ability of this class to compute the result for input dataframe table and return the results always in MATLAB table format.

Note
See the documentation of the class constructor pm.stats.Cov below.


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:
Joshua Alexander Osborne, May 21 2024, 4:25 AM, University of Texas at Arlington
Fatemeh Bagheri, May 20 2024, 1:25 PM, NASA Goddard Space Flight Center (GSFC), Washington, D.C.
Amir Shahmoradi, July 5 2024, 1:07 PM, NASA Goddard Space Flight Center (GSFC), Washington, D.C.

Definition at line 20 of file Cov.m.

Constructor & Destructor Documentation

◆ Cov()

function Cov::Cov ( in  dfref,
in  method 
)

Return an object of class pm.stats.Cov.

This is the constructor of the pm.stats.Cov class.

Parameters
[in]dfref: The input MATLAB matrix or table of rank 2 containing the data as ncol columns of nrow observations whose covariance matrix must be computed.
Ideally, the user would want to pass a reference to a dataframe (e.g., as a function handle @()df) so that the data remains dynamically up-to-date.
(optional. If missing or empty, the covariance matrix will not be computed.)
[in]method: The input scalar MATLAB string that can be either:
  1. "pearson" : for computing the Pearson covariance matrix of the input data.
  2. "spearman" : for computing the Spearman rank covariance matrix of the input data.
(optional, default = "pearson")
Returns
self : The output object of class pm.stats.Cov.


Possible calling interfaces

mat = pm.stats.Cov([])
mat = pm.stats.Cov([], [])
mat = pm.stats.Cov([], method)
mat = pm.stats.Cov(dfref)
mat = pm.stats.Cov(dfref, [])
mat = pm.stats.Cov(dfref, method)
Property method
Definition: Cov.m:47
Property dfref
Definition: Cov.m:34


Example usage

1cd(fileparts(mfilename('fullpath'))); % Change working directory to source code directory.
2addpath('../../../'); % Add the ParaMonte library root directory to the search path.
3
4% Make a positive-definite random matrix.
5
6pm.matlab.show()
7pm.matlab.show("cholow = chol(pm.stats.dist.cov.getRand(5), 'lower');")
8 cholow = chol(pm.stats.dist.cov.getRand(5), 'lower');
9pm.matlab.show("df = pm.stats.dist.mvn.getRand(zeros(length(cholow), 1), cholow, 5000)';")
10 df = pm.stats.dist.mvn.getRand(zeros(length(cholow), 1), cholow, 5000)';
11
12pm.matlab.show()
13pm.matlab.show('c = pm.stats.Cov(df, "spearman"); c.val')
14 c = pm.stats.Cov(df, "spearman"); c.val
15
16pm.matlab.show()
17pm.matlab.show('c = pm.stats.Cov(df, "pearson"); c.val')
18 c = pm.stats.Cov(df, "pearson"); c.val
19
20pm.matlab.show()
21pm.matlab.show('c = pm.stats.Cov(df); c.val')
22 c = pm.stats.Cov(df); c.val
23
24pm.matlab.show()
25pm.matlab.show('c.vis.heatmap.make(); c.vis.heatmap.subplot.setColorLim();')
26 c.vis.heatmap.make(); c.vis.heatmap.subplot.setColorLim();
27pm.matlab.show('c.vis.heatmap.savefig("Cov.unifrnd.png", "-m3");')
28 c.vis.heatmap.savefig("Cov.unifrnd.png", "-m3");
function root()
Return a scalar MATLAB string containing the root directory of the ParaMonte library package.

Example output
1
2cholow = chol(pm.stats.dist.cov.getRand(5), 'lower');
3df = pm.stats.dist.mvn.getRand(zeros(length(cholow), 1), cholow, 5000)';
4
5c = pm.stats.Cov(df, "spearman"); c.val
6ans =
7 5x5 table
8 df1 df2 df3 df4 df5
9 _________________ _________________ _________________ _________________ _________________
10 df1 2083750 1458914.36707341 1137096.07261452 -1179355.46209242 -189786.848569714
11 df2 1458914.36707341 2083750 1650239.97959592 -1180383.54190838 607204.25205041
12 df3 1137096.07261452 1650239.97959592 2083750 -1897611.17023405 26434.4462892579
13 df4 -1179355.46209242 -1180383.54190838 -1897611.17023405 2083750 627761.368273655
14 df5 -189786.848569714 607204.25205041 26434.4462892579 627761.368273655 2083750
15
16c = pm.stats.Cov(df, "pearson"); c.val
17ans =
18 5x5 table
19 df1 df2 df3 df4 df5
20 ___________________ __________________ __________________ __________________ ___________________
21 df1 1.00117455060051 0.721742673091111 0.565302599618301 -0.5822753319977 -0.0941241024078713
22 df2 0.721742673091111 1.01050607708839 0.808780909081777 -0.583825005133369 0.304942256601464
23 df3 0.565302599618301 0.808780909081777 0.989443138503714 -0.903519601500489 0.0112491487881783
24 df4 -0.5822753319977 -0.583825005133369 -0.903519601500489 0.98105309467735 0.31342680383306
25 df5 -0.0941241024078713 0.304942256601464 0.0112491487881783 0.31342680383306 1.00461470583648
26
27c = pm.stats.Cov(df); c.val
28ans =
29 5x5 table
30 df1 df2 df3 df4 df5
31 ___________________ __________________ __________________ __________________ ___________________
32 df1 1.00117455060051 0.721742673091111 0.565302599618301 -0.5822753319977 -0.0941241024078713
33 df2 0.721742673091111 1.01050607708839 0.808780909081777 -0.583825005133369 0.304942256601464
34 df3 0.565302599618301 0.808780909081777 0.989443138503714 -0.903519601500489 0.0112491487881783
35 df4 -0.5822753319977 -0.583825005133369 -0.903519601500489 0.98105309467735 0.31342680383306
36 df5 -0.0941241024078713 0.304942256601464 0.0112491487881783 0.31342680383306 1.00461470583648
37
38c.vis.heatmap.make(); c.vis.heatmap.subplot.setColorLim();
39c.vis.heatmap.savefig("Cov.unifrnd.png", "-m3");

Visualization of the example output


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:
Joshua Alexander Osborne, May 21 2024, 4:29 AM, University of Texas at Arlington
Fatemeh Bagheri, May 20 2024, 1:25 PM, NASA Goddard Space Flight Center (GSFC), Washington, D.C.
Amir Shahmoradi, May 16 2016, 9:03 AM, Oden Institute for Computational Engineering and Sciences (ICES), UT Austin

Member Function Documentation

◆ get()

function Cov::get ( in  self,
in  dfref,
in  method 
)

Return the covariance matrix of the input data.

This is a dynamic method of the pm.stats.Cov class.
This method automatically stores any input information in the corresponding components of the parent object.
However, any components of the parent object corresponding to the output of this method must be set explicitly manually.

Parameters
[in,out]self: The implicitly-passed input argument representing the parent object of the method.
[in]dfref: The input (reference of function handle returning a) MATLAB matrix or table of rank 2 containing the ncol columns of nrow data whose covariance matrix must be computed.
Ideally, the user would want to pass a reference to a dataframe (e.g., as a function handle @()df) so that the data remains dynamically up-to-date.
(optional. If missing, the contents of the corresponding internal component of the parent object will be used.)
[in]method: The input scalar MATLAB string that can be either:
  1. "pearson" : for computing the Pearson covariance matrix of the input data.
  2. "spearman" : for computing the Spearman rank covariance matrix of the input data.
(optional, default = "pearson")
Returns
val : The output MATLAB table containing the covariance matrix.


Possible calling interfaces

mat = pm.stats.Cov(dfref, method)
mat.val = mat.get()
mat.val = mat.get([])
mat.val = mat.get([], [])
mat.val = mat.get([], method)
mat.val = mat.get(dfref)
mat.val = mat.get(dfref, [])
mat.val = mat.get(dfref, method)
Note
See the documentation of the class constructor pm.stats.Cor for example usage.


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:
Joshua Alexander Osborne, May 21 2024, 4:31 AM, University of Texas at Arlington
Fatemeh Bagheri, May 20 2024, 1:25 PM, NASA Goddard Space Flight Center (GSFC), Washington, D.C.
Amir Shahmoradi, May 16 2016, 9:03 AM, Oden Institute for Computational Engineering and Sciences (ICES), UT Austin

◆ setvis()

function Cov::setvis ( in  self,
in  val 
)

Set up the visualization tools of the covariance matrix.

This is a dynamic Hidden method of the pm.stats.Cov class.
This method is inaccessible to the end users of the ParaMonte MATLAB library.

Parameters
[in,out]self: The implicitly-passed input argument representing the parent object of the method.
[in]val: The input (reference of function handle returning a) MATLAB matrix or table of rank 2 containing the computed covariance matrix to be visualized.
Ideally, the user would want to pass a reference to a dataframe (e.g., as a function handle @()df) so that the data remains dynamically up-to-date.
(optional. If missing, the contents of the corresponding var attribute of the parent object will be used.)


Possible calling interfaces

mat = pm.stats.Cov(dfref, method)
mat.setvis(); % This method is automatically called within the object constructor.


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:
Fatemeh Bagheri, May 20 2024, 1:25 PM, NASA Goddard Space Flight Center (GSFC), Washington, D.C.
Amir Shahmoradi, May 16 2016, 9:03 AM, Oden Institute for Computational Engineering and Sciences (ICES), UT Austin

Field Documentation

◆ dfref

Property Cov::dfref

dfref

A scalar object of class pm.container.DataFrame containing the user-specified data whose covariance must be computed.

Definition at line 34 of file Cov.m.

◆ method

Property Cov::method

method

The scalar MATLAB string containing the method of computing the covariance matrix.
It can be either:

  1. "pearson" : for computing the Pearson covariance matrix of the input data.
  2. "spearman" : for computing the Spearman rank covariance matrix of the input data.

Definition at line 47 of file Cov.m.

◆ val

Property Cov::val

val

The MATLAB table of rank 2 serving as a convenient storage component for the covariance matrix.
This component is automatically populated at the time of constructing an object of class pm.stats.Cov.
It must be populated manually at all other times.

Definition at line 58 of file Cov.m.

◆ vis

Property Cov::vis

vis

The scalar MATLAB struct containing the set of predefined visualizations for the output data.

Definition at line 66 of file Cov.m.


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