---
title: "Introduction to Moreau-Yosida MCMC Importance Sampling (`MYIS`)"
author: "Shikhar Tyagi, Arvind Pandey, Bhupendra Singh, Vrijesh Tripathi"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{Introduction to Moreau-Yosida MCMC Importance Sampling (`MYIS`)}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

```{r setup, include = FALSE}
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
if (requireNamespace("MYIS", quietly = TRUE)) {
  library(MYIS)
} else if (file.exists("../R")) {
  r_files <- list.files("../R", full.names = TRUE)
  lapply(r_files, source)
}
```

## Overview

The `MYIS` package provides a distribution-independent framework for **Moreau-Yosida Markov Chain Monte Carlo Importance Sampling (MY-IS)** based on the theoretical paradigm established by Shukla, Vats, and Chi (2025).

In modern statistical modeling, Bayesian target posteriors $\pi(\theta \mid \mathbf{x}) \propto \exp(-\psi(\theta))$ often exhibit non-differentiable priors (e.g., Lasso, fused Lasso, nuclear norm penalties) or light tails (e.g. Poisson random effects), precluding standard gradient-based MCMC algorithms such as MALA or HMC.

`MYIS` addresses this challenge by approximating non-smooth potentials $\psi(\theta)$ with their smooth **Moreau-Yosida envelopes**:
$$\psi_\lambda(\theta) = \inf_{\eta} \left\{ \psi(\eta) + \frac{1}{2\lambda} \|\eta - \theta\|^2 \right\}$$

Gradient-based samplers ($\pi_\lambda$-MALA, $\pi_\lambda$-HMC, or $\pi_\lambda$-RWM) draw samples from the smooth importance density $\pi_\lambda(\theta) \propto \exp(-\psi_\lambda(\theta))$, while self-normalized importance weights:
$$w_\lambda(\theta) = \exp\big(-(\psi(\theta) - \psi_\lambda(\theta))\big) \le 1$$
re-weight samples to yield consistent, finite-variance estimators $\hat{\theta}_n^{\text{MY}}$ and Bayesian marginal quantiles (Chen and Shao, 1999).

## Basic Usage Example

Below is a simple demonstration estimating the rate parameter of an Exponential distribution from complete observations:

```{r example-complete}
set.seed(123)
true_rate <- 1.8
sample_data <- rexp(100, rate = true_rate)

# User provides custom PDF function
my_pdf <- function(x, theta) {
  dexp(x, rate = theta[1])
}

# Run Moreau-Yosida MCMC Importance Sampling
fit <- my_is_estimate(
  pdf = my_pdf,
  data = sample_data,
  initial_theta = c(1.0),
  par_lower = 0.001,
  sampler = "mala",
  n_samples = 200,
  burnin = 50
)

# Print Summary
print(fit)
```

## Inference Under Right Censoring

`MYIS` supports arbitrary censoring schemes including complete, right, left, interval, Type-I, Type-II, progressive Type-II, and truncation.

```{r example-censored}
set.seed(456)
n <- 80
x_obs <- rexp(n, rate = 1.2)
c_times <- rexp(n, rate = 0.8)
t_obs <- pmin(x_obs, c_times)
delta <- as.numeric(x_obs <= c_times)

fit_censored <- my_is_estimate(
  pdf = my_pdf,
  data = t_obs,
  initial_theta = c(1.0),
  censoring = "right",
  censoring_params = list(delta = delta),
  par_lower = 0.001,
  sampler = "mala",
  n_samples = 200,
  burnin = 50
)

summary(fit_censored)
```

## Diagnostic Plots

`MYIS` includes diagnostic plotting functions to inspect trace plots, autocorrelation, posterior density, and weight distribution:

```{r example-plot, fig.width=7, fig.height=6}
plot(fit_censored, type = "all")
```

## References

- Shukla, A., Vats, D., & Chi, E. C. (2025). MCMC Importance Sampling via Moreau-Yosida Envelopes. arXiv:2501.02228v2.
- Chen, M. H., & Shao, Q. M. (1999). Monte Carlo estimation of Bayesian credible quantities. Journal of Computational and Graphical Statistics, 8(1), 69-92.
- Pereyra, M. (2016). Proximal Markov chain Monte Carlo algorithms. Statistics and Computing, 26(4), 745-760.
- Durmus, A., Moulines, E., & Pereyra, M. (2022). Efficient Bayesian computation by proximal Markov chain Monte Carlo sampling. Electronic Journal of Statistics, 16(1), 1404-1447.
