## SRN – evidence and cross-validation

A paper that has intrigued me recently is “On the marginal likelihood and cross-validation” by E. Fong and C.C.Holmes on Biometrika.

Model evidence appears as marginal likelihood or prior predictive in this paper:

As the paper seeks to establish the connection between model evidence and cross-validation (CV), which is based on predictive performance on held-out test sets, it notes that the log evidence relates to log posterior predictive probability

So log evidence can be interpreted as a predictive sequential scoring rule with score function

The paper begins by arguing that model evidence is the unique scoring rule that guarantees coherency (data ordering should not change the result of inference when data are exchangeable).

Then the authors move on to show the equivalence between evidence and cumulative cross-validation scores. When we consider leave--out CV, there are number of held-out test sets and each set has some predictive score when the rest of the data is used for training. The leave--out CV score, denoted by , is the average of these predictive scores. When the log posterior predictive probability is used as the scoring rule, then we must have

So the log evidence is also the sum of leave--out CV scores, for all values of

## SRN – Bayesian regret of Thompson Sampling

Hello 2021! This is my second Sunday Reading Notes post of the year. This week I have the chance of reading about Thompson Sampling, a topic I have been interested in since 2018. The paper “On Thompson Sampling for Smoother-than-Lipschitz Bandits” by Grant and Leslie, from Lancaster University, concerns the bounds on the regret for Thompson Sampling for continuum bandits. The regret bound is in terms of *eluder dimension* and *ball-width function* of the function class of the reward function .

Both eluder dimension and ball-width function are new concepts to me. I was able to read more about them in Russo and Roy (2014) and was intrigued by the concept of -eluder dimension, which is a measure of complexity of a set of functions. An action is independent of actions with respect to if we can find two functions in can have similar function values at but very different function values at . Based on this notion of -independence, we can define the notion of -eluder dimension in a similar fashion to how we define dimension based on linear independence in linear algebra.

A key assumption of this framework is that the model is well-specified. The true reward function is not only included in the function class , but also a sample from the posterior distribution . Being a Bayesian statistician, I am naturally curious about the ‘miss-specified’ case. Will the regret bound decompose in terms of distance from to and complexity of . Is the analysis feasible and what techniques should we use?

Reference:

Grant, J. & Leslie, D.. (2020). On Thompson Sampling for Smoother-than-Lipschitz Bandits. Proceedings of the Twenty Third International Conference on Artificial Intelligence and Statistics, in Proceedings of Machine Learning Research 108:2612-2622

Russo, D., & Van Roy, B. (2014). Learning to optimize via posterior sampling. *Mathematics of Operations Research*, *39*(4), 1221-1243.

## SRN – the magical 0.574

Hello 2021! This week, I keep reading about optimal scaling of Markov chain Monte Carlo algorithms and I move on to a new class of algorithms: MALA. This time, the magical number is 0.574.

Hello 2021! Here is the first post in the Sunday Reading Notes series in the year of 2021. This week, I keep reading about optimal scaling of Markov chain Monte Carlo algorithms and I move on to a new class of algorithms: MALA.

Roberts and Rosenthal (1998, JRSSB) concerns the optimal scaling of Metropolis-Adjusted Langevin algorithm (MALA) for target distributions of the form . Unlike random walk Metropolis algorithm, in MALA, the proposal distribution uses the gradient of at :

Here is the step variance and is a d-dimensional standard normal. Following this proposal, we perform an accept / reject step, so that the resulting Markov chain has the desired stationary distribution:

There are some smoothness assumptions on the log-density : absolute value of the first 8 order derivatives are bounded, is Lipschitz, and all moments exist for .

**Theorem 3 (diffusion limit of first component)**

Consider the chain starting from stationarity and following the MALA algorithm with variance for some . Let be a Poisson process with rate , and is the first component of , i.e. . We must have, as , the process , where is a Langevin diffusion defined by

Here is the speed measure and .

The skeleton of the proof is similar to that of proving diffusion limit of random walk Metropolis. We will find sets such that and on these sets the generators converges uniformly.

**Theorem 4 (convergence of acceptance rate)**

where

As a result, when is maximized, the acceptance rate . Also the step variance should be tuned to be

MALA enjoys a faster convergence rate of order compared to order of RWM. But let’s also keep in mind that MALA requires an extra step to compute the gradients , which takes steps to compute.

Reference:

Roberts, G. O., & Rosenthal, J. S. (1998). Optimal scaling of discrete approximations to Langevin diffusions. *Journal of the Royal Statistical Society: Series B (Statistical Methodology)*, *60*(1), 255-268.

## SRN – about the magical 0.234 acceptance rate

Sunday Reading Notes series is back : Let’s understand the magical rule of ‘tuning your MH algorithm so that the acceptance rate is roughly 25%’ together!

