ParaMonte C 2.0.0
Parallel Monte Carlo and Machine Learning Library
See the latest version documentation.
runParaDRAM

Generate and return a non-zero value (1) if the procedure fails to fully accomplish the task of generating a Monte Carlo sample of the specified input mathematical objective function, otherwise, return 0. More...

Collaboration diagram for runParaDRAM:

Functions

int32_t runParaDRAML (long double(*getLogFunc)(long double state[], int32_t ndim), const int32_t ndim, const char *input)
 
int32_t runParaDRAMD (double(*getLogFunc)(double state[], int32_t ndim), const int32_t ndim, const char *input)
 
int32_t runParaDRAMF (float(*getLogFunc)(float state[], int32_t ndim), const int32_t ndim, const char *input)
 

Detailed Description

Generate and return a non-zero value (1) if the procedure fails to fully accomplish the task of generating a Monte Carlo sample of the specified input mathematical objective function, otherwise, return 0.

This interface group is the entry point to all C-style interfaces to the ParaDRAM samplers of mathematical density functions.
Although the procedures of this generic interface return a single scalar of type int32_t, the procedures generate massive amounts of information about each simulation which are stored in appropriate external hard drive files.

See,

  1. this generic documentation page for more information on the generated output files for samplings performed using the ParaDRAM sampler.
Parameters
[in]getLogFunc: The input user-specified procedure pointer to the natural logarithm of the target density function.
On input, the function must take an input vector state of size ndim of type floating-point of kind float, double, or long double representing a state (point) from within the domain of the user-specified target density function whose function value must be returned.
On output, the user-specified procedure getLogFunc() must return the function value corresponding to the input state[ndim].
The following illustrate the generic interface of input function pointer getLogFunc(state, ndim),
REAL getLogFunc(REAL[] state, int32_t ndim);
where REAL can be a floating-point type of kind float, double, or long double for the corresponding varying-precision sampler interfaces:
  1. runParaDRAMF,
  2. runParaDRAMD,
  3. runParaDRAML.
[in]ndim: The input scalar constant of type int32_t representing the number of dimensions of the domain of the objective function.
[in]input: The input scalar pointer of type char representing the null-terminated C string that contains either,
  1. the path to an external input file containing the namelist group of ParaDRAM sampler specifications as outlined in the corresponding page of ParaMonte library generic documentation website.
  2. the namelist group of ParaDRAM sampler specifications as the can appear in an external input specification file.
While all input simulation specifications are optional, it is highly recommended to pay attention to the default settings of the domain boundaries and sampler starting point.
(optional. It is considered as missing if set to NULL.)
Returns
stat : The output scalar of type int32_t that is 0 if and only if the sampler succeeds in sampling the specified density function.


Possible calling interfaces

#include "pm_sampling.h"
stat = runParaDRAMF(getLogFunc, ndim, input)
stat = runParaDRAMD(getLogFunc, ndim, input)
stat = runParaDRAML(getLogFunc, ndim, input)
int32_t runParaDRAML(long double(*getLogFunc)(long double state[], int32_t ndim), const int32_t ndim, const char *input)
int32_t runParaDRAMF(float(*getLogFunc)(float state[], int32_t ndim), const int32_t ndim, const char *input)
int32_t runParaDRAMD(double(*getLogFunc)(double state[], int32_t ndim), const int32_t ndim, const char *input)
Warning
Beware that the definition of extended precision real type long double is compiler and platform dependent making the use of long double with precompiled ParaMonte libraries problematic and non-functional.
The condition 0 < ndim must hold for the corresponding input arguments.
This condition is verified only if the library is built with the preprocessor macro CHECK_ENABLED=1.


Example usage

