2%> This is the base
class for generating objects
3%> that contain the contents of a restart file
4%> generated by a ParaMonte sampler.<br>
7%> This
class is meant to be primarily internally
8%> used by the ParaMonte MATLAB library samplers.<br>
11%> The attributes of
this class are considered
12%> internal implementation of the ParaMonte library.<br>
13%> As such, the
interface of this class may change over time.<br>
16%> See the documentation of the
class constructor.<br>
19%> See below
for information on the attributes (properties).<br>
22%> See below
for information on the methods.<br>
27%> \JoshuaOsborne, May 21 2024, 3:26 AM, University of Texas at Arlington<br>
28%> \FatemehBagheri, May 20 2024, 1:25 PM, NASA Goddard Space Flight Center (GSFC), Washington, D.C.<br>
29%> \AmirShahmoradi, May 16 2016, 9:03 AM, Oden Institute
for Computational Engineering and Sciences (ICES), UT Austin<br>
32 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
34 properties(Access =
public)
36 %> ``meanAcceptanceRateSinceStart``
38 %> The real-valued MATLAB array of rank ``1`` of
39 %> shape ``(1:self.count)`` containing the set of
40 %> average MCMC acceptance rates of the sampler proposal
41 %> distribution over the course of the simulation.<br>
43 meanAcceptanceRateSinceStart = [];
45 %> ``proposalAdaptiveScaleSq``
47 %> The real-valued MATLAB array of rank ``1`` of
48 %> shape ``(1:self.count)`` containing the set of
49 %> adaptive squared scale factors of the sampler proposal
50 %> distribution over the course of the simulation.<br>
52 proposalAdaptiveScaleSq = [];
56 %> The real-valued MATLAB array of rank ``3`` of
57 %> shape ``(self.ndim, self.ndim, self.count)`` containing
58 %> the set of correlation matrices of the proposal distribution
59 %> of the sampler, representing the evolution of the proposal
60 %> correlation matrix over the course of the simulation.<br>
66 %> The real-valued MATLAB array of rank ``3`` of
67 %> shape ``(1:self.ndim, 1:self.ndim, 1:self.count)`` containing
68 %> the set of covariance matrices of the proposal distribution
69 %> of the sampler, representing the evolution of the proposal
70 %> covariance matrix over the course of the simulation.<br>
74 %> ``proposalCovLogVol``
76 %> The real-valued MATLAB array of rank ``1`` of
77 %> shape ``(1:self.count)`` containing the set of
78 %> ``log(determinant(covmat))`` of the proposal distribution
79 %> representing the evolution of mean of proposal distribution
80 %> over the course of the simulation.<br>
82 proposalCovLogVol = [];
86 %> The real-valued MATLAB array of rank ``2`` of
87 %> shape ``(1:self.ndim, 1:self.count)`` containing
88 %> the set of mean vectors of the proposal distribution
89 %> of the sampler, representing the evolution of the proposal
90 %> mean over the course of the simulation.<br>
94 %> ``uniqueStateVisitCount``
96 %> The scalar MATLAB integer containing the number of
97 %> states uniquely visited within the domain of the
98 %> objective function up to the stage specified
99 %> within the specified restart file.<br>
101 uniqueStateVisitCount = [];
105 %> The scalar MATLAB ``
struct`` containing the set of
106 %> predefined visualizations
for the restart data.<br>
111 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
113 methods(Access =
public)
119 %> This is the constructor of the
class [pm.sampling.FileContentsRestartDRAM](@ref
FileContentsRestartDRAM).<br>
121 %> \param[in] file : The input scalar MATLAB
string containing the path to an external report file.<br>
122 %> \param[in] silent : See the corresponding argument of [pm.sampling.FileContentsRestart](@ref
FileContentsRestart)
class.<br>
123 %> (**optional**. The
default is set by [pm.sampling.FileContentsRestart](@ref
FileContentsRestart).)
126 %> ``self`` : The output scalar
object of
class [pm.sampling.FileContentsRestartDRAM](@ref
FileContentsRestartDRAM).<br>
132 %> contents = pm.sampling.FileContentsRestartDRAM(file, [])
133 %> contents = pm.sampling.FileContentsRestartDRAM(file, silent)
134 %> contents = pm.sampling.FileContentsRestartDRAM(file, [], [])
135 %> contents = pm.sampling.FileContentsRestartDRAM(file, silent, [])
136 %> contents = pm.sampling.FileContentsRestartDRAM(file, silent, method)
159 %> \JoshuaOsborne, May 21 2024, 3:31 AM, University of Texas at Arlington<br>
160 %> \FatemehBagheri, May 20 2024, 1:25 PM, NASA Goddard Space Flight Center (GSFC), Washington, D.C.<br>
161 %> \AmirShahmoradi, May 16 2016, 9:03 AM, Oden Institute
for Computational Engineering and Sciences (ICES), UT Austin<br>
168 self = self@pm.sampling.FileContentsRestart(file, silent,
"ParaDRAM");
171 %%%% Find the update count in the file.
174 self.count = count(self.contents,
'uniqueStateVisitCount');
177 %%%% Parse the restart file contents.
180 cholupp = zeros(self.ndim, self.ndim);
181 self.meanAcceptanceRateSinceStart = zeros(self.count, 1);
182 self.proposalAdaptiveScaleSq = zeros(self.count, 1);
183 self.proposalCovLogVol = zeros(self.count, 1);
184 self.proposalMean = zeros(self.ndim, self.count);
185 self.proposalCov = zeros(self.ndim, self.ndim, self.count);
186 self.proposalCor = zeros(self.ndim, self.ndim, self.count);
187 self.uniqueStateVisitCount = zeros(self.count, 1);
188 skip = 10 + self.ndim * (self.ndim + 3) / 2;
192 while istart < length(self.lineList) - skip
194 if ~strcmp(self.lineList{self.ilast + istart}, self.lineList{self.ilast + istart + 2})
196 if ~self.silent && mod(icount, 10) == 0
197 self.spinner.spin(icount / self.count);
199 self.meanAcceptanceRateSinceStart (icount) = str2double(self.lineList(self.ilast + istart + 1));
200 self.uniqueStateVisitCount (icount) = str2double(self.lineList(self.ilast + istart + 3));
201 self.proposalAdaptiveScaleSq (icount) = str2double(self.lineList(self.ilast + istart + 5));
202 self.proposalCovLogVol (icount) = str2double(self.lineList(self.ilast + istart + 7));
204 iend = istart + self.ndim;
205 self.proposalMean(1 : self.ndim, icount) = str2double(self.lineList(self.ilast + istart : self.ilast + iend - 1));
206 for idim = 1 : self.ndim % covmat
209 cholupp(1 : idim, idim) = str2double(self.lineList(self.ilast + istart : self.ilast + iend)); % This is the upper Cholesky.
211 self.proposalCov(:, :, icount) = cholupp' * cholupp;
220 %%%% Ensure the intrinsic ``corrcov`` is installed.
225 for icount = 1 : size(self.proposalCov, 3)
226 self.proposalCor(:, :, icount) = corrcov(squeeze(self.proposalCov(:, :, icount)));
231 self.proposalCor = self.proposalCov;
232 warning ( newline ...
233 +
string(me.identifier) + " : " +
string(me.message) + newline ...
234 + "The component ``proposalCor`` will be set to the same values as the component ``proposalCov``." + newline ...
241 self.spinner.spin(1);
246 %%%% Add the restart visualizations.
252 self.vis.cascade = struct();
253 silent_kws = {
"silent", self.silent};
255 self.checkpoint(
"adding restart data visualization tools for proposal evolution...");
257 dims = self.ndim * (self.ndim - 1) / 2;
258 dimx = zeros(dims, 1);
259 dimy = zeros(dims, 1);
261 for ix = 1 : self.ndim - 1
262 for iy = 2 : self.ndim
265 counter = counter + 1;
269 for field = [
"proposalCor",
"proposalCov"]
270 self.vis.(field) =
struct();
271 self.vis.(field).cascade =
struct();
272 self.vis.(field).cascade.ellipse = pm.vis.CascadeEllipse( @()self.(field) ...
273 , @()self.proposalMean ...
275 , "dimx", dimx, "dimy", dimy ...
276 , "names", self.domainAxisName ...
279 self.vis.(field).cascade.ellipse3 = pm.vis.CascadeEllipse3 ( @()self.(field) ...
280 , @()self.proposalMean ...
281 , @()transpose(self.uniqueStateVisitCount) ...
283 , "axes", {
"zscale",
"log"} ...
284 ,
"dimx", dimx,
"dimy", dimy ...
285 ,
"names", self.domainAxisName ...
286 ,
"zlabel", {
"txt",
"Unique State Visit Count"} ...
291 self.checkpoint(
"adding restart data visualization tools for other proposal properties...");
293 colnames = [
"uniqueStateVisitCount" ...
294 ,
"meanAcceptanceRateSinceStart" ...
295 ,
"proposalAdaptiveScaleSq" ...
296 ,
"proposalCovLogVol" ...
298 %fullnames = [
"Unique State Visit Count" ...
299 % ,
"Mean Acceptance Rate Since Start" ...
300 % ,
"Proposal Adaptive Scale-Squared" ...
301 % ,
"Proposal Covriance Log-Volume" ...
303 cdf = array2table( [ self.(colnames(1))(:) ...
304 , self.(colnames(2))(:) ...
305 , self.(colnames(3))(:) ...
306 , self.(colnames(4))(:) ...
308 cdf.Properties.VariableNames = colnames;
309 self.vis.cascade.line = pm.vis.CascadeLine ( cdf ...
310 ,
"colx", colnames(1) ...
311 ,
"coly", colnames(2 : end) ...
312 ,
"axes", {
"xscale",
"log"} ...
313 ,
"colormap", {
"enabled",
false} ...
314 ...,
"xlabel", {
"txt", fullnames(1)} ...
315 ...,
"ylabel", {
"txt", fullnames(2 : end)} ...
316 ,
"plot", {
"linewidth", 3} ...
324 warning ( newline ...
325 +
"Failed to create the visualizations for the restart data." + newline ...
326 +
"Here is the error message:" + newline ...
328 +
string(me.identifier) + newline +
string(me.message) + newline ...
336 end % methods(Access =
public)
338 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
340 methods(Access =
public, Hidden)
344 warning ( newline ...
345 +
"The structure of the file:" + newline ...
347 + pm.io.tab + self.file + newline ...
349 +
"does not match a DRAM-class restart file." + newline ...
350 +
"The contents of the file may have been compromised." + newline ...
351 +
"Verify the integrity of the file contents before attempting a reread." + newline ...
356 end % methods(Access = Hidden)
358 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
This is the base class for generating objects that contain the contents of a restart file generated b...
Property proposalCovLogVol
function FileContentsRestartDRAM(in file, in silent)
Return a scalar object of class pm.sampling.FileContentsRestartDRAM.
Property proposalAdaptiveScaleSq
Property uniqueStateVisitCount
Property meanAcceptanceRateSinceStart
This is the base class for generating objects that contain the contents of a restart file generated b...