‘Tune your MH algorithm so that the acceptance rate is roughly 25%’ has been general advice given to students in Bayesian statistics classes. It has been almost 4 years since I first read about it from the book Bayesian Data Analysis, but I never read the original paper where this result first appeared. This Christmas, I decided to read the paper ‘Weak Convergence and Optimal Scaling of Random Walk Metropolis Algorithms’ by Roberts, Gelman and Gilks and to resume by Sunday Reading Notes series with a short exposition of this paper.

In Roberts, Gelman and Gilk (1997), the authors obtain a weak convergence result for the sequence of algorithms targeting the sequence of distributions converging to a Langevin diffusion. The asymptotic optimal scaling problem becomes a matter optimizing the speed of the Langevin diffusion, and it is related to the asymptotic acceptance rate of proposed moves.

A one-sentence summary of the paper would be

if you have a d-dimensional target that is independent in each coordinate, then choose the step size of random walk kernel to be 2.38 / sqrt(d) or tune your acceptance rate to be around 1/4.

Unfortunately, in practice the ‘if’ condition is often overlooked and people are tuning the acceptance rate to be 0.25 as long as the proposal is random walk, no matter what the target distribution is. It has been 20 years since the publication of the 0.234 result and we are witnessing the use of MCMC algorithms on more complicated target distributions, for example parameter inference for state-space models. I feel that this is good time that we revisit and appreciate the classical results while re-educating ourselves on their limitations.

Reference:

Roberts, G. O., Gelman, A., & Gilks, W. R. (1997). Weak convergence and optimal scaling of random walk Metropolis algorithms. *The annals of applied probability*, *7*(1), 110-120.

——–TECHNICAL EXPOSITION——-

Assumption 1 The marginal density of each component is such that is Lipschitz continuous and

Roberts et al. (1997) considers random walk proposal where We use to denote the Markov chain and define another Markov process with , which is the speed-up version of . Let denote the floor of . Define , the first component of .

Theorem 1 (diffusion limit of first component) Suppose is positive and in and that (1)-(2) hold. Let be such that all components are distributed according to and assume for all . Then as ,

The and satisfies the Langevin SDE

and

with being the standard normal cdf and

Here is the speed measure of the diffusion process and the `most efficient’ asymptotic diffusion has the largest speed measure. measures the `roughness’ of .

Example 1 If is normal, then

So when the target density is normal, then the optimal value of is scaled by , which coincides with the standard deviation of .

Proof: (of Theorem 1.1) This is a proof sketch. The strategy is to prove that the generator of , defined by

converges to the generator of the limiting Langevin diffusion, defined by

Here the function is a function of the first component only.

First define a set

where

and

For fixed , one can show that goes to 1 as . On these sets , we have

which essentially says , because we have uniform convergence for vectors contained in a set of limiting probability 1.

Corollary 2 (heuristics for RWMH) Let

be the average acceptance rate of the random walk MH in dimensions.

We must have where .

is maximized by and and

The authors consider two extensions of the target density , where the convergence and optimal scaling properties will still hold. The first extension concerns the case where ‘s are different, but there is an law of large numbers on these density functions. Another extension concerns the case , with some conditions on .

## [TM] assigning a value to a name in R

In RStudio editor and in R console, ‘alt’ + ‘-‘ gives us ‘<-'.

This is indeed very trivial but really deserves a post!

In RStudio editor and in R console, `alt`

+ `-`

gives us `<-`

.

Such great news for my fingers!

## Troubleshooting: build packages in RStudio after MacOS update

I have never considered myself a good developer. Coding activities such as writing some functions in Rcpp for an R package and building my personal website (nianqiaoju.github.io) already makes me proud.

Last night, I had some trouble building a package in RStudio. At the beginning, I thought it was because I accidentally included a test file in the `ProjectDirectory/R`

folder, but it was not the case. So I had no choice but to read the error messages carefully.

I did not keep a record of this, but important bits of the messages look like:

`ld: unknown option: -platform_version`

clang: error: linker command failed with exit code 1 (use -v to see invocation)

That’s when I started to realize that this had to do with a recent MacOS update and probably my package was fine. Interestingly, I did not recall authorizing a system update and learned about this only through running `sessionInfo()`

in console. These are some trouble shooting steps I did in RStudio console:

- check if devtools works:
`devtools::load_all()`

–>> leads to error messages - check if Rcpp works:
`Rcpp::evalCpp("2+2")`

–>> leads to error messages.

It seemed like the operating system update has ‘disabled’ my R compiler tools for RCpp. Unfortunately, despite the huge amount of information on stack-overflow and github issues, I did not see any error messages matching exactly what I saw and there were some conflicting information. Moreover, I did not want to install the whole XCode app or to cause any irreversible damages. After one hour of trial and errors, below is what I think solved my crisis.

- run in terminal
`xcode-select --install`

and it turns out my command line tools are already installed since the message`xcode-select: error: command line tools are already installed, use "Software Update" to install updates.`

- run in terminal
`gcc --version`