1//
2// Description
3// -----------
4//
5// Run the Monte Carlo samplers of the ParaMonte library
6// given the input log-target density function `getLogFunc()`.
7//
8// Author
9// ------
10//
11// Computational Data Science Lab, Monday 9:03 AM, May 16, 2016,
12// Institute for Computational Engineering and Sciences (ICES),
13// The University of Texas at Austin
14//
15// Documentation
16// -------------
17//
18// https://www.cdslab.org/paramonte
19//
20// LICENSE
21// -------
22//
23// https://github.com/cdslaborg/paramonte/blob/main/LICENSE.md
24//
25#include <math.h>
26#include <stdio.h>
27#include <stdint.h>
28#include <stdlib.h>
29#include <string.h>
30#include "pm_sampling.h"
31// The `runParaDRAM` and `REAL` macros can be set to other possibilities.
32#define runParaDRAM runParaDRAMD
33#define REAL double
34#define NDIM 4
35
36REAL getLogFunc(REAL state[], int32_t ndim){
37 //
38 // Return the natural logarithm of a `ndim`-dimensional Multivariate Normal (MVN)
39 // probability density function (PDF) with the Mean and Covariance Matrix as defined below.
40 // See also: https://en.wikipedia.org/wiki/Multivariate_normal_distribution
41 //
42 const REAL LOG_INVERSE_SQRT_TWO_PI = log(0.398942280401432); // log(1/sqrt(2*Pi))
43 const REAL MEAN[NDIM] = {-6., -2., +2., +6.}; // mean vector of the MVN.
44 const REAL COVMAT[NDIM][NDIM] = {
45 {+1.0, +0.5, +0.5, +0.5},
46 {+0.5, +1.0, +0.5, +0.5},
47 {+0.5, +0.5, +1.0, +0.5},
48 {+0.5, +0.5, +0.5, +1.0}
49 }; // covariance matrix of the MVN.
50 const REAL INVCOV[NDIM][NDIM] = {
51 {+1.6, -0.4, -0.4, -0.4},
52 {-0.4, +1.6, -0.4, -0.4},
53 {-0.4, -0.4, +1.6, -0.4},
54 {-0.4, -0.4, -0.4, +1.6}
55 }; // inverse covariance matrix of the MVN.
56 const REAL LOG_SQRT_DET_INVCOV = 0.581575404902840; // logarithm of square root of the determinant of the inverse covariance matrix.
57
58 // subtract mean vector from the input point.
59
60 int idim;
61 REAL stateNormed[NDIM];
62 for(idim = 0; idim < NDIM; idim++){
63 stateNormed[idim] = state[idim] - MEAN[idim];
64 }
65
66 // compute the log probability density function of the MVN
67
68 REAL exponentTerm = 0.;
69 for(idim = 0; idim < NDIM; idim++){
70 REAL matMulResult[NDIM];
71 matMulResult[idim] = 0.;
72 int jdim;
73 for(jdim = 0; jdim < NDIM; jdim++){
74 matMulResult[idim] += INVCOV[idim][jdim] * stateNormed[jdim];
75 }
76 exponentTerm += stateNormed[idim] * matMulResult[idim];
77 }
78 REAL logFunc = NDIM * LOG_INVERSE_SQRT_TWO_PI + LOG_SQRT_DET_INVCOV - 0.5 * exponentTerm;
82 return logFunc;
83}
84
85int main()
86{
87 int32_t failed;
88 const char* input = "./input.nml"; // null-terminated string. It can be empty or NULL.
89
90 // Call the ParaDRAM Adaptive MCMC sampler with the requested floating point precision.
91
92 failed = runParaDRAM(&getLogFunc, NDIM, input);
93 if (failed != 0) exit(failed);
94
95 // Call the ParaDRAM Adaptive MCMC sampler with the requested floating point precision with an internal namelist input specifications.
96
97 failed = runParaDRAM(&getLogFunc, NDIM, "&paradram parallelismNumThread = 16, outputChainSize = 30000, parallelismMpiFinalizeEnabled = false /");
98 if (failed != 0) exit(failed);
99
100 // Call the ParaDRAM Adaptive MCMC sampler with the requested floating point precision without input specifications.
101
102 failed = runParaDRAM(&getLogFunc, NDIM, NULL);
103 if (failed != 0) exit(failed);
104}

