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%> \AmirShahmoradi, 3:31 PM Friday, November 8, 2024, Dallas, TX<br>
21%> \FatemehBagheri, May 20 2024, 1:25 PM, NASA Goddard Space Flight Center (GSFC), Washington, D.C.<br>
22classdef FileContentsSample < pm.io.FileContentsTabular
23
24 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
25
26 properties(Access = public)
27 %>
28 %> ``ndim``
29 %>
30 %> The scalar MATLAB integer representing the number of
31 %> dimensions of the domain of the objective function sampled.<br>
32 %> This integer is also the number of columns in the file that
33 %> correspond that contain the sampled states from the domain
34 %> of the mathematical objective function.<br>
35 %>
36 ndim = 0;
37 %>
38 %> ``slfc``
39 %>
40 %> 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 %>
46 %> \code{.m}
48 %> \endcode
49 %>
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 slfc = 0;
56 %>
57 %> ``stats``
58 %>
59 %> The scalar MATLAB object containing the set of
60 %> computed properties of the contents of the file.<br>
61 %> This component is populated by the subclasses automatically.<br>
62 %> It can also be manually constructed by calling the ``Hidden`` class method
63 %> [pm.sampling.FileContentsSample::setstats](@ref FileContentsSample::setstats).<br>
64 %>
65 stats = [];
66 %>
67 %> ``vis``
68 %>
69 %> The scalar MATLAB ``struct`` containing the set of
70 %> predefined visualizations for the output data.<br>
71 %> This component is populated by the subclasses automatically.<br>
72 %> It can also be manually constructed by calling the ``Hidden`` class method
73 %> [pm.sampling.FileContentsSample::setvis](@ref FileContentsSample::setvis).<br>
74 vis = [];
75 end
76
77 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
78
79 properties(Hidden)
80 %>
81 %> ``slfcname``
82 %>
83 %> The ``Hidden`` scalar MATLAB string representing
84 %> the column name of the dataframe component ``df`` that
85 %> contains the natural logarithm of the objective function
86 %> values corresponding to the sampled states next to this column.<br>
87 %>
88 %> \warning
89 %> This is an internal ``Hidden`` class attribute
90 %> that is inaccessible to the end users.<br>
91 %>
92 slfcname = "sampleLogFunc";
93 end
94
95 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
96
97 methods(Access = public)
98
99 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
100
101 %> \brief
102 %> Return a scalar object of class [pm.sampling.FileContentsSample](@ref FileContentsSample).<br>
103 %>
104 %> \details
105 %> This is the constructor of the class [pm.sampling.FileContentsSample](@ref FileContentsSample).<br>
106 %>
107 %> \param[in] file : The input scalar MATLAB string containing the path to an external file.<br>
108 %> \param[in] silent : See the corresponding argument of [pm.sampling.FileContentsRestart](@ref FileContentsRestart) class.<br>
109 %> (**optional**. The default is set by [pm.sampling.FileContentsRestart](@ref FileContentsRestart).)
110 %> \param[in] sep : The input scalar MATLAB string containing the field separator used in the file.<br>
111 %> (**optional**, default = ``","``)
112 %>
113 %> \return
114 %> ``self`` : The output scalar object of class [pm.sampling.FileContentsSample](@ref FileContentsSample).<br>
115 %>
116 %> \interface{FileContentsSample}
117 %> \code{.m}
118 %>
119 %> contents = pm.sampling.FileContentsSample(file)
120 %> contents = pm.sampling.FileContentsSample(file, [])
121 %> contents = pm.sampling.FileContentsSample(file, silent)
122 %> contents = pm.sampling.FileContentsSample(file, [], [])
123 %> contents = pm.sampling.FileContentsSample(file, [], sep)
124 %> contents = pm.sampling.FileContentsSample(file, silent, [])
125 %> contents = pm.sampling.FileContentsSample(file, silent, sep)
126 %>
127 %> \endcode
128 %>
129 %> \note
130 %> See the documentations of the subclasses of this class for example usage.<br>
131 %>
132 %> \final{FileContentsSample}
133 %>
134 %> \author
135 %> \JoshuaOsborne, May 21 2024, 3:36 AM, University of Texas at Arlington<br>
136 %> \FatemehBagheri, May 20 2024, 1:25 PM, NASA Goddard Space Flight Center (GSFC), Washington, D.C.<br>
137 %> \AmirShahmoradi, May 16 2016, 9:03 AM, Oden Institute for Computational Engineering and Sciences (ICES), UT Austin<br>
138 function self = FileContentsSample(file, silent, sep)
139
140 if nargin < 3
141 sep = [];
142 end
143 if nargin < 2
144 silent = [];
145 end
147 self = self@pm.io.FileContentsTabular(file, silent, sep);
148
149 for icol = 1 : self.ncol
150 if strcmpi(self.df.Properties.VariableNames{icol}, self.slfcname)
151 break;
152 end
153 end
154
155 self.slfc = icol;
156 self.ndim = self.ncol - self.slfc;
157 if self.nrow <= self.ndim
158 warning ( newline ...
159 + "There are insufficient number of states in the specified file:" + newline ...
160 + newline ...
161 + pm.io.tab() + self.file + newline ...
162 + newline ...
163 + "for computing the covariance/correlation matrices. Skipping..." + newline ...
164 + newline ...
165 );
166 return;
167 end
168
169 %%%%
170 %%%% statistics (actual computations are all done in the ``setstats`` method and respective subclasses).
171 %%%%
172
173 %self.setstats();
174
175 %%%%
176 %%%% visualization (actual visualization setup are all done in ``setvis`` method and the respective subclasses).
177 %%%%
178
179 %self.setvis();
180
181 end
182
183 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
184
185 end
186
187 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
188
189 methods(Access = public, Hidden)
190
191 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
192
193 %> \brief
194 %> Compute the statistics of the parent object of class [pm.sampling.FileContentsSample](@ref FileContentsSample)
195 %> and store the results in the respective fields of the ``stats`` attribute of the parent object.<br>
196 %>
197 %> \brief
198 %> This is a dynamic ``Hidden`` method of class [pm.sampling.FileContentsSample](@ref FileContentsSample).<br>
199 %> It is **inaccessible** to the end users of the library.<br>
200 %>
201 %> \param[in] self : The input parent object of class [pm.sampling.FileContentsSample](@ref FileContentsSample)
202 %> which is **implicitly** passed to this dynamic method (not by the user).<br>
203 %>
204 %> \interface{setstats}
205 %> \code{.m}
206 %>
207 %> contents = pm.sampling.FileContentsSample();
208 %>
209 %> contents.setstats();
210 %>
211 %> \endcode
212 %>
213 %> \final{setstats}
214 %>
215 %> \author
216 %> \AmirShahmoradi, 2:11 PM Friday, November 8, 2024, Dallas, TX<br>
217 %> \FatemehBagheri, May 20 2024, 1:25 PM, NASA Goddard Space Flight Center (GSFC), Washington, D.C.<br>
218 function setstats(self)
219
220 self.stats = struct();
221
222 self.checkpoint("adding the stats components...", false);
223
224 %%%%
225 %%%% Add chain cormat.
226 %%%%
228 self.checkpoint("computing the sample correlation matrix...", false);
229 self.stats.cor = pm.stats.Cor(self.df(:, self.slfc + 1 : end));
230 self.checkpoint();
231
232 %%%%
233 %%%% Add chain covmat.
234 %%%%
235
236 self.checkpoint("computing the sample covariance matrix...", false);
237 self.stats.cov = pm.stats.Cov(self.df(:, self.slfc + 1 : end));
238 self.checkpoint();
239
240 %%%%
241 %%%% Add chain acf.
242 %%%%
243
244 self.checkpoint("computing the sample autocorrelation...", false);
245 self.stats.acf = pm.stats.AutoCorr(self.df(:, self.slfc : end));
246 self.checkpoint();
247
248 self.stats.max = struct("val", [], "loc", []);
249 self.stats.min = struct("val", [], "loc", []);
250
251 %%%%
252 %%%% The `{:,:}` slice is essential in MATLAB ~2020a.
253 %%%%
254
255 [self.stats.max.val, self.stats.max.loc] = max(self.df{:,:});
256 [self.stats.min.val, self.stats.min.loc] = min(self.df{:,:});
257 self.stats.avg = mean(self.df{:,:});
258 self.stats.std = std(self.df{:,:});
259
260 %%%%
261 %%%% Add the ACF stats information.
262 %%%%
263
264 self.stats.acf = pm.stats.AutoCorr(@()self.df);
265
266 %%%%
267 %%%% Add the correlation/covariance matrix information.
268 %%%%
269
270 self.stats.cor = pm.stats.Cor(@()self.df);
271 self.stats.cov = pm.stats.Cov(@()self.df);
272
273 self.checkpoint();
274
275 end
276
277 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
278
279 %> \brief
280 %> Compute the statistics of the parent object of class [pm.sampling.FileContentsSample](@ref FileContentsSample)
281 %> and store the results in the respective fields of the ``stats`` attribute of the parent object.<br>
282 %>
283 %> \brief
284 %> This is a dynamic ``Hidden`` method of class [pm.sampling.FileContentsSample](@ref FileContentsSample).<br>
285 %> It is **inaccessible** to the end users of the library.<br>
286 %>
287 %> \param[in] self : The input parent object of class [pm.sampling.FileContentsSample](@ref FileContentsSample)
288 %> which is **implicitly** passed to this dynamic method (not by the user).<br>
289 %>
290 %> \interface{setvis}
291 %> \code{.m}
292 %>
293 %> contents = pm.sampling.FileContentsSample();
294 %>
295 %> contents.setvis();
296 %>
297 %> \endcode
298 %>
299 %> \final{setvis}
300 %>
301 %> \author
302 %> \AmirShahmoradi, 2:12 PM Friday, November 8, 2024, Dallas, TX<br>
303 %> \FatemehBagheri, May 20 2024, 1:25 PM, NASA Goddard Space Flight Center (GSFC), Washington, D.C.<br>
304 function setvis(self)
305
306 self.vis = struct();
307
308 self.checkpoint("adding the visualization components...", false);
309
310 colf = self.slfc;
311 cols = self.slfc + [1 : self.ndim];
312 silent_kws = {"silent", self.silent};
313
314 self.vis.cascade = struct();
315
316 self.vis.cascade.line = pm.vis.CascadeLine(@()self.df, "coly", cols, "colc", colf, silent_kws{:});
317 self.vis.cascade.scatter = pm.vis.CascadeScatter(@()self.df, "coly", cols, "colc", colf, silent_kws{:});
318 self.vis.cascade.lineScatter = pm.vis.CascadeLineScatter(@()self.df, "coly", cols, "colc", colf, silent_kws{:});
319
320 self.vis.cascade.line3 = pm.vis.CascadeLine3(@()self.df, "coly", cols, "colz", colf, "colc", colf, silent_kws{:});
321 self.vis.cascade.scatter3 = pm.vis.CascadeScatter3(@()self.df, "coly", cols, "colz", colf, "colc", colf, silent_kws{:});
322 self.vis.cascade.lineScatter3 = pm.vis.CascadeLineScatter3(@()self.df, "coly", cols, "colz", colf, "colc", colf, silent_kws{:});
323
324 self.vis.cascade.histfit = pm.vis.CascadeHistfit(@()self.df, "colx", cols, silent_kws{:});
325 self.vis.cascade.histogram = pm.vis.CascadeHistogram(@()self.df, "colx", cols, silent_kws{:});
326 self.vis.cascade.histogram2 = pm.vis.CascadeHistogram2(@()self.df, "colx", cols, "coly", colf, silent_kws{:});
327
328 self.vis.cascade.contour = pm.vis.CascadeContour(@()self.df, "colx", cols, "coly", colf, silent_kws{:});
329 self.vis.cascade.contourf = pm.vis.CascadeContourf(@()self.df, "colx", cols, "coly", colf, silent_kws{:});
330 self.vis.cascade.contour3 = pm.vis.CascadeContour3(@()self.df, "colx", cols, "coly", colf, silent_kws{:});
331
332 self.vis.plot = struct();
333
334 self.vis.plot.line = pm.vis.PlotLine(@()self.df, "coly", cols, "colc", colf, silent_kws{:});
335 self.vis.plot.scatter = pm.vis.PlotScatter(@()self.df, "coly", cols, "colc", colf, silent_kws{:});
336 self.vis.plot.lineScatter = pm.vis.PlotLineScatter(@()self.df, "coly", cols, "colc", colf, silent_kws{:});
337
338 self.vis.plot.line3 = pm.vis.PlotLine3(@()self.df, "coly", cols, "colc", colf, silent_kws{:});
339 self.vis.plot.scatter3 = pm.vis.PlotScatter3(@()self.df, "coly", cols, "colz", colf, "colc", colf, silent_kws{:});
340 self.vis.plot.lineScatter3 = pm.vis.PlotLineScatter3(@()self.df, "coly", cols, "colz", colf, "colc", colf, silent_kws{:});
341
342 self.vis.plot.histfit = pm.vis.PlotHistfit(@()self.df, "colx", cols, silent_kws{:});
343 self.vis.plot.histogram = pm.vis.PlotHistogram(@()self.df, "colx", cols, silent_kws{:});
344 self.vis.plot.histogram2 = pm.vis.PlotHistogram2(@()self.df, "colx", colf, "coly", cols, silent_kws{:});
345
346 self.vis.plot.contour = pm.vis.PlotContour(@()self.df, "colx", cols, "coly", colf, silent_kws{:});
347 self.vis.plot.contourf = pm.vis.PlotContourf(@()self.df, "colx", cols, "coly", colf, silent_kws{:});
348 self.vis.plot.contour3 = pm.vis.PlotContour3(@()self.df, "colx", cols, "coly", colf, silent_kws{:});
349
350 self.vis.tile = struct();
351
352 self.vis.tile.line = pm.vis.TileLine(@()self.df, "coly", cols, "colc", colf, silent_kws{:});
353 self.vis.tile.scatter = pm.vis.TileScatter(@()self.df, "coly", cols, "colc", colf, silent_kws{:});
354 self.vis.tile.lineScatter = pm.vis.TileLineScatter(@()self.df, "coly", cols, "colc", colf, silent_kws{:});
355
356 self.vis.tile.line3 = pm.vis.TileLine3(@()self.df, "coly", cols, "colc", colf, silent_kws{:});
357 self.vis.tile.scatter3 = pm.vis.TileScatter3(@()self.df, "coly", cols, "colz", colf, "colc", colf, silent_kws{:});
358 self.vis.tile.lineScatter3 = pm.vis.TileLineScatter3(@()self.df, "coly", cols, "colz", colf, "colc", colf, silent_kws{:});
359
360 self.vis.tile.histfit = pm.vis.TileHistfit(@()self.df, "colx", cols, silent_kws{:});
361 self.vis.tile.histogram = pm.vis.TileHistogram(@()self.df, "colx", cols, silent_kws{:});
362 self.vis.tile.histogram2 = pm.vis.TileHistogram2(@()self.df, "colx", colf, "coly", cols, silent_kws{:});
363
364 self.vis.tile.contour = pm.vis.TileContour(@()self.df, "colx", cols, "coly", colf, silent_kws{:});
365 self.vis.tile.contourf = pm.vis.TileContourf(@()self.df, "colx", cols, "coly", colf, silent_kws{:});
366 self.vis.tile.contour3 = pm.vis.TileContour3(@()self.df, "colx", cols, "coly", colf, silent_kws{:});
367
368 self.vis.triplex.lshc2 = pm.vis.Triplex ( pm.vis.SubplotLineScatter(@()self.df, "colx", cols, "coly", cols, "colc", colf, "colorbar", {"enabled", false}) ...
369 , pm.vis.SubplotHistogram(@()self.df, "colx", cols) ...
370 , pm.vis.SubplotContour(@()self.df, "colx", cols, "coly", cols, "colorbar", {"enabled", false}) ...
371 , silent_kws{:} ...
372 );
373
374 self.vis.triplex.lshcf = pm.vis.Triplex ( pm.vis.SubplotLineScatter(@()self.df, "colx", cols, "coly", cols, "colc", colf, "colorbar", {"enabled", false}) ...
375 , pm.vis.SubplotHistogram(@()self.df, "colx", cols) ...
376 , pm.vis.SubplotContourf(@()self.df, "colx", cols, "coly", cols, "colorbar", {"enabled", false}) ...
377 , silent_kws{:} ...
378 );
379
380 self.vis.triplex.lshc3 = pm.vis.Triplex ( pm.vis.SubplotLineScatter(@()self.df, "colx", cols, "coly", cols, "colc", colf, "colorbar", {"enabled", false}) ...
381 , pm.vis.SubplotHistogram(@()self.df, "colx", cols) ...
382 , pm.vis.SubplotContour3(@()self.df, "colx", cols, "coly", cols, "colorbar", {"enabled", false}) ...
383 , silent_kws{:} ...
384 );
385
386 %if 5 < ndim
387 % self.vis.triplex.layout.tiling.position = [.1, .1, nan, nan];
388 % self.vis.triplex.layout.cbarh.position = [];
389 % self.vis.triplex.layout.cbarv.position = [];
390 % self.vis.triplex.layout.tiling.tile.width = [];
391 %end
392
393 self.checkpoint();
394
395 end
396
397 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
398
399 end
400
401 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
402
403end
function name(in vendor)
Return the MPI library name as used in naming the ParaMonte MATLAB shared library directories.
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 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 setvis(in self)
Compute the statistics of the parent object of class pm.sampling.FileContentsSample and store the res...
function setstats(in self)
Compute the statistics of the parent object of class pm.sampling.FileContentsSample and store the res...
function FileContentsSample(in file, in silent, in sep)
Return a scalar object of class pm.sampling.FileContentsSample.
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.
function which(in vendor)
Return the a MATLAB string containing the path to the first mpiexec executable binary found in system...