Monte Carlo Integration Library 1.0
High-performance Monte Carlo methods for numerical integration and optimization
Classes | Functions | Variables
benchmarks.hpp File Reference

Benchmarking framework for Monte Carlo integration algorithms. More...

#include <montecarlo/domains/hypercylinder.hpp>
#include <montecarlo/domains/hyperrectangle.hpp>
#include <montecarlo/domains/hypersphere.hpp>
#include <montecarlo/geometry.hpp>
#include <montecarlo/integrators/MCintegrator.hpp>
#include <montecarlo/integrators/MHintegrator.hpp>
#include <montecarlo/integrators/ISintegrator.hpp>
#include <montecarlo/proposals/uniformProposal.hpp>
#include <montecarlo/utils/plotter.hpp>
#include <montecarlo/optimizers/PSO.hpp>
#include <montecarlo/optimizers/GA.hpp>
#include <fstream>
#include <iostream>
#include <chrono>
#include <iomanip>
#include <vector>
#include <string>
#include <functional>
#include <thread>
#include <cmath>
#include <cstdint>
Include dependency graph for benchmarks.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  results
 Stores benchmark result for a single sample count. More...
 

Functions

void saveResults (const std::string &filename, const std::vector< results > &results, const std::string &function_expr)
 Save benchmark results to a CSV file.
 
void uniDimIntegration ()
 1D integration test: f(x) = x²
 
void circleIntegration ()
 2D circular integration: f(x,y) = x²+y² over unit disk
 
void sphereIntegration ()
 3D spherical integration: f(x,y,z) = x²+y²+z² over unit ball
 
void rectangularIntegration ()
 2D rectangular integration over axis-aligned box
 
void cylinderIntegration ()
 3D cylindrical integration: hypercylinder base with height
 
void parallelepipedIntegration ()
 3D parallelepiped (rectangular box) integration
 
void fiveDimIntegration ()
 5-dimensional integration benchmark
 
void fourDimIntegration ()
 4-dimensional integration benchmark
 
void eightDimIntegration ()
 8-dimensional integration benchmark
 
void twelveDimIntegration ()
 12-dimensional integration benchmark
 
void runBenchmarks (bool useGnuplot)
 Run integration benchmarks with hardcoded integrands.
 
void runBenchmarks (const std::string &expression, bool useGnuplot)
 Run integration benchmarks with custom mathematical expression.
 
void runBenchmarksMH ()
 Run Metropolis-Hastings MCMC integration benchmarks.
 
void runOptimizationBenchmarksPSO ()
 
void runOptimizationBenchmarksGA ()
 

Variables

const std::vector< size_t > n_samples_vector
 Global benchmark configuration.
 
unsigned int n_threads
 Global OpenMP thread count (set at runtime)
 

Detailed Description

Benchmarking framework for Monte Carlo integration algorithms.

Author
Domenico
Date
12/3/25

Provides infrastructure for evaluating integration accuracy and performance across multiple algorithms (uniform MC, importance sampling, MCMC) and dimensionalities.

Key Features:

Benchmark Types:

Definition in file benchmarks.hpp.

Function Documentation

◆ circleIntegration()

void circleIntegration ( )

2D circular integration: f(x,y) = x²+y² over unit disk

◆ cylinderIntegration()

void cylinderIntegration ( )

3D cylindrical integration: hypercylinder base with height

◆ eightDimIntegration()

void eightDimIntegration ( )

8-dimensional integration benchmark

◆ fiveDimIntegration()

void fiveDimIntegration ( )

5-dimensional integration benchmark

◆ fourDimIntegration()

void fourDimIntegration ( )

4-dimensional integration benchmark

◆ parallelepipedIntegration()

void parallelepipedIntegration ( )

3D parallelepiped (rectangular box) integration

◆ rectangularIntegration()

void rectangularIntegration ( )

2D rectangular integration over axis-aligned box

◆ runBenchmarks() [1/2]

void runBenchmarks ( bool  useGnuplot)

Run integration benchmarks with hardcoded integrands.

Parameters
useGnuplotIf true, generate gnuplot script for visualization.

Definition at line 292 of file integration_benchmarks.cpp.

Here is the call graph for this function:

◆ runBenchmarks() [2/2]

void runBenchmarks ( const std::string &  expression,
bool  useGnuplot 
)

Run integration benchmarks with custom mathematical expression.

Parameters
expressionMathematical function string (muParserX syntax)
useGnuplotIf true, generate gnuplot script

Definition at line 449 of file integration_benchmarks.cpp.

Here is the call graph for this function:

◆ runBenchmarksMH()

void runBenchmarksMH ( )

Run Metropolis-Hastings MCMC integration benchmarks.

Definition at line 309 of file integration_benchmarks.cpp.

Here is the call graph for this function:

◆ runOptimizationBenchmarksGA()

void runOptimizationBenchmarksGA ( )

Definition at line 352 of file ga_benchmarks.cpp.

Here is the call graph for this function:

◆ runOptimizationBenchmarksPSO()

void runOptimizationBenchmarksPSO ( )

Definition at line 338 of file pso_benchmarks.cpp.

Here is the call graph for this function:

◆ saveResults()

void saveResults ( const std::string &  filename,
const std::vector< results > &  results,
const std::string &  function_expr 
)

Save benchmark results to a CSV file.

Parameters
filenameOutput CSV filename
resultsVector of result structures
function_exprString describing the integrand for reference

Save benchmark results to a CSV file.

Parameters
filenameOutput CSV filename
resultsVector of benchmark results {n_samples, integration_result, duration_ms}
function_exprString description of the integrated function

CSV Format:

  • Header: Function description and column labels
  • Each row: n_samples \t result \t duration_ms

Useful for:

  • Plotting convergence curves: error vs sample count
  • Computing empirical convergence rate
  • Analyzing computational efficiency
  • Comparing algorithm scalability

Definition at line 49 of file benchmarks.cpp.

◆ sphereIntegration()

void sphereIntegration ( )

3D spherical integration: f(x,y,z) = x²+y²+z² over unit ball

◆ twelveDimIntegration()

void twelveDimIntegration ( )

12-dimensional integration benchmark

◆ uniDimIntegration()

void uniDimIntegration ( )

1D integration test: f(x) = x²

Domain: [0,1], Expected: 1/3 ≈ 0.333...

Variable Documentation

◆ n_samples_vector

const std::vector<size_t> n_samples_vector
extern

Global benchmark configuration.

Global benchmark configuration.

Definition at line 28 of file benchmarks.cpp.

◆ n_threads

unsigned int n_threads
extern

Global OpenMP thread count (set at runtime)

Definition at line 31 of file benchmarks.cpp.