The contents of example specifications namelist input file input.nml
1! DESCRIPTION:
2!
3! The external input file for sampling the 4-dimensional Multivariate Normal distribution function as implemented in the accompanying source files.
4! This file is common between all supported programming language environments.
5!
6! NOTE:
7!
8! All simulation specifications (including this whole file) are optional and can be nearly safely commented out.
9! However, if domain boundaries are finite, set them explicitly.
10!
11! USAGE:
12!
13! -- Comments must begin with an exclamation mark `!`.
14! -- Comments can appear anywhere on an empty line or, after a variable assignment
15! (but not in the middle of a variable assignment whether in single or multiple lines).
16! -- All variable assignments are optional and can be commented out. In such cases, appropriate default values will be assigned.
17! -- Use ParaDRAM namelist (group) name to group a set of ParaDRAM simulation specification variables.
18! -- The order of the input variables in the namelist groups is irrelevant and unimportant.
19! -- Variables can be defined multiple times, but only the last definition will be considered as input.
20! -- All variable names are case insensitive. However, for clarity, this software follows the camelCase code-writing practice.
21! -- String values must be enclosed with either single or double quotation marks.
22! -- Logical values are case-insensitive and can be either .true., true, or t for a TRUE value, and .false., false, or f for a FALSE value.
23! -- All vectors and arrays in the input file begin with index 1. This is following the convention of
24! the majority of science-oriented programming languages: Fortran, Julia, Mathematica, MATLAB, and R.
25!
26! For comprehensive guidelines on the input file organization and rules, visit:
27!
28! https://www.cdslab.org/paramonte/generic/latest/usage/sampling/paradram/input/
29!
30! To see detailed descriptions of each of variables, visit:
31!
32! https://www.cdslab.org/paramonte/generic/latest/usage/sampling/paradram/specifications/
33!
34&paradram
35
36 ! Base specifications.
37
38 description = "
39This\n
40 is a\n
41 multi-line\n
42 description.\\n" ! strings must be enclosed with "" or '' and can be continued on multiple lines.
43 ! No comments within strings are allowed.
44 domain = "cube"
45 domainAxisName = "variable1"
46 "variable2" ! values can appear in multiple lines.
47 domainBallAvg = 0 0 0 0 ! values can be separated with blanks or commas.
48 domainBallCor = 1 0 0 0
49 0 1 0 0
50 0 0 1 0
51 0 0 0 1
52 domainBallCov = 1 0 0 0
53 0 1 0 0
54 0 0 1 0
55 0 0 0 1
56 domainBallStd = 1 1 1 1
57 domainCubeLimitLower = 4*-1.e10 ! repetition pattern rules apply here. 4 dimensions => 4-element vector of values.
58 domainCubeLimitUpper(1) = +1.e10 ! Elements of vectors can be set individually.
59 domainCubeLimitUpper(2:4) = 3*+1.e10 ! Elements of vectors can be set individually.
60 domainErrCount = 100
61 domainErrCountMax = 1000
62 inputFileHasPriority = FALSE ! This is relevant only to simulations within the Fortran programming language.
63 outputChainFileFormat = "compact"
64 !outputColumnWidth = 25 ! This is an example of a variable that is commented out.
65 ! Therefore, its value will not be read by the sampler routine.
66 ! To pass it to the routine, simply remove the `!` mark at the beginning of the line.
67 outputFileName = "./out/mvn" ! A forward-slash character at the end of the string value would indicate the specified path
68 ! is to be interpreted as the name of the folder to contain the simulation output files.
69 ! The base name for the simulation output files will be generated from the current date and time.
70 ! Otherwise, the specified base name at the end of the string will be used in naming the simulation output files.
71 outputPrecision = 17
72 outputReportPeriod = 1000
73 outputRestartFileFormat = "ascii"
74 outputSampleSize = -1
75 outputSeparator = ","
76 outputSplashMode = "normal" ! or quiet or silent.
77 outputStatus = "retry" ! or extend.
78 parallelism = "multi chain" ! "singleChain" would also work. Similarly, "multichain", "multi chain", or "multiChain".
79 parallelismMpiFinalizeEnabled = false ! TRUE, true, .true., .t., and t would be also all valid logical values representing truth.
80 parallelismNumThread = 3 ! number of threads to use in shared-memory parallelism.
81 !randomSeed = 2136275,
82 !targetAcceptanceRate = 0.23e0
83
84 ! MCMC specifications.
85
86 outputChainSize = 10000
87 outputSampleRefinementCount = 10
88 outputSampleRefinementMethod = "BatchMeans"
89 proposal = "normal" ! or "uniform" as you wish.
90 proposalCor(:, 1) = 1 0 0 0 ! first matrix column.
91 proposalCor(:, 2:4) = 0 1 0 0
92 0 0 1 0
93 0 0 0 1 ! other matrix columns.
94 proposalCov = 1 0 0 0
95 0 1 0 0
96 0 0 1 0
97 0 0 0 1 ! or specify all matrix elements in one statement.
98 proposalScale = "2*0.5*Gelman" ! The asterisk here means multiplication since it is enclosed within quotation marks.
99 !proposalStart = 4*1.e0 ! four values of 1.e0 are specified here by the repetition pattern symbol *
100 proposalStartDomainCubeLimitLower = 4*-10.e0 ! repetition pattern rules apply again here. 4 dimensions => 4-element vector of values.
101 proposalStartDomainCubeLimitUpper = 4*+10.e0 ! repetition pattern rules apply again here. 4 dimensions => 4-element vector of values.
102 proposalStartRandomized = false
103 proposalStd = 4*1.0 ! repetition pattern rules apply again here. 4 dimensions => 4-element vector of values.
104
105 ! DRAM specifications.
106
107 proposalAdaptationBurnin = 1.
108 proposalAdaptationCount = 10000000
109 proposalAdaptationCountGreedy = 0
110 proposalAdaptationPeriod = 35
111 proposalDelayedRejectionCount = 5
112 proposalDelayedRejectionScale = 4*1., 2. ! The first four elements are 1, followed by 2.
113
114/

