ParaMonte MATLAB 3.0.0
Parallel Monte Carlo and Machine Learning Library
See the latest version documentation.
FileContentsSample.m
Go to the documentation of this file.
1%> \brief
2%> This is the base class for generating objects
3%> that contain the contents of a sample/chain file
4%> generated by a ParaMonte sampler.<br>
5%> This class is meant to be primarily internally
6%> used by the ParaMonte MATLAB library samplers.<br>
7%>
8%> \note
9%> See the documentation of the class constructor.<br>
10%>
11%> \note
12%> See below for information on the attributes (properties).<br>
13%>
14%> \note
15%> See below for information on the methods.<br>
16%>
17%> \final{FileContentsSample}
18%>
19%> \author
20%> \JoshuaOsborne, May 21 2024, 3:32 AM, University of Texas at Arlington<br>
21%> \FatemehBagheri, May 20 2024, 1:25 PM, NASA Goddard Space Flight Center (GSFC), Washington, D.C.<br>
22%> \AmirShahmoradi, May 16 2016, 9:03 AM, Oden Institute for Computational Engineering and Sciences (ICES), UT Austin<br>
23classdef FileContentsSample < pm.io.FileContentsTabular
24
25 properties(Access = public)
26 %>
27 %> ``stats`` : The scalar MATLAB object containing the set of
28 %> computed properties of the contents of the file.<br>
29 %>
30 stats = [];
31 %>
32 %> ``ndim`` : The scalar MATLAB integer representing the number of
33 %> dimensions of the domain of the objective function sampled.<br>
34 %> This integer is also the number of columns in the file that
35 %> correspond that contain the sampled states from the domain
36 %> of the mathematical objective function.<br>
37 %>
38 ndim = 0;
39 %>
40 %> ``sampleLogFuncColIndex`` : The scalar MATLAB integer representing the column
41 %> index of the dataframe component ``df`` that contains
42 %> the natural logarithm of the objective function values
43 %> corresponding to the sampled states next to this column,
44 %> such that the following relationship holds.<br>
45 %> \code{.m}
47 %> FileContentsSample.ncol -
49 %> \endcode
50 %> While this column index can be readily inferred by exploring
51 %> the contents of the dataframe component, this column index is also
52 %> computed and explicitly offered to conveniently slice the values of
53 %> the sampled states and their corresponding log-function values.<br>
54 %>
55 sampleLogFuncColIndex = 0;
56 end
57
58 properties(Hidden)
59 %>
60 %> ``sampleLogFuncColName`` : The scalar MATLAB string representing the column
61 %> name of the dataframe component ``df`` that contains
62 %> the natural logarithm of the objective function values
63 %> corresponding to the sampled states next to this column.<br>
64 %>
65 sampleLogFuncColName = "sampleLogFunc";
66 end
67
68 methods(Access = public)
69
70 %> \brief
71 %> Return a scalar object of class [pm.sampling.FileContentsSample](@ref FileContentsSample).<br>
72 %> This is the constructor of the class [pm.sampling.FileContentsSample](@ref FileContentsSample).<br>
73 %>
74 %> \param[in] file : The input scalar MATLAB string containing the path to an external file.<br>
75 %> \param[in] silent : See the corresponding argument of [pm.sampling.FileContentsRestart](@ref FileContentsRestart) class.<br>
76 %> (**optional**. The default is set by [pm.sampling.FileContentsRestart](@ref FileContentsRestart).)
77 %> \param[in] sep : The input scalar MATLAB string containing the field separator used in the file.<br>
78 %> (**optional**, default = ``","``)
79 %>
80 %> \return
81 %> ``self`` : The output scalar object of class [pm.sampling.FileContentsSample](@ref FileContentsSample).<br>
82 %>
83 %> \interface{FileContentsSample}
84 %> \code{.m}
85 %>
86 %> contents = pm.sampling.FileContentsSample(file)
87 %> contents = pm.sampling.FileContentsSample(file, [])
88 %> contents = pm.sampling.FileContentsSample(file, silent)
89 %> contents = pm.sampling.FileContentsSample(file, [], [])
90 %> contents = pm.sampling.FileContentsSample(file, [], sep)
91 %> contents = pm.sampling.FileContentsSample(file, silent, [])
92 %> contents = pm.sampling.FileContentsSample(file, silent, sep)
93 %>
94 %> \endcode
95 %>
96 %> \final{FileContentsSample}
97 %>
98 %> \author
99 %> \JoshuaOsborne, May 21 2024, 3:36 AM, University of Texas at Arlington<br>
100 %> \FatemehBagheri, May 20 2024, 1:25 PM, NASA Goddard Space Flight Center (GSFC), Washington, D.C.<br>
101 %> \AmirShahmoradi, May 16 2016, 9:03 AM, Oden Institute for Computational Engineering and Sciences (ICES), UT Austin<br>
102 function self = FileContentsSample(file, silent, sep)
103 if nargin < 3
104 sep = [];
105 end
106 if nargin < 2
107 silent = [];
108 end
109 self = self@pm.io.FileContentsTabular(file, silent, sep);
110
111 for icol = 1 : self.ncol
112 if strcmpi(self.df.Properties.VariableNames{icol}, self.sampleLogFuncColName)
113 break;
114 end
115 end
116 self.sampleLogFuncColIndex = icol;
117 self.ndim = self.ncol - self.sampleLogFuncColIndex;
118 if self.nrow <= self.ndim
119 warning ( newline ...
120 + "There are insufficient number of states in the specified file:" + newline ...
121 + newline ...
122 + pm.io.tab() + self.file + newline ...
123 + newline ...
124 + "for computing the covariance/correlation matrices. Skipping..." + newline ...
125 + newline ...
126 );
127 return;
128 end
129
130 %%%%
131 %%%% statistics
132 %%%%
133
134 self.stats = struct();
135
136 %%%% Add chain cormat.
137
138 self.checkpoint("computing the sample correlation matrix...", false);
139 self.stats.cor = pm.stats.Cor(self.df(:, self.sampleLogFuncColIndex + 1 : end));
140 self.checkpoint();
141
142 %%%% Add chain covmat.
143
144 self.checkpoint("computing the sample covariance matrix...", false);
145 self.stats.cov = pm.stats.Cov(self.df(:, self.sampleLogFuncColIndex + 1 : end));
146 self.checkpoint();
147
148 %%%% Add chain acf.
149
150 self.checkpoint("computing the sample autocorrelation...", false);
151 self.stats.acf = pm.stats.AutoCorr(self.df(:, self.sampleLogFuncColIndex : end));
152 self.checkpoint();
153
154 self.stats.max = struct("val", [], "loc", []);
155 self.stats.min = struct("val", [], "loc", []);
156
157 %%%% The `{:,:}` slice is essential in MATLAB ~2020a.
158
159 [self.stats.max.val, self.stats.max.loc] = max(self.df{:,:});
160 [self.stats.min.val, self.stats.min.loc] = min(self.df{:,:});
161 self.stats.avg = mean(self.df{:,:});
162 self.stats.std = std(self.df{:,:});
163
164 end
165
166 end
167
168end
function name(in vendor)
Return the MPI library name as used in naming the ParaMonte MATLAB shared libraries.
function index(in array)
Given array(1 : n), return the array index indx(1 : n) such that array(indx) is in ascending order.
This is the base class for generating objects containing information about autocorrelation of the inp...
Definition: AutoCorr.m:24
This is the base class for generating objects with methods and storage components for computing and s...
Definition: Cor.m:24
This is the base class for generating objects with methods and storage components for computing and s...
Definition: Cov.m:24
This is the base class for generating objects that contain the contents of a restart file generated b...
This is the base class for generating objects that contain the contents of a sample/chain file genera...
function FileContentsSample(in file, in silent, in sep)
Return a scalar object of class pm.sampling.FileContentsSample. This is the constructor of the class...
This is the base class for generating objects that contain the tabular contents of a given file.
function statistics()
Return a scalar MATLAB logical that is true if and only if the current installation of MATLAB contain...
function tab()
Return a scalar MATLAB string containing 4 blank characters equivalent to a tab character.