and this is to confirm that the command`gcc`

is recognized by my terminal. - set the file
`~/.R/Makevars`

to point to the system headers. I did it with vim: add the following lines to the file and comment out what’s already there.

```
# clang: start
CFLAGS=-isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk
CCFLAGS=-isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk
CXXFLAGS=-isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk
# clang: end
```

I believe that the last step did the magic for me and I was able to build packages from source without any trouble.

In this process this stack-overflow discussion and this blogpost were the most helpful.

## Getting started with RStudio on AWS in 4 steps

This blog is a quick guide to setting up an RStudio server on Amazon Web Services. The credits should be given to Louis Aslett for setting up the Amazon Machine Images and making life easier for all of us.

Step 1 : creating an AWS account

A free account give access to the t2.micro serves, which means that you can run it for 750 hours a month.

Step 2: choosing an Amazon Machine Image (AMI) prepared by Louis Aslett

I can be painfully to boot your own virtual machine and install R and RStudio yourself. Louis Aslett has already done the job for us and this is a huge service to the community!!!

He has prepared some virtual machines for us and installed R,RStudio, Latex, etc. for us. You can choose one of the AMIs based on your location and the links will direct you to choose an instance type (the default is the free tier t2.micro). We can rely on the default settings until ‘Step 6: Configure Security Group”. Click on “Add Rule” and select “HTTP”, to allow internet traffic to this instance, and change “Source” to specify one IP address or an IP address range. Setting “Source” to “Anywhere” allows all IP addresses to access the instance and you can also set it to “My IP”. You can also create a new security group on this page.

While this is not secure, we can “proceed without a key pair” to launch the instances.

Step 3: changing password for the RStudio Server

It can take a few minutes to launch the instance. Once the instance is “running”, you can copy and paste the “Public IPv4 address” from the instance summary to your browser. You will see a RStudio Server. The initial username is “rstudio” and the password is “<Your instance ID>”.

This AMI comes with a pre-installed and loaded package “RStudioAMI”. We can use the the function `passwd()`

to change the password for the RStudio server.

Step 4: Link Dropbox or Github repository

If you use Dropbox to sync files, you can get started by running the function `linkDropbox()`

. Of course we do not want to sync our entire Dropbox account here. We can sync our project folder by `excludeSyncDropbox("*")`

followed by `includeSyncDropbox("projectFolder")`

. It seems to me that we can only sync directories differently under Dropbox, not subdirectories like “projectFolder/subDir”.

## [TM] Stein’s lemma

This post is about Stein’s lemma, which first appeared in the landmark paper of Stein in 1981. This lemma is leads to Stein’s unbiased risk estimator and is useful for proving central limit theorems. It has also been called `Gaussian integration by parts’, which is in fact a high level description of the proof.

Lemma 1 (Stein’s lemma)If follows the standard normal distribution, then

if the expectations are well-defined.

*Proof:* If is `nice’, then

It is also convinient to denote as the standard Normal density and remember that

Stein’s lemma can be generalized to exponential family distributions. In particular, for multivariate normals, if and is any differentiable estimator, then we have

This is Equation (12.56) in `Computer Age Statistical Inference’ by Efron and Hastie.

This post is the second in the category `trivial matters’, where I formally write down some notes to myself about identities, tricks, and facts that I repeatedly use but (unfortunately) need to re-derive everytime I use them. Although these posts are short, they discuss important topics. The term `trivial matters’ is used as a sarcasm, because my blood boils everytime I see terms like `obviously’ or `it is trivial to show that …’ when I grade students’ homeworks.

## [TM] Change of Variables in MCMC

This post is about change of variables in Markov chain Monte Carlo (MCMC), which is used quite often when the target distribution is supported on a subset of . For example, the Exponential distribution and the Log-Normal distribution are only supported on positive reals.

Consider a target distribution that is supported on a subset . If we use a random walk proposal , then we might end up with a proposal such that and, this might cause too few acceptance in the MCMC chain. If we can find a transformation that is one-to-one, differentiable and spans , then we can consider a proposal where . This proposal always yields a proposal such that

Of course, when we employ such a transformation in the proposal kernel, we need to be careful about evaluating the proposal densities. We know that the acceptance probability is , and it should be no surprise that unless is the identity map.

Let’s work out the acceptance ratio together carefully. Recall that change of variables proceeds as follows: when and we consider the transformation , the pdf of is

When we apply this to the kernels and we get that

Example 1{Symmetric proposal on transformed space} If is a symmetric proposal, then the acceptance probability becomes

Here are two common transformations.

Example 2 (Log-transformation for supported on )

If , then and acceptance probability is

Example 3 (Logit transformation for supported on )If ,then the inverse transformation is The acceptance probability is

This post is the first one in the category `trivial matters’, where I formally write down some notes to myself about tricks and facts that I repeatedly use but (unfortunately) need to re-derive everytime I use them.