Example CMakeLists build generator file
1cmake_minimum_required(VERSION 3.14)
2set(CMAKE_BUILD_TYPE Release)
3if ("${CMAKE_Fortran_COMPILER}" STREQUAL "")
4 set(CMAKE_Fortran_COMPILER "/usr/bin/cc")
5endif()
6project(main LANGUAGES C)
7set(CMAKE_MACOSX_RPATH ON)
8set(CMAKE_INSTALL_RPATH_USE_LINK_PATH ON)
9add_executable(binary main.c)
10set_target_properties(binary PROPERTIES OUTPUT_NAME "main" SUFFIX ".exe")
11target_include_directories(binary PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/../../../inc")
12find_library(pmlib NAMES libparamonte libparamonte.a libparamonte.dll libparamonte.dylib libparamonte.lib libparamonte.so PATHS
13 "${CMAKE_CURRENT_SOURCE_DIR}/../../../../lib" # library directory for code coverage.
14 "${CMAKE_CURRENT_SOURCE_DIR}/../../../lib" # library directory for examples/benchmarks.
15 )
16target_link_libraries(binary PUBLIC "${pmlib}")
17target_link_libraries(binary PUBLIC "${pmlib}")
18if (APPLE)
19 set(rpath_prop "@loader_path")
20elseif(UNIX)
21 set(rpath_prop "$ORIGIN")
22endif()
23set_target_properties(binary PROPERTIES INSTALL_RPATH "")
24if ("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU")
25 target_link_libraries(binary PUBLIC m)
26endif()
27add_custom_target(run COMMAND ./main.exe DEPENDS binary WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}")

Example Unix Bash build command via CMake build generator
1#!/bin/bash
2cmake . -G "Unix Makefiles" && make && make run

Example Windows CMD Batch build command via CMake build generator
1REM Add the library path to the environment PATH variable.
2setlocal EnableDelayedExpansion
3set "PATH=..\..\..\lib;%PATH%"
4REM Generate build, build, and run
5cmake . -G "NMake Makefiles" && nmake && nmake run

Postprocessing of the example output
1#!/usr/bin/env python
2
3import matplotlib.pyplot as plt
4#import paramonte as pm
5import pandas as pd
6import numpy as np
7import glob
8import sys
9import os
10funcname = os.path.basename(os.getcwd())
11
12linewidth = 2
13fontsize = 17
14files = glob.glob("./out/*_chain.txt")
15
16for file in files:
17
18 df = pd.read_csv(file, delimiter = ",")
19 sindex = list(df.columns).index("sampleLogFunc") + 1 # start column index.
20
21 # traceplot
22
23 #print(df.values)
24 fig = plt.figure(figsize = (8, 6))
25 ax = plt.subplot(1,1,1)
26 ax.plot ( range(len(df.values[:, 0]))
27 , df.values[:, sindex:]
28 , zorder = 1000
29 )
30 plt.minorticks_on()
31 ax.set_xscale("log")
32 ax.set_xlabel("MCMC Count", fontsize = 17)
33 ax.set_ylabel("MCMC State", fontsize = 17)
34 ax.tick_params(axis = "x", which = "minor")
35 ax.tick_params(axis = "y", which = "minor")
36 plt.grid(visible = True, which = "both", axis = "both", color = "0.85", linestyle = "-")
37 #ax.legend(df.columns.values, fontsize = fontsize)
38 plt.tight_layout()
39 plt.savefig(funcname + ".traceplot.png")
40
41 # scatterplot
42
43 if len(df.values[1, sindex:]) > 1:
44 #print(df.values)
45 fig = plt.figure(figsize = (8, 6))
46 ax = plt.subplot(1,1,1)
47 ax.scatter ( df.values[:, sindex]
48 , df.values[:, sindex + 1]
49 , zorder = 1000
50 , alpha = 0.5
51 , s = 1
52 )
53 plt.minorticks_on()
54 #ax.set_xscale("log")
55 ax.set_xlabel(df.columns.values[sindex], fontsize = 17)
56 ax.set_ylabel(df.columns.values[sindex + 1], fontsize = 17)
57 ax.tick_params(axis = "x", which = "minor")
58 ax.tick_params(axis = "y", which = "minor")
59 plt.grid(visible = True, which = "both", axis = "both", color = "0.85", linestyle = "-")
60 #ax.legend(df.columns.values, fontsize = fontsize)
61 plt.tight_layout()
62 plt.savefig(funcname + ".scatterplot.png")
63
64 # adaptation measure.
65
66 #print(df.values)
67 if "proposalAdaptation" in df.columns.values:
68 if any(df["proposalAdaptation"].values != 0):
69 fig = plt.figure(figsize = (8, 6))
70 ax = plt.subplot(1,1,1)
71 ax.scatter ( range(len(df.values[:, 0]))
72 , df["proposalAdaptation"].values
73 , zorder = 1000
74 , alpha = 0.5
75 , c = "red"
76 , s = 1
77 )
78 plt.minorticks_on()
79 #ax.set_xscale("log")
80 ax.set_yscale("log")
81 ax.set_xlabel("MCMC Count", fontsize = 17)
82 ax.set_ylabel("proposalAdaptation", fontsize = 17)
83 ax.tick_params(axis = "x", which = "minor")
84 ax.tick_params(axis = "y", which = "minor")
85 plt.grid(visible = True, which = "both", axis = "both", color = "0.85", linestyle = "-")
86 #ax.legend(df.columns.values, fontsize = fontsize)
87 plt.tight_layout()
88 plt.savefig(funcname + ".proposalAdaptation.png")
89
90 #sim = pm.ParaDRAM()
91 #sample = sim.readSample("./out/", renabled = True)
92 #sample[0].plot.grid()

Visualization of the example output


Example usage

1//
2// Description
3// -----------
4//
5// Run the Monte Carlo samplers of the ParaMonte library
6// given the input log-target density function `getLogFunc()`.
7//
8// Author
9// ------
10//
11// Computational Data Science Lab, Monday 9:03 AM, May 16, 2016,
12// Institute for Computational Engineering and Sciences (ICES),
13// The University of Texas at Austin
14//
15// Documentation
16// -------------
17//
18// https://www.cdslab.org/paramonte
19//
20// LICENSE
21// -------
22//
23// https://github.com/cdslaborg/paramonte/blob/main/LICENSE.md
24//
25#include <math.h>
26#include <stdio.h>
27#include <stdint.h>
28#include <stdlib.h>
29#include <string.h>
30#include "pm_sampling.h"
31// The `runParaDRAM` and `REAL` macros can be set to other possibilities.
32#define runParaDRAM runParaDRAMD
33#define REAL double
34#define NDIM 2
35
36REAL getLogFunc(REAL state[], int32_t ndim){
37 //
38 // Return the negative natural logarithm of Himmelblau function at the specified state.
39 // See also: https://en.wikipedia.org/wiki/Himmelblau%27s_function
40 //
41 REAL logFunc = -log ( pow(pow(state[0], 2) + state[1] - 11, 2)
42 + pow(state[0] + pow(state[1], 2) - 7, 2)
43 + 0.1
44 );
45 return logFunc;
46}
47
48int main()
49{
50 int32_t failed;
51 const char* input = "./input.nml"; // null-terminated string. It can be empty or NULL.
52
53 // Call the ParaDRAM Adaptive MCMC sampler with the requested floating point precision.
54
55 failed = runParaDRAM(&getLogFunc, NDIM, input);
56 if (failed != 0) exit(failed);
57
58 // Call the ParaDRAM Adaptive MCMC sampler with the requested floating point precision with an internal namelist input specifications.
59
60 failed = runParaDRAM(&getLogFunc, NDIM, "&paradram parallelismNumThread = 16, outputChainSize = 30000, parallelismMpiFinalizeEnabled = false /");
61 if (failed != 0) exit(failed);
62
63 // Call the ParaDRAM Adaptive MCMC sampler with the requested floating point precision without input specifications.
64
65 failed = runParaDRAM(&getLogFunc, NDIM, NULL);
66 if (failed != 0) exit(failed);
67}

The contents of example specifications namelist input file input.nml
1! DESCRIPTION:
2!
3! The external input file for sampling the 2-dimensional Himmelblau function as implemented in the accompanying source files.
4! This file is common between all supported programming language environments.
5!
6! NOTE:
7!
8! All simulation specifications (including this whole file) are optional and can be nearly safely commented out.
9! However, if domain boundaries are finite, set them explicitly.
10!
11! USAGE:
12!
13! -- Comments must begin with an exclamation mark `!`.
14! -- Comments can appear anywhere on an empty line or, after a variable assignment
15! (but not in the middle of a variable assignment whether in single or multiple lines).
16! -- All variable assignments are optional and can be commented out. In such cases, appropriate default values will be assigned.
17! -- Use ParaDRAM namelist (group) name to group a set of ParaDRAM simulation specification variables.
18! -- The order of the input variables in the namelist groups is irrelevant and unimportant.
19! -- Variables can be defined multiple times, but only the last definition will be considered as input.
20! -- All variable names are case insensitive. However, for clarity, this software follows the camelCase code-writing practice.
21! -- String values must be enclosed with either single or double quotation marks.
22! -- Logical values are case-insensitive and can be either .true., true, or t for a TRUE value, and .false., false, or f for a FALSE value.
23! -- All vectors and arrays in the input file begin with index 1. This is following the convention of
24! the majority of science-oriented programming languages: Fortran, Julia, Mathematica, MATLAB, and R.
25!
26! For comprehensive guidelines on the input file organization and rules, visit:
27!
28! https://www.cdslab.org/paramonte/generic/latest/usage/sampling/paradram/input/
29!
30! To see detailed descriptions of each of variables, visit:
31!
32! https://www.cdslab.org/paramonte/generic/latest/usage/sampling/paradram/specifications/
33!
34&paradram
35
36 ! Base specifications.
37
38 description = "
39This\n
40 is a\n
41 multi-line\n
42 description.\\n" ! strings must be enclosed with "" or '' and can be continued on multiple lines.
43 ! No comments within strings are allowed.
44 domain = "cube"
45 domainAxisName = "variable1"
46 "variable2" ! values can appear in multiple lines.
47 domainBallAvg = 0 0 ! values can be separated with blanks or commas.
48 domainBallCor = 1 0
49 0 1
50 domainBallCov = 1, 0
51 0, 1
52 domainBallStd = 1, 1
53 domainCubeLimitLower = 2*-1.e30 ! repetition pattern rules apply here. 2 dimensions => 2-element vector of values.
54 domainCubeLimitUpper(1) = +1.e30 ! Elements of vectors can be set individually.
55 domainCubeLimitUpper(2) = +1.e30 ! Elements of vectors can be set individually.
56 domainErrCount = 100
57 domainErrCountMax = 1000
58 inputFileHasPriority = FALSE ! This is relevant only to simulations within the Fortran programming language.
59 outputChainFileFormat = "compact"
60 !outputColumnWidth = 25 ! This is an example of a variable that is commented out.
61 ! Therefore, its value will not be read by the sampler routine.
62 ! To pass it to the routine, simply remove the `!` mark at the beginning of the line.
63 outputFileName = "./out/himmelblau" ! A forward-slash character at the end of the string value would indicate the specified path
64 ! is to be interpreted as the name of the folder to contain the simulation output files.
65 ! The base name for the simulation output files will be generated from the current date and time.
66 ! Otherwise, the specified base name at the end of the string will be used in naming the simulation output files.
67 outputPrecision = 17
68 outputReportPeriod = 1000
69 outputRestartFileFormat = "ascii"
70 outputSampleSize = -1
71 outputSeparator = ","
72 outputSplashMode = "normal" ! or quiet or silent.
73 outputStatus = "extend" ! or retry.
74 parallelism = "multi chain" ! "singleChain" would also work. Similarly, "multichain", "multi chain", or "multiChain".
75 parallelismMpiFinalizeEnabled = false ! TRUE, true, .true., .t., and t would be also all valid logical values representing truth.
76 parallelismNumThread = 3 ! number of threads to use in shared-memory parallelism.
77 !randomSeed = 2136275,
78 !targetAcceptanceRate = 0.23e0
79
80 ! MCMC specifications.
81
82 outputChainSize = 10000
83 outputSampleRefinementCount = 10
84 outputSampleRefinementMethod = "BatchMeans"
85 proposal = "normal" ! or "uniform" as you wish.
86 proposalCor(:, 1) = 1 0 ! first matrix column.
87 proposalCor(:, 2) = 0 1 ! second matrix column.
88 proposalCov = 1 0 0 1 ! or specify all matrix elements in one statement.
89 proposalScale = "2*0.5*Gelman" ! The asterisk here means multiplication since it is enclosed within quotation marks.
90 proposalStart = 2*1.e0 ! four values of 1.e0 are specified here by the repetition pattern symbol *
91 proposalStartDomainCubeLimitLower = 2*-100.e0 ! repetition pattern rules apply again here. 2 dimensions => 2-element vector of values.
92 proposalStartDomainCubeLimitUpper = 2*+100.e0 ! repetition pattern rules apply again here. 2 dimensions => 2-element vector of values.
93 proposalStartRandomized = false
94 proposalStd = 2*1.0 ! repetition pattern rules apply again here. 2 dimensions => 2-element vector of values.
95
96 ! DRAM specifications.
97
98 proposalAdaptationBurnin = 1.
99 proposalAdaptationCount = 10000000
100 proposalAdaptationCountGreedy = 0
101 proposalAdaptationPeriod = 35
102 proposalDelayedRejectionCount = 5
103 proposalDelayedRejectionScale = 4*1., 2. ! The first four elements are 1, followed by 2.
104
105/

Example CMakeLists build generator file
1cmake_minimum_required(VERSION 3.14)
2set(CMAKE_BUILD_TYPE Release)
3if ("${CMAKE_Fortran_COMPILER}" STREQUAL "")
4 set(CMAKE_Fortran_COMPILER "/usr/bin/cc")
5endif()
6project(main LANGUAGES C)
7set(CMAKE_MACOSX_RPATH ON)
8set(CMAKE_INSTALL_RPATH_USE_LINK_PATH ON)
9add_executable(binary main.c)
10set_target_properties(binary PROPERTIES OUTPUT_NAME "main" SUFFIX ".exe")
11target_include_directories(binary PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/../../../inc")
12find_library(pmlib NAMES libparamonte libparamonte.a libparamonte.dll libparamonte.dylib libparamonte.lib libparamonte.so PATHS
13 "${CMAKE_CURRENT_SOURCE_DIR}/../../../../lib" # library directory for code coverage.
14 "${CMAKE_CURRENT_SOURCE_DIR}/../../../lib" # library directory for examples/benchmarks.
15 )
16target_link_libraries(binary PUBLIC "${pmlib}")
17target_link_libraries(binary PUBLIC "${pmlib}")
18if (APPLE)
19 set(rpath_prop "@loader_path")
20elseif(UNIX)
21 set(rpath_prop "$ORIGIN")
22endif()
23set_target_properties(binary PROPERTIES INSTALL_RPATH "")
24if ("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU")
25 target_link_libraries(binary PUBLIC m)
26endif()
27add_custom_target(run COMMAND ./main.exe DEPENDS binary WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}")

Example Unix Bash build command via CMake build generator
1#!/bin/bash
2cmake . -G "Unix Makefiles" && make && make run

Example Windows CMD Batch build command via CMake build generator
1REM Add the library path to the environment PATH variable.
2setlocal EnableDelayedExpansion
3set "PATH=..\..\..\lib;%PATH%"
4REM Generate build, build, and run
5cmake . -G "NMake Makefiles" && nmake && nmake run

Postprocessing of the example output
1#!/usr/bin/env python
2
3import matplotlib.pyplot as plt
4#import paramonte as pm
5import pandas as pd
6import numpy as np
7import glob
8import sys
9import os
10funcname = os.path.basename(os.getcwd())
11
12linewidth = 2
13fontsize = 17
14files = glob.glob("./out/*_chain.txt")
15
16for file in files:
17
18 df = pd.read_csv(file, delimiter = ",")
19 sindex = list(df.columns).index("sampleLogFunc") + 1 # start column index.
20
21 # traceplot
22
23 #print(df.values)
24 fig = plt.figure(figsize = (8, 6))
25 ax = plt.subplot(1,1,1)
26 ax.plot ( range(len(df.values[:, 0]))
27 , df.values[:, sindex:]
28 , zorder = 1000
29 )
30 plt.minorticks_on()
31 ax.set_xscale("log")
32 ax.set_xlabel("MCMC Count", fontsize = 17)
33 ax.set_ylabel("MCMC State", fontsize = 17)
34 ax.tick_params(axis = "x", which = "minor")
35 ax.tick_params(axis = "y", which = "minor")
36 plt.grid(visible = True, which = "both", axis = "both", color = "0.85", linestyle = "-")
37 #ax.legend(df.columns.values, fontsize = fontsize)
38 plt.tight_layout()
39 plt.savefig(funcname + ".traceplot.png")
40
41 # scatterplot
42
43 if len(df.values[1, sindex:]) > 1:
44 #print(df.values)
45 fig = plt.figure(figsize = (8, 6))
46 ax = plt.subplot(1,1,1)
47 ax.scatter ( df.values[:, sindex]
48 , df.values[:, sindex + 1]
49 , zorder = 1000
50 , alpha = 0.5
51 , s = 1
52 )
53 plt.minorticks_on()
54 #ax.set_xscale("log")
55 ax.set_xlabel(df.columns.values[sindex], fontsize = 17)
56 ax.set_ylabel(df.columns.values[sindex + 1], fontsize = 17)
57 ax.tick_params(axis = "x", which = "minor")
58 ax.tick_params(axis = "y", which = "minor")
59 plt.grid(visible = True, which = "both", axis = "both", color = "0.85", linestyle = "-")
60 #ax.legend(df.columns.values, fontsize = fontsize)
61 plt.tight_layout()
62 plt.savefig(funcname + ".scatterplot.png")
63
64 # adaptation measure.
65
66 #print(df.values)
67 if "proposalAdaptation" in df.columns.values:
68 if any(df["proposalAdaptation"].values != 0):
69 fig = plt.figure(figsize = (8, 6))
70 ax = plt.subplot(1,1,1)
71 ax.scatter ( range(len(df.values[:, 0]))
72 , df["proposalAdaptation"].values
73 , zorder = 1000
74 , alpha = 0.5
75 , c = "red"
76 , s = 1
77 )
78 plt.minorticks_on()
79 #ax.set_xscale("log")
80 ax.set_yscale("log")
81 ax.set_xlabel("MCMC Count", fontsize = 17)
82 ax.set_ylabel("proposalAdaptation", fontsize = 17)
83 ax.tick_params(axis = "x", which = "minor")
84 ax.tick_params(axis = "y", which = "minor")
85 plt.grid(visible = True, which = "both", axis = "both", color = "0.85", linestyle = "-")
86 #ax.legend(df.columns.values, fontsize = fontsize)
87 plt.tight_layout()
88 plt.savefig(funcname + ".proposalAdaptation.png")
89
90 #sim = pm.ParaDRAM()
91 #sample = sim.readSample("./out/", renabled = True)
92 #sample[0].plot.grid()

Visualization of the example output
Test:
test_pm_sampling
Bug:

Status: Unresolved
Source: Intel LLVM Fortran Compiler ifx version 2024.0.0 20231017
Description: Intel LLVM Fortran Compiler ifx This interface yields a segmentation fault error for all real types supported when linked with the ParaMonte library built with Intel LLVM Fortran Compiler ifx.
Remedy (as of ParaMonte Library version 2.0.0): For now, only Intel Classic Fortran Compiler ifort will be used.
Bug:

Status: Unresolved
Source: Intel Classic Fortran Compiler ifort version 2021.11.0 20231010
Description: The runParaDRAML interface for long double yields a segmentation fault error.
Remedy (as of ParaMonte Library version 2.0.0): None as of today.
Todo:
Critical Priority: The current tests for long double interface fail with Intel LLVM Fortran Compiler ifx and Intel LLVM C/C++ Compiler icx compilers.
Apparently, there is a mismatch between long double and c_long_double storage.
This issue does not exist with GNU compilers, although the GNU definition of long double appears to yield incorrect values in some calculations, e.g., in isFailedGeomCyclicFit() of the ParaMonte library.


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:
Amir Shahmoradi, May 16 2016, 9:03 AM, Oden Institute for Computational Engineering and Sciences (ICES), UT Austin

Function Documentation

◆ runParaDRAMD()

int32_t runParaDRAMD ( double(*)(double state[], int32_t ndim)  getLogFunc,
const int32_t  ndim,
const char *  input 
)

◆ runParaDRAMF()

int32_t runParaDRAMF ( float(*)(float state[], int32_t ndim)  getLogFunc,
const int32_t  ndim,
const char *  input 
)

◆ runParaDRAML()

int32_t runParaDRAML ( long double(*)(long double state[], int32_t ndim)  getLogFunc,
const int32_t  ndim,
const char *  input 
)