In this vignette, we explain how one can bridge sampling can be performed when we are faced with parameter spaces that are in some way non-standard. We will look at simplex parameters and circular parameters.

Simplex parameters are encountered often, in particular in mixture models or when modeling compositional data, where a set of parameters $\theta_1, \dots, \theta_k$ is used that are constrained by $0 \leq \theta \leq 1$ and $\sum_{j=1}^k \theta_j = 1$. This happens often when we use relative weights of several components, or when we model proportions or probabilities.

Circular parameters are angles that lie on the circle, that is, the parameters are given in degrees ($0^\circ - 360^\circ$) or radians ($0 - 2\pi$). The core property of this type of parameter space is that it is periodical, that is, for example $\theta = 0^\circ = 360^\circ.$ Another way to think of such parameters is as two-dimensional unit vectors, $\boldsymbol{x} = {x_1, x_2}$, which are constrained by $\sqrt{x_1^2 + x_2^2} = 1$.

This vignette will only focus on the computing the marginal likelihood for such parameters. For information on further computations, see the other vignettes.

Posterior sample

We will assume a posterior sample was obtained through some method, and we will show how to compute the marginal likelihood from this sample. The example posterior sample will simply be generated randomly, just for illustration.

The model under consideration will be a circular mixture model, where for simplicity we only look at its mixture weigths and circular means.

library(bridgesampling)

# Posterior sample size Q, number of components nc, and data sample size n. 
Q <- 50
nc <- 3
n <- 100 

# Sample simplex parameters. 
ru <- replicate(nc, runif(Q)) 
simplex_param <- ru / rowSums(ru)
colnames(simplex_param) <- paste0("sim", 1:nc)

# Sample circular parameters.
th <- replicate(nc, atan2(rnorm(Q, 2), rnorm(Q, 1)))
colnames(th) <- paste0("circ", 1:nc)


# Example circular mixture data.
data <- c(atan2(rnorm(n, 2), rnorm(n, 1)),
          atan2(rnorm(n, 6), rnorm(n, 3)),
          atan2(rnorm(n, 2), rnorm(n, -1)))

# Posterior sample.
post_sample <- cbind(simplex_param, circ = th)

# Dummy log-posterior.
log_posterior = function(s, data) -.5*t(s) %*% s

Note that the posterior of the specific model you are using should be used. Here, a simple dummy posterior is used that does not depend on the data, but it is just by means of example.

Bridge sampling

For this posterior sample, we can provide the variable types to the bridge sampling functions. In order to use simplex and circular parameters, we must use bridge_sampler.matrix, the bridgesampling method for matrices of posterior samples.

Using this method, we must pass the type of the parameters under consideration. Here, we pass respectively "simplex" and "circular" to the param_types argument of bridge_sampler. We can do this as follows:

# Give the type of parameter.
parameter_types <- c(rep("simplex", nc),
                     rep("circular", nc))
lb <- c(rep(0, 3), rep(0, 3))
ub <- c(rep(1, 3), rep(2*pi, 3))

bs_obj <- bridge_sampler(post_sample, 
                         data = data,
                         param_types = parameter_types,
                         log_posterior = log_posterior, 
                         lb = lb, 
                         ub = ub)
bs_obj

Because we have told the bridge_sampler function to treat these variables as simplex or circular variables, it can select the correct transformations behind the scenes to ensure that the bridge sampling can proceed as normal. Note that after this procedure, all the available methods for bridge sampling objects can be used.

A few notes on the use of these variables:



quentingronau/bridgesampling documentation built on June 6, 2023, 3:57 p.m.