2%> This is the ParaDRAM
class for generating instances of serial and
parallel
3%> Delayed-Rejection Adaptive Metropolis-Hastings Markov Chain Monte Carlo
4%> sampler of the ParaMonte MATLAB library.<br>
7%> For more information, see the documentation of the
class
11%> See the documentation of the
class constructor
for usage interface and examples.<br>
16%> \AmirShahmoradi, May 16 2016, 9:03 AM, Oden Institute
for Computational Engineering and Sciences (ICES), UT Austin<br>
19 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
21 methods(Access =
public)
23 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
26 %> Generate and
return an instance of the serial and
parallel
27 %> Delayed-Rejection Adaptive Metropolis-Hastings Markov Chain Monte Carlo
28 %> sampler of the ParaMonte MATLAB library.<br>
31 %> This function is the constructor of the [pm.sampling.Paradram](@ref
Paradram) sampler
class.<br>
32 %> Once you assign the desired simulation specifications to the corresponding attributes within the
33 %> component `spec` of an
object of
class [pm.sampling.Paradram](@ref
Paradram), call the ParaDRAM
34 %> sampler via the
object method [pm.sampling.Paradram.run()](@ref
Paradram::run).<br>
36 %> While the constructor of
this class does not take any input arguments,
37 %> all ParaDRAM simulation specifications can be set after creating the
object.<br>
40 %> ``sampler`` : The output scalar
object of
class [pm.sampling.Paradram](@ref
Paradram).<br>
50 %> When
using the ParaMonte MATLAB library functionalities, particularly ParaMonte samplers in
parallel,
51 %> it would be best to close any such aggressive software/applications as **Dropbox**, **ZoneAlarm**, ...
52 %> that interfere with your ParaMonte MATLAB library output files, potentially causing the tasks
53 %> to fail and crash before successful completion.<br>
54 %> These situations scarcely happen.<br>
57 %> On Windows systems, when restarting an old interrupted ParaDRAM simulation,
58 %> ensure your MATLAB session is also restarted before the simulation restart.<br>
59 %> This may be needed as **Windows frequently locks access to some or all simulation output files**.<br>
62 %> To unset an already-set input simulation specification, simply set the
63 %> simulation attribute to empty
double `[]` or re-instantiate an
object
64 %> of
class [pm.sampling.Paradram.run()](@ref
Paradram).<br>
67 %> [ParaDRAM simulation specifications listing](\pmdoc_usage_sampling/paradram/specifications/)<br>
68 %> [ParaDRAM simulation restart functionality](\pmdoc_usage_sampling/paradram/restart/)<br>
69 %> [ParaDRAM simulation output files](\pmdoc_usage_sampling/paradram/output/)<br>
71 %> ParaDRAM Simulation Specifications
72 %> ----------------------------------
74 %> The ParaDRAM simulation specifications have lengthy comprehensive descriptions
75 %> that appear in full in the output report files of every ParaDRAM simulation.<br>
77 %> The best way to learn about individual ParaDRAM simulation attributes
78 %> is to a run a minimal serial simulation as given in the above.<br>
79 %> You can also use the ``sampler.spec.doc()`` method:
82 %> sampler = pm.sampling.Paradram();
86 %> Example Usage: Serial
87 %> ---------------------
89 %> First, ensure the ParaMonte ``+pm`` package (i.e., folder) is available in your MATLAB paths.
91 %> Here is a MATLAB script ``main.m``
for a serial ParaDRAM simulation.<br>
92 %> Copy and paste the following code into your MATLAB session:<br>
97 %> sampler = pm.sampling.Paradram();
98 %> sampler.run ( @(x) - sum(x.^2) ...
getLogFunc: the natural log of the objective function.
99 %> , ndim ... ndim: the number of dimensions of the objective function.
101 %> samples = sampler.readSample();
102 %> sample = samples{1};
103 %> tile = pm.vis.TileLine(sample.df);
104 %> tile.make(
"coly", sample.slfc + 1 : sample.slfc + ndim,
"colc",
"sampleLogFunc");
108 %> The mathematical objective function in the above example is a
109 %> is a multivariate Normal distribution centered at the origin,
110 %> whose natural logarithm is returned by the lambda (``Anonymous``)
111 %> function defined as a function handle input to the ParaDRAM sampler.<br>
113 %> Running
this code will generate a set of simulation output files (in the current working directory of MATLAB).<br>
114 %> Among these, the file suffixed with
"_report.txt" contains the full description of all input specifications
115 %> of the ParaDRAM simulation as well as other information about the simulation results.<br>
117 %> Example Usage: Thread-Parallel
118 %> ------------------------------
120 %> First, ensure the ParaMonte ``+pm`` package (i.e., folder) is available in your MATLAB paths.<br>
122 %> Threading parallelism is possible as of ParaMonte MATLAB
version ``3.0.0``.<br>
123 %> However, only ``singleChain`` ParaDRAM simulations are supported.<br>
125 %> Here is a MATLAB script ``main.m``
for a thread-
parallel ParaDRAM simulation.<br>
126 %> Copy and paste the following code and paste into your MATLAB session:<br>
130 %> sampler = pm.sampling.Paradram();
131 %> sampler.spec.parallelismNumThread = 0; % use all available threads.
132 %> sampler.run ( @(x) - sum(x.^2) ...
getLogFunc: the natural log of the objective function.
133 %> , 4 ... ndim: the number of dimensions of the objective function.
135 %> samples = sampler.readSample();
136 %> sample = samples{1};
137 %> pm.vis.tile(sample.contents)
141 %> The mathematical objective function in the above example is a
142 %> is a multivariate Normal distribution centered at the origin,
143 %> whose natural logarithm is returned by the lambda (``Anonymous``)
144 %> function defined as a function handle input to the ParaDRAM sampler.<br>
146 %> Running
this code will generate a set of simulation output files (in the current working directory of MATLAB).<br>
147 %> Among these, the file suffixed with ``
"_report.txt"`` contains the full description of all input specifications
148 %> of the ParaDRAM simulation as well as other information about the simulation results.<br>
150 %> Specifying ``0`` as the number of threads will lead to
using
151 %> all available CPU threads
for thread-
parallel ParaDRAM simulation.<br>
154 %> **Benefits of thread-parallelism**<br>
155 %> Thread-
parallel simulations offer a much more flexible
156 %> and easier approach to benefiting from parallelism without
157 %> going through the hassle of MPI-
parallel simulations.<br>
158 %> But they can still potentially offer much faster speed than serial simulations.<br>
159 %> The actual speedup depends on a lot of factors.<br>
160 %> Moreover, the number of threads is limited to maximum
161 %> number of physical cores available on your system.<br>
162 %> As such, thread-
parallel simulations are not scalable.<br>
163 %> If you need scalability, checkout MPI-parallelism below.<br>
165 %> Example Usage: MPI-Parallel
166 %> ---------------------------
168 %> First, ensure the ParaMonte ``+pm`` package (i.e., folder) is available in your MATLAB paths.<br>
170 %> MPI-
parallel simulations can be slightly more cumbersome than thread-
parallel simulations
171 %> described above because MPI-
parallel simulations cannot be performed from within a MATLAB GUI
172 %> session and require launching MATLAB via a compatible ``mpiexec`` launcher.<br>
175 %> <li> Ensure you need and will get a speedup by running the an MPI-
parallel simulation.<br>
176 %> Typically, your simulation may then benefit from parallelism only
if a single
177 %> evaluation of the objective function takes longer than a few milliseconds.<br>
179 %> <li> Ensure the required MPI libraries are installed on your system
180 %> (You can skip
this step
if you know that you already have
181 %> a compatible MPI library installed on your system).<br>
182 %> On the MATLAB command line type the following,<br>
186 %> This will
verify the existence of a valid MPI library on your system and,
187 %>
if missing, will guide you to
install the MPI library on your system.<br>
189 %> <li> Once the MPI installation is verified,
copy and paste the following
190 %> code into your MATLAB session:
193 %> fid = fopen(
"main_mpi.m",
"w");
195 %>
"sampler = pm.sampling.Paradram();" + newline + ...
196 %>
"%sampler.mpiname = ''; % set this to an explicit MPI library name if needed." + newline + ...
197 %>
"sampler.run( @(x) - sum(x.^2) ... getLogFunc: the natural log of the objective function." + newline + ...
198 %>
" , 4 ... ndim: the number of dimensions of the objective function" + newline + ...
200 %> fprintf(fid,
"%s\n", sourceCode);
205 %> <li> This will generate a ``main_mpi.m`` MATLAB script file in the current working directory of your MATLAB session.<br>
206 %> Now, you can execute
this MATLAB script file (``main_mpi.m``) in
parallel.<br>
207 %> To do so, you need to call MATLAB on a command-line, **out of MATLAB GUI**.<br>
209 %> <li> **On Windows**:<br>
210 %> From within command prompt that recognizes both MATLAB and ``mpiexec``,
211 %> ideally, the Intel dedicated command-prompt that is shipped with Intel MPI library,
212 %> type the following,
215 %> mpiexec -localonly -n 3 matlab -batch
"main_mpi"
220 %> In the above MPI launcher command
for Windows OS,
221 %> we assumed that you would be
using the Intel MPI library, hence,
222 %> the reason
for the extra flag ``-localonly``.<br>
223 %> This flag runs the
parallel code only on one node, but in doing so,
224 %> it avoids the use of Hydra service and its registration.<br>
225 %> If you are not on a Windows cluster, (e.g., you are
using your personal device),
226 %> then we recommend specifying
this flag.<br>
228 %> <li> **On macOS/Linux**:<br>
229 %> From within a Bash terminal that recognizes both MATLAB and ``mpiexec``,
230 %> type the following,
233 %> mpiexec -n 3 matlab -batch
"main_mpi"
238 %> In both cases in the above, the script ``main_mpi.m`` will run on 3 processors.<br>
239 %> Feel free to change the number of processors to any number desired.<br>
240 %> But
do not request more than the available number of physical cores on your system.<br>
245 %> Do not add postprocessing codes (such as reading and plotting the output samples) in your MPI-
parallel code.<br>
246 %> There is no point in doing so, since MATLAB will run in ``-batch`` mode
for parallel simulations, disabling all plotting capabilities.<br>
247 %> Moreover,
if you read and postprocess the output files in
parallel mode, the task will be done
248 %> by all
parallel processes, potentially overwriting external IO activities of each other.<br>
249 %> Only perform the sampling as described above in MPI-
parallel mode.<br>
251 %> \example{himmelblau}
252 %> \include{lineno} example/sampling/
Paradram/himmelblau/main.m
253 %> \output{himmelblau}
254 %> \include{lineno} example/sampling/
Paradram/himmelblau/main.out.m
256 %> \image html example/sampling/
Paradram/himmelblau/
Paradram.himmelblau.domain.2d.png width=700
258 %> \image html example/sampling/
Paradram/himmelblau/
Paradram.himmelblau.domain.3d.png width=700
260 %> \image html example/sampling/
Paradram/himmelblau/
Paradram.himmelblau.triplex.lshc2.png width=700
262 %> \image html example/sampling/
Paradram/himmelblau/
Paradram.himmelblau.triplex.lshc3.png width=700
264 %> \image html example/sampling/
Paradram/himmelblau/
Paradram.himmelblau.triplex.lshcf.png width=700
266 %> \image html example/sampling/
Paradram/himmelblau/
Paradram.himmelblau.traceplot.png width=700
268 %> \image html example/sampling/
Paradram/himmelblau/
Paradram.himmelblau.proposalCov.png width=700
270 %> \image html example/sampling/
Paradram/himmelblau/
Paradram.himmelblau.proposalAdaptation.png width=700
272 %> \image html example/sampling/
Paradram/himmelblau/
Paradram.himmelblau.proposalAdaptation.line.png width=700
274 %> \image html example/sampling/
Paradram/himmelblau/
Paradram.himmelblau.proposalAdaptation.scatter.png width=700
276 %> \image html example/sampling/
Paradram/himmelblau/
Paradram.himmelblau.parallelism.speedup.scaling.strong.sameeff.png width=700
278 %> \image html example/sampling/
Paradram/himmelblau/
Paradram.himmelblau.parallelism.speedup.scaling.strong.zeroeff.png width=700
283 %> \AmirShahmoradi, May 16 2016, 9:03 AM, Oden Institute
for Computational Engineering and Sciences (ICES), UT Austin<br>
285 self = self@pm.sampling.
Sampler("ParaDRAM")
288 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
292 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
294 chainMarkovList = readChainMarkov(self, pattern, sep)
296 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
300 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
304 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
308 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
312 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function verify(in varval, in vartype, in varsize, in varname)
Verify the type and number of elements of the input varval match the specified input vartype and vars...
function version(in silent)
Return a scalar MATLAB string containing the latest available ParaMonte MATLAB version newer than the...
This is the ParaDRAM class for generating instances of serial and parallel Delayed-Rejection Adaptive...
function getppm(in self)
Generate and return the relevant Post-Processing Message (ppm) for the current ParaMonte sampler to b...
function run(in self, in getLogFunc, in ndim)
Run the ParaDRAM sampler and return nothing.
function Paradram()
Generate and return an instance of the serial and parallel Delayed-Rejection Adaptive Metropolis-Hast...
function readChainMarkov(in self, in pattern, in sep)
Return a list of objects of class pm.sampling.FileContentsChainDRAM containing the content(s) of the ...
This is the base class for the ParaMonte sampler routines.
function copy(in from, in to, in field, in exclude)
Copy the contents of the struct/object from to the struct/object to recursively and without destroyin...
function getLogFunc(in point)
function install(in vendor, in isyes)
Install or provide instructions to install the MPI library from the requested input MPI vendor.
function parallel()
Return a scalar MATLAB logical that is true if and only if the current installation of MATLAB contain...