| Type: | Package |
| Title: | Proximal Hamiltonian Monte Carlo for Non-Smooth Bayesian Inference |
| Version: | 0.1.0 |
| Description: | Implements the Proximal Hamiltonian Monte Carlo (p-HMC) algorithm for Bayesian sampling and estimation from non-differentiable target densities. The method decomposes a target potential into a smooth component f(x) and a non-smooth convex component g(x), approximating only g(x) via its Moreau-Yosida envelope while retaining exact gradient information for f(x). This approach, based on the methodology described in Shukla, Vats, and Chi (2025) <doi:10.48550/arXiv.2510.22252>, yields improved Hamiltonian conservation over full-potential smoothing approaches. The package provides generalized routines accepting user-defined probability density functions, log-likelihoods, priors, and proximal operators, together with automated hyperparameter tuning for the Moreau-Yosida regularization parameter, Markov chain Monte Carlo convergence diagnostics, effective sample size computation, and model evaluation metrics including the Akaike information criterion and Bayesian information criterion. |
| License: | GPL-2 | GPL-3 [expanded from: GPL (≥ 2)] |
| Encoding: | UTF-8 |
| RoxygenNote: | 7.3.3 |
| Imports: | stats, graphics, grDevices, utils, Matrix |
| Suggests: | testthat (≥ 3.0.0) |
| Config/testthat/edition: | 3 |
| NeedsCompilation: | no |
| Packaged: | 2026-08-05 11:36:31 UTC; shikhar tyagi |
| Author: | Shikhar Tyagi |
| Maintainer: | Shikhar Tyagi <shikhar1093tyagi@gmail.com> |
| Repository: | CRAN |
| Date/Publication: | 2026-08-21 12:40:09 UTC |
Generalized Proximal Hamiltonian Monte Carlo Sampler and Estimator
Description
Fits Bayesian models and estimates parameters using the Proximal Hamiltonian Monte Carlo (p-HMC) algorithm for non-differentiable target densities as proposed by Shukla, Vats, and Chi (2025).
Usage
phmc(
fn,
grad_f = NULL,
g = NULL,
prox_fn = "l1",
start,
data = NULL,
n_draws = 2000,
burnin = floor(n_draws/2),
thin = 1,
epsilon = 0.01,
L = 10,
lambda_g = 0.01,
M = NULL,
tune_lambda = FALSE,
verbose = FALSE,
...
)
Arguments
fn |
Function. The smooth potential component |
grad_f |
Function or |
g |
Function or |
prox_fn |
Function or character. Proximal mapping operator for
|
start |
Numeric vector or matrix. Initial parameter values. |
data |
Optional dataset passed as second argument to
|
n_draws |
Integer > 0. Total number of MCMC iterations to run (default 2000). |
burnin |
Integer >= 0. Number of initial draws to discard
as burn-in (default |
thin |
Integer >= 1. Thinning interval (default 1). |
epsilon |
Numeric scalar > 0. Leapfrog step size (default 0.01). |
L |
Integer >= 1. Number of leapfrog steps per proposal (default 10). |
lambda_g |
Numeric scalar > 0. Moreau-Yosida regularization parameter (default 0.01). |
M |
Mass matrix or |
tune_lambda |
Logical. If |
verbose |
Logical. If |
... |
Additional arguments passed to |
Value
An object of class "phmc", which is a list containing:
draws |
A numeric matrix of class |
estimates |
A summary matrix of class |
accept_rate |
A numeric scalar of class |
ess |
A named numeric vector of class |
ess_per_sec |
A named numeric vector of class |
logLik |
A numeric scalar of class |
AIC |
A numeric scalar of class |
BIC |
A numeric scalar of class |
DIC |
A numeric scalar of class |
elapsed_time |
A numeric scalar of class |
lambda_g |
A numeric scalar of class |
call |
An object of class |
References
Shukla A, Vats D, Chi EC (2025). “Proximal Hamiltonian Monte Carlo.” arXiv preprint, doi:10.48550/arXiv.2510.22252.
Examples
set.seed(42)
y_data <- rnorm(100, mean = 1, sd = 0.5)
f_smooth <- function(x, y) 0.5 * sum((y - x)^2)
grad_f_smooth <- function(x, y) -sum(y - x)
fit <- phmc(fn = f_smooth, grad_f = grad_f_smooth,
prox_fn = "l1", start = 0.5,
data = y_data, lambda_g = 0.01,
n_draws = 500)
summary(fit)
S3 Methods for Proximal Hamiltonian Monte Carlo Objects
Description
Provides summary, printing, extraction, and diagnostic plotting
methods for objects returned by phmc.
Usage
## S3 method for class 'phmc'
print(x, ...)
## S3 method for class 'phmc'
summary(object, ...)
## S3 method for class 'summary.phmc'
print(x, ...)
## S3 method for class 'phmc'
coef(object, ...)
## S3 method for class 'phmc'
vcov(object, ...)
## S3 method for class 'phmc'
logLik(object, ...)
## S3 method for class 'phmc'
plot(x, type = c("all", "trace", "acf", "density"), par_indices = NULL, ...)
Arguments
x |
An object of class |
... |
Additional arguments passed to generic methods. |
object |
An object of class |
type |
Character string specifying plot type: |
par_indices |
Optional integer vector specifying parameter indices to plot. |
Value
Depending on the S3 method invoked, returns the following:
print.phmcInvisibly returns the input object
xof class"phmc"(called for its side effect of printing summary metrics to the console).summary.phmcReturns an object of class
"summary.phmc", which is a list containing model parameter estimates, acceptance rate, log-likelihood, information criteria (AIC, BIC, DIC), elapsed time, and regularization parameterlambda_g.print.summary.phmcInvisibly returns the input object
xof class"summary.phmc"(called for its side effect of printing detailed summary results to the console).coef.phmcReturns a named numeric vector of class
"numeric"containing posterior mean parameter estimates.vcov.phmcReturns a numeric matrix of class
"matrix"containing the empirical posterior variance-covariance matrix of the MCMC parameter draws.logLik.phmcReturns an object of class
"logLik"representing the log-likelihood value evaluated at the MAP estimate, with attributes"df"(number of estimated parameters) and"nobs"(number of retained MCMC draws).plot.phmcInvisibly returns the input object
xof class"phmc"(called for its side effect of generating diagnostic MCMC trace plots, autocorrelation functions, and posterior density curves).
Hyperparameter Tuning for Moreau-Yosida Regularization Parameter
Description
Evaluates the relative Hamiltonian error metric across a grid of
candidate lambda_g values to select the optimal regularization
parameter balancing potential smoothness and Hamiltonian conservation,
as detailed in Section V of Shukla, Vats, and Chi (2025).
Usage
phmc_tune(
fn,
grad_f = NULL,
g = NULL,
prox_fn = "l1",
start,
lambda_grid = 10^seq(-5, 0, length.out = 15),
epsilon = 0.001,
L = 10,
M = NULL,
target_rel_err = 1e-04,
data = NULL,
seed = NULL,
...
)
Arguments
fn |
Function. Smooth component |
grad_f |
Function or |
g |
Function or |
prox_fn |
Function or character. Proximal operator or
built-in name ( |
start |
Numeric vector. Starting parameter value. |
lambda_grid |
Numeric vector. Grid of candidate
|
epsilon |
Numeric scalar > 0. Leapfrog step size. |
L |
Integer >= 1. Number of leapfrog steps. |
M |
Mass matrix or |
target_rel_err |
Numeric scalar. Maximum acceptable relative Hamiltonian error (default 1e-4). |
data |
Optional dataset passed as second argument to |
seed |
Optional integer or |
... |
Additional arguments forwarded to |
Details
The relative Hamiltonian error metric is defined as
R_{\lambda_g} = \left| \frac{H(x_0, p_0) -
H(\tilde{T}_{\epsilon, L}^{\lambda_g}(x_0, p_0))}{H(x_0, p_0)}
\right|.
Value
An object of class "phmc_tune", which is a list containing:
optimal_lambda_g |
A numeric scalar of class |
grid_results |
A data frame of class |
target_rel_err |
A numeric scalar of class |
References
Shukla A, Vats D, Chi EC (2025). “Proximal Hamiltonian Monte Carlo.” arXiv preprint, doi:10.48550/arXiv.2510.22252.
Proximal Mapping Operators and Moreau-Yosida Envelope Gradients
Description
Evaluates proximal operators for common non-smooth penalties (L1 norm, nuclear norm, L2 norm, elastic net) and computes the gradient of the Moreau-Yosida envelope as described in Shukla, Vats, and Chi (2025).
Usage
prox_l1(x, tau)
prox_l2(x, tau)
prox_elastic_net(x, tau, alpha = 0.5)
prox_nuclear(x, tau)
grad_my_envelope(x, prox_fn = "l1", lambda_g = 0.01, ...)
Arguments
x |
Numeric vector or matrix. Parameter value at which to evaluate the operator. |
tau |
Numeric scalar. Thresholding parameter (typically
|
alpha |
Numeric scalar in [0, 1]. Mixing parameter for elastic net penalty. |
prox_fn |
Function or character string. Proximal mapping function or
name of built-in proximal operator ( |
lambda_g |
Numeric scalar > 0. Moreau-Yosida regularization parameter. |
... |
Additional arguments passed to the proximal operator. |
Details
The Moreau-Yosida envelope of a proper, lower-semicontinuous,
convex function g with scaling parameter
\lambda_g > 0 is defined as
g_{\lambda_g}(x) = \inf_y \{g(y) +
\frac{1}{2\lambda_g} \|y - x\|^2\}.
Its gradient is given by
\nabla g_{\lambda_g}(x) =
\frac{1}{\lambda_g}(x - \mathrm{prox}_{\lambda_g}^{g}(x)).
Value
For prox_l1, prox_l2, prox_elastic_net, and
prox_nuclear, returns a numeric vector or matrix of class "numeric"
or "matrix" (matching the shape and dimensions of input x)
representing the evaluated proximal point operator. For grad_my_envelope,
returns a numeric vector or matrix of class "numeric" or "matrix"
containing the computed gradient of the Moreau-Yosida envelope at x.
References
Shukla A, Vats D, Chi EC (2025). “Proximal Hamiltonian Monte Carlo.” arXiv preprint, doi:10.48550/arXiv.2510.22252.
Specialized High-Level Estimators Using Proximal HMC
Description
Fits sparse logistic regression, nuclear-norm low-rank matrix recovery, and Bayesian Lasso linear regression models using the p-HMC algorithm, matching the case studies in Section VI of Shukla, Vats, and Chi (2025).
Usage
phmc_logistic(
X,
y,
alpha = 1,
lambda_g = 0.01,
n_draws = 2000,
epsilon = 0.002,
L = 10,
...
)
phmc_matrix(
X,
alpha = 1,
sigma_sq = 1,
lambda_g = 1e-04,
n_draws = 1000,
epsilon = 0.001,
L = 10,
...
)
phmc_lasso(
X,
y,
alpha = 1,
sigma_sq = 1,
lambda_g = 0.01,
n_draws = 2000,
epsilon = 0.005,
L = 10,
...
)
Arguments
X |
Numeric design matrix (for regression models) or observed noisy matrix (for matrix recovery). |
y |
Numeric binary response vector for logistic regression or continuous response vector for Lasso. |
alpha |
Numeric scalar > 0. Regularization penalty parameter (default 1.0). |
lambda_g |
Numeric scalar > 0. Moreau-Yosida envelope regularization parameter. |
n_draws |
Integer > 0. Total number of MCMC iterations. |
epsilon |
Numeric scalar > 0. Step size parameter. |
L |
Integer >= 1. Number of leapfrog steps. |
... |
Additional arguments passed to |
sigma_sq |
Numeric scalar > 0. Error variance parameter (default 1.0). |
Value
An object of class "phmc", which is a list containing posterior MCMC draws, parameter summary estimates matrix, log-likelihood, information criteria (AIC, BIC, DIC), acceptance rate, and execution metadata. See phmc for detailed descriptions of the list elements and output meaning.
References
Shukla A, Vats D, Chi EC (2025). “Proximal Hamiltonian Monte Carlo.” arXiv preprint, doi:10.48550/arXiv.2510.22252.