<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom"><title>Sebastian Nowozin's slow blog</title><link href="https://www.nowozin.net/sebastian/blog/" rel="alternate"/><link href="https://www.nowozin.net/sebastian/blog/feeds/all.atom.xml" rel="self"/><id>https://www.nowozin.net/sebastian/blog/</id><updated>2022-08-09T19:00:00+01:00</updated><subtitle>Machine Learning and Statistics</subtitle><entry><title>Thoughts on Trace Estimation in Deep Learning</title><link href="https://www.nowozin.net/sebastian/blog/thoughts-on-trace-estimation-in-deep-learning.html" rel="alternate"/><published>2022-08-09T19:00:00+01:00</published><updated>2022-08-09T19:00:00+01:00</updated><author><name>Sebastian Nowozin</name></author><id>tag:www.nowozin.net,2022-08-09:/sebastian/blog/thoughts-on-trace-estimation-in-deep-learning.html</id><summary type="html">&lt;p&gt;Efficiently estimating the &lt;em&gt;trace&lt;/em&gt; &lt;span class="math"&gt;\(\textrm{tr}(A) = \sum_{i=1}^d A_{ii}\)&lt;/span&gt; of a
square matrix &lt;span class="math"&gt;\(A \in \mathbb{R}^{d \times d}\)&lt;/span&gt; is an important problem required
in a number of recent deep learning and machine learning models.  In those
cases the matrix &lt;span class="math"&gt;\(A\)&lt;/span&gt; is typically
&lt;a href="https://en.wikipedia.org/wiki/Definite_matrix"&gt;positive-definite&lt;/a&gt;, large …&lt;/p&gt;</summary><content type="html">&lt;p&gt;Efficiently estimating the &lt;em&gt;trace&lt;/em&gt; &lt;span class="math"&gt;\(\textrm{tr}(A) = \sum_{i=1}^d A_{ii}\)&lt;/span&gt; of a
square matrix &lt;span class="math"&gt;\(A \in \mathbb{R}^{d \times d}\)&lt;/span&gt; is an important problem required
in a number of recent deep learning and machine learning models.  In those
cases the matrix &lt;span class="math"&gt;\(A\)&lt;/span&gt; is typically
&lt;a href="https://en.wikipedia.org/wiki/Definite_matrix"&gt;positive-definite&lt;/a&gt;, large and
dense.&lt;/p&gt;
&lt;p&gt;As a sample of recent occurences of needing to compute the trace of large
matrices in machine learning, I picked the following applications.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Continuous normalizing flows&lt;/strong&gt;, as in diffusion models &lt;a href="https://arxiv.org/pdf/2011.13456.pdf"&gt;(Song et al., ICLR
  2021)&lt;/a&gt;, FFJORD &lt;a href="https://arxiv.org/pdf/1810.01367.pdf"&gt;(Grathwohl et al., ICLR
  2019)&lt;/a&gt; and Neural ODEs &lt;a href="https://proceedings.neurips.cc/paper/2018/file/69386f6bb1dfed68692a24c8686939b9-Paper.pdf"&gt;(Chen et al.,
  NeurIPS 2018)&lt;/a&gt;,
  where an initial sample &lt;span class="math"&gt;\(x(0) \sim p_0\)&lt;/span&gt; is continuously transformed by a function, i.e.
  &lt;span class="math"&gt;\(\partial x(t)/\partial t = f(x(t),t)\)&lt;/span&gt; from &lt;span class="math"&gt;\(t=0\)&lt;/span&gt; to &lt;span class="math"&gt;\(t=1\)&lt;/span&gt;.
  To evaluate &lt;span class="math"&gt;\(\log p(x(1))\)&lt;/span&gt; we need to rely on the &lt;em&gt;instantaneous change of variable&lt;/em&gt; formula,
  &lt;div class="math"&gt;$$\frac{\partial \log p(x(t))}{\partial t} = -\textrm{tr}\left(
  \frac{\partial f}{\partial x(t)}\right),$$&lt;/div&gt;
  such that the log-probability is determined by
  &lt;div class="math"&gt;$$\log p(x(1)) = \log p(x(0)) - \int_0^1 \textrm{tr}\left(
  \frac{\partial f}{\partial x(t)}\right)\,\textrm{d}t.$$&lt;/div&gt;
  Computing the trace of the &lt;a href="https://en.wikipedia.org/wiki/Jacobian_matrix_and_determinant"&gt;Jacobian &lt;span class="math"&gt;\(\frac{\partial f}{\partial x(t)}\)&lt;/span&gt;&lt;/a&gt; is the computational bottleneck.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Efficient Gaussian Process evidence computation&lt;/strong&gt;. &lt;a href="https://proceedings.mlr.press/v162/wenger22a/wenger22a.pdf"&gt;(Wenger et al., ICML
  2022)&lt;/a&gt;, where
  trace estimation is used to estimate the log-marginal likelihood, and the
  matrix &lt;span class="math"&gt;\(A\)&lt;/span&gt; is a &lt;a href="https://en.wikipedia.org/wiki/Positive-definite_kernel"&gt;kernel matrix&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Approximating log-determinants in invertible ResNets&lt;/strong&gt;.  &lt;a href="https://arxiv.org/pdf/1811.00995.pdf"&gt;(Behrmann et al.,
  2018)&lt;/a&gt; propose a variant of ResNet
  blocks that is invertible by constraining the Lipschitz-constant of the ResNet
  block update to be smaller than one.  Once invertible the ResNet block can be
  used for generative modelling via a normalizing flow model.  That is, we sample
  &lt;span class="math"&gt;\(x_0 \sim p_0\)&lt;/span&gt; from a simple prior &lt;span class="math"&gt;\(p_0\)&lt;/span&gt; and then map &lt;span class="math"&gt;\(f(x_0)\)&lt;/span&gt; to the target
  density.  To compute log-likelihoods for a given &lt;span class="math"&gt;\(x\)&lt;/span&gt; we invert the map and
  compute &lt;span class="math"&gt;\(\log p(x) = \log p_0(f^{-1}(x)) + \log |\det J_{f^{-1}}(x)|\)&lt;/span&gt;.
  By exploiting the structure of the &lt;span class="math"&gt;\(i\)&lt;/span&gt;'th ResNet block, &lt;span class="math"&gt;\(f_i(x) = x +
  g_i(x)\)&lt;/span&gt;, and the Lipschitz constraint on &lt;span class="math"&gt;\(g_i\)&lt;/span&gt;, the log-determinant
  computation can be reduced to a convergent power series,
  &lt;span class="math"&gt;\(\textrm{tr}(\log (I + J_g(x))) = \sum_{k=1}^{\infty} \frac{(-1)^{k+1}}{k} \textrm{tr}(J^k_g).\)&lt;/span&gt;
  Without going into detail, Behrmann et al. truncate the power series and
  compute the trace terms using Hutchinson's trace estimator, thus are able to
  use invertible ResNets for generative modelling.
  The same group, in &lt;a href="https://arxiv.org/pdf/1906.02735.pdf"&gt;(Chen et al.,
  2019)&lt;/a&gt;, improve on the finite truncation
  by using stochastic truncation in the form of &lt;em&gt;Russian roulette estimators&lt;/em&gt;,
  managing to create unbiased estimates, again using trace estimation for each
  term of the power series.   (If you hear the term "Russian
  roulette estimator" for the first time, it is a quite general technique that is
  worth knowing about; a good self-contained brief introduction and history of
  randomized series truncation can be found in section 2.1 and 2.2 of &lt;a href="http://proceedings.mlr.press/v97/beatson19a/beatson19a.pdf"&gt;(Beatson
  and Adams, 2019)&lt;/a&gt;.)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Regularizing continuous dynamics&lt;/strong&gt;. &lt;a href="http://proceedings.mlr.press/v119/finlay20a/finlay20a.pdf"&gt;(Finlay et al., ICML
  2020)&lt;/a&gt; regularize
  the &lt;a href="https://en.wikipedia.org/wiki/Matrix_norm#Frobenius_norm"&gt;Frobenius norm&lt;/a&gt;
  &lt;span class="math"&gt;\(\|A\|_F^2 = \textrm{tr}(A^T A)\)&lt;/span&gt; of the Jacobian of a neural ODE leading to
  smoother dynamics and fewer adaptive integrator steps.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Neural network quantization layer-wise sensitivity metric&lt;/strong&gt;.
  &lt;a href="https://proceedings.neurips.cc/paper/2020/file/d77c703536718b95308130ff2e5cf9ee-Paper.pdf"&gt;(Dong et al., NeurIPS 2020)&lt;/a&gt; and &lt;a href="https://arxiv.org/pdf/2008.08284.pdf"&gt;(Qian et al., 2020)&lt;/a&gt; use the
  trace-of-Hessian of parameters belonging to the same neural network layer to
  allocate the quantization fidelity needed.
  Such a &lt;em&gt;trace-of-Hessian&lt;/em&gt; regularization is also effectively used in one of
  the early papers on energy-based models, &lt;a href="https://proceedings.neurips.cc/paper/2010/file/6f3e29a35278d71c7f65495871231324-Paper.pdf"&gt;(Kingma and Le Cun,
  2010)&lt;/a&gt;,
  there it is used to regularize the curvature of learned energy functions.
  The diagonal of the Hessian is a natural local sensitivity measure and
  perhaps the earliest use in neural networks is in the classic &lt;em&gt;optimal brain
  damage&lt;/em&gt; sensitivity metric of &lt;a href="https://proceedings.neurips.cc/paper/1989/file/6c9882bbac1c7093bd25041881277658-Paper.pdf"&gt;(Le Cun et al., 1989)&lt;/a&gt;,
  which used second derivatives for each parameter to determine deletion
  of neurons.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Sliced score matching&lt;/strong&gt;.  &lt;a href="https://www.jmlr.org/papers/volume6/hyvarinen05a/hyvarinen05a.pdf"&gt;(Hyvarinen, JMLR
  2005)&lt;/a&gt;
  introduced &lt;em&gt;score matching&lt;/em&gt; as a learning objective for energy-based models,
  &lt;span class="math"&gt;\(p(x) \propto \exp(-E(x))\)&lt;/span&gt;, and in the score matching objective a sum of
  second derivates of the energy function needs to be evaluated,
  &lt;span class="math"&gt;\(\sum_{i=1}^d \partial^2 E(x) / (\partial x_i)^2\)&lt;/span&gt;.  Because evaluating these
  second-order derivates is expensive this limited the applicability of score
  matching until &lt;a href="http://proceedings.mlr.press/v115/song20a/song20a.pdf"&gt;(Song et al., UAI
  2020)&lt;/a&gt; introduced
  &lt;em&gt;sliced score matching&lt;/em&gt; where the expensive term is replaced by a stochastic estimate
  &lt;span class="math"&gt;\(\mathbb{E}_z\left[\sum_{i=1}^d \sum_{j=1}^d \frac{\partial^2 E(x)}{\partial x_i \, \partial x_j} z_i z_j\right]\)&lt;/span&gt;, i.e. a Hutchinson estimate of the trace of the Hessian of &lt;span class="math"&gt;\(E\)&lt;/span&gt;.
  For a great overview of these techniques see the recent review by &lt;a href="https://arxiv.org/pdf/2101.03288.pdf"&gt;(Song and
  Kingma, 2021)&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;What is the shared difficulty in all of the above applications?
After all, computing the trace of an &lt;em&gt;explicitly given matrix&lt;/em&gt; &lt;span class="math"&gt;\(A\)&lt;/span&gt; is trivial:
simply sum the diagonal elements,&lt;/p&gt;
&lt;div class="math"&gt;$$\textrm{tr}(A) := \sum_i A_{ii}.$$&lt;/div&gt;
&lt;p&gt;However, in the above applications arising in deep learning the problem is that
it is very expensive to compute &lt;span class="math"&gt;\(A\)&lt;/span&gt; explicitly, but we &lt;em&gt;can&lt;/em&gt; query
matrix-vector products efficiently.  Given &lt;span class="math"&gt;\(z \in \mathbb{R}^d\)&lt;/span&gt;, we can
efficiently compute&lt;/p&gt;
&lt;div class="math"&gt;$$y = A \, z.$$&lt;/div&gt;
&lt;p&gt;Clearly, if we are able to compute many such products, say &lt;span class="math"&gt;\(d\)&lt;/span&gt; times, we can
reconstruct the matrix &lt;span class="math"&gt;\(A\)&lt;/span&gt; completely.  The simplest example is to take
&lt;span class="math"&gt;\(z^{(m)} := e_m\)&lt;/span&gt;, the natural basis vectors in &lt;span class="math"&gt;\(\mathbb{R}^d\)&lt;/span&gt;, such that
&lt;span class="math"&gt;\(y^{(m)} = A \, z^{(m)}\)&lt;/span&gt; directly extracts the &lt;span class="math"&gt;\(m\)&lt;/span&gt;'th row of the matrix.  By
extracting all rows we could obtain &lt;span class="math"&gt;\(A\)&lt;/span&gt; in explicit forms.&lt;/p&gt;
&lt;p&gt;The drawback of this technique is that performing many matrix-vector
multiplications is expensive, where typically each matrix-vector product
corresponds to one forward-backprop operation in a neural network.
Is there a better way, requiring only a &lt;em&gt;small&lt;/em&gt; number of matrix-vector
products to obtain an accurate &lt;em&gt;estimate&lt;/em&gt; of the trace of &lt;span class="math"&gt;\(A\)&lt;/span&gt;?&lt;/p&gt;
&lt;p&gt;Yes, and we will discuss the main technique below.  But first, to add more
excitement to our goal: if the problem of trace estimation is amenable, a
number of related problems are also in reach using extended methods such as
variants of conjugate gradients &lt;a href="https://link.springer.com/chapter/10.1007/978-94-015-7860-8_48"&gt;(Seeger,
2000)&lt;/a&gt; and the
&lt;em&gt;stochastic Lanczos quadrature&lt;/em&gt; method of &lt;a href="https://shashankaubaru.github.io/Papers/Lanc_Quad.pdf"&gt;(Ubaru et al.,
2017)&lt;/a&gt; which allows
efficient estimation of functions of the form&lt;/p&gt;
&lt;div class="math"&gt;$$\textrm{tr}(f(A)),$$&lt;/div&gt;
&lt;p&gt;where &lt;span class="math"&gt;\(f: \mathbb{R} \to \mathbb{R}\)&lt;/span&gt; is a scalar function and
&lt;span class="math"&gt;\(\textrm{tr}(f(\cdot))\)&lt;/span&gt; is the resulting &lt;a href="https://en.wikipedia.org/wiki/Trace_inequality#Trace_function"&gt;trace
function&lt;/a&gt;,
&lt;span class="math"&gt;\(\textrm{tr}(f(A)) := \sum_{i=1}^d f(\lambda_i(A))\)&lt;/span&gt;.  Through different choices
of &lt;span class="math"&gt;\(f\)&lt;/span&gt; trace functions enable estimation of other quantities,&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;em&gt;Log-determinants&lt;/em&gt;,
  &lt;span class="math"&gt;\(\log \det(A) = \textrm{tr}(\log(A)) = \sum_{i=1}^d \log(\lambda_i)\)&lt;/span&gt;.&lt;/li&gt;
&lt;li&gt;&lt;em&gt;Nuclear norm&lt;/em&gt;, for &lt;span class="math"&gt;\(X \in \mathbb{R}^{k \times d}\)&lt;/span&gt; defined as &lt;span class="math"&gt;\(\|X\|_*
  = \textrm{tr}(\sqrt{X^T X})\)&lt;/span&gt;, and more general &lt;em&gt;Schatten &lt;span class="math"&gt;\(p\)&lt;/span&gt;-norms&lt;/em&gt;.&lt;/li&gt;
&lt;li&gt;&lt;em&gt;Trace of &lt;span class="math"&gt;\(A^{-1}\)&lt;/span&gt;&lt;/em&gt;, where &lt;span class="math"&gt;\(\textrm{tr}(A^{-1}) = \textrm{tr}(f(A))\)&lt;/span&gt; with &lt;span class="math"&gt;\(f(t)=1/t\)&lt;/span&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;As we will see below, another quantity that can be estimated using
Hutchinson-style estimators is the &lt;em&gt;diagonal&lt;/em&gt; of a matrix &lt;span class="math"&gt;\(A\)&lt;/span&gt;.&lt;/p&gt;
&lt;h2&gt;Skilling-Hutchinson 1989 trace estimator&lt;/h2&gt;
&lt;p&gt;The estimator appeared in two works in parallel.
In his original 1989 paper, &lt;a href="https://www.tandfonline.com/doi/abs/10.1080/03610918908812806?journalCode=lssp20"&gt;(Hutchinson, "A Stochastic Estimator of the Trace
of the Influence Matrix for Laplacian Smoothing Splines",
1989)&lt;/a&gt;,
Hutchinson introduced the first stochastic estimator of the matrix trace, and
simultaneously John Skilling introduced the same technique in &lt;a href="https://link.springer.com/chapter/10.1007/978-94-015-7860-8_48"&gt;(Skilling, "The
Eigenvalues of Mega-dimensional Matrices",
1989)&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;The Skilling-Hutchinson trace estimator is not just historially interesting; it
is still the most common method used today due to its general applicability and
simplicity of implementation.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Skilling-Hutchinson's trace estimate:&lt;/strong&gt;
If &lt;span class="math"&gt;\(z \in \mathbb{R}^{d}\)&lt;/span&gt; is a random vector satisfying
&lt;span class="math"&gt;\(\mathbb{E}[z z^T] = I\)&lt;/span&gt;, then&lt;/p&gt;
&lt;div class="math"&gt;$$\mathbb{E}[z^T A z] = \textrm{tr}(A).$$&lt;/div&gt;
&lt;p&gt;The Skilling-Hutchinson estimator is&lt;/p&gt;
&lt;div class="math"&gt;$$\hat{T}_{\cdot,M}(A) := \frac{1}{M} \sum_{m=1}^M (z^{(m)})^T A\, z^{(m)},$$&lt;/div&gt;
&lt;p&gt;where &lt;span class="math"&gt;\(z^{(m)}\)&lt;/span&gt; are random vectors satisfying the above condition.  In
Hutchinson's original estimator these vectors are &lt;em&gt;Rademacher vectors&lt;/em&gt; with
elements iid in &lt;span class="math"&gt;\(\{-1,1\}\)&lt;/span&gt; and we write &lt;span class="math"&gt;\(\hat{T}_{H,M}\)&lt;/span&gt;, but the term
&lt;em&gt;Hutchinson's trace estimator&lt;/em&gt; is also commonly used nowadays if standard
Normal vectors are used in the &lt;em&gt;Gaussian trace estimator&lt;/em&gt; &lt;span class="math"&gt;\(\hat{T}_{G,M}\)&lt;/span&gt;.&lt;/p&gt;
&lt;p&gt;The Skilling-Hutchinson estimator is &lt;em&gt;unbiased&lt;/em&gt;, meaning
&lt;span class="math"&gt;\(\mathbb{E}[\hat{T}_{\cdot,M}(A)] = \textrm{tr}(A)\)&lt;/span&gt;.
Moreover, it is known that for standard Normal vectors we have&lt;/p&gt;
&lt;div class="math"&gt;$$\mathbb{V}[\hat{T}_{G,M}(A)] = \frac{2}{M} \|A\|_F^2 = \frac{2}{M} \sum_{i=1}^d \lambda^2_i(A),$$&lt;/div&gt;
&lt;p&gt;where &lt;span class="math"&gt;\(\lambda_i(A)\)&lt;/span&gt; is the &lt;span class="math"&gt;\(i\)&lt;/span&gt;'th Eigenvalue of &lt;span class="math"&gt;\(A\)&lt;/span&gt;.
For Rademacher vectors it is known that&lt;/p&gt;
&lt;div class="math"&gt;$$\mathbb{V}[\hat{T}_{H,M}(A)] = \frac{2}{M} \left(\|A\|_F^2 - \sum_{i=1}^d A_{ii}^2\right).$$&lt;/div&gt;
&lt;p&gt;You can see that using Rademacher vectors has provably smaller variance than
using Gaussian vectors,&lt;/p&gt;
&lt;div class="math"&gt;$$\mathbb{V}[\hat{T}_{H,M}(A)] \leq \mathbb{V}[\hat{T}_{G,M}(A)].$$&lt;/div&gt;
&lt;p&gt;There is a wealth of theory available for the estimator, and a good recent
entry point into known results is &lt;em&gt;Maciej Skorksi&lt;/em&gt;'s paper "A Modern Analysis
of Hutchinson's Trace Estimator" from 2020
(&lt;a href="https://arxiv.org/pdf/2012.12895.pdf"&gt;PDF&lt;/a&gt;).
In it he gives a error bound for the Rademacher version, using the &lt;em&gt;relative
error&lt;/em&gt;&lt;/p&gt;
&lt;div class="math"&gt;$$\textrm{err}(\hat{T}_{H,M}, A) := \frac{\hat{T}_{H,M}(A)}{\textrm{tr}(A)}-1.$$&lt;/div&gt;
&lt;p&gt;For this error and for any &lt;span class="math"&gt;\(d \geq 2\)&lt;/span&gt; he gives the tail bound for any &lt;span class="math"&gt;\(0 &amp;lt;
\varepsilon &amp;lt; 3/8\)&lt;/span&gt; of the form&lt;/p&gt;
&lt;div class="math"&gt;$$P(|\textrm{err}(\hat{T}_{H,M}, A)| \geq \varepsilon)
\leq \exp\left(-\frac{M \varepsilon^2}{2(1-8/3\varepsilon)}\right).$$&lt;/div&gt;
&lt;h2&gt;Praise for Hutchinson's estimator&lt;/h2&gt;
&lt;p&gt;There is a lot of good to say about Hutchinson's trace estimator:&lt;/p&gt;
&lt;p&gt;&lt;em&gt;It is simple&lt;/em&gt;: the estimator is easy to understand and implement.  It is free
from exotic ingredients, uses just basic linear algebra, and does not make
strong assumptions thus is widely applicable.  Because it is simple it works
well with auto-differentiation.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Linear trade-off &lt;span class="math"&gt;\(M\)&lt;/span&gt;&lt;/em&gt;: Hutchinson's estimator comes with a free choice of &lt;span class="math"&gt;\(M
\geq 1\)&lt;/span&gt;, the number of matrix-vector products to evaluate.  The parameter &lt;span class="math"&gt;\(M\)&lt;/span&gt;
linearly controls both variance and computational effort with the estimator
becoming exact for &lt;span class="math"&gt;\(M \to \infty\)&lt;/span&gt;.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Parallelizable&lt;/em&gt;: for larger values of &lt;span class="math"&gt;\(M\)&lt;/span&gt; all evaluations can be done in
parallel, i.e. the sequential compute depth does not increase for more
accurate estimates.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Unbiasedness&lt;/em&gt;: for any &lt;span class="math"&gt;\(M \geq 1\)&lt;/span&gt; the estimator is unbiased.  How valuable is
an unbiased estimator?  In general whether an estimator is unbiased or not may
not matter (see &lt;em&gt;Andrew Gelman's&lt;/em&gt; points
&lt;a href="https://statmodeling.stat.columbia.edu/2011/10/15/the-bias-variance-tradeoff/"&gt;here&lt;/a&gt;
and
&lt;a href="https://statmodeling.stat.columbia.edu/2015/05/11/theres-no-such-thing-as-unbiased-estimation-and-its-a-good-thing-too/"&gt;here&lt;/a&gt;).
But our situation here is special for two reasons: 1. there is an exact
quantity of interest, &lt;span class="math"&gt;\(\textrm{tr}(A)\)&lt;/span&gt;, and our estimation is done only for
computational benefits; and 2. for most deep learning applications it is
incredibly important: it allows iterative stochastic optimization algorithms to
work correctly and to asymptotically average out estimator variance.&lt;/p&gt;
&lt;p&gt;So is all good then with Hutchinson's estimator?&lt;/p&gt;
&lt;h2&gt;Problems of Hutchinson's estimator&lt;/h2&gt;
&lt;p&gt;Despite singing the praise just now, the estimator has a number of fundamental
problems as well.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;High Monte Carlo variance&lt;/em&gt;: the estimator has a decaying variance at rate &lt;span class="math"&gt;\(O(1/M)\)&lt;/span&gt;
arising from taking the average of &lt;span class="math"&gt;\(M\)&lt;/span&gt; estimates.  To see why this is a bad
rate, consider the case where we take &lt;span class="math"&gt;\(M=d\)&lt;/span&gt;, and we take Normal vectors
&lt;span class="math"&gt;\(z^{(m)} \sim \mathcal{N}_d(0,I)\)&lt;/span&gt;.  We then could recover the exact matrix &lt;span class="math"&gt;\(A\)&lt;/span&gt;
and thus its trace without any uncertainty.  Hutchinson would still offer us
only a &lt;span class="math"&gt;\(1/d\)&lt;/span&gt; decrease in variance and hence does not use all information
contained in our measurements.&lt;/p&gt;
&lt;p&gt;The analysis from Skorski reflects this hungryness for large sample sizes.
Skorksi's analysis estimates that for given &lt;span class="math"&gt;\((\varepsilon,\delta)\)&lt;/span&gt; parameters,
we need &lt;span class="math"&gt;\(n(\varepsilon,\delta) =
2(1-(8/3)\varepsilon)\log(1/\delta)/\varepsilon^2\)&lt;/span&gt; samples to achieve an
absolute bound of &lt;span class="math"&gt;\(\varepsilon\)&lt;/span&gt; on the relative error with probability
&lt;span class="math"&gt;\(1-\delta\)&lt;/span&gt;.  As an example, his results requires that &lt;span class="math"&gt;\(n(0.1, 0.1) = 337\)&lt;/span&gt; and
&lt;span class="math"&gt;\(n(0.01, 0.1)=44824\)&lt;/span&gt; for example, independent of &lt;span class="math"&gt;\(d\)&lt;/span&gt;.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Complete prior ignorance&lt;/em&gt;: in some applications we may have a prior idea about
&lt;span class="math"&gt;\(A\)&lt;/span&gt; or of its trace value.  For example, in deep learning we learn iteratively
by gradient descent, and a matrix &lt;span class="math"&gt;\(A_t\)&lt;/span&gt; at step &lt;span class="math"&gt;\(t\)&lt;/span&gt; may not be too different
from a matrix &lt;span class="math"&gt;\(A_{t+\Delta}\)&lt;/span&gt; for small &lt;span class="math"&gt;\(\Delta\)&lt;/span&gt;.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Complete random design &lt;span class="math"&gt;\((z^{(1)},\dots,z^{(M)})\)&lt;/span&gt;&lt;/em&gt;:
whether Normal or Rademacher vectors are used, the random vectors &lt;span class="math"&gt;\(z^{(m)}\)&lt;/span&gt; are
chosen independently at random.  Can we improve the estimate by chosing them
&lt;em&gt;dependently&lt;/em&gt;?
Or by chosing &lt;span class="math"&gt;\(z^{(m)}\)&lt;/span&gt; adaptively based on &lt;span class="math"&gt;\((y^{(j)},z^{(j)})_{j &amp;lt; m}\)&lt;/span&gt;?
The latter is an &lt;em&gt;adaptive experimental design&lt;/em&gt; and may or may not be an option
depending on our needs to parallelize computation over &lt;span class="math"&gt;\(z^{(m)}\)&lt;/span&gt;'s.&lt;/p&gt;
&lt;h1&gt;Variance Reduction Approaches&lt;/h1&gt;
&lt;p&gt;A number of approaches have been proposed to preserve the spirit of the
Hutchinson estimator but to lower its variance.  The shared idea is to think
sequentially and to use prior measurements to construct some form of estimate
&lt;span class="math"&gt;\(\hat{A}\)&lt;/span&gt; of &lt;span class="math"&gt;\(A\)&lt;/span&gt;, which can then be used to lower the variance.&lt;/p&gt;
&lt;p&gt;I am aware of two classes of methods: one based on control-variates, and one
based on constructing a low-rank approximation to &lt;span class="math"&gt;\(A\)&lt;/span&gt;.&lt;/p&gt;
&lt;p&gt;In addition to these two classes, I will also throw in an attractive new method
into the mix, based on randomized quasi Monte Carlo.&lt;/p&gt;
&lt;h2&gt;Control-variate Methods&lt;/h2&gt;
&lt;p&gt;&lt;em&gt;Control variates&lt;/em&gt; are a classic method for variance reduction and are
frequently used in reinforcement learning, where they are called &lt;em&gt;baselines&lt;/em&gt;.
A great introduction to classic variance reduction methods can be found in
&lt;a href="https://artowen.su.domains/mc/Ch-var-basic.pdf"&gt;Chapter 8&lt;/a&gt; of &lt;a href="https://artowen.su.domains/mc/"&gt;Art Owen's
yet-unreleased Monte Carlo book&lt;/a&gt;, with
&lt;a href="https://artowen.su.domains/mc/Ch-var-basic.pdf"&gt;Section 8.9&lt;/a&gt; introducing
various forms of control variates.&lt;/p&gt;
&lt;p&gt;In its simplest form the idea is this: we are interested in estimating
&lt;span class="math"&gt;\(\mathbb{E}_{z \sim p}[f(z)]\)&lt;/span&gt; using samples from &lt;span class="math"&gt;\(p(z)\)&lt;/span&gt;.  If we know a "simple"
function &lt;span class="math"&gt;\(h\)&lt;/span&gt; and this function is similar to &lt;span class="math"&gt;\(f\)&lt;/span&gt;, i.e. we have &lt;span class="math"&gt;\(h(z) \approx
f(z)\)&lt;/span&gt;, then we can instead attempt to estimate the equivalent quantity&lt;/p&gt;
&lt;div class="math"&gt;$$\mathbb{E}_{z \sim p}[f(z) - h(z)] + \mathbb{E}_{z \sim p}[h(z)].$$&lt;/div&gt;
&lt;p&gt;The first expectation is now likely smaller in magnitude, so our Monte Carlo
estimate of this first term has smaller variance.  But what about the second
term?  If &lt;span class="math"&gt;\(h\)&lt;/span&gt; is simple enough we may be able to compute this quantity
analytically, with no Monte Carlo variance at all.&lt;/p&gt;
&lt;p&gt;To make this idea realistic, we typically relax the definition somewhat and
define &lt;span class="math"&gt;\(h_{\beta}(z) := \beta \, h(z)\)&lt;/span&gt;, where &lt;span class="math"&gt;\(\beta \in \mathbb{R}\)&lt;/span&gt; can be
estimated to maximally mimic the behaviour of &lt;span class="math"&gt;\(f(z)\)&lt;/span&gt; and thus to reduce the
variance of &lt;span class="math"&gt;\(f(z) - h_{\beta}(z)\)&lt;/span&gt; the most.&lt;/p&gt;
&lt;p&gt;For trace estimation &lt;a href="https://arxiv.org/pdf/1802.03451.pdf"&gt;(Adams et al.,
2018)&lt;/a&gt; first proposed to use control
variates to reduce variance:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;They propose to set &lt;span class="math"&gt;\(h_{\beta}(z) = \beta \, z^T B z\)&lt;/span&gt;, where &lt;span class="math"&gt;\(B \in
  \mathbb{R}^{d \times d}\)&lt;/span&gt; is a matrix chosen by us, ideally &lt;span class="math"&gt;\(B \approx A\)&lt;/span&gt;, and
  &lt;span class="math"&gt;\(\beta \in \mathbb{R}\)&lt;/span&gt; is estimated or fixed to &lt;span class="math"&gt;\(\beta=1\)&lt;/span&gt;.&lt;/li&gt;
&lt;li&gt;The &lt;span class="math"&gt;\(M\)&lt;/span&gt;-sample trace estimator now becomes
  &lt;div class="math"&gt;$$\hat{T}_{C}(A,B,\beta) = \frac{1}{M}\sum_{m=1}^M \left[(z^{(m)})^T A z^{(m)} - \beta (z^{m})^T B z^{(m)}\right] + \beta \textrm{tr}(B).$$&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;When &lt;span class="math"&gt;\(z^{(m)} \sim \mathcal{N}_d(0,I)\)&lt;/span&gt;, Adams et al. show (Lemma 4.1 in their
  work) that the variance-minimizing choice of &lt;span class="math"&gt;\(\beta\)&lt;/span&gt; is &lt;span class="math"&gt;\(\beta^* =
  \textrm{tr}(A\,B)/\textrm{tr}(B\,B)\)&lt;/span&gt; and that for this choice the variance of
  the estimator is &lt;em&gt;reduced&lt;/em&gt; compared to the Gaussian trace estimator by &lt;span class="math"&gt;\(2
  \textrm{tr}(A \,B)^2 / \textrm{tr}(B \, B)\)&lt;/span&gt;.  This also shows that when &lt;span class="math"&gt;\(B=A\)&lt;/span&gt;
  the estimator variance is zero.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;How to select the matrix &lt;span class="math"&gt;\(B\)&lt;/span&gt;?  Adams et al. make one efficient proposal, which
is to estimate the diagonal of &lt;span class="math"&gt;\(A\)&lt;/span&gt; in the form &lt;span class="math"&gt;\(B = \textrm{diag}(b)\)&lt;/span&gt;, where &lt;span class="math"&gt;\(b
\in \mathbb{R}^d\)&lt;/span&gt;.  The diagonal is a simple choice because we can evaluate
&lt;span class="math"&gt;\(\textrm{tr}(B) = \sum_{i=1}^d b_i\)&lt;/span&gt; but also because the Hutchinson-style trace
estimator already contains an estimator of the diagonal within it:&lt;/p&gt;
&lt;div class="math"&gt;$$\mathbb{E}_{z}[z \odot (A z)] = \textrm{diag}(A),$$&lt;/div&gt;
&lt;p&gt;where &lt;span class="math"&gt;\(\odot\)&lt;/span&gt; is the elementwise product.
This identity holds for both the Rademacher vectors and the Gaussian vectors
because &lt;span class="math"&gt;\(\mathbb{E}[z_i^2] = 1\)&lt;/span&gt;.  For the &lt;span class="math"&gt;\(i\)&lt;/span&gt;'th element of the diagonal, we
can see that
&lt;/p&gt;
&lt;div class="math"&gt;$$
\begin{align*}
\mathbb{E}\left[z_i \left(\sum_{j=1}^d A_{ij} z_j\right)\right]
&amp;amp;= \sum_{j=1}^d A_{ij} \mathbb{E}[z_i z_j]\\
&amp;amp;= A_{ii} \underbrace{\mathbb{E}[z_i^2]}_{=1}
    + \sum_{j \neq i} A_{ij} \underbrace{\mathbb{E}[z_i]}_{=0}
        \underbrace{\mathbb{E}[z_j]}_{=0}\\
&amp;amp;= A_{ii}.
\end{align*}
$$&lt;/div&gt;
&lt;p&gt;Adams et al. also propose to apply the control variate idea once more to the
diagonal estimate itself.
To see one way to achieve this is to look at the &lt;span class="math"&gt;\(m\)&lt;/span&gt;'th iteration, where our
instantaneous diagonal estimate is&lt;/p&gt;
&lt;div class="math"&gt;$$\hat{b}^{(m)} = z^{(m)} \odot A z^{(m)}.$$&lt;/div&gt;
&lt;p&gt;Instead we can use our existing knowledge of &lt;span class="math"&gt;\(A\)&lt;/span&gt;, in the form of &lt;span class="math"&gt;\(\hat{b}^{(m)}\)&lt;/span&gt;:&lt;/p&gt;
&lt;div class="math"&gt;$$
\begin{align*}
\hat{b}^{(m)}
&amp;amp;:= z^{(m)} \odot \left(A-\textrm{diag}(\hat{b}^{(m-1)})\right) z^{(m)}
    + \mathbb{E}_z\left[z \odot \textrm{diag}(\hat{b}^{(m-1)}) z\right]\\
&amp;amp;= z^{(m)} \odot \left(A-\textrm{diag}(\hat{b}^{(m-1)})\right) z^{(m)}
    + \hat{b}^{(m-1)}.
\end{align*}
$$&lt;/div&gt;
&lt;p&gt;Putting the two control variate ideas together, we can implement the Adams et
al. trace estimator in the following Julia code.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="k"&gt;function&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;adams_trace_estimator&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;A&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;M&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="kt"&gt;Int&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;use_diag_cv&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nb"&gt;false&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;d&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;size&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;A&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;b_diag&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;zeros&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;d&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt;   &lt;/span&gt;&lt;span class="c"&gt;# B = diag(b_diag)&lt;/span&gt;

&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;tr_est&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mf"&gt;0.0&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;m&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="n"&gt;M&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;z&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;randn&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;d&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="c"&gt;# Gaussian z^{(m)}&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;A&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;z&lt;/span&gt;

&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;y_B&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;b_diag&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;.*&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;z&lt;/span&gt;&lt;span class="w"&gt;   &lt;/span&gt;&lt;span class="c"&gt;# B z&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;tr_est&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;+=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;z&lt;/span&gt;&lt;span class="o"&gt;&amp;#39;*&lt;/span&gt;&lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;z&lt;/span&gt;&lt;span class="o"&gt;&amp;#39;*&lt;/span&gt;&lt;span class="n"&gt;y_B&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;b_diag&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;&lt;span class="w"&gt;   &lt;/span&gt;&lt;span class="c"&gt;# z&amp;#39;Az - (z&amp;#39;Bz - tr(B))&lt;/span&gt;

&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="c"&gt;# Update diagonal estimate&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;use_diag_cv&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="n"&gt;b_diag_cur&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;z&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;.*&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;y_B&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;b_diag&lt;/span&gt;&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="c"&gt;# z .* ((A-B)z) + diag(B)&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="k"&gt;else&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="n"&gt;b_diag_cur&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;z&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;.*&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="w"&gt;   &lt;/span&gt;&lt;span class="c"&gt;# instantaneous estimate of diag(A)&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="k"&gt;end&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;b_diag&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;.*=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;m&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;b_diag&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;+=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;b_diag_cur&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;b_diag&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;./=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;m&lt;/span&gt;&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="c"&gt;# Invariant: b^{(M)} = (1/M) sum_{m=1}^M (z^{(m)} .* y^{(m)})&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="k"&gt;end&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;tr_est&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;M&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;b_diag&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;h2&gt;Low-rank Approximation Methods (Hutch++)&lt;/h2&gt;
&lt;p&gt;&lt;a href="https://arxiv.org/pdf/2010.09649.pdf"&gt;(Meyer et al., 2021)&lt;/a&gt; present
improvements on the Hutchinson estimator by first extracting a low-rank
approximation to &lt;span class="math"&gt;\(A\)&lt;/span&gt; and then using this low-rank approximation to reduce the
variance of the trace estimate.&lt;/p&gt;
&lt;p&gt;Given a good approximation &lt;span class="math"&gt;\(\tilde{A}\)&lt;/span&gt; of &lt;span class="math"&gt;\(A\)&lt;/span&gt; the method also uses the same
technique as the control variate approach, representing&lt;/p&gt;
&lt;div class="math"&gt;$$\textrm{tr}(A) = \textrm{tr}(\tilde{A}) + \textrm{tr}(A - \tilde{A}),$$&lt;/div&gt;
&lt;p&gt;where &lt;span class="math"&gt;\(\textrm{tr}(\tilde{A})\)&lt;/span&gt; is computed analytically and the second term is
stochastically estimated at reduced variance.
How to obtain a good approximation &lt;span class="math"&gt;\(\tilde{A}\)&lt;/span&gt;?
Meyer et al. make two proposals, which then form the Hutch++ and the
Nystroem-Hutch++ estimator.  I will only discuss the Hutch++ briefly here.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Hutch++ estimator&lt;/strong&gt;.  Given a symmetric psd matrix &lt;span class="math"&gt;\(A \in \mathbb{R}^{d
\times d}\)&lt;/span&gt; and an overall budget of &lt;span class="math"&gt;\(m\)&lt;/span&gt; query vectors, split this budget into
&lt;span class="math"&gt;\(q_k\)&lt;/span&gt; and &lt;span class="math"&gt;\(\ell\)&lt;/span&gt; such that &lt;span class="math"&gt;\(2 q_k + \ell = m\)&lt;/span&gt;.  Create &lt;span class="math"&gt;\(S \in
\mathbb{R}^{d,q_k}\)&lt;/span&gt; with each element &lt;span class="math"&gt;\(S_{ij} \sim \mathcal{N}(0,1)\)&lt;/span&gt;.  Evaluate
&lt;span class="math"&gt;\(Y = A S\)&lt;/span&gt; and orthonormalize &lt;span class="math"&gt;\(Y\)&lt;/span&gt; to &lt;span class="math"&gt;\(Q \in \mathbb{R}^{d \times q_k}\)&lt;/span&gt;.
Set &lt;span class="math"&gt;\(\tilde{A} = Q^T A Q\)&lt;/span&gt; and apply the control variate method on &lt;span class="math"&gt;\(\ell\)&lt;/span&gt;
additional samples.&lt;/p&gt;
&lt;p&gt;In Julia this can be implemented as follows.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="k"&gt;function&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;hutchpp&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;A&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;m&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;d&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;size&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;A&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;k&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;floor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;Int&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;m&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt;   &lt;/span&gt;&lt;span class="c"&gt;# Variance-optimal allocation of initial queries&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;qk&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;k&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="w"&gt;                &lt;/span&gt;&lt;span class="c"&gt;# qk: number of initial query vectors&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;ell&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;m&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;qk&lt;/span&gt;&lt;span class="w"&gt;            &lt;/span&gt;&lt;span class="c"&gt;# ell: remaining budget for final estimate&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nd"&gt;@assert&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;qk&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="n"&gt;ell&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;&amp;lt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;m&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="c"&gt;# make sure total query budget m is satisfied&lt;/span&gt;

&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="c"&gt;# initial basis construction&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;S&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;randn&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;d&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;qk&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt;      &lt;/span&gt;&lt;span class="c"&gt;# qk initial query vectors&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;Y&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;A&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;S&lt;/span&gt;&lt;span class="w"&gt;              &lt;/span&gt;&lt;span class="c"&gt;# query matrix&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;Q&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kt"&gt;Matrix&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;qr&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Y&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Q&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="c"&gt;# orthonormalize SY to a (d,qk) basis&lt;/span&gt;

&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="c"&gt;# variance-reduced stochastic estimate&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;z&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;randn&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;d&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;ell&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt;      &lt;/span&gt;&lt;span class="c"&gt;# ell remaining queries&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;y0&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;A&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;z&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;y0&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;Q&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Q&lt;/span&gt;&lt;span class="o"&gt;&amp;#39;*&lt;/span&gt;&lt;span class="n"&gt;y0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="c"&gt;# adjust estimate using low-rank approximation&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;tr_ests&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;z&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;.*&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;dims&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;tr_est&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;Statistics&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;mean&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;tr_ests&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;tr&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Q&lt;/span&gt;&lt;span class="o"&gt;&amp;#39;*&lt;/span&gt;&lt;span class="n"&gt;A&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;Q&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt;   &lt;/span&gt;&lt;span class="c"&gt;# another qk queries&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;tr_est&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;A problem of the Hutch++ family of estimators shared with the control
variate one is that it is difficult to parallelize: there are two sequential
steps and the second step relies on the output of the first.  This may not be a
problem in most applications, but in training deep neural networks we typically
prefer parallelization.&lt;/p&gt;
&lt;h2&gt;Preconditioning&lt;/h2&gt;
&lt;p&gt;If the matrix &lt;span class="math"&gt;\(A\)&lt;/span&gt; is a &lt;em&gt;kernel matrix&lt;/em&gt;, i.e. &lt;span class="math"&gt;\(K_{ij} = k(x_i, x_j)\)&lt;/span&gt; for some
&lt;em&gt;kernel function&lt;/em&gt; &lt;span class="math"&gt;\(k\)&lt;/span&gt;, then variance of a stochastic trace estimator can be
greatly reduced using an appropriate preconditioner.&lt;/p&gt;
&lt;p&gt;An extensive set of results is given by &lt;a href="https://proceedings.mlr.press/v162/wenger22a/wenger22a.pdf"&gt;(Wenger et al., "Preconditioning for
Scalable GP Hyperparameter Optimization", ICML
2022)&lt;/a&gt; with the
application of computing the log-marginal likelihood (evidence) of Gaussian
processes.&lt;/p&gt;
&lt;p&gt;In their application, they exploit the identity&lt;/p&gt;
&lt;div class="math"&gt;$$\log \det K = \log \det P + \textrm{tr}(\log K - \log P),$$&lt;/div&gt;
&lt;p&gt;and estimate the second term using a stochastic trace estimator for variance
reduction.&lt;/p&gt;
&lt;p&gt;Wenger et al. show in theory and through experiments that this leads to large
reduction in variance.
As an example, if &lt;span class="math"&gt;\(A\)&lt;/span&gt; is a kernel matrix arising from a radial basis function
(RBF) kernel in one dimension then the variance scaling that can be achieved
with a suitable precondition can be exponential, &lt;span class="math"&gt;\(\mathbb{V}[\hat{T}_P] =
exp(-c m)\)&lt;/span&gt;.&lt;/p&gt;
&lt;p&gt;The paper by Wenger et al. is very well written and the &lt;a href="https://github.com/cornellius-gp/gpytorch"&gt;code is already
available in GPyTorch&lt;/a&gt;.&lt;/p&gt;
&lt;h2&gt;Randomized Quasi Monte-Carlo (RQMC)&lt;/h2&gt;
&lt;p&gt;Quasi Monte Carlo methods (QMC) aim to improve on Monte Carlo integration.
Whereas basic Monte Carlo methods draw samples independently, quasi Monte Carlo
methods draw samples from a dependent distribution chosen such that for classes
of integrands better convergence rates are obtained.
Typically QMC methods start with a &lt;em&gt;uniform&lt;/em&gt; distribution in the hypercube
&lt;span class="math"&gt;\([0,1]^d\)&lt;/span&gt;.
We can map the hypercube &lt;span class="math"&gt;\([0,1]^d\)&lt;/span&gt; to a domain such as &lt;span class="math"&gt;\([-\infty,\infty]^d\)&lt;/span&gt; using the
&lt;a href="https://en.wikipedia.org/wiki/Inverse_transform_sampling"&gt;inverse cumulative distribution
function&lt;/a&gt; (inverse CDF)
of a chosen distribution.  For example, for the standard Normal distribution
the inverse CDF would be the &lt;a href="https://en.wikipedia.org/wiki/Normal_distribution#Quantile_function"&gt;Normal quantile
function&lt;/a&gt;.
QMC points are deterministic and this determinism would lead to unavoidable
bias when used for sampling.  An effective remedy is to &lt;em&gt;randomize&lt;/em&gt; QMC methods
once more, by shifting all generated points using a randomly chosen offset.
This is the RQMC constructions and it guarantees that the marginal distribution
of every point is following the target distribution.&lt;/p&gt;
&lt;p&gt;To see intuitively how selecting dependent samples could lead to better
properties, here is a visual example of 64 multivariate Normal samples in 2D as
used in Monte Carlo methods such as the Gaussian trace estimator:&lt;/p&gt;
&lt;p&gt;&lt;img alt="Monte Carlo Normal draws in 2D" src="https://www.nowozin.net/sebastian/blog/images/trace-estimation-mc-2D-draws.png"&gt;&lt;/p&gt;
&lt;p&gt;Now, for comparison, the following Figure shows a draw of marginally
Normal-distributed points generated with a RQMC construction, implemented by
the following Julia code using the &lt;a href="https://github.com/stevengj/Sobol.jl"&gt;Sobol.jl
package&lt;/a&gt;.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="n"&gt;M&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;64&lt;/span&gt;
&lt;span class="n"&gt;d&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;
&lt;span class="n"&gt;points&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;zeros&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;M&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;d&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;sobolseq&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;skip&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;SobolSeq&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;d&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;max_M&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;m&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="n"&gt;max_M&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;points&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;m&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;Sobol&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;next!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sobolseq&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;span class="n"&gt;points&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;mod&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;points&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;.+&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;rand&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;d&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mf"&gt;1.0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;points&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;quantile&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Normal&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;points&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;&lt;img alt="Randomized QMC Normal draws in 2D" src="https://www.nowozin.net/sebastian/blog/images/trace-estimation-rqmc-2D-draws.png"&gt;&lt;/p&gt;
&lt;p&gt;As you can see the points are more equally spaced out.  The hope with RQMC
methods is that such more homogeneous spacing improves the rate of the Monte
Carlo average.&lt;/p&gt;
&lt;p&gt;Formally, the &lt;a href="https://hal.inria.fr/hal-01561550/document"&gt;starting point of RQMC
methods&lt;/a&gt; is to assume an
integration problem over a function &lt;span class="math"&gt;\(f: [0,1]^d \to \mathbb{R}\)&lt;/span&gt;.
Here, for the purpose of trace estimation, we can define our function as&lt;/p&gt;
&lt;div class="math"&gt;$$f(u) = (\Psi^{-1}(u))^T A \, \Psi^{-1}(u),$$&lt;/div&gt;
&lt;p&gt;where &lt;span class="math"&gt;\(\Psi^{-1}\)&lt;/span&gt; is the &lt;a href="https://en.wikipedia.org/wiki/Normal_distribution#Quantile_function"&gt;standard Normal quantile
function&lt;/a&gt;,
applied elementwise.  We have&lt;/p&gt;
&lt;div class="math"&gt;$$\int_{u \in [0,1]^d} f(u) \,\textrm{d}u = \textrm{tr}(A).$$&lt;/div&gt;
&lt;p&gt;This construction is beneficial if we can approximate the integral of &lt;span class="math"&gt;\(f\)&lt;/span&gt; over
the &lt;span class="math"&gt;\(d\)&lt;/span&gt;-dimensional unit cube effectively.  This is what randomized QMC methods
do.  The theory of most QMC results requires &lt;span class="math"&gt;\(f\)&lt;/span&gt; to satisfy bounded variation
conditions on partial derivatives ("bounded variation in the sense of Hardy and
Krause", aka BVHK), but these conditions can be difficult to verify.  Here &lt;span class="math"&gt;\(f\)&lt;/span&gt;
has unbounded derivatives and even &lt;span class="math"&gt;\(\Psi^{-1}\)&lt;/span&gt; itself is unbounded when
approaching the boundary at zero or one.  Nevertheless, we can still go ahead
and simply apply RQMC methods to assess their performance empirically.  This is
popular practice in quantitative finance and other applications of RQMC
methods, and as safety net RQMC methods typically never perform worse than
plain Monte Carlo and has also been used successfully in other applications in
machine learning, e.g. for variational inference in &lt;a href="https://ml.cs.uni-kl.de/publications/2018/qmcvi_ICML.pdf"&gt;(Buchholz et al.,
2018)&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;RQMC trace estimator.&lt;/strong&gt; The proposed trace estimator is simply the Hutchinson
construction but using a RQMC point set instead of independent samples.  Here I
use a &lt;a href="https://en.wikipedia.org/wiki/Sobol_sequence"&gt;Sobol sequence&lt;/a&gt;.&lt;/p&gt;
&lt;h1&gt;Comparison&lt;/h1&gt;
&lt;p&gt;For testing the estimators we will use a matrix extracted from a recent
diffusion model for image generation.  This model generates 32x32x3 ImageNet
images and in order to compute the training objective we need to estimate the
trace of a 3072-by-3072 matrix.  I extracted this implicit matrix by performing
3072 matrix-vector products with the canonical basis vectors.  The matrix is
quite benign, is positive-definite and has a rather smooth spectrum (see plot
below).
I assume these nice properties are present in most image diffusion models.&lt;/p&gt;
&lt;p&gt;&lt;img alt="Spectrum" src="https://www.nowozin.net/sebastian/blog/images/trace-estimation-spectrum-unet.png"&gt;&lt;/p&gt;
&lt;p&gt;I ran 500 replicates of the following experiment: draw &lt;span class="math"&gt;\(z^{(m)} \sim
\mathcal{N}_d(0,I)\)&lt;/span&gt;, &lt;span class="math"&gt;\(m=1,2,\dots,250\)&lt;/span&gt;, and pass this vector to all estimators.
I record the estimate after each value of &lt;span class="math"&gt;\(m\)&lt;/span&gt; for each replicate.  Then I
estimate the variance of the estimator, as well as its bias.  All estimators
are unbiased for all values of &lt;span class="math"&gt;\(m\)&lt;/span&gt;, as expected, so the main quantity of
interest is the variance as a function of &lt;span class="math"&gt;\(m\)&lt;/span&gt;.&lt;/p&gt;
&lt;p&gt;We can understand the variance behaviour best in a &lt;a href="https://en.wikipedia.org/wiki/Log%E2%80%93log_plot"&gt;log-log
plot&lt;/a&gt; because relationships
of the form &lt;span class="math"&gt;\(y=b x^{\alpha}\)&lt;/span&gt; become linear in the log-log plot, &lt;span class="math"&gt;\(\log y = \log
b + \alpha \log x\)&lt;/span&gt;, and if the behaviour is well modelled as a line in the
log-log plot, then the slope coefficient &lt;span class="math"&gt;\(\alpha\)&lt;/span&gt; gives us the scaling behavior
as &lt;span class="math"&gt;\(M \to \infty\)&lt;/span&gt;.  For example, simple Monte Carlo estimates have variance
behavior &lt;span class="math"&gt;\(M^{-1}\)&lt;/span&gt; so &lt;span class="math"&gt;\(\alpha = -1\)&lt;/span&gt;.  Any value smaller than &lt;span class="math"&gt;\(-1\)&lt;/span&gt; denotes an
improvement over simple Monte Carlo.  Randomized Quasi Monte Carlo methods can
achieve &lt;span class="math"&gt;\(\alpha = -2\)&lt;/span&gt; for example, &lt;a href="https://rss.onlinelibrary.wiley.com/doi/pdf/10.1111/rssb.12104"&gt;(Gerber and Chopin,
2015)&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;img alt="Variance comparison" src="https://www.nowozin.net/sebastian/blog/images/trace-estimator-unet-variance.png"&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Hutch++ estimator&lt;/strong&gt;: Unfortunately, despite solid theory in the paper, I have
not been able to observe practical improvements over even the simple Gaussian
trace estimate on my test matrix.&lt;/p&gt;
&lt;p&gt;&lt;img alt="Hutch++ estimator variance" src="https://www.nowozin.net/sebastian/blog/images/trace-estimation-hutchpp.png"&gt;&lt;/p&gt;
&lt;h1&gt;Bayesian Estimation&lt;/h1&gt;
&lt;p&gt;A classic method for approaching estimation problems is Bayesian decision
theory.  (Sidenote: I have mentioned &lt;a href="https://www.wiley.com/en-us/Decision+Theory%3A+Principles+and+Approaches-p-9780471496571"&gt;(Parmigiani and Inoue, "Decision Theory:
Principles and Approaches",
2009)&lt;/a&gt;
in my blog before, but it really is a wonderful introduction to the topic.)&lt;/p&gt;
&lt;p&gt;The key steps in the Bayesian approach are: 1. write down what you know; 2.
write down how what you know relates to what you would like to know; and 3.
make optimal decisions by optimizing expected utility.  This recipe is simple
and elegant in principle but becomes challenging quickly, as we will see
shortly for trace estimation.&lt;/p&gt;
&lt;h2&gt;Benefits and Pitfalls of Bayesian Estimation&lt;/h2&gt;
&lt;p&gt;Before we look at trace estimation, I want to give one concrete example of the
risks but also benefits of the Bayesian approach to estimation.  This is the
example of &lt;a href="http://www.nowozin.net/sebastian/blog/estimating-discrete-entropy-part-3.html"&gt;estimating the entropy of a discrete random variable discussed on
this blog
before&lt;/a&gt;.
A short summary is this: between 1993-1995 David Wolpert and David Wolf proposed a &lt;a href="http://www.santafe.edu/media/workingpapers/93-07-046.pdf"&gt;sound
Bayesian approach to the
problem&lt;/a&gt;, using a
standard &lt;a href="https://en.wikipedia.org/wiki/Dirichlet-multinomial_distribution"&gt;Dirichlet-Multinomial model&lt;/a&gt;,
which allows for efficient estimation due to
&lt;a href="https://en.wikipedia.org/wiki/Conjugate_prior"&gt;conjugacy&lt;/a&gt;.  The model appears
elegant, and has support everywhere, thus can recover the true entropy and is
asymptotically unbiased as well.&lt;/p&gt;
&lt;p&gt;However, six years later, in 2001, Ilya Nemenman and colleagues found grave
flaws in this benign looking Bayesian approach: the prior almost completely
specifies the entropy, i.e. the prior predictive is highly concentrated when
samples from the Dirichlet distribution, i.e. probability vectors, are
mapped to their entropy.  The full story is in my &lt;a href="http://www.nowozin.net/sebastian/blog/estimating-discrete-entropy-part-3.html"&gt;prior blog
article&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;It is really nice that the story does not end here: &lt;a href="http://arxiv.org/abs/physics/0108025"&gt;(Nemenman, Shafee, and
Bialek, "Entropy and inference, revisited",
2001)&lt;/a&gt; proposed to add one more
hyperprior layer to the Dirichlet-Multinomial model and chose this hyperprior
to be maximially uninformative with respect to entropy, akin to a &lt;em&gt;reference
prior&lt;/em&gt; approach, but targetted to entropy inference.  This estimator, the &lt;em&gt;NSB
estimator of entropy&lt;/em&gt; is still state-of-the-art for estimating the entropy of
discrete random variables, dominating almost all other methods in terms of RMSE
and bias in a wide variety of practical distribution types.  However, it is
computationally expensive compared to most other entropy estimates.&lt;/p&gt;
&lt;p&gt;This story is very concrete but the lessons implied are general:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Bayesian estimation relies on a suitable prior, and whether a prior is
  suitable or not also depends on the &lt;em&gt;implied prior predictive&lt;/em&gt; over the
  quantity of interest.&lt;/li&gt;
&lt;li&gt;It may be hard to construct suitable uninformative priors, and it may not be
  obvious when to call a model a success.&lt;/li&gt;
&lt;li&gt;When a suitable prior can be designed, the Bayesian approach uses &lt;em&gt;all&lt;/em&gt;
  information in the data, and can provide accurate estimates with uncertainty
  quantification.&lt;/li&gt;
&lt;li&gt;There may be a tradeoff between computational efficiency and suitability of
  the model.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;Bayesian Trace Estimation&lt;/h2&gt;
&lt;p&gt;For Bayesian trace estimation we can propose the following directed graphical model.&lt;/p&gt;
&lt;p&gt;&lt;img alt="Directed graphical model for trace estimation" src="https://www.nowozin.net/sebastian/blog/images/trace-estimation-bayes-240.png"&gt;&lt;/p&gt;
&lt;p&gt;The unknown matrix &lt;span class="math"&gt;\(A\)&lt;/span&gt; is assumed to come from a &lt;em&gt;prior&lt;/em&gt; &lt;span class="math"&gt;\(p(A)\)&lt;/span&gt; and
&lt;span class="math"&gt;\(T=\textrm{tr}(A)\)&lt;/span&gt; is the implied distribution over the trace.
&lt;span class="math"&gt;\(z^{(m)} \sim p(z)\)&lt;/span&gt; independently, for example &lt;span class="math"&gt;\(z^{(m)} \sim \mathcal{N}_d(0,I)\)&lt;/span&gt;.
We then observe &lt;span class="math"&gt;\(y^{(m)} = A z^{(m)}\)&lt;/span&gt; and are interested in
&lt;span class="math"&gt;\(p(T|(z^{(m)},y^{(m)})_{m=1,\dots,M})\)&lt;/span&gt;.&lt;/p&gt;
&lt;p&gt;To make things concrete we can assume &lt;span class="math"&gt;\(A\)&lt;/span&gt; is symmetric and model &lt;span class="math"&gt;\(A_{ij} \sim
\mathcal{N}(0,\sigma^2)\)&lt;/span&gt; for &lt;span class="math"&gt;\(i \leq j\)&lt;/span&gt;.  Thus &lt;span class="math"&gt;\(A \sim \mathcal{N}(\mu, \Sigma)\)&lt;/span&gt; with
&lt;span class="math"&gt;\(\mu = 0_n\)&lt;/span&gt; and &lt;span class="math"&gt;\(\Sigma = \sigma^2 I_n\)&lt;/span&gt;, where &lt;span class="math"&gt;\(n=d(d+1)/2\)&lt;/span&gt; are the number of
upper-triangular elements in the unknown &lt;span class="math"&gt;\(A\)&lt;/span&gt;, so we index with coordinates of
&lt;span class="math"&gt;\(A\)&lt;/span&gt;, like so &lt;span class="math"&gt;\(\mu_{(i,j)}\)&lt;/span&gt;, and &lt;span class="math"&gt;\(\Sigma_{(i,j),(k,l)}\)&lt;/span&gt;.&lt;/p&gt;
&lt;p&gt;When observing &lt;span class="math"&gt;\(y^{(m)}\)&lt;/span&gt; we know with certainty that&lt;/p&gt;
&lt;div class="math"&gt;$$y^{(m)} = A z^{(m)}$$&lt;/div&gt;
&lt;p&gt;must hold for any possible &lt;span class="math"&gt;\(A\)&lt;/span&gt;.  Thus we can remove all matrices from our prior
which violate this equality constraint.  This means we condition our
multivariate Normal belief
&lt;span class="math"&gt;\(A \sim \mathcal{N}(A; \mu, \Sigma)\)&lt;/span&gt;
on a subspace implied by the equality.  Doing so is not a standard operation on
multivariate Normals, but is possible and results in a rank-deficient
multivariate Normal.  The result is a new posterior belief
&lt;span class="math"&gt;\(A \sim \mathcal{N}(A; \mu', \Sigma')\)&lt;/span&gt;.&lt;/p&gt;
&lt;p&gt;Graphically, in 2D, this conditioning on a subspace looks as in this figure.
(The detailed equation for conditioning a multivariate Normal on a subspace are
in the appendix below.)
The black dots are samples of possible matrices from the prior, and after
conditioning on an observed subspace we retain a rank-deficient posterior,
visualized by blue samples.&lt;/p&gt;
&lt;p&gt;&lt;img alt="Conditioning 2D Normal on subspace" src="https://www.nowozin.net/sebastian/blog/images/trace-estimation-mvn-conditioning.png"&gt;&lt;/p&gt;
&lt;p&gt;Thus, for our simple choice of multivariate Normal prior on &lt;span class="math"&gt;\(A\)&lt;/span&gt; we can, for
each observed &lt;span class="math"&gt;\((z^{(m)}, y^{(m)})\)&lt;/span&gt; pair update our posterior beliefs
analytically.  (This update is relatively expensive and may preclude the
Bayesian approach entirely, see discussion below.)&lt;/p&gt;
&lt;p&gt;At any time, we can also compute the closed-form posterior over the trace
itself, as it is a sum of Normal random variables and thus &lt;a href="https://en.wikipedia.org/wiki/Variance#Sum_of_correlated_variables"&gt;Bienayme's
identity&lt;/a&gt;
applies and moreover the resulting sum is again Normal.
We have &lt;span class="math"&gt;\(T \sim \mathcal{N}(\mu_T, \sigma^2_T)\)&lt;/span&gt;, with&lt;/p&gt;
&lt;div class="math"&gt;$$\mu_{T} = \sum_{i=1}^d \mu_{ii},$$&lt;/div&gt;
&lt;div class="math"&gt;$$\sigma^2_T = \sum_{i=1}^d \Sigma_{(i,i),(i,i)} + 2 \sum_{i=1}^d \sum_{j=i+1}^d \Sigma_{(i,i),(j,j)}.$$&lt;/div&gt;
&lt;p&gt;Overall this seems a satisfactory if computationally heavy model for trace
estimation.  But we can go further with the Bayesian approach and choose
&lt;span class="math"&gt;\(z^{(m)}\)&lt;/span&gt; intelligently using &lt;em&gt;adaptive experimental design&lt;/em&gt; techniques.&lt;/p&gt;
&lt;h2&gt;Adaptive Experimental Design&lt;/h2&gt;
&lt;p&gt;&lt;em&gt;Experimental design&lt;/em&gt; refers to making intelligent choices about what to
measure in order to draw more informative inferences.
In &lt;em&gt;static&lt;/em&gt; experimental design one chooses a set of things to measure apriori,
selecting measurements that for example are on average not too strongly
correlated in order to maximize the expected information content of the
measurements.  The RQMC approach would be a simple example of a static
experimental design because the &lt;span class="math"&gt;\(z^{(m)}\)&lt;/span&gt; choices are &lt;em&gt;dependent&lt;/em&gt; for different
values of &lt;span class="math"&gt;\(m\)&lt;/span&gt;.&lt;/p&gt;
&lt;p&gt;In &lt;em&gt;adaptive&lt;/em&gt; experimental design we consider a sequential setting and thus
sequentially decide &lt;em&gt;what to measure&lt;/em&gt; based on all observations measured up
to that point.
You can think of adaptive experimental design as a simplification to the
general reinforcement learning setup: your actions (what to measure) do not
have an effect on the state of the world, and your reward is internal in terms
of what information you have gained.&lt;/p&gt;
&lt;p&gt;As a simple example, consider a paper survey setting: a static experimental
design consists of a printed questionnaire with a set of well-chosen questions.
An adaptive experimental design would only show one question to you at first
and pick the next question based on your answer to all prior questions.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Personal anecdote.&lt;/strong&gt; As a personal anecdote, I first used Bayesian
experimental design to great effect in my work with Microsoft Israel on
time-of-flight (ToF) camera technology (around 2013-2017).  A time-of-flight
camera is an active sensing system where time-modulated light is emitted into
the world and the light bounces are recorded back on a camera, whose
sensitivies are also time-modulated.  By using Bayesian experimental design
methods we were able to design the actively controllable part of the system and
halve the mean absolute range estimation error (&lt;a href="http://www.nowozin.net/sebastian/papers/adam2016bayesiantof.pdf"&gt;Section 7 in TPAMI 2016
paper&lt;/a&gt;) and to
learn to measure maximally complementary information over time (&lt;a href="http://www.nowozin.net/sebastian/papers/schober2017dynamictof.pdf"&gt;dynamic
time-of-flight CVPR 2017
paper&lt;/a&gt;).
The Bayesian ToF approach shipped in a few thousand first-gen Hololens
prototypes to developers but was replaced a year later with a different sensor
and algorithm and unfortunately the entire Microsoft Israel time-of-flight team
was let go, thus four years of hard work and my collaboration with an
outstanding team in Israel, Amit Adam in particular, came to an end.  (That is
a separate story for another day.)&lt;/p&gt;
&lt;p&gt;Later, in 2018, Cheng Zhang, Chao Ma, myself, and colleagues at Microsoft used
adaptive Bayesian experimental design in more general settings such as
questionnaire design (&lt;a href="https://arxiv.org/abs/1809.11142"&gt;ICML 2019 paper&lt;/a&gt;,
&lt;a href="https://arxiv.org/abs/1908.04537"&gt;NeurIPS 2019 paper&lt;/a&gt;) and Cheng and team
productized much of this work, now available through Azure and shipped in
successful products.&lt;/p&gt;
&lt;p&gt;For a wonderful introduction to experimental design and decision theory more
generally, I highly recommend the book &lt;a href="https://www.wiley.com/en-us/Decision+Theory%3A+Principles+and+Approaches-p-9780471496571"&gt;(Parmigiani and Inoue, "Decision
Theory: Principles and Approaches",
2009)&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;For trace estimation&lt;/strong&gt;, here is what the adaptive experimental design
model would look like, visualized as &lt;a href="https://en.wikipedia.org/wiki/Influence_diagram"&gt;influence
diagram&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;img alt="Influence diagram for adaptive trace estimation" src="https://www.nowozin.net/sebastian/blog/images/trace-estimation-bayes-adaptive-240.png"&gt;&lt;/p&gt;
&lt;p&gt;Choice nodes &lt;span class="math"&gt;\(z^{(m)}\)&lt;/span&gt; are now rectangular to indicate that they are under our
control and not independent random variables as before.
How should we choose &lt;span class="math"&gt;\(z^{(m)}\)&lt;/span&gt;?  A natural approach is to select &lt;span class="math"&gt;\(z^{(m)}\)&lt;/span&gt; as
the one that maximizes the reduction in posterior uncertainty or variance.
For this, denote all prior observations as
&lt;span class="math"&gt;\(\mathcal{D}_{&amp;lt;k} := \{(z^{(i)},y^{(i)})\}_{i &amp;lt; k}\)&lt;/span&gt;.
Then we can choose &lt;span class="math"&gt;\(z^{(m)}\)&lt;/span&gt; as&lt;/p&gt;
&lt;div class="math"&gt;$$z^{(m)} = \textrm{argmax}_{z \in \mathbb{R}^d}
    \mathbb{V}[T | \mathcal{D}_{&amp;lt;m}]
    - \mathbb{E}_{(y,A) \sim p(y|A,z) \, p(A| \mathcal{D}_{&amp;lt;m})}\left[
        \mathbb{V}[T | \mathcal{D}_{&amp;lt;m}, (z, y)]
    \right].
$$&lt;/div&gt;
&lt;p&gt;This expression looks somewhat complex but here are some interpretation aids:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;It reads "variance before minus variance after".  The "variance after", i.e.
  after additionally measuring &lt;span class="math"&gt;\((z,y)\)&lt;/span&gt; is &lt;em&gt;always&lt;/em&gt; smaller than the "variance
  before".  Hence the objective measures the &lt;em&gt;reduction&lt;/em&gt; in variance, which we
  want to maximize.&lt;/li&gt;
&lt;li&gt;The "variance after" term is also contained in an expectation over &lt;span class="math"&gt;\((y,A)\)&lt;/span&gt;.
  How come?  We do not know &lt;span class="math"&gt;\(y\)&lt;/span&gt; and &lt;span class="math"&gt;\(A\)&lt;/span&gt;, so we take an expectation over our
  best current beliefs up to that point.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The optimization problem may or may not have a closed-form solution, I did not
investigate this.  Instead, I did a simple implementation where I sample 100
points from &lt;span class="math"&gt;\(\mathcal{N}(0,I)\)&lt;/span&gt;, then pick the point that maximizes the
objective.&lt;/p&gt;
&lt;p&gt;Here is a small experiment.  The experiment is smaller than small: with &lt;span class="math"&gt;\(d=16\)&lt;/span&gt;
I sampled &lt;span class="math"&gt;\(A \sim \textrm{symmat}(\mathcal{N}_k(0,\Sigma_0)\)&lt;/span&gt;, where
&lt;span class="math"&gt;\(k=d(d+1)/2\)&lt;/span&gt; and &lt;span class="math"&gt;\(\Sigma_0\)&lt;/span&gt; is chosen such that
&lt;span class="math"&gt;\(\Sigma_{(i,i),(i,i)}=\sigma_d^2\)&lt;/span&gt; and &lt;span class="math"&gt;\(\Sigma_{(i,i),(j,j)}=\sigma_o^2\)&lt;/span&gt; for
&lt;span class="math"&gt;\(i\neq j\)&lt;/span&gt;.  I used &lt;span class="math"&gt;\(\sigma_d=200\)&lt;/span&gt; and &lt;span class="math"&gt;\(\sigma_o=5\)&lt;/span&gt;.  This prior encodes
diagonal-dominant matrices.
To give the maximal possible edge to the Bayesian model I sampled &lt;span class="math"&gt;\(A\)&lt;/span&gt; from this
prior, i.e. there is no misspecification in this experiment.
I ran 500 replicates of the trace estimation experiment, so the plots will be a
bit noisy, but here are the results.&lt;/p&gt;
&lt;p&gt;&lt;img alt="Bayesian experiment variance results" src="https://www.nowozin.net/sebastian/blog/images/trace-estimation-bayes16-var.png"&gt;&lt;/p&gt;
&lt;p&gt;The Bayes model has an order of magnitude lower variance than the next best
method (RQMC).
The Bayesian method is not unbiased, so this low variance could be due to strong influence of the prior, so let's look at the root-mean-squared-error (RMSE) as well.&lt;/p&gt;
&lt;p&gt;&lt;img alt="Bayesian experiment RMSE results" src="https://www.nowozin.net/sebastian/blog/images/trace-estimation-bayes16-rmse.png"&gt;&lt;/p&gt;
&lt;p&gt;Again both Bayes methods are doing very well.  If my implementation is correct,
this must in fact be the case, as the Bayes estimate is optimal and thus the
model achieves the Bayes risk in terms of RMSE.
But is the model biased?  The limited experiments do not allow a conclusion
except that the plot shows that the unbiased methods show up as biased due to
the estimated bias itself having an estimation error and the Bayesian models
being in that same range.&lt;/p&gt;
&lt;p&gt;&lt;img alt="Bayesian experiment mean results" src="https://www.nowozin.net/sebastian/blog/images/trace-estimation-bayes16-mean.png"&gt;&lt;/p&gt;
&lt;h2&gt;Difficulties of the Bayesian approach&lt;/h2&gt;
&lt;p&gt;Clearly, the Bayesian approach to trace estimation is not ready to be used due
to excessive runtime requirements.  It may be possible to intelligently perform
the same computation in terms of sparse updates or implicit representations of
the evolution of &lt;span class="math"&gt;\(\Sigma\)&lt;/span&gt;, and thus make the Bayesian approach relevant.&lt;/p&gt;
&lt;h1&gt;Conclusion and Future Directions&lt;/h1&gt;
&lt;p&gt;We looked at a few existing estimators of the trace of a matrix.
Here is a list of ideas for research in this area:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;em&gt;Sequential or not&lt;/em&gt;?  The estimators we have discussed can be divided into
  two classes.  In the first class we have &lt;em&gt;static&lt;/em&gt; estimators that can be
  parallelized because no computation depends on the output of prior
  computation.  In the second class we have estimators that do some clever
  &lt;em&gt;sequential&lt;/em&gt; processing (estimating control variates, estimating a low-rank
  approximation, or similar) and then benefit in a second stage.  In practice,
  for deep learning applications, we may be able to get the best of both worlds
  by amortizing computation over time: instead of treating one optimization
  step as a closed-world, we can estimate the necessary quantities over multiple
  steps, for example in the control variate or low-rank approximation case.  So
  the dichotomy between static and sequential is not as hard, which brings me
  to the following concrete idea.&lt;/li&gt;
&lt;li&gt;&lt;em&gt;Parameterized control variates&lt;/em&gt;: in ML applications we often need trace
  estimates where the matrix &lt;span class="math"&gt;\(A\)&lt;/span&gt; is a function of other quantities.  For
  example, in diffusion models the matrix &lt;span class="math"&gt;\(A\)&lt;/span&gt; may depend an input vector or
  time variable, e.g. &lt;span class="math"&gt;\(A=A(x,t)\)&lt;/span&gt;, and we do not have one trace estimation task
  but a large number of unique tasks with varying &lt;span class="math"&gt;\(x\)&lt;/span&gt; and &lt;span class="math"&gt;\(t\)&lt;/span&gt;.  This makes
  Hutchinson's estimator so popular: it is cheap in this setting, and this
  dependence on inputs seems to rule out approaches such as the control variate
  method which requires multiple samples.  However, in reinforcement learning
  control variates called &lt;em&gt;state-dependent baselines&lt;/em&gt; are commonly employed for
  variance reduction in policy gradient methods, e.g. &lt;a href="https://arxiv.org/pdf/1802.10031.pdf"&gt;(Tucker et al.,
  2018)&lt;/a&gt;.  So if our matrix has
  dependencies such as &lt;span class="math"&gt;\(A(x,t)\)&lt;/span&gt; it may be beneficial to simultaneously learn a
  cheap control variate &lt;span class="math"&gt;\(B(x,t)\)&lt;/span&gt;, perhaps as an auxiliary output of the main
  model, in order to amortize computation over learning iterations, in effect
  is a simple form of learning-to-learn more efficiently.&lt;/li&gt;
&lt;li&gt;&lt;em&gt;Bayesian trace estimation&lt;/em&gt;?  Conceptually the Bayesian approach is
  particularly attractive for trace estimation as the latent structure of the
  problem is exactly known.  In practice I have my doubts whether this approach
  will be useful in deep learning, for three reasons: 1. already the simplest
  faithful model I could come up with is computationally very expensive; 2. it
  seems challenging to find suitable priors &lt;span class="math"&gt;\(p(A)\)&lt;/span&gt; over matrices for two
  reasons, a) standard choices such as Wishart distributions are not closed
  under subspace conditioning so must be handled using even more expensive
  computational approaches, and b) trace estimation is used in a wide variety
  of domains and a generally useful yet uninformative prior seems too much to
  ask for; and 3. unbiasedness is highly desirable in most deep learning uses
  of trace estimation and Bayesian estimates are generally biased in the small
  sample setting and only asymptotically unbiased for &lt;span class="math"&gt;\(M \to \infty\)&lt;/span&gt;, whereas
  Hutchinson's estimator is unbiased for any &lt;span class="math"&gt;\(M\)&lt;/span&gt;.
  Finding a general prior for matrices that is computationally efficient under
  subspace conditioning would could be interesting.  Perhaps a good starting
  point would be the multivariate Normal distribution but then to marginalize
  most dimensions away.  This would make computation more efficient while
  retaining tractability.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;So there you have it.  Given my understanding so far, I even venture to make
some recommendations for the current estimators:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;First, use Hutchinson's estimator or the Gaussian trace estimator.  Try both
   and measure the variance.&lt;/li&gt;
&lt;li&gt;If you can afford &lt;span class="math"&gt;\(M &amp;gt; 1\)&lt;/span&gt; and &lt;span class="math"&gt;\(d &amp;lt; 21,201\)&lt;/span&gt;: give the RQMC approach a try; it
   should be simple to implement, with
   &lt;a href="https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.qmc.Sobol.html"&gt;SciPy&lt;/a&gt;,
   &lt;a href="https://www.tensorflow.org/api_docs/python/tf/math/sobol_sample"&gt;Tensorflow&lt;/a&gt;,
   and
   &lt;a href="https://pytorch.org/docs/stable/generated/torch.quasirandom.SobolEngine.html"&gt;PyTorch&lt;/a&gt;
   all supporting Sobol sequence generation.  (The restriction to &lt;span class="math"&gt;\(d &amp;lt; 21,201\)&lt;/span&gt;
   is not intrinsic to the approach but a &lt;a href="https://web.maths.unsw.edu.au/~fkuo/sobol/"&gt;practical constraint due to limited
   availability of so called direction numbers&lt;/a&gt;.)&lt;/li&gt;
&lt;li&gt;If variance of the estimates in your trace estimates are a major bottleneck
   in your application, try the diagonal control variate approach, perhaps
   learning this control variate as part of your learning objective if the
   matrix is varying with the inputs to your network.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;em&gt;Acknowledgements.&lt;/em&gt; I thank &lt;a href="https://yang-song.net/"&gt;Yang Song&lt;/a&gt; for careful
reading and feedback on the draft including a number of corrections and
pointing me to two more uses of trace estimation;
to &lt;a href="http://florianwenzel.com/"&gt;Florian Wenzel&lt;/a&gt; for corrections, references, and
improvements to the quasi Monte Carlo methods.&lt;/p&gt;
&lt;h2&gt;Appendix&lt;/h2&gt;
&lt;h3&gt;Conditioning a multivariate Normal on a subspace&lt;/h3&gt;
&lt;p&gt;First, the following result: if &lt;span class="math"&gt;\(x \sim \mathcal{N}(\mu,\Sigma)\)&lt;/span&gt;, and&lt;/p&gt;
&lt;div class="math"&gt;$$T(x) := Ax + b,$$&lt;/div&gt;
&lt;p&gt;then &lt;span class="math"&gt;\(T(x) \sim \mathcal{N}(A\mu + b, A\Sigma A^T)\)&lt;/span&gt;.
Furthermore we have joint Normality,&lt;/p&gt;
&lt;div class="math"&gt;$$\left[\begin{array}{c}x\\T(x)\end{array}\right] \sim
\mathcal{N}\left(
\left[\begin{array}{c}\mu\\ A\mu + b\end{array}\right],
\left[\begin{array}{cc}\Sigma,&amp;amp;\Sigma A^T\\ A\Sigma,&amp;amp; A\Sigma A^T\end{array}\right]
\right).$$&lt;/div&gt;
&lt;p&gt;Observing &lt;span class="math"&gt;\(y=T(x)\)&lt;/span&gt; we have &lt;span class="math"&gt;\(x | y \sim \mathcal{N}(\bar{\mu},\bar{\Sigma})\)&lt;/span&gt;, with&lt;/p&gt;
&lt;div class="math"&gt;$$\bar{\mu} = \mu + \Sigma A^T (A \Sigma A^T)^{-1} (y-(A\mu + b)),$$&lt;/div&gt;
&lt;div class="math"&gt;$$\bar{\Sigma} = \Sigma - \Sigma A^T (A \Sigma A^T)^{-1} A \Sigma.$$&lt;/div&gt;
&lt;script type="text/javascript"&gt;if (!document.getElementById('mathjaxscript_pelican_#%@#$@#')) {
    var align = "center",
        indent = "0em",
        linebreak = "false";

    if (false) {
        align = (screen.width &lt; 768) ? "left" : align;
        indent = (screen.width &lt; 768) ? "0em" : indent;
        linebreak = (screen.width &lt; 768) ? 'true' : linebreak;
    }

    var mathjaxscript = document.createElement('script');
    mathjaxscript.id = 'mathjaxscript_pelican_#%@#$@#';
    mathjaxscript.type = 'text/javascript';
    mathjaxscript.src = 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.3/latest.js?config=TeX-AMS-MML_HTMLorMML';

    var configscript = document.createElement('script');
    configscript.type = 'text/x-mathjax-config';
    configscript[(window.opera ? "innerHTML" : "text")] =
        "MathJax.Hub.Config({" +
        "    config: ['MMLorHTML.js']," +
        "    TeX: { extensions: ['AMSmath.js','AMSsymbols.js','noErrors.js','noUndefined.js'], equationNumbers: { autoNumber: 'none' } }," +
        "    jax: ['input/TeX','input/MathML','output/HTML-CSS']," +
        "    extensions: ['tex2jax.js','mml2jax.js','MathMenu.js','MathZoom.js']," +
        "    displayAlign: '"+ align +"'," +
        "    displayIndent: '"+ indent +"'," +
        "    showMathMenu: true," +
        "    messageStyle: 'normal'," +
        "    tex2jax: { " +
        "        inlineMath: [ ['\\\\(','\\\\)'] ], " +
        "        displayMath: [ ['$$','$$'] ]," +
        "        processEscapes: true," +
        "        preview: 'TeX'," +
        "    }, " +
        "    'HTML-CSS': { " +
        "        availableFonts: ['STIX', 'TeX']," +
        "        preferredFont: 'STIX'," +
        "        styles: { '.MathJax_Display, .MathJax .mo, .MathJax .mi, .MathJax .mn': {color: 'inherit ! important'} }," +
        "        linebreaks: { automatic: "+ linebreak +", width: '90% container' }," +
        "    }, " +
        "}); " +
        "if ('default' !== 'default') {" +
            "MathJax.Hub.Register.StartupHook('HTML-CSS Jax Ready',function () {" +
                "var VARIANT = MathJax.OutputJax['HTML-CSS'].FONTDATA.VARIANT;" +
                "VARIANT['normal'].fonts.unshift('MathJax_default');" +
                "VARIANT['bold'].fonts.unshift('MathJax_default-bold');" +
                "VARIANT['italic'].fonts.unshift('MathJax_default-italic');" +
                "VARIANT['-tex-mathit'].fonts.unshift('MathJax_default-italic');" +
            "});" +
            "MathJax.Hub.Register.StartupHook('SVG Jax Ready',function () {" +
                "var VARIANT = MathJax.OutputJax.SVG.FONTDATA.VARIANT;" +
                "VARIANT['normal'].fonts.unshift('MathJax_default');" +
                "VARIANT['bold'].fonts.unshift('MathJax_default-bold');" +
                "VARIANT['italic'].fonts.unshift('MathJax_default-italic');" +
                "VARIANT['-tex-mathit'].fonts.unshift('MathJax_default-italic');" +
            "});" +
        "}";

    (document.body || document.getElementsByTagName('head')[0]).appendChild(configscript);
    (document.body || document.getElementsByTagName('head')[0]).appendChild(mathjaxscript);
}
&lt;/script&gt;</content><category term="Statistics, Machine Learning"/></entry><entry><title>Longevity and Supplements</title><link href="https://www.nowozin.net/sebastian/blog/longevity-and-supplements.html" rel="alternate"/><published>2021-02-03T22:00:00+00:00</published><updated>2021-02-03T22:00:00+00:00</updated><author><name>Sebastian Nowozin</name></author><id>tag:www.nowozin.net,2021-02-03:/sebastian/blog/longevity-and-supplements.html</id><summary type="html">&lt;p&gt;&lt;em&gt;TLDR&lt;/em&gt;: in the past decade longevity has emerged as a serious research field.
There are now a number of studies that indicate that a number of safe
supplements may likely extend lifespan and health in adult humans.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Note&lt;/em&gt;: I normally blog about statistics and machine learning.  This article is
different …&lt;/p&gt;</summary><content type="html">&lt;p&gt;&lt;em&gt;TLDR&lt;/em&gt;: in the past decade longevity has emerged as a serious research field.
There are now a number of studies that indicate that a number of safe
supplements may likely extend lifespan and health in adult humans.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Note&lt;/em&gt;: I normally blog about statistics and machine learning.  This article is
different and I hope my readers will find the information interesting.&lt;/p&gt;
&lt;h1&gt;Healthy Ageing&lt;/h1&gt;
&lt;blockquote&gt;
&lt;p&gt;"I would like to live long and in good health."&lt;/p&gt;
&lt;p&gt;-- Approximately 99 percent of humans.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Modern societies enable us to live in good health.  Investment into healthcare
systems, emergency response, medical research, pharmaceutical industries, but
also elderly care facilities, gyms and sports, as well as educational policies
and taxes for products causing ill health such as alcohol and tobacco all lead
to better health outcomes and longer lives.  Even policies and politics that
lead to &lt;a href="https://towardsdatascience.com/has-global-violence-declined-a-look-at-the-data-5af708f47fba"&gt;world peace and lower violence have remarkable outcomes on
longevity&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;These efforts have been remarkably effective, and globally so:
in 1900 the &lt;a href="https://www.who.int/global_health_histories/seminars/presentation07.pdf"&gt;global average life expectancy at
birth&lt;/a&gt;
was just 31 years.
In 2020 it is 72.6 years.
The &lt;a href="https://www.macrotrends.net/countries/WLD/world/life-expectancy"&gt;average increase per year in life expectancy globally between 2000 and
2020&lt;/a&gt; has been
0.46 percent.&lt;/p&gt;
&lt;p&gt;Despite this amazing progress, the idea of systematically aiming scientific
research at directly extending lifespan or even to overcome death entirely is
recent.
Of course, the idea of living forever---to cheat death---is not new.
In fact, it appears in the &lt;a href="https://en.wikipedia.org/wiki/Epic_of_Gilgamesh"&gt;oldest surviving
story&lt;/a&gt;.
However, before the last decade most serious scientists did not consider
it possible to overcome death;
after all any empiricist can see that all humans eventually have to die.
&lt;a href="https://www.ynharari.com/"&gt;Yuval Harari&lt;/a&gt; puts this as follows:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;"Even a few years ago, very few doctors or scientists would seriously say
that they are trying to overcome old age and death. They would say no, I am
trying to overcome this particular disease, whether it's tuberculosis or
cancer or Alzheimers. Defeating disease and death, this is nonsense, this is
science fiction."&lt;/p&gt;
&lt;p&gt;--- Yuval Harari, in a &lt;a href="https://www.edge.org/conversation/yuval_noah_harari-daniel_kahneman-death-is-optional"&gt;2015 interview with Daniel Kahnemann&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Not only has the last decade changed the view of serious scientists, there are now organized efforts and serious funding.
The &lt;a href="https://www.sens.org/"&gt;SENS foundation&lt;/a&gt;, founded in 2009, has &lt;a href="https://www.sens.org/wp-content/uploads/2020/10/SRF-2020-Annual-Report-R2.pdf"&gt;limited
funding&lt;/a&gt;
but coordinates a number of research programmes and &lt;a href="https://www.sens.org/our-research/investments/"&gt;investments in longevity
startups&lt;/a&gt;.
&lt;a href="https://www.calicolabs.com/"&gt;Calico&lt;/a&gt;, founded in 2013 as part of Google, has a
mission to combat ageing and 2.5B USD investment.
&lt;a href="https://www.juvlabs.com/"&gt;Juvenescence&lt;/a&gt;, a UK-based longevity startup &lt;a href="https://www.ft.com/content/ddec6a10-c046-11e9-b350-db00d509634e"&gt;secured
100M USD investment in 2019&lt;/a&gt;.
There are many other smaller companies and institutional investors now
regularly fund these startups.
For investors it makes sense: not only is the total addressable market of
longevity products all of humanity, but it also seems that a technical solution
to death is in reach within our lifetime.
Yuval Harari again puts it better than I could:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;"People never die because the Angel of Death comes, they die because their
heart stops pumping, or because an artery is clogged, or because cancerous
cells are spreading in the liver or somewhere. These are all technical
problems, and in essence, they should have some technical solution. And this
way of thinking is now becoming very dominant in scientific circles, and also
among the ultra-rich who have come to understand that, wait a minute,
something is happening here. For the first time in history, if I'm rich
enough, maybe I don't have to die."&lt;/p&gt;
&lt;p&gt;--- Yuval Harari, in the same &lt;a href="https://www.edge.org/conversation/yuval_noah_harari-daniel_kahneman-death-is-optional"&gt;2015 interview&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;In parallel to these more visible investments and research efforts, there is
also a renewed interest in the study of ageing-related effects in existing
medication and nutritional supplements.
In the remainder of this post we will look at some of the safer supplements and
what we now know about them.&lt;/p&gt;
&lt;p&gt;But first, a disclaimer.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Disclaimer&lt;/em&gt;:
This article is not a substitute for consulting your physician about which
supplements may or may not be right for you.  I do not endorse supplement use
or any product or supplement vendor, and all descriptions here are for
scientific interest.  Also: I am not a medical doctor or physician.&lt;/p&gt;
&lt;p&gt;With the disclaimer out of the way, lets start.&lt;/p&gt;
&lt;h2&gt;Alpha-Ketoglutarate (AKG)&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Supplement name: Arginine Alpha-Ketoglutarate (AAKG)&lt;/li&gt;
&lt;li&gt;Typical supplement dosage: 2000 mg/day&lt;/li&gt;
&lt;li&gt;Typical supplement price: 0.35 USD/day&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Alpha-Ketoglutarate is naturally present in human blood plasma and is part of
the metabolic cycle.  However, naturally occuring AKG levels decrease severely
with age, with a ten-fold reduction between the age of 40 and 80 years.
As a supplement AKG has an excellent safety record and is widely and freely
available, commonly used in the bodybuilding community.
Two reviews on what is known about the effects on AKG in the human body are
&lt;a href="https://www.ncbi.nlm.nih.gov/pmc/articles/PMC4703346/"&gt;(Wu et al., Biomol Ther,
2016)&lt;/a&gt; and &lt;a href="https://downloads.hindawi.com/journals/bmri/2018/3408467.pdf"&gt;(Liu et al.,
BioMed Research International,
2018)&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;AKG was first identified as a possible longevity supplement in the &lt;a href="https://en.wikipedia.org/wiki/Nematode"&gt;nematode&lt;/a&gt;
&lt;a href="https://en.wikipedia.org/wiki/Caenorhabditis_elegans"&gt;&lt;em&gt;C.  elegans&lt;/em&gt;&lt;/a&gt; animal model,
&lt;a href="https://www.nature.com/articles/nature13264"&gt;(Chin et al., Nature 2014)&lt;/a&gt;,
&lt;a href="https://www.researchgate.net/profile/Stephen_Whelan2/publication/262340044_The_metabolite_a-ketoglutarate_extends_lifespan_by_inhibiting_ATP_synthase_and_TOR/links/54f8d6e00cf2ccffe9df5eee/The-metabolite-a-ketoglutarate-extends-lifespan-by-inhibiting-ATP-synthase-and-TOR.pdf"&gt;(free PDF)&lt;/a&gt;.
In that study the authors demonstrated a concentration-dependent improvement of lifespan,
achieving an almost 50 percent increase in lifespan and delaying age-related diseases.
Moreover, Chin et al. identified one causal mechanism for these benefits.&lt;/p&gt;
&lt;p&gt;&lt;a href="https://www.cell.com/cell-metabolism/fulltext/S1550-4131(20)30417-4"&gt;(Shahmirzadi et al., Cell, 2020)&lt;/a&gt;,
&lt;a href="https://www.biorxiv.org/content/biorxiv/early/2019/10/04/779157.full.pdf"&gt;(preprint PDF)&lt;/a&gt;
report on a study done in mice.  They demonstrate robust improvements in
lifespan and healthspan when supplementing the mouse diet with AKG, with
lifespan increased by about 10 percent (slightly more for female mice, slightly
less for male mice).
In particular, the AKG supplementation postpones the occurence of a number of
aging phenotypes such as deterioration of color in the fur and weakened grip
strength of the mice, and improvements are also present when only starting AKG
supplementation in the later half of the mouse's life.&lt;/p&gt;
&lt;p&gt;The study concludes:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;"Given its &lt;a href="https://en.wikipedia.org/wiki/Generally_recognized_as_safe"&gt;GRAS
status&lt;/a&gt; and human
safety record, our findings point to a potential safe human intervention that
may impact important elements of aging and improve quality of life in the
elderly population."&lt;/p&gt;
&lt;p&gt;--- Shahmirzadi et al., 2020&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2&gt;Glucosamine Sulphate&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Supplement name: Glucosamine Sulphate&lt;/li&gt;
&lt;li&gt;Typical supplement dosage: 1500 mg/day&lt;/li&gt;
&lt;li&gt;Typical supplement price: 0.10 USD/day&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Glucosamine is a supplement commonly used to manage joint pain as it &lt;a href="https://www.magonlinelibrary.com/doi/abs/10.12968/bjcn.2002.7.3.10214"&gt;has been
shown to be able to relieve joint
pain&lt;/a&gt;.
A recent study &lt;a href="https://www.bmj.com/content/bmj/365/bmj.l1628.full.pdf"&gt;(Ma et al., BMJ, 2019)&lt;/a&gt; 
based on large sample observational &lt;a href="https://www.ukbiobank.ac.uk/"&gt;UK Biobank&lt;/a&gt;
data showed that regular use of glucosamine supplements is associated with
lowering the risk of cardiovascular disease.
Another recent study,
&lt;a href="https://ard.bmj.com/content/79/6/829"&gt;(Li et al., Annals of the Rheumatic Diseases, 2020)&lt;/a&gt;,
also based on large sample observational &lt;a href="https://www.ukbiobank.ac.uk/"&gt;UK Biobank&lt;/a&gt; data (&lt;span class="math"&gt;\(n=495,077\)&lt;/span&gt;)
finds compelling evidence that Glucosamine may lead to overall reduced mortality.
While Li et al. do not perform a randomized controlled trial and hence such
observational data does not imply causation, they do consider confounders and
perform a detailed analysis on large sample subgroups.  They carefully note:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;"In general, with the current observational study design the possibility of
residual confounding due to imprecise measurements or unknown factors cannot
be excluded for all findings in our study, despite our careful adjustment of
all measured confounders."&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;However, the effect size in Li's study is large: assuming an absence of non-measured
confounders, the &lt;a href="https://en.wikipedia.org/wiki/Hazard_ratio"&gt;hazard ratio&lt;/a&gt; for
a nine year follow-up period for overall mortality is 0.85 with regular
glucosamine supplementation, meaning that there is a 15 percent less death
compared to the non-glucosamine supplemented group.  For cardiovascular
mortality, respiratory mortality, and digestive mortality the hazard ratio is
even stronger at 0.82, 0.73, and 0.74, respectively.
The authors conclude that&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;"regular glucosamine supplementation was associated with lower mortality due
to all causes, cancer, CVD, respiratory and digestive diseases."&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Glucosamine supplementation is considered safe by the &lt;a href="https://www.nccih.nih.gov/health/glucosamine-and-chondroitin-for-osteoarthritis"&gt;US National Center for
Complementary and Integrative
Health&lt;/a&gt;
and no side effects are known when used regularly for multiple years.&lt;/p&gt;
&lt;h2&gt;NAD+ boosters: NMN / NR&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Supplement name: Nicotinamide riboside chloride (NR)&lt;/li&gt;
&lt;li&gt;Typical supplement dosage: 300-1000mg NR (sold as "TRU NIAGEN"), taken in the morning on an empty stomach&lt;/li&gt;
&lt;li&gt;Typical supplement price: 1.80 USD/day (300mg dose)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;and&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Supplement name: Nicotinamide mononucleotide (NMN)&lt;/li&gt;
&lt;li&gt;Typical supplement dosage: 500-2000mg MNM, taken in the morning on an empty stomach&lt;/li&gt;
&lt;li&gt;Typical supplement price: 0.34 USD/day (500mg dose)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;NAD+, &lt;em&gt;nicotinamide adenine dinucleotide&lt;/em&gt;, is central to metabolism in many
organisms, including humans.  NAD+ levels decrease strongly with age,
&lt;a href="https://doi.org/10.1371/journal.pone.0042357"&gt;(Massudi et al., PLoS ONE,
2012)&lt;/a&gt;.
The reasons for this decline is not yet fully understood but is actively
researched, &lt;a href="https://www.ncbi.nlm.nih.gov/pmc/articles/PMC5088772/pdf/nihms824727.pdf"&gt;(Schultz and Sinclair, Cell Metabolism,
2017)&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;While NAD+ decreases with age, does the low NAD+ level cause aspects of ageing?
Schultz and Sinclair put this poetically,&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;"The discovery of nicotinamide adenine dinucleotide (NAD+) as a "cozymase"
factor in fermentation has its 110th anniversary this year [2016].
Of the two billion people who were alive back in 1906, only 150 people
remain.  Interestingly, NAD+ itself may be the reason for their longevity."&lt;/p&gt;
&lt;p&gt;--- Schultz and Sinclair, 2017&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;A growing line of research in the last 15 years proposes to artificially
elevate NAD+ levels to improve health in ageing individuals.  For a number of
reasons NAD+ cannot be directly used as supplement.  Instead a
number of precursors are used.  Two of these, NR and NMN, have been shown to
lead to dose-dependent increase of bioavailable NAD+ in humans, &lt;a href="https://pubmed.ncbi.nlm.nih.gov/27721479/"&gt;(Trammell et al., Nature
Communications, 2016)&lt;/a&gt;, and &lt;a href="https://www.mdpi.com/2218-273X/9/1/34/pdf"&gt;(Poddar
et al., 2019)&lt;/a&gt;.
NR is a &lt;a href="https://en.wikipedia.org/wiki/Vitamer"&gt;vitamer&lt;/a&gt; of &lt;a href="https://en.wikipedia.org/wiki/Vitamin_B3"&gt;Vitamin
B3&lt;/a&gt; and present in normal human diet.
Likewise NMN is found naturally in small amounts in some foods such as broccoli
and avocado.&lt;/p&gt;
&lt;p&gt;In an important paper, &lt;a href="https://pubmed.ncbi.nlm.nih.gov/27127236/"&gt;(Zhang et al., Science, 2016)&lt;/a&gt;,
NR supplementation has extended lifespan in mice by 10 percent.
In particular, NR supplementation has direct observable effects on markers of
ageing such as muscle function.
The authors conclude that:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;"Our findings suggest that NAD+ repletion may be revealed as an attractive
strategy for lengthening mammalian life span."&lt;/p&gt;
&lt;p&gt;--- Zhang et al., 2016&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;There is now strong causal evidence that NAD+ supplementation in the
form of NMN or NR has health and ageing benefits in mice through a broad set of
mechanisms, &lt;a href="https://www.cell.com/cell-metabolism/pdf/S1550-4131(17)30670-8.pdf"&gt;(Yoshino et al., Cell Metabolism,
2018)&lt;/a&gt;,
&lt;a href="https://www.mdpi.com/2218-273X/9/1/34/pdf"&gt;(Poddar et al., 2019)&lt;/a&gt;.
Recently NAD+ supplementation via NMN has even been shown to restore female
fertility in ageing mice, &lt;a href="https://www.sciencedirect.com/science/article/pii/S2211124720300838"&gt;(Bertoldo et al., Cell Reports,
2020)&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;For both NR and NMN there are no large scale studies in humans.  A small scale
study on NR in human adults, &lt;a href="https://www.nature.com/articles/s41467-018-03421-7.pdf"&gt;(Martens et al., Nature Communications,
2018)&lt;/a&gt; showed some
cardiovascular benefits but the small scale of the study makes conclusions difficult.&lt;/p&gt;
&lt;p&gt;The safety of NMN and NR is only partially established.  Both occur naturally
in a normal human diet but only in small amounts, much smaller than the amount
used in supplements.
NR is &lt;a href="https://en.wikipedia.org/wiki/Generally_recognized_as_safe"&gt;generally recognized as safe&lt;/a&gt;
and a randomized controlled human trial study, &lt;a href="https://www.nature.com/articles/s41598-019-46120-z"&gt;(Conze et al., Nature
scientific reports, 2019)&lt;/a&gt;,
finds no adverse effects over a duration of eight weeks.
In comparison NMN has limited safety studies, &lt;a href="https://www.jstage.jst.go.jp/article/endocrj/advpub/0/advpub_EJ19-0313/_pdf/-char/en"&gt;(Irie et al., 2019)&lt;/a&gt;.
However, for both NMN and NR there are is no long-term safety data available for humans.&lt;/p&gt;
&lt;p&gt;Overall NMN and NR supplementation are promising supplements to improve
healthspan in humans, but a definite conclusion is still open.
Definite results will likely be available within the next ten years.
In practical terms one big disadvantage at the moment is that NR is comparatively expensive.&lt;/p&gt;
&lt;h2&gt;Resveratrol&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Supplement name: Resveratrol&lt;/li&gt;
&lt;li&gt;Typical supplement dosage: 500-1000 mg/day&lt;/li&gt;
&lt;li&gt;Typical supplement price: 0.15-0.30 USD/day&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Resveratrol is a substance naturally occuring in plants in low concentrations.
In food one of the highest concentrations of resveratrol is present in red
wine, however, even the highest concentrations occuring naturally in food
(up to 15mg per liter) are well below doses used when using resveratrol as
supplement.&lt;/p&gt;
&lt;p&gt;There is a wide body of evidence that supplementation with resveratrol has
strong beneficial health effects in a wide variety of animals.
A comprehensive review article, &lt;a href="https://www.researchgate.net/profile/Andrei_Gonzales_I/post/Is_there_any_mechanism_on_the_influence_of_resveratrol_on_growth_hormone/attachment/59d623bf6cda7b8083a1e8fc/AS:347637640384512@1459894680107/download/Therapeutic_potential_of_resveratrol.pdf"&gt;(Baur and Sinclair, Nature Reviews, 2006)&lt;/a&gt;,
summarizes the state of knowledge around 2006:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;"Resveratrol, a constituent of red wine, has long been suspected to have
cardioprotective effects. Interest in this compound has been renewed in
recent years, first from its identification as a chemopreventive agent for
skin cancer, and subsequently from reports that it activates sirtuin
deacetylases and extends the lifespans of lower organisms. Despite scepticism
concerning its bioavailability, a growing body of in vivo evidence indicates
that resveratrol has protective effects in rodent models of stress and
disease."&lt;/p&gt;
&lt;p&gt;--- Baur and Sinclair, 2006&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Most importantly at that time there already was evidence of lifespan and
healthspan extension by resveratrol:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="https://en.wikipedia.org/wiki/Saccharomyces_cerevisiae"&gt;Yeast&lt;/a&gt;, 70 percent mean lifespan extension;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://en.wikipedia.org/wiki/Caenorhabditis_elegans"&gt;Nematode Caenorhabditis elegans&lt;/a&gt;, 18 percent mean lifespan extension;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://en.wikipedia.org/wiki/Drosophila_melanogaster"&gt;Fly Drosophila melanogaster&lt;/a&gt;, 29 percent mean lifespan extension;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://en.wikipedia.org/wiki/Nothobranchius_furzeri"&gt;Turquoise killifish Nothobranchius furzeri&lt;/a&gt;, 56 percent mean lifespan extension.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;While these are very different animals and the lifespan extension varies, the effect size is nevertheless remarkably strong.
In 2006, Baur and Sinclair state:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;"The question of whether enhanced SIRT1 activity and/or resveratrol treatment
will increase mammalian lifespan looms large in the ageing-research
community. (...)
It is becoming clear that resveratrol and more potent mimetics show great
promise in the treatment of the leading causes of morbidity and mortality in
the Western world. So far, little evidence suggests that these health
benefits are coupled with deleterious side effects. Even the trade off
between individual health and reproductive potential that is characteristic
of caloric restriction does not seem to occur in animals with lifespans that
have been extended by resveratrol. Could resveratrol and similar molecules
form the next class of wonder-drugs?"&lt;/p&gt;
&lt;p&gt;--- Baur and Sinclair, 2006&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;A first study on mammals in the form of mice was also published by the same authors in 2006,
&lt;a href="https://www.ncbi.nlm.nih.gov/pmc/articles/PMC4990206/pdf/nihms763280.pdf"&gt;(Baur et al., Nature, 2006)&lt;/a&gt;.
It demonstrated no lifespan extension by resveratrol supplementation but
convincingly demonstrated that mice that are fed on a high calorie diet
together with resveratrol survive as well as normally fed mice and have similar
health characteristics, whereas mice fed the same high calorie diet without
resveratrol suffers adverse health and shortened lifespan.
Interestingly the mice fed with the high calorie diet and resveratrol were
healthier but had the same body weight as the mice that only received the high
calorie diet.&lt;/p&gt;
&lt;p&gt;A result similar to the "high calorie diet" study on mice was repeated on humans:
&lt;a href="https://reader.elsevier.com/reader/sd/pii/S155041311100386X?token=95C0135D4F6407DA0AC00A235BCC833DCB1A7114862C8ECA2F918A0727248638BD6FF57A2580EAAC0E0105998477276B"&gt;(Timmers at al., Cell Metabolism, 2011)&lt;/a&gt;
report broad improvements of health markers on obese humans supplemented with resveratrol.
The authors conclude,&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;"In conclusion, we demonstrate beneficial effects of resveratrol
supplementation for 30 days on the metabolic profile in healthy obese males,
which seems to reflect effects observed during calorie restriction. Although
most of the effects that we observed were modest, they were very consistently
pointing toward beneficial metabolic adaptations. Furthermore, therewere no
effects on safety parameters, and no adverse events were reported."&lt;/p&gt;
&lt;p&gt;--- Timmers et al., 2011&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Given these promising findings on health benefits, what about lifespan
extension in mammals and humans?
A meta-analysis across studies with different species, &lt;a href="https://royalsocietypublishing.org/doi/pdf/10.1098/rsbl.2012.0316"&gt;(Hector et al., Biological Letters, 2012)&lt;/a&gt; could
confirm the life extension effect of resveratrol but found a diminished effect for higher-order species.&lt;/p&gt;
&lt;p&gt;&lt;a href="https://reader.elsevier.com/reader/sd/pii/S1550413108001824?token=303818F867739DD5EED75F7C70661273DF92847F539E8A0E4600DCBE2F219FE337AECBEF6B4F16633D9E69E2ED5FC845"&gt;(Pearson et al., Cell Metabolism,
2008)&lt;/a&gt;
perform a study on mice that demonstrates no increase in lifespan for normally
fed mice that received resveratrol supplements.  But again these mice showed a
marked improvement in health markers when compared to mice that did not receive
resveratrol:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Significantly improved bone density at age;&lt;/li&gt;
&lt;li&gt;Reduction in age-related cataracts at age;&lt;/li&gt;
&lt;li&gt;Improved balance and motor coordination at age; and&lt;/li&gt;
&lt;li&gt;Improved cardiovascular function at age.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The observed health benefits are similar to those of a low calorie diet, which
has been shown to lead to both increased healthspan as well as lifespan
extensions in mammals, &lt;a href="https://www.sciencedirect.com/science/article/abs/pii/S0278584619302702?via%3Dihub"&gt;(Pifferi and Aujard,
2019)&lt;/a&gt;.
However, here only health is improved, not lifespan.&lt;/p&gt;
&lt;p&gt;The authors conclude:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;"In conclusion, long-term resveratrol treatment of mice can mimic
transcriptional changes induced by dietary restriction and allow them to live
healthier, more vigorous lives.  In addition to improving insulin sensitivity
and increasing survival in HC mice [high calorie diet mice], we show that resveratrol improves
cardiovascular function, bone density, and motor coordination, and delays
cataracts, even in nonobese rodents.  Together, these findings confirm the
feasibility of finding an orally available DR [dietary restriction] mimetic.
Since cardiovascular disease is a major cause of age-related morbidity and mortality in humans but
not mice, it is possible that DR mimetics such as resveratrol could have a greater impact on humans.
However, resveratrol does not seem to mimic all of the salutary effects of DR [dietary restriction]
in that its introduction into the diet of normal 1-year-old mice did not
increase longevity."&lt;/p&gt;
&lt;p&gt;--- Pearson et al., 2008&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Overall, the available evidence makes it likely that humans will also enjoy
some health benefits at age when regularly using resveratrol supplementation.
Whether resveratrol supplementation also has longevity benefits in humans is an
open question.&lt;/p&gt;
&lt;p&gt;Safety: a metastudy of clinical trials of resveratrol, &lt;a href="https://nyaspubs.onlinelibrary.wiley.com/doi/epdf/10.1111/j.1749-6632.2010.05853.x"&gt;(Patel et al., Annals
of the New York Academy of Sciences,
2011)&lt;/a&gt;,
analyzed the data of 17 studies of resveratrol in humans and found no adverse
effects for typical doses up to 1g per day in humans and minor dose-dependent side
effects for doses up to 5g per day.&lt;/p&gt;
&lt;h2&gt;Multivitamin Supplementation&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Supplement name: generic multivitamin supplement&lt;/li&gt;
&lt;li&gt;Typical supplement dosage: typically 1 pill/day with dosages matching &lt;a href="https://www.fda.gov/media/99069/download"&gt;US FDA recommendations&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Typical supplement price: 0.10 USD/day&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;General multivitamin supplements are widely available and widely used.
A recent study finds that users of multivitamins often self-report better
health status than clinically present, see &lt;a href="https://bmjopen.bmj.com/content/10/11/e039119.abstract"&gt;(Paranjpe et al.,
2020)&lt;/a&gt;.
In addition the study finds that no clinical differences exist between people
using multivitamin supplements and people who do not.&lt;/p&gt;
&lt;p&gt;However, vitamin deficiency is a real thing and multivitamin supplements are
safe, cheap, and effectively guard against certain deficiencies.&lt;/p&gt;
&lt;p&gt;Take &lt;em&gt;vitamin D deficiency&lt;/em&gt; for example:
&lt;a href="https://www.sciencedirect.com/science/article/abs/pii/S0271531710002599"&gt;(Forrest and Stuhldreher, Nutrition Research, 2011)&lt;/a&gt;
report that 41.6 percent of US adults have a vitamin D deficiency (higher
depending on skin type, with a vitamin D deficiency present in 82.1 percent of
blacks, and in 69.2 percent of Hispanics).  They conclude:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;"Given that vitamin D deficiency is linked to some of the important risk
factors of leading causes of death in the United States, it is important that
health professionals are aware of this connection and offer dietary and other
intervention strategies to correct vitamin D deficiency, especially in
minority groups."&lt;/p&gt;
&lt;p&gt;--- Forrest and Stuhldreher, 2011&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Take &lt;em&gt;vitamin B deficiency&lt;/em&gt; for example:
&lt;a href="https://www.researchgate.net/profile/Gianpietro_Sechi/publication/299540197_Advances_in_clinical_determinants_and_neurological_manifestations_of_B_vitamin_deficiency_in_adults/links/5b0a90e6aca2725783e8e0a5/Advances-in-clinical-determinants-and-neurological-manifestations-of-B-vitamin-deficiency-in-adults.pdf"&gt;(Sechi et al., Nutrition Reviews, 2016)&lt;/a&gt;
summarize multiple studies of empirically observed vitamin B deficiencies in different populations.
For elderly persons (age 65 and up) vitamin B deficiency is observed at 22.9
percent for vitamin B1, 11.7 percent for vitamin B2, and 30 percent for vitamin
B9.  They also report on the potential neurological impairments that come with
vitamin B deficiencies and while they do not advocate for broad supplementation
they conclude:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;"Taken together, these findings indicate that subclinical or overt B vitamin
deficiency, with frequent involvement both of the central and peripheral
nervous system at all stages of life, is a global health concern,
especially in selected populations at risk and in certain clinical settings."&lt;/p&gt;
&lt;p&gt;--- Sechi et al., 2016&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;So overall, while you will likely not benefit from multivitamin supplementation
if you have a varied diet and an active lifestyle, it is still cheap and safe
and provides an additional guard against certain vitamin deficiencies which can
have real health consequences.&lt;/p&gt;
&lt;h2&gt;Summary&lt;/h2&gt;
&lt;p&gt;In the last 15 years scientists have identified a number of promising
supplements that yield health benefits and potentially increase lifespan.
Should we all take these supplements then?  Given the partial evidence we
always have to make an uncertain risk/benefit tradeoff, the main risks being
the known side effects and the unknown potential long-term consequences.&lt;/p&gt;
&lt;p&gt;The potential benefits of healthspan and lifespan extension are large and we are
objectively at the dawn of a revolution in our understanding of ageing and in
treating ageing.  We should not be surprised if any of the above supplements
prove their promise in human studies within the next decade.&lt;/p&gt;
&lt;h3&gt;Not included&lt;/h3&gt;
&lt;p&gt;I intentionally did not include medications and certain supplements:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;em&gt;Creatine&lt;/em&gt;: generally a beneficial supplement for muscular function. It has
  been studied for possible beneficial effects on aging, but it is too early to
  tell, see &lt;a href="https://www.ncbi.nlm.nih.gov/pmc/articles/PMC4304302/pdf/f1000research-3-5564.pdf"&gt;(Smith et al., 2015)&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;&lt;em&gt;Metformin&lt;/em&gt;: a prescription medicine used for treating diabetes.  There is
  strong causal evidence of a link of Metformin to delaying ageing in mice,
  &lt;a href="https://www.nature.com/articles/ncomms3192.pdf?origin=ppub"&gt;(Martin-Montalvo et al., Nature Comms,
  2013)&lt;/a&gt;, and
  strong evidence of a potential Metformin-related reduction of overall mortality in
  humans with effect size measured in years, &lt;a href="https://www.sciencedirect.com/science/article/pii/S1568163717301472?via%3Dihub"&gt;(Campbell et al., Ageing Research Reviews,
  2017)&lt;/a&gt;,
  and potential link to reduction of dementia, &lt;a href="https://content.iospress.com/articles/journal-of-alzheimers-disease/jad180263"&gt;(Campbell et al., Journal of
  Alzheimer's Disease,
  2018)&lt;/a&gt;.
  A recent summary of what we know about Metformin in ageing is &lt;a href="https://www.researchgate.net/profile/Oleh_Lushchak/publication/327879100_Metformin_as_geroprotector_experimental_and_clinical_evidence/links/5e07968ea6fdcc283745dbac/Metformin-as-geroprotector-experimental-and-clinical-evidence.pdf"&gt;(Piskovatska et
  al., Biogerontology, 2018)&lt;/a&gt;.
  There are three reasons why I do not include Metformin in the above list: 1.
  Metform in a prescription medicine in most of the world, not a supplement; 2. while Metformin
  overall is relatively safe and has been used for decades to treat diabetes,
  there are &lt;a href="https://bnf.nice.org.uk/drug/metformin-hydrochloride.html#sideEffects"&gt;very common and unpleasant side effects&lt;/a&gt;
  including diarrhoea, nausea, and vomiting; and 3. two large randomized controlled human
  trials evaluating Metformin specifically as a treatment for ageing are
  currently underway.&lt;/li&gt;
&lt;li&gt;&lt;a href="https://bigthink.com/health/unlucky-history-rapamycin-anti-aging/"&gt;&lt;em&gt;Rapamycin&lt;/em&gt;&lt;/a&gt;:
  a prescription medicine that is an
  &lt;a href="https://www.science.org/doi/10.1126/scitranslmed.3009892"&gt;immunomodulator&lt;/a&gt; and
  has an overwhelming evidence base of increasing longevity and to enhance
  health markers in a wide variety of animals including mammals with large effect
  sizes.  A randomized double-blind placebo-controlled study, the &lt;a href="https://clinicaltrials.gov/ct2/show/NCT04488601"&gt;PEARL
  study&lt;/a&gt;, to be completed in
  December 2023 studies the anti-ageing effects of Rapamycin in 150 humans. For
  an opinionated but well-written overview of the primary literature, see
  &lt;a href="https://www.ncbi.nlm.nih.gov/pmc/articles/PMC6814615/pdf/aging-11-102355.pdf"&gt;(Blagosklonny, Aging, 2019)&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;script type="text/javascript"&gt;if (!document.getElementById('mathjaxscript_pelican_#%@#$@#')) {
    var align = "center",
        indent = "0em",
        linebreak = "false";

    if (false) {
        align = (screen.width &lt; 768) ? "left" : align;
        indent = (screen.width &lt; 768) ? "0em" : indent;
        linebreak = (screen.width &lt; 768) ? 'true' : linebreak;
    }

    var mathjaxscript = document.createElement('script');
    mathjaxscript.id = 'mathjaxscript_pelican_#%@#$@#';
    mathjaxscript.type = 'text/javascript';
    mathjaxscript.src = 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.3/latest.js?config=TeX-AMS-MML_HTMLorMML';

    var configscript = document.createElement('script');
    configscript.type = 'text/x-mathjax-config';
    configscript[(window.opera ? "innerHTML" : "text")] =
        "MathJax.Hub.Config({" +
        "    config: ['MMLorHTML.js']," +
        "    TeX: { extensions: ['AMSmath.js','AMSsymbols.js','noErrors.js','noUndefined.js'], equationNumbers: { autoNumber: 'none' } }," +
        "    jax: ['input/TeX','input/MathML','output/HTML-CSS']," +
        "    extensions: ['tex2jax.js','mml2jax.js','MathMenu.js','MathZoom.js']," +
        "    displayAlign: '"+ align +"'," +
        "    displayIndent: '"+ indent +"'," +
        "    showMathMenu: true," +
        "    messageStyle: 'normal'," +
        "    tex2jax: { " +
        "        inlineMath: [ ['\\\\(','\\\\)'] ], " +
        "        displayMath: [ ['$$','$$'] ]," +
        "        processEscapes: true," +
        "        preview: 'TeX'," +
        "    }, " +
        "    'HTML-CSS': { " +
        "        availableFonts: ['STIX', 'TeX']," +
        "        preferredFont: 'STIX'," +
        "        styles: { '.MathJax_Display, .MathJax .mo, .MathJax .mi, .MathJax .mn': {color: 'inherit ! important'} }," +
        "        linebreaks: { automatic: "+ linebreak +", width: '90% container' }," +
        "    }, " +
        "}); " +
        "if ('default' !== 'default') {" +
            "MathJax.Hub.Register.StartupHook('HTML-CSS Jax Ready',function () {" +
                "var VARIANT = MathJax.OutputJax['HTML-CSS'].FONTDATA.VARIANT;" +
                "VARIANT['normal'].fonts.unshift('MathJax_default');" +
                "VARIANT['bold'].fonts.unshift('MathJax_default-bold');" +
                "VARIANT['italic'].fonts.unshift('MathJax_default-italic');" +
                "VARIANT['-tex-mathit'].fonts.unshift('MathJax_default-italic');" +
            "});" +
            "MathJax.Hub.Register.StartupHook('SVG Jax Ready',function () {" +
                "var VARIANT = MathJax.OutputJax.SVG.FONTDATA.VARIANT;" +
                "VARIANT['normal'].fonts.unshift('MathJax_default');" +
                "VARIANT['bold'].fonts.unshift('MathJax_default-bold');" +
                "VARIANT['italic'].fonts.unshift('MathJax_default-italic');" +
                "VARIANT['-tex-mathit'].fonts.unshift('MathJax_default-italic');" +
            "});" +
        "}";

    (document.body || document.getElementsByTagName('head')[0]).appendChild(configscript);
    (document.body || document.getElementsByTagName('head')[0]).appendChild(mathjaxscript);
}
&lt;/script&gt;</content><category term="Longevity"/></entry><entry><title>Debiasing Approximate Inference</title><link href="https://www.nowozin.net/sebastian/blog/debiasing-approximate-inference.html" rel="alternate"/><published>2018-12-05T08:30:00+00:00</published><updated>2018-12-05T08:30:00+00:00</updated><author><name>Sebastian Nowozin</name></author><id>tag:www.nowozin.net,2018-12-05:/sebastian/blog/debiasing-approximate-inference.html</id><summary type="html">&lt;p&gt;This year at &lt;a href="http://neurips.cc/"&gt;NeurIPS 2018&lt;/a&gt; the
&lt;a href="http://approximateinference.org/"&gt;Symposium on Advances in Approximate Bayesian
Inference&lt;/a&gt; discussed challenges and advances
in approximating probabilistic inference in rich models.  It was a genuinely
exciting program!&lt;/p&gt;
&lt;p&gt;I was lucky enough to give an invited talk at the event.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Title: &lt;em&gt;Debiasing Approximate Inference&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;Abstract:&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;At its heart …&lt;/p&gt;</summary><content type="html">&lt;p&gt;This year at &lt;a href="http://neurips.cc/"&gt;NeurIPS 2018&lt;/a&gt; the
&lt;a href="http://approximateinference.org/"&gt;Symposium on Advances in Approximate Bayesian
Inference&lt;/a&gt; discussed challenges and advances
in approximating probabilistic inference in rich models.  It was a genuinely
exciting program!&lt;/p&gt;
&lt;p&gt;I was lucky enough to give an invited talk at the event.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Title: &lt;em&gt;Debiasing Approximate Inference&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;Abstract:&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;At its heart, the field of approximate inference is about trade-offs between
computation and estimation accuracy: when we approximate quantities such as the
evidence or posterior expectations no randomness is left and given limitless
computation budget all quantities can be evaluated exactly.  But given finite
computation, how do we select inference methods such that they provide accurate
estimates of quantities of interest?
In this talk I will argue for a more explicit consideration of bias-variance
tradeoffs of common inference methods.  In particular, I highlight that current
inference methods such as variational inference and Markov Chain Monte Carlo
make a particular bias-variance tradeoffs which may be suboptimal for our
inferential question at hand.  What can we do about this?  There is a rich
portfolio of methods to change bias-variance tradeoffs in the form of debiasing
methods; I will provide a brief overview and demonstrate a number of recent
successful applications of these methods to variational inference and
stochastic gradient MCMC.&lt;/p&gt;
&lt;p&gt;Here are the talk slides and a voice recording (I believe the symposium
organizers plan to eventually release a video recording).&lt;/p&gt;
&lt;iframe src="https://onedrive.live.com/embed?cid=6B87C0D396848478&amp;resid=6B87C0D396848478%21302673&amp;authkey=AE32qfwl4bKRia0&amp;em=2" width="402" height="327" frameborder="0" scrolling="no"&gt;&lt;/iframe&gt;

&lt;p&gt;&lt;audio controls&gt;
&lt;source src="/sebastian/talks/aabi2018-talk-nowozin.mp3" type="audio/mpeg"/&gt;
&lt;source src="/sebastian/talks/aabi2018-talk-nowozin.ogg" type="audio/ogg"/&gt;
&lt;/audio&gt;&lt;/p&gt;</content><category term="Approximate Inference, Machine Learning"/></entry><entry><title>MLSS 2018 in Madrid</title><link href="https://www.nowozin.net/sebastian/blog/mlss-2018-in-madrid.html" rel="alternate"/><published>2018-09-02T23:00:00+01:00</published><updated>2018-09-02T23:00:00+01:00</updated><author><name>Sebastian Nowozin</name></author><id>tag:www.nowozin.net,2018-09-02:/sebastian/blog/mlss-2018-in-madrid.html</id><summary type="html">&lt;p&gt;The &lt;a href="http://mlss.cc/"&gt;&lt;em&gt;Machine Learning Summer Schools&lt;/em&gt; (MLSS)&lt;/a&gt; is the largest
and most popular machine learning summer school series.  For two weeks in
August and September the &lt;a href="http://mlss.ii.uam.es/mlss2018/index.html"&gt;MLSS 2018 is held in Madrid&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;I am happy to speak on the topics of &lt;em&gt;generative adversarial networks&lt;/em&gt; (GANs) this year.&lt;/p&gt;
&lt;p&gt;&lt;a href="https://github.com/nowozin/mlss2018-madrid-gan"&gt;My talk materials are …&lt;/a&gt;&lt;/p&gt;</summary><content type="html">&lt;p&gt;The &lt;a href="http://mlss.cc/"&gt;&lt;em&gt;Machine Learning Summer Schools&lt;/em&gt; (MLSS)&lt;/a&gt; is the largest
and most popular machine learning summer school series.  For two weeks in
August and September the &lt;a href="http://mlss.ii.uam.es/mlss2018/index.html"&gt;MLSS 2018 is held in Madrid&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;I am happy to speak on the topics of &lt;em&gt;generative adversarial networks&lt;/em&gt; (GANs) this year.&lt;/p&gt;
&lt;p&gt;&lt;a href="https://github.com/nowozin/mlss2018-madrid-gan"&gt;My talk materials are now available&lt;/a&gt;.
The total talk duration is 3 hours.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Talk, PDF version: &lt;a href="http://www.nowozin.net/sebastian/talks/mlss2018/MLSS%202018%20-%20Nowozin%20-%20GANs%20introduction.pdf"&gt;Introduction, 9MB&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Talk, PowerPoint version: &lt;a href="http://www.nowozin.net/sebastian/talks/mlss2018/MLSS%202018%20-%20Nowozin%20-%20GANs%20introduction.pptx"&gt;Introduction, (286MB), pptx&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The PowerPoint version contains animations which unfortunately are not preserved in the PDF version.
However, the PDF version is much smaller and works across all platforms.&lt;/p&gt;</content><category term="Machine Learning"/></entry><entry><title>Do Bayesians Overfit?</title><link href="https://www.nowozin.net/sebastian/blog/do-bayesians-overfit.html" rel="alternate"/><published>2018-07-11T22:30:00+01:00</published><updated>2018-07-11T22:30:00+01:00</updated><author><name>Sebastian Nowozin</name></author><id>tag:www.nowozin.net,2018-07-11:/sebastian/blog/do-bayesians-overfit.html</id><summary type="html">&lt;p&gt;&lt;em&gt;TLDR:&lt;/em&gt; Yes, and there are precise results, although they are not as well known
as they perhaps should be.&lt;/p&gt;
&lt;p&gt;Over the last few years I had many conversations in which the statement was
made that Bayesians methods are generally immune to overfitting, or at least,
robust against overfitting, or---everybody would …&lt;/p&gt;</summary><content type="html">&lt;p&gt;&lt;em&gt;TLDR:&lt;/em&gt; Yes, and there are precise results, although they are not as well known
as they perhaps should be.&lt;/p&gt;
&lt;p&gt;Over the last few years I had many conversations in which the statement was
made that Bayesians methods are generally immune to overfitting, or at least,
robust against overfitting, or---everybody would have to agree, right?---it
clearly is better than maximum aposteriori estimation.&lt;/p&gt;
&lt;p&gt;Various loose arguments in support include the built-in Bayesian version of
Occam's razor, and the principled treatment of any uncertainty throughout the estimation.
However, over the years it has always bothered me that this argument is only
made casually and for many years I was not aware of a formal proof or
discussion except for the well-known result that in case the model is
well-specified the Bayes posterior predictive is risk-optimal.&lt;/p&gt;
&lt;p&gt;Until recently!  A colleague pointed me to a book written by
&lt;a href="http://watanabe-www.math.dis.titech.ac.jp/users/swatanab/"&gt;Sumio Watanabe&lt;/a&gt;
(reference and thanks below) and this blog post is the result of the findings
in this nice book.&lt;/p&gt;
&lt;h1&gt;Overfitting&lt;/h1&gt;
&lt;p&gt;In machine learning, the concept of &lt;em&gt;overfitting&lt;/em&gt; is very important in practice.
In fact, it is perhaps the most important concept to understand when learning from data.
Many practices and methods aim squarely at measuring and preventing
overfitting.  The following are just a few examples:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;em&gt;Regularization&lt;/em&gt; limits the &lt;em&gt;capacity&lt;/em&gt; of a machine learning model in order to avoid overfitting;&lt;/li&gt;
&lt;li&gt;&lt;em&gt;Separating data into a training, validation, and test set&lt;/em&gt;, is best practice
  to assess generalization performance and to avoid overfitting;&lt;/li&gt;
&lt;li&gt;&lt;em&gt;Dropout&lt;/em&gt;, a regularization scheme for deep neural networks, is popularly
  used to mitigate overfitting.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;But what is overfitting?  Can we formally define it?&lt;/p&gt;
&lt;h2&gt;Defining Overfitting&lt;/h2&gt;
&lt;p&gt;The most widely used loose definition is the following.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Overfitting is the gap between the performance on the training set and the performance on the test set.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;This definition makes a number of assumptions:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;The data is independent and identically distributed and comes separated in a training set and a test set.&lt;/li&gt;
&lt;li&gt;There is a clearly defined performance measure.&lt;/li&gt;
&lt;li&gt;The test set is of sufficient size so that the performance estimation error is negligible.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;For example, in a classification task the performance measure may be the
classification error or the softmax-cross-entropy loss (log-loss).&lt;/p&gt;
&lt;p&gt;However, in practice this definition of overfitting can be too strict:
in many cases we care about minimizing generalization error, not about the difference between generalization error and training error.
For deep learning in particular, the training error is often zero for the model that is selected as the one minimizing validation error.
The recent paper &lt;a href="http://proceedings.mlr.press/v80/belkin18a.html"&gt;(Belkin, Ma, Mandal, "To Understand Deep Learning We Need to Understand Kernel Learning", ICML 2018)&lt;/a&gt; is studying this phenomenon.&lt;/p&gt;
&lt;p&gt;Is overfitting relevant for Bayesians as well?&lt;/p&gt;
&lt;h2&gt;The Bayesian Case&lt;/h2&gt;
&lt;p&gt;(This paragraph summarizes Bayesian prediction and contains nothing new or controversial.)&lt;/p&gt;
&lt;p&gt;Since &lt;em&gt;de Finetti&lt;/em&gt;, a subjective Bayesian measures the performance of any model
by the predicted likelihood of future observables.
Given a sample &lt;span class="math"&gt;\(D_n=(x_1, \dots, x_n)\)&lt;/span&gt;, generated from some true
data-generating distribution &lt;span class="math"&gt;\(x_i \sim Q\)&lt;/span&gt;, a Bayesian proceeds by setting up a
model &lt;span class="math"&gt;\(P(x|\theta)\)&lt;/span&gt;, where &lt;span class="math"&gt;\(\theta\)&lt;/span&gt; are unknown parameters of the model, with
prior &lt;span class="math"&gt;\(P(\theta)\)&lt;/span&gt;.
The data reveals information about &lt;span class="math"&gt;\(\theta\)&lt;/span&gt; in the form of a posterior distribution &lt;span class="math"&gt;\(P(\theta|D_n)\)&lt;/span&gt;.
The posterior distribution over parameters is then useful in constructing our best guess of what we will see next, in the form of the
&lt;em&gt;posterior predictive distribution&lt;/em&gt;,&lt;/p&gt;
&lt;div class="math"&gt;$$P(x | D_n) = \int P(x | \theta) \, P(\theta | D_n) \,\textrm{d}\theta.$$&lt;/div&gt;
&lt;p&gt;Note that in particular the only degrees of freedom are in the choice of model &lt;span class="math"&gt;\(P(x|\theta)\)&lt;/span&gt; and in the prior &lt;span class="math"&gt;\(P(\theta)\)&lt;/span&gt;.&lt;/p&gt;
&lt;p&gt;How good is &lt;span class="math"&gt;\(P(x|D_n)\)&lt;/span&gt;?
A Bayesian cares about the predicted likelihood of future observables, which
corresponds to the cross-entropy loss, and is also called the &lt;em&gt;Bayesian
generalization loss&lt;/em&gt;,&lt;/p&gt;
&lt;div class="math"&gt;$$B_g = -\mathbb{E}_{x \sim Q}[\log P(x|D_n)].$$&lt;/div&gt;
&lt;p&gt;Likewise, given our training sample &lt;span class="math"&gt;\(D_n\)&lt;/span&gt;, we can define the &lt;em&gt;Bayesian training
loss&lt;/em&gt;,&lt;/p&gt;
&lt;div class="math"&gt;$$B_t = - \frac{1}{n} \sum_{i=1}^n \log P(X_{n+1}=x_i | D_n).$$&lt;/div&gt;
&lt;p&gt;However, the concept of a "Bayesian training loss'' is unnatural to a Bayesian
because it uses the data twice: first, to construct the posterior predictive
&lt;span class="math"&gt;\(P(x|D_n)\)&lt;/span&gt;, and then a second time, to evaluate the likelihood on &lt;span class="math"&gt;\(D_n\)&lt;/span&gt;.
Nevertheless, we will see below that the concept, combined with the so called
Gibbs training loss, is a very useful one.&lt;/p&gt;
&lt;p&gt;The question of whether Bayesians overfit is then clearly stated as:&lt;/p&gt;
&lt;div class="math"&gt;$$B_t \ll B_g\,?$$&lt;/div&gt;
&lt;h1&gt;A Simple Experiment&lt;/h1&gt;
&lt;p&gt;We consider an elementary experiment of sampling data from a Normal distribution with unknown mean.
&lt;/p&gt;
&lt;div class="math"&gt;\begin{eqnarray}
\mu &amp;amp; \sim &amp;amp; \mathcal{N}(\mu_0, \sigma^2_0),\\
x_i &amp;amp; \sim &amp;amp; \mathcal{N}(\mu, \sigma^2), \qquad i=1,\dots,n.
\end{eqnarray}&lt;/div&gt;
&lt;p&gt;In this case, exact Bayesian inference is feasible because the &lt;a href="https://www.cs.ubc.ca/~murphyk/Papers/bayesGauss.pdf"&gt;posterior and
posterior-predictive distributions have a simple closed-form
solution&lt;/a&gt;, each of which is a
Normal distributions.&lt;/p&gt;
&lt;p&gt;For varying sample size &lt;span class="math"&gt;\(n\)&lt;/span&gt; we perform 2,000 replicates of generating data
according to the above sampling procedure and evaluate the Bayesian
generalization loss and the Bayesian training loss.
The following plot shows the average errors over all replicates.&lt;/p&gt;
&lt;p&gt;&lt;img alt="Bayesian overfitting on a Normal mean
experiment" src="https://www.nowozin.net/sebastian/blog/images/bayesian-bias-normal-mean.svg"&gt;&lt;/p&gt;
&lt;p&gt;Clearly &lt;span class="math"&gt;\(B_t &amp;lt; B_g\)&lt;/span&gt;, and there is overfitting.&lt;/p&gt;
&lt;p&gt;What about non-Bayesian estimators, such as MAP estimation and maximum likelihood estimation?&lt;/p&gt;
&lt;h2&gt;Maximum Aposteriori (MAP) and Maximum Likelihood (MLE)&lt;/h2&gt;
&lt;p&gt;Two popular point estimators are the maximum aposteriori estimator (MAP), defined as&lt;/p&gt;
&lt;div class="math"&gt;$$\hat{\theta}_{\textrm{map}} = \textrm{argmax}_{\theta} P(\theta | D_n),$$&lt;/div&gt;
&lt;p&gt;and the maximum likelihood estimator (MLE), defined as&lt;/p&gt;
&lt;div class="math"&gt;$$\hat{\theta}_{\textrm{mle}} = \textrm{argmax}_{\theta} \sum_{i=1}^n \log P(x_i|\theta).$$&lt;/div&gt;
&lt;p&gt;Each of these estimators also has a generalization loss and a training loss.
In our experiment the MLE estimator is dominated by the MAP estimator, which is
in turn dominated by the Bayesian estimate, which is optimal in terms of generalization loss.&lt;/p&gt;
&lt;p&gt;&lt;img alt="MAP and MLE comparison for the Normal mean experiment" src="https://www.nowozin.net/sebastian/blog/images/bayesian-bias-normal-mean-mapmle.svg"&gt;&lt;/p&gt;
&lt;p&gt;The gap between the MLE generalization error (top line, dotted) and the MAP
generalization error (black dashed line) is due to the use of the informative
prior about &lt;span class="math"&gt;\(\mu\)&lt;/span&gt;.
The gap between the Bayesian generalization error (black solid line) and the
MAP generalization error (black dashed line) is due to the Bayesian handling of
estimation uncertainty.
In this simple example the information contained in the prior is more important
than the Bayesian treatment of estimation uncertainty.&lt;/p&gt;
&lt;p&gt;Can we estimate &lt;span class="math"&gt;\(B_g\)&lt;/span&gt; except via prediction on hold-out data?&lt;/p&gt;
&lt;h1&gt;WAIC: Widely Applicable Information Criterion&lt;/h1&gt;
&lt;p&gt;It turns out that we can estimate &lt;span class="math"&gt;\(B_g\)&lt;/span&gt; to order &lt;span class="math"&gt;\(O(n^{-2})\)&lt;/span&gt; from just our training set.
This is useful because it provides us an estimate of our generalization
performance, and hence can be used for model selection and hyperparameter
optimization.&lt;/p&gt;
&lt;p&gt;The &lt;em&gt;Widely Applicable Information Criterion (WAIC)&lt;/em&gt;, invented by &lt;a href="http://watanabe-www.math.dis.titech.ac.jp/users/swatanab/"&gt;Sumio
Watanabe&lt;/a&gt;, estimates
the Bayesian generalization error,&lt;/p&gt;
&lt;div class="math"&gt;$$\textrm{WAIC} = B_t + 2(G_t - B_t),$$&lt;/div&gt;
&lt;p&gt;where &lt;span class="math"&gt;\(G_t\)&lt;/span&gt; is the &lt;em&gt;Gibbs training loss&lt;/em&gt;, defined as the average loss of individual models from the posterior,&lt;/p&gt;
&lt;div class="math"&gt;$$G_t = -\mathbb{E}_{\theta \sim P(\theta|D_n)}\left[\frac{1}{n} \sum_{i=1}^n \log P(X_{n+1} = x_i|\theta)\right].$$&lt;/div&gt;
&lt;p&gt;Due to &lt;a href="https://en.wikipedia.org/wiki/Jensen%27s_inequality"&gt;Jensen's
inequality&lt;/a&gt; we always have
&lt;span class="math"&gt;\(G_t &amp;gt; B_t\)&lt;/span&gt; so the right hand summand in &lt;span class="math"&gt;\(\textrm{WAIC}\)&lt;/span&gt; is always positive.
Importantly, given a training set we can actually evaluate &lt;span class="math"&gt;\(\textrm{WAIC}\)&lt;/span&gt;, but we cannot evaluate &lt;span class="math"&gt;\(B_g\)&lt;/span&gt;.&lt;/p&gt;
&lt;p&gt;Watanabe showed that&lt;/p&gt;
&lt;div class="math"&gt;$$\mathbb{E}[B_g] = \mathbb{E}[\textrm{WAIC}] + O(n^{-2}).$$&lt;/div&gt;
&lt;p&gt;Evaluating the previous experiment we can see that &lt;span class="math"&gt;\(\textrm{WAIC}\)&lt;/span&gt; indeed accurately estimates &lt;span class="math"&gt;\(B_g\)&lt;/span&gt;.&lt;/p&gt;
&lt;p&gt;&lt;img alt="Widely applicable information criterion (WAIC): demonstrating good agreement with Bayesian generalization error" src="https://www.nowozin.net/sebastian/blog/images/bayesian-bias-normal-mean-waic1.svg"&gt;&lt;/p&gt;
&lt;p&gt;Even better, Watanabe also showed that &lt;span class="math"&gt;\(\textrm{WAIC}\)&lt;/span&gt; continues to estimate
the Bayesian generalization error accurately in singular models and in case the
model is misspecified.
Here, &lt;em&gt;singular&lt;/em&gt; means that there is not a bijective map between model parameters and distributions.
&lt;em&gt;Misspecified&lt;/em&gt; means that no parameter exists which matches the true data-generating distribution.&lt;/p&gt;
&lt;h2&gt;WAIC with Approximate Posteriors&lt;/h2&gt;
&lt;p&gt;The above definition of &lt;span class="math"&gt;\(\textrm{WAIC}\)&lt;/span&gt; assumes an exact Bayesian posterior.
In practice we may not have the luxury of being able to compute the exact
posterior, and instead use approximate inference methods such as
&lt;a href="http://www.mcmchandbook.net/"&gt;Markov chain Monte Carlo (MCMC)&lt;/a&gt; to get sample
based approximations to the posterior,
or &lt;a href="https://arxiv.org/pdf/1711.05597.pdf"&gt;variational Bayes (VB)&lt;/a&gt; to get
approximations within a parametric family of distributions.&lt;/p&gt;
&lt;p&gt;For such approximations WAIC can degenerate considerably.
For example, consider a posterior family&lt;/p&gt;
&lt;div class="math"&gt;$$\mathcal{U}_v := \{ \mathcal{N}(\mu, C) \, | \, \mu \in \mathbb{R}^d, \, 0 \prec C \prec vI \},$$&lt;/div&gt;
&lt;p&gt;where a scalar &lt;span class="math"&gt;\(v &amp;gt; 0\)&lt;/span&gt; bounds the eigenvalues of &lt;span class="math"&gt;\(C\)&lt;/span&gt; from above.
Doing variational Bayes with &lt;span class="math"&gt;\(\mathcal{U}_{\epsilon}\)&lt;/span&gt; then corresponds to MAP
estimation and the difference &lt;span class="math"&gt;\(G_t - B_t\)&lt;/span&gt; will be close to zero, yet &lt;span class="math"&gt;\(B_t\)&lt;/span&gt; can
be very small.  In this case, applying the &lt;span class="math"&gt;\(\textrm{WAIC}\)&lt;/span&gt; equation would
suggest that &lt;span class="math"&gt;\(B_g \approx B_t\)&lt;/span&gt;, so we severely underestimate the Bayesian
generalization loss.&lt;/p&gt;
&lt;p&gt;The same holds true for MCMC: even if &lt;span class="math"&gt;\(\theta^{(1)}, \dots, \theta^{(K)}\)&lt;/span&gt; would be exact samples from
&lt;span class="math"&gt;\(P(\theta|D_n)\)&lt;/span&gt; and we approximate the exact posterior by the set of these
parameters, the estimate of &lt;span class="math"&gt;\(B_t\)&lt;/span&gt; is now too large so &lt;span class="math"&gt;\(G_t - B_t\)&lt;/span&gt; is
underestimated.&lt;/p&gt;
&lt;h1&gt;Conclusion&lt;/h1&gt;
&lt;p&gt;Clearly, Bayesians do overfit, just like any other procedure does.&lt;/p&gt;
&lt;p&gt;The following is a list of relevant literature with some comments.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.cambridge.org/core/books/algebraic-geometry-and-statistical-learning-theory/9C8FD1BDC817E2FC79117C7F41544A3A#"&gt;(Sumio Watanabe, "Algebraic Geometry and Statistical Learning Theory", Cambridge University Press, 2009)&lt;/a&gt;,
  a monograph summarizing in detail earlier results.  The results are
  particularly relevant for neural networks (which are singular models) and for Bayesian neural networks.&lt;/li&gt;
&lt;li&gt;For WAIC, see also Section 7.1 in &lt;a href="http://www.jmlr.org/papers/volume14/watanabe13a/watanabe13a.pdf"&gt;(Sumio Watanabe, "A Widely Applicable Bayesian Information Criterion", JMLR, 2013)&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;&lt;a href="http://stat.columbia.edu/~gelman/research/published/waic_understand3.pdf"&gt;(Gelman, Hwang, Vehtari, "Understanding predictive information criteria for Bayesian models", Statistics and Computing, 2013)&lt;/a&gt;
  have good things to say about WAIC when comparing multiple information
  criteria (AIC, DIC, WAIC), "&lt;em&gt;WAIC is fully Bayesian (using the posterior
  distribution rather than a point estimate), gives reasonable results in the
  examples we have considered here, and has a more-or-less explicit connection to
  cross-validation&lt;/em&gt;"&lt;/li&gt;
&lt;li&gt;The application of WAIC to select hyperparameters is studied by Watanabe in
  &lt;a href="https://arxiv.org/pdf/1503.07970.pdf"&gt;(Watanabe, "Bayesian Cross Validation and WAIC for Predictive Prior Design in Regular Asymptotic Theory", 2015)&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Can one improve on the Bayesian risk?  Yes, if the model is misspecified.  A not so well-known paper,
  &lt;a href="https://projecteuclid.org/download/pdf_1/euclid.bj/1126126768"&gt;(Fushiki, "Bootstrap prediction and Bayesian prediction under misspecified models", Bernoulli, 2005)&lt;/a&gt;
  compares the Bayesian posterior predictive generalization loss with the
  generalization loss of a so-called &lt;em&gt;Bootstrap prediction&lt;/em&gt; posterior, proving
  that the latter is more efficient asymptotically in the misspecified setting.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;em&gt;Acknowledgements&lt;/em&gt;.  I thank &lt;a href="https://www.microsoft.com/en-us/research/people/ryoto/"&gt;Ryota
Tomioka&lt;/a&gt; for exciting
discussions and for pointing me to Watanabe's book.
Thanks also to &lt;a href="https://www.inference.vc/about/"&gt;Ferenc Husz&amp;aacute;r&lt;/a&gt; and
&lt;a href="http://cbl.eng.cam.ac.uk/Public/Turner/Turner"&gt;Richard Turner&lt;/a&gt; for
feedback on a draft of the article and to
&lt;a href="https://yobibyte.github.io/"&gt;Vitaly Kurin&lt;/a&gt; and Artem for a correction.&lt;/p&gt;
&lt;script type="text/javascript"&gt;if (!document.getElementById('mathjaxscript_pelican_#%@#$@#')) {
    var align = "center",
        indent = "0em",
        linebreak = "false";

    if (false) {
        align = (screen.width &lt; 768) ? "left" : align;
        indent = (screen.width &lt; 768) ? "0em" : indent;
        linebreak = (screen.width &lt; 768) ? 'true' : linebreak;
    }

    var mathjaxscript = document.createElement('script');
    mathjaxscript.id = 'mathjaxscript_pelican_#%@#$@#';
    mathjaxscript.type = 'text/javascript';
    mathjaxscript.src = 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.3/latest.js?config=TeX-AMS-MML_HTMLorMML';

    var configscript = document.createElement('script');
    configscript.type = 'text/x-mathjax-config';
    configscript[(window.opera ? "innerHTML" : "text")] =
        "MathJax.Hub.Config({" +
        "    config: ['MMLorHTML.js']," +
        "    TeX: { extensions: ['AMSmath.js','AMSsymbols.js','noErrors.js','noUndefined.js'], equationNumbers: { autoNumber: 'none' } }," +
        "    jax: ['input/TeX','input/MathML','output/HTML-CSS']," +
        "    extensions: ['tex2jax.js','mml2jax.js','MathMenu.js','MathZoom.js']," +
        "    displayAlign: '"+ align +"'," +
        "    displayIndent: '"+ indent +"'," +
        "    showMathMenu: true," +
        "    messageStyle: 'normal'," +
        "    tex2jax: { " +
        "        inlineMath: [ ['\\\\(','\\\\)'] ], " +
        "        displayMath: [ ['$$','$$'] ]," +
        "        processEscapes: true," +
        "        preview: 'TeX'," +
        "    }, " +
        "    'HTML-CSS': { " +
        "        availableFonts: ['STIX', 'TeX']," +
        "        preferredFont: 'STIX'," +
        "        styles: { '.MathJax_Display, .MathJax .mo, .MathJax .mi, .MathJax .mn': {color: 'inherit ! important'} }," +
        "        linebreaks: { automatic: "+ linebreak +", width: '90% container' }," +
        "    }, " +
        "}); " +
        "if ('default' !== 'default') {" +
            "MathJax.Hub.Register.StartupHook('HTML-CSS Jax Ready',function () {" +
                "var VARIANT = MathJax.OutputJax['HTML-CSS'].FONTDATA.VARIANT;" +
                "VARIANT['normal'].fonts.unshift('MathJax_default');" +
                "VARIANT['bold'].fonts.unshift('MathJax_default-bold');" +
                "VARIANT['italic'].fonts.unshift('MathJax_default-italic');" +
                "VARIANT['-tex-mathit'].fonts.unshift('MathJax_default-italic');" +
            "});" +
            "MathJax.Hub.Register.StartupHook('SVG Jax Ready',function () {" +
                "var VARIANT = MathJax.OutputJax.SVG.FONTDATA.VARIANT;" +
                "VARIANT['normal'].fonts.unshift('MathJax_default');" +
                "VARIANT['bold'].fonts.unshift('MathJax_default-bold');" +
                "VARIANT['italic'].fonts.unshift('MathJax_default-italic');" +
                "VARIANT['-tex-mathit'].fonts.unshift('MathJax_default-italic');" +
            "});" +
        "}";

    (document.body || document.getElementsByTagName('head')[0]).appendChild(configscript);
    (document.body || document.getElementsByTagName('head')[0]).appendChild(mathjaxscript);
}
&lt;/script&gt;</content><category term="Statistics, Machine Learning"/></entry><entry><title>Stable GAN Models and Creative Machines</title><link href="https://www.nowozin.net/sebastian/blog/stable-gan-models-and-creative-machines.html" rel="alternate"/><published>2017-12-04T15:00:00+00:00</published><updated>2017-12-04T15:00:00+00:00</updated><author><name>Sebastian Nowozin</name></author><id>tag:www.nowozin.net,2017-12-04:/sebastian/blog/stable-gan-models-and-creative-machines.html</id><content type="html">&lt;p&gt;We just published an &lt;a href="https://www.microsoft.com/en-us/research/blog/will-machines-one-day-creative-humans/"&gt;article discussing our recent work on stabilizing generative adversarial networks&lt;/a&gt;.&lt;/p&gt;</content><category term="Machine Learning"/></entry><entry><title>NIPS 2016 Generative Adversarial Training workshop talk</title><link href="https://www.nowozin.net/sebastian/blog/nips-2016-generative-adversarial-training-workshop-talk.html" rel="alternate"/><published>2016-12-10T22:30:00+00:00</published><updated>2016-12-10T22:30:00+00:00</updated><author><name>Sebastian Nowozin</name></author><id>tag:www.nowozin.net,2016-12-10:/sebastian/blog/nips-2016-generative-adversarial-training-workshop-talk.html</id><summary type="html">&lt;p&gt;The biggest AI conference of the year has just ended:
&lt;a href="http://nips.cc/"&gt;NIPS&lt;/a&gt; in Barcelona broke all records this year and the
program was exciting as always.  It certainly remains my favorite conference
to attend.&lt;/p&gt;
&lt;p&gt;One of the best things about NIPS are the numerous high-quality workshops;
this year &lt;a href="http://lopezpaz.org/"&gt;David Lopez-Paz&lt;/a&gt;,
&lt;a href="https://twitter.com/alecrad"&gt;Alex …&lt;/a&gt;&lt;/p&gt;</summary><content type="html">&lt;p&gt;The biggest AI conference of the year has just ended:
&lt;a href="http://nips.cc/"&gt;NIPS&lt;/a&gt; in Barcelona broke all records this year and the
program was exciting as always.  It certainly remains my favorite conference
to attend.&lt;/p&gt;
&lt;p&gt;One of the best things about NIPS are the numerous high-quality workshops;
this year &lt;a href="http://lopezpaz.org/"&gt;David Lopez-Paz&lt;/a&gt;,
&lt;a href="https://twitter.com/alecrad"&gt;Alex Radford&lt;/a&gt;, and
&lt;a href="http://leon.bottou.org/"&gt;Léon Bottou&lt;/a&gt; put together a workshop on
&lt;a href="https://sites.google.com/site/nips2016adversarial/"&gt;Adversarial Training&lt;/a&gt;,
with most of the content related to &lt;em&gt;generative adversarial networks&lt;/em&gt; (GAN).&lt;/p&gt;
&lt;p&gt;If you have not heard of GANs before, &lt;a href="http://www.iangoodfellow.com/"&gt;Ian
Goodfellow&lt;/a&gt; gave a detailed &lt;a href="https://nips.cc/Conferences/2016/Schedule?showEvent=6202"&gt;tutorial on
GANs&lt;/a&gt;, &lt;a href="http://www.iangoodfellow.com/slides/2016-12-04-NIPS.pdf"&gt;slides
here&lt;/a&gt;, earlier in the
week and certainly GANs were the hot topic of this years NIPS.&lt;/p&gt;
&lt;h2&gt;&lt;span class="math"&gt;\(f\)&lt;/span&gt;-GAN Talk Slides&lt;/h2&gt;
&lt;p&gt;I gave an invited talk at the GAN workshop on the NIPS 2016 paper on
&lt;a href="http://www.nowozin.net/sebastian/papers/nowozin2016fgan.pdf"&gt;f-GAN&lt;/a&gt;, authored
by &lt;a href="https://www.microsoft.com/en-us/research/people/ryoto/"&gt;Ryota Tomioka&lt;/a&gt;,
Botond Cseke, and myself.&lt;/p&gt;
&lt;p&gt;Here is the slide deck I used during the talk.&lt;/p&gt;
&lt;p&gt;&lt;iframe
src="https://onedrive.live.com/embed?cid=6B87C0D396848478&amp;resid=6B87C0D396848478%21282256&amp;authkey=AMnj1btWAs8J-aU&amp;em=2"
width="402" height="327" frameborder="0" scrolling="no"&gt;&lt;/iframe&gt;
&lt;/p&gt;
&lt;p&gt;Please let me know your feedback.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Acknowledgments.&lt;/em&gt;  This is joint work with Ryota Tomioka and Botond Cseke.&lt;/p&gt;
&lt;script type="text/javascript"&gt;if (!document.getElementById('mathjaxscript_pelican_#%@#$@#')) {
    var align = "center",
        indent = "0em",
        linebreak = "false";

    if (false) {
        align = (screen.width &lt; 768) ? "left" : align;
        indent = (screen.width &lt; 768) ? "0em" : indent;
        linebreak = (screen.width &lt; 768) ? 'true' : linebreak;
    }

    var mathjaxscript = document.createElement('script');
    mathjaxscript.id = 'mathjaxscript_pelican_#%@#$@#';
    mathjaxscript.type = 'text/javascript';
    mathjaxscript.src = 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.3/latest.js?config=TeX-AMS-MML_HTMLorMML';

    var configscript = document.createElement('script');
    configscript.type = 'text/x-mathjax-config';
    configscript[(window.opera ? "innerHTML" : "text")] =
        "MathJax.Hub.Config({" +
        "    config: ['MMLorHTML.js']," +
        "    TeX: { extensions: ['AMSmath.js','AMSsymbols.js','noErrors.js','noUndefined.js'], equationNumbers: { autoNumber: 'none' } }," +
        "    jax: ['input/TeX','input/MathML','output/HTML-CSS']," +
        "    extensions: ['tex2jax.js','mml2jax.js','MathMenu.js','MathZoom.js']," +
        "    displayAlign: '"+ align +"'," +
        "    displayIndent: '"+ indent +"'," +
        "    showMathMenu: true," +
        "    messageStyle: 'normal'," +
        "    tex2jax: { " +
        "        inlineMath: [ ['\\\\(','\\\\)'] ], " +
        "        displayMath: [ ['$$','$$'] ]," +
        "        processEscapes: true," +
        "        preview: 'TeX'," +
        "    }, " +
        "    'HTML-CSS': { " +
        "        availableFonts: ['STIX', 'TeX']," +
        "        preferredFont: 'STIX'," +
        "        styles: { '.MathJax_Display, .MathJax .mo, .MathJax .mi, .MathJax .mn': {color: 'inherit ! important'} }," +
        "        linebreaks: { automatic: "+ linebreak +", width: '90% container' }," +
        "    }, " +
        "}); " +
        "if ('default' !== 'default') {" +
            "MathJax.Hub.Register.StartupHook('HTML-CSS Jax Ready',function () {" +
                "var VARIANT = MathJax.OutputJax['HTML-CSS'].FONTDATA.VARIANT;" +
                "VARIANT['normal'].fonts.unshift('MathJax_default');" +
                "VARIANT['bold'].fonts.unshift('MathJax_default-bold');" +
                "VARIANT['italic'].fonts.unshift('MathJax_default-italic');" +
                "VARIANT['-tex-mathit'].fonts.unshift('MathJax_default-italic');" +
            "});" +
            "MathJax.Hub.Register.StartupHook('SVG Jax Ready',function () {" +
                "var VARIANT = MathJax.OutputJax.SVG.FONTDATA.VARIANT;" +
                "VARIANT['normal'].fonts.unshift('MathJax_default');" +
                "VARIANT['bold'].fonts.unshift('MathJax_default-bold');" +
                "VARIANT['italic'].fonts.unshift('MathJax_default-italic');" +
                "VARIANT['-tex-mathit'].fonts.unshift('MathJax_default-italic');" +
            "});" +
        "}";

    (document.body || document.getElementsByTagName('head')[0]).appendChild(configscript);
    (document.body || document.getElementsByTagName('head')[0]).appendChild(mathjaxscript);
}
&lt;/script&gt;</content><category term="Machine Learning"/></entry><entry><title>Book Review: Computer Age Statistical Inference</title><link href="https://www.nowozin.net/sebastian/blog/book-review-computer-age-statistical-inference.html" rel="alternate"/><published>2016-11-23T21:00:00+00:00</published><updated>2016-11-23T21:00:00+00:00</updated><author><name>Sebastian Nowozin</name></author><id>tag:www.nowozin.net,2016-11-23:/sebastian/blog/book-review-computer-age-statistical-inference.html</id><summary type="html">&lt;p&gt;&lt;img alt="Book cover: Computer Age Statistical
Inference" src="https://www.nowozin.net/sebastian/blog/images/computer-age-statistical-inference.jpg"&gt;&lt;/p&gt;
&lt;p&gt;A new book, &lt;a href="http://www.cambridge.org/us/academic/subjects/statistics-probability/statistical-theory-and-methods/computer-age-statistical-inference-algorithms-evidence-and-data-science"&gt;Computer Age Statistical Inference: Algorithms, Evidence, and Data
Science&lt;/a&gt; by
&lt;a href="http://statweb.stanford.edu/~ckirby/brad/"&gt;Bradley Efron&lt;/a&gt; and
&lt;a href="http://web.stanford.edu/~hastie/"&gt;Trevor Hastie&lt;/a&gt;, was released in July this
year.  I finished reading it a few weeks ago and this is a short review from
the point of view of a machine learning researcher.&lt;/p&gt;
&lt;p&gt;Living in …&lt;/p&gt;</summary><content type="html">&lt;p&gt;&lt;img alt="Book cover: Computer Age Statistical
Inference" src="https://www.nowozin.net/sebastian/blog/images/computer-age-statistical-inference.jpg"&gt;&lt;/p&gt;
&lt;p&gt;A new book, &lt;a href="http://www.cambridge.org/us/academic/subjects/statistics-probability/statistical-theory-and-methods/computer-age-statistical-inference-algorithms-evidence-and-data-science"&gt;Computer Age Statistical Inference: Algorithms, Evidence, and Data
Science&lt;/a&gt; by
&lt;a href="http://statweb.stanford.edu/~ckirby/brad/"&gt;Bradley Efron&lt;/a&gt; and
&lt;a href="http://web.stanford.edu/~hastie/"&gt;Trevor Hastie&lt;/a&gt;, was released in July this
year.  I finished reading it a few weeks ago and this is a short review from
the point of view of a machine learning researcher.&lt;/p&gt;
&lt;p&gt;Living in Cambridge I indulge myself every once in a while by taking a break
at the &lt;a href="http://www.cambridge.org/about-us/visit-bookshop/history-bookshop"&gt;Cambridge University Press
bookstore&lt;/a&gt;
at the market square, located just opposite of King's College it is the oldest
book shop in England.
Besides having an excellent collection of mathematics and computer science
books, at the entrance of the shop they showcase new releases from Cambridge
University Press.
Most of these new books fall outside my interest, but what a pleasure it was
to discover a new bold book on the broad theme of statistics in the modern
age, written by two experts in the field!
I took a look at the table of contents and a minute later purchased the book.&lt;/p&gt;
&lt;h1&gt;Review&lt;/h1&gt;
&lt;p&gt;The book examines statistics broadly through three lenses.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;First&lt;/em&gt;, it tells the history of the field of statistics, often with
interesting remarks about the prevalent views at the time a method was
invented.
&lt;em&gt;Second&lt;/em&gt;, correlated with the chronological order, the authors classify
methods by their use of computation.  Classic methods use few to none
computation but often leverage asymptotic arguments.  Newer methods
are increasingly realistic in their assumptions but rely on heavy use of
machine computation.
&lt;em&gt;Third&lt;/em&gt;, the flavour of the presented methods is interpreted as &lt;em&gt;Fisherian&lt;/em&gt;,
&lt;em&gt;frequentist&lt;/em&gt;, or &lt;em&gt;Bayesian&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;The terminology in the book is easily accessible to a person with basic
statistics training, perhaps with the exception of the word "&lt;em&gt;Inference&lt;/em&gt;" in
the title.
In the book the authors use "inference" to describe the means by which
legitimacy of statistical results can be established.
This sense is different from the common use of the word in the machine
learning community, where it would usually refer in a broad sense to "perform
computation of consequences given a model and observations".&lt;/p&gt;
&lt;p&gt;From a machine learner's perspective the most interesting parts of the book
are the wide applicability of the empirical Bayes methodology, which is
demonstrated in a number of generally relevant applications including
&lt;em&gt;large-scale testing&lt;/em&gt; and &lt;em&gt;deconvolution&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;Another benefit for someone with a machine learning background is the modern
view on classic methods such as resampling methods (bootstrap and jackknife),
a readable motivation for topics and applications which are popular in
statistics but not popular in machine learning (survival analysis, large-scale
testing, confidence intervals, etc.), and the historical remarks and
subjective commentary on developments in the field.&lt;/p&gt;
&lt;p&gt;The subjective commentary in the &lt;em&gt;Epilogue&lt;/em&gt; makes predictions about the field
of statistics and data science as a whole, with the main trends being a
branching out into applications and an increased reliance on computation.&lt;/p&gt;
&lt;h2&gt;Criticism&lt;/h2&gt;
&lt;p&gt;The book is a wonderful book and many readers will enjoy reading it, as I did.
There are only two minor points where I feel the book could be improved.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;First&lt;/em&gt;, while the authors readily acknowledge that many topics could have
been added to the book, I feel that certain topics should have been included
due to their broad applicability and heavy use of computation in many
successful models:
variational Bayesian inference, approximate Bayesian computation (ABC),
kernel methods more generally, and Bayesian nonparametrics.
Perhaps variational inference and kernel methods have not reached the core
statistics community yet, but ABC and Bayesian nonparametrics originate with
them and are only possible because of the massive computation available today.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Second&lt;/em&gt;, in the description of solutions to statistical problems throughout
the book there is a strong emphasis on empirical Bayes and the bootstrap.&lt;/p&gt;
&lt;h1&gt;Summary&lt;/h1&gt;
&lt;p&gt;If you enjoy statistics, computation, or machine learning, get the book!
The breadth of topics and the independence between the chapters will make it
easy for you to find something interesting.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Acknowledgements.&lt;/em&gt;  Thanks to Diana Gillooly for corrections.&lt;/p&gt;</content><category term="Machine Learning, Statistics, Book Review"/></entry><entry><title>Streaming Log-sum-exp Computation</title><link href="https://www.nowozin.net/sebastian/blog/streaming-log-sum-exp-computation.html" rel="alternate"/><published>2016-05-08T21:30:00+01:00</published><updated>2016-05-08T21:30:00+01:00</updated><author><name>Sebastian Nowozin</name></author><id>tag:www.nowozin.net,2016-05-08:/sebastian/blog/streaming-log-sum-exp-computation.html</id><summary type="html">&lt;p&gt;A common numerical operation in statistical computing is to compute&lt;/p&gt;
&lt;div class="math"&gt;$$\log \sum_{i=1}^n \exp x_i,$$&lt;/div&gt;
&lt;p&gt;where &lt;span class="math"&gt;\(x_i \in \mathbb{R}\)&lt;/span&gt;, and &lt;span class="math"&gt;\(n\)&lt;/span&gt; is potentially very large.&lt;/p&gt;
&lt;p&gt;We can implement the above computation by exponentiating each number, then
summing them, then taking a logarithm as follows (written in
&lt;a href="http://julialang.org/"&gt;Julia …&lt;/a&gt;&lt;/p&gt;</summary><content type="html">&lt;p&gt;A common numerical operation in statistical computing is to compute&lt;/p&gt;
&lt;div class="math"&gt;$$\log \sum_{i=1}^n \exp x_i,$$&lt;/div&gt;
&lt;p&gt;where &lt;span class="math"&gt;\(x_i \in \mathbb{R}\)&lt;/span&gt;, and &lt;span class="math"&gt;\(n\)&lt;/span&gt; is potentially very large.&lt;/p&gt;
&lt;p&gt;We can implement the above computation by exponentiating each number, then
summing them, then taking a logarithm as follows (written in
&lt;a href="http://julialang.org/"&gt;Julia&lt;/a&gt;).&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="n"&gt;logsumexp_naive&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;X&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;exp&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;X&lt;/span&gt;&lt;span class="p"&gt;)))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;When the above function returns a finite number then it is numerically
accurate.  However, the above computation is not robust if one of the elements is very large (say, larger than 710 for double precision IEEE floating point).
Then &lt;span class="math"&gt;\(\exp(x_i)\)&lt;/span&gt; returns a floating point infinity and the entire computation
returns a floating point infinity as well.&lt;/p&gt;
&lt;h2&gt;Standard Batch Solution&lt;/h2&gt;
&lt;p&gt;The standard solution to this problem is to use the mathematical identity&lt;/p&gt;
&lt;div class="math"&gt;$$\log \sum_{i=1}^n \exp x_i = \alpha + \log \sum_{i=1}^n \exp (x_i - \alpha),$$&lt;/div&gt;
&lt;p&gt;which holds for any &lt;span class="math"&gt;\(\alpha \in \mathbb{R}\)&lt;/span&gt;.
By selecting &lt;span class="math"&gt;\(\alpha = \max_{i=1,\dots,n} x_i\)&lt;/span&gt; no argument to the
&lt;span class="math"&gt;\(\exp\)&lt;/span&gt;-function will be larger than zero and the above naive computation can
be applied on the transformed numbers.
The code is as follows.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="k"&gt;function&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;logsumexp_batch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;X&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;alpha&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;maximum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;X&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="c"&gt;# Find maximum value in X&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;exp&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;X&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;alpha&lt;/span&gt;&lt;span class="p"&gt;)))&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;alpha&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Code such as the above is used in almost all packages for performing
statistical computation and is described as the standard solution, see e.g.
&lt;a href="https://hips.seas.harvard.edu/blog/2013/01/09/computing-log-sum-exp/"&gt;here&lt;/a&gt;
and &lt;a href="https://en.wikipedia.org/wiki/LogSumExp"&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;However, there are the following problems:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;It requires two scans over the data array, one to find the maximum, one to
   compute the summation.  For modern systems and large input arrays the above
   computation is memory-bandwidth limited so two memory scans mean twice the
   runtime.&lt;/li&gt;
&lt;li&gt;It requires knowledge of the number of elements in the sum prior to
   computation.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;Streaming log-sum-exp Computation&lt;/h2&gt;
&lt;p&gt;The solution is to also compute the maximum element in a streaming manner and
to correct a running estimate whenever a new maximum is found.
I have not seen this solution elsewhere, but I hope you may find it useful.&lt;/p&gt;
&lt;p&gt;First, here is the code.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="k"&gt;function&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;logsumexp_stream&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;X&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;alpha&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nb"&gt;Inf&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mf"&gt;0.0&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;X&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;&amp;lt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;alpha&lt;/span&gt;
&lt;span class="w"&gt;            &lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;+=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;exp&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;alpha&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="k"&gt;else&lt;/span&gt;
&lt;span class="w"&gt;            &lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;*=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;exp&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;alpha&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="w"&gt;            &lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;+=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mf"&gt;1.0&lt;/span&gt;
&lt;span class="w"&gt;            &lt;/span&gt;&lt;span class="n"&gt;alpha&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="k"&gt;end&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="k"&gt;end&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;alpha&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;As you can see by glancing over the code, only one linear access over the
input is required and we do not need to know the number of elements.&lt;/p&gt;
&lt;p&gt;To understand how the code works, assume we maintain two quantities.
The first is the largest value seen after &lt;span class="math"&gt;\(i\)&lt;/span&gt; elements,&lt;/p&gt;
&lt;div class="math"&gt;$$\alpha_i := \max_{j = 1,\dots,i} x_i.$$&lt;/div&gt;
&lt;p&gt;The second is the accumulated sum so far with the current maximum subtracted,&lt;/p&gt;
&lt;div class="math"&gt;$$r_i := \sum_{j=1}^i \exp(x_j - \alpha_i).$$&lt;/div&gt;
&lt;p&gt;Now when we visit a new element &lt;span class="math"&gt;\(x_{i+1}\)&lt;/span&gt; there are two cases that can happen.
If &lt;span class="math"&gt;\(x_{i+1} \leq \alpha_i\)&lt;/span&gt; then &lt;span class="math"&gt;\(\alpha_{i+1} = \alpha_i\)&lt;/span&gt; and we simply update&lt;/p&gt;
&lt;div class="math"&gt;$$r_{i+1} = r_i + \exp(x_{i+1} - \alpha_{i+1}).$$&lt;/div&gt;
&lt;p&gt;However, if we see a new largest element, we can write &lt;span class="math"&gt;\(r_i\)&lt;/span&gt; as&lt;/p&gt;
&lt;div class="math"&gt;$$r_i := \sum_{j=1}^i \exp(x_j - \alpha_i) = \exp(-\alpha_i) \sum_{j=1}^i \exp(x_j).$$&lt;/div&gt;
&lt;p&gt;We correct this estimate in order to use the new maximum &lt;span class="math"&gt;\(x_{i+1}\)&lt;/span&gt; and
cancelling the old maximum &lt;span class="math"&gt;\(\alpha_i\)&lt;/span&gt;,&lt;/p&gt;
&lt;div class="math"&gt;$$r'_{i+1} = \exp(\alpha_i - x_{i+1}) \, r_i.$$&lt;/div&gt;
&lt;p&gt;The factor is always smaller than one.
Then we proceed to accumulate as normal to obtain&lt;/p&gt;
&lt;div class="math"&gt;$$r_{i+1} = r'_{i+1} + \exp(x_{i+1} - \alpha_{i+1}) = r'_{i+1} + 1.$$&lt;/div&gt;
&lt;p&gt;The above code is as numerically robust as the commonly used batch version and
for large arrays can be twice as fast.&lt;/p&gt;
&lt;h2&gt;Example&lt;/h2&gt;
&lt;p&gt;Running&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;10_000_000&lt;/span&gt;
&lt;span class="n"&gt;X&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mf"&gt;500.0&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;randn&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;logsumexp_naive&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;X&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;logsumexp_batch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;X&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;logsumexp_stream&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;X&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;gives the following output&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;Inf&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mf"&gt;2686.7659554831052&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mf"&gt;2686.7659554831052&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;script type="text/javascript"&gt;if (!document.getElementById('mathjaxscript_pelican_#%@#$@#')) {
    var align = "center",
        indent = "0em",
        linebreak = "false";

    if (false) {
        align = (screen.width &lt; 768) ? "left" : align;
        indent = (screen.width &lt; 768) ? "0em" : indent;
        linebreak = (screen.width &lt; 768) ? 'true' : linebreak;
    }

    var mathjaxscript = document.createElement('script');
    mathjaxscript.id = 'mathjaxscript_pelican_#%@#$@#';
    mathjaxscript.type = 'text/javascript';
    mathjaxscript.src = 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.3/latest.js?config=TeX-AMS-MML_HTMLorMML';

    var configscript = document.createElement('script');
    configscript.type = 'text/x-mathjax-config';
    configscript[(window.opera ? "innerHTML" : "text")] =
        "MathJax.Hub.Config({" +
        "    config: ['MMLorHTML.js']," +
        "    TeX: { extensions: ['AMSmath.js','AMSsymbols.js','noErrors.js','noUndefined.js'], equationNumbers: { autoNumber: 'none' } }," +
        "    jax: ['input/TeX','input/MathML','output/HTML-CSS']," +
        "    extensions: ['tex2jax.js','mml2jax.js','MathMenu.js','MathZoom.js']," +
        "    displayAlign: '"+ align +"'," +
        "    displayIndent: '"+ indent +"'," +
        "    showMathMenu: true," +
        "    messageStyle: 'normal'," +
        "    tex2jax: { " +
        "        inlineMath: [ ['\\\\(','\\\\)'] ], " +
        "        displayMath: [ ['$$','$$'] ]," +
        "        processEscapes: true," +
        "        preview: 'TeX'," +
        "    }, " +
        "    'HTML-CSS': { " +
        "        availableFonts: ['STIX', 'TeX']," +
        "        preferredFont: 'STIX'," +
        "        styles: { '.MathJax_Display, .MathJax .mo, .MathJax .mi, .MathJax .mn': {color: 'inherit ! important'} }," +
        "        linebreaks: { automatic: "+ linebreak +", width: '90% container' }," +
        "    }, " +
        "}); " +
        "if ('default' !== 'default') {" +
            "MathJax.Hub.Register.StartupHook('HTML-CSS Jax Ready',function () {" +
                "var VARIANT = MathJax.OutputJax['HTML-CSS'].FONTDATA.VARIANT;" +
                "VARIANT['normal'].fonts.unshift('MathJax_default');" +
                "VARIANT['bold'].fonts.unshift('MathJax_default-bold');" +
                "VARIANT['italic'].fonts.unshift('MathJax_default-italic');" +
                "VARIANT['-tex-mathit'].fonts.unshift('MathJax_default-italic');" +
            "});" +
            "MathJax.Hub.Register.StartupHook('SVG Jax Ready',function () {" +
                "var VARIANT = MathJax.OutputJax.SVG.FONTDATA.VARIANT;" +
                "VARIANT['normal'].fonts.unshift('MathJax_default');" +
                "VARIANT['bold'].fonts.unshift('MathJax_default-bold');" +
                "VARIANT['italic'].fonts.unshift('MathJax_default-italic');" +
                "VARIANT['-tex-mathit'].fonts.unshift('MathJax_default-italic');" +
            "});" +
        "}";

    (document.body || document.getElementsByTagName('head')[0]).appendChild(configscript);
    (document.body || document.getElementsByTagName('head')[0]).appendChild(mathjaxscript);
}
&lt;/script&gt;</content><category term="Algorithms"/></entry><entry><title>Where will Artificial Intelligence come from?</title><link href="https://www.nowozin.net/sebastian/blog/where-will-artificial-intelligence-come-from.html" rel="alternate"/><published>2016-04-20T23:30:00+01:00</published><updated>2016-04-20T23:30:00+01:00</updated><author><name>Sebastian Nowozin</name></author><id>tag:www.nowozin.net,2016-04-20:/sebastian/blog/where-will-artificial-intelligence-come-from.html</id><summary type="html">&lt;p&gt;Artificial Intelligence (AI) is making progress in great strides, or at least
it appears so!
Almost no week passes by without some major announcements of new challenges
solved by AI technology or new products powered by AI.&lt;/p&gt;
&lt;p&gt;Indeed many quantifiable factors attest an unprecedented level of activity:
capital investments, number …&lt;/p&gt;</summary><content type="html">&lt;p&gt;Artificial Intelligence (AI) is making progress in great strides, or at least
it appears so!
Almost no week passes by without some major announcements of new challenges
solved by AI technology or new products powered by AI.&lt;/p&gt;
&lt;p&gt;Indeed many quantifiable factors attest an unprecedented level of activity:
capital investments, number of academic papers, number of products involving AI technology, they all are on a steep rise in the past five years.&lt;/p&gt;
&lt;p&gt;Computers are already very capable at some specialized tasks that require
reasoning and other abilities that we typically associate with intelligence.
For example, computers can play a decent game of chess or can help us order
our holiday photos.
Despite this genuine progress, we are still a long way from human level
intelligence because our best artificial intelligence systems are not
&lt;em&gt;general&lt;/em&gt; purpose.
They cannot quickly adapt to novel tasks the way most humans can do.&lt;/p&gt;
&lt;p&gt;When talking about artificial intelligent systems there is a risk of
emphasizing humans too much.  Computers are &lt;em&gt;already&lt;/em&gt; more capable than any
human at many tasks, for example in numerical computation and search.
Yet, in discussions about artificial intelligence we emphasize the shrinking
set of abilities where humans still outperform machines.
For a nice and more balanced recent discussion on issues surrounding
artificial intelligence I recommend reading the &lt;a href="http://edge.org/responses/q2015"&gt;edge
contributions towards the Edge 2015
question&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;As artificial intelligence continues to make progress, I would like to ask the
following question:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Where will the next major advance towards general purpose artificial
intelligence come from?&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Below I list seven possible areas which I believe could be the answer to this
question; these answers are highly subjective and biased and they may be all
wrong, but hopefully they do contain some interesting pointers for everyone.&lt;/p&gt;
&lt;p&gt;The point of this exercise is to show that there are many strands of active
research that could result in major AI advances.
So here are they, the seven areas where a major general purpose AI
breakthrough could come from.&lt;/p&gt;
&lt;h1&gt;1. Composable Differentiable Architectures (aka Deep Learning)&lt;/h1&gt;
&lt;p&gt;&lt;em&gt;Composable differentiable architectures&lt;/em&gt; describes current state-of-the-art
deep learning systems.
Frameworks such as
&lt;a href="http://caffe.berkeleyvision.org/"&gt;Caffe&lt;/a&gt;,
&lt;a href="http://deeplearning.net/software/theano/"&gt;Theano&lt;/a&gt;,
&lt;a href="http://torch.ch/"&gt;Torch&lt;/a&gt;,
&lt;a href="http://chainer.org/"&gt;Chainer&lt;/a&gt;, all allow the specification of function
classes and to automatically compose and differentiate such functions.
Because of this mix-and-match composability there is a frictionless and rapid
diffusion of components and (sub-)models across application domains.&lt;/p&gt;
&lt;p&gt;This &lt;em&gt;commoditizes&lt;/em&gt; machine learning and allows customization to specific
applications;
it commoditizes machine learning because the level of knowledge required to
leverage modern deep learning frameworks is low.
These deep learning frameworks also allow for easy
&lt;em&gt;customization&lt;/em&gt; of the model to the application at hand.
Years ago, this &lt;em&gt;was&lt;/em&gt; the unattained dream for graphical models, but today it
&lt;em&gt;is&lt;/em&gt; achieved by deep learning frameworks where bespoke models are build for
most applications.&lt;/p&gt;
&lt;p&gt;&lt;img alt="Deep tree" src="https://www.nowozin.net/sebastian/blog/images/ai-deep-tree.png"&gt;&lt;/p&gt;
&lt;p&gt;But is it enough for general purpose AI?  What is missing?&lt;/p&gt;
&lt;p&gt;I believe there are two obstacles;
&lt;em&gt;first&lt;/em&gt;, almost all deep learning systems
require large amounts of supervised data to work.
For high-value industrial applications this may be okay because the required
label data can be collected.
However, there is a long tail of useful applications where label data is rare
but unlabeled data is abundant.
Future AI systems need to be able to leverage this abundant data source.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Second&lt;/em&gt;, what is missing are general architectures for reasoning, and an
intense search for such building blocks is currently taking place.  Maybe
classic ideas from AI, such as &lt;em&gt;blackboard systems&lt;/em&gt;, could be adapted and made
differentiable to enable reasoning, or maybe some entirely unexpected new
building block will appear.&lt;/p&gt;
&lt;p&gt;Besides better models, the key novel technology to look out for in deep
learning is custom hardware and novel engineering abstractions.
Custom hardware could enable energy savings, or increased speed, or both.
Current deep learning piggybacks on GPU development funded largely by the
gaming industry.  This is a great thing because developing a new GPU
generation such as Nvidia's new Pascal GPU requires very large research and
development budgets.
Novel engineering abstractions in the form of next generation deep learning
frameworks could enable automatic scalability, distributed computation, or
offer help in identifying the right architecture for the task.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Scalability&lt;/em&gt; is important beyond just training speed.  For example, consider
&lt;a href="http://people.idsia.ch/~juergen/raw.html"&gt;basic estimates of the computing power of the human
brain&lt;/a&gt; or the following quote from a
&lt;a href="http://www.macleans.ca/society/science/the-meaning-of-alphago-the-ai-program-that-beat-a-go-champ/"&gt;recent interview with Geoff
Hinton&lt;/a&gt;.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;"So in the brain, you have connections between the neurons called synapses,
and they can change. All your knowledge is stored in those synapses. You
have about 1,000-trillion synapses-10 to the 15, it's a very big number. So
that's quite unlike the neural networks we have right now. They're far, far
smaller, the biggest ones we have right now have about a billion synapses.
That's about a million times smaller than the brain."&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;This puts up a ballpark estimate for the number of primitive computational
units in the human brain, and it is quite reasonable to attempt to achieve
this scale.&lt;/p&gt;
&lt;p&gt;One important fact to consider: the driving force behind applications of deep
learning is largely the industry, and this will remain the case as long as it
pays dividends (it does so greatly at the moment).&lt;/p&gt;
&lt;h1&gt;2. Brain Simulations&lt;/h1&gt;
&lt;p&gt;Understanding the brain and simulating it is what I think of as the
&lt;em&gt;safe route&lt;/em&gt; to general AI.
We do not know whether it will take 5, 50, or 500 years, but it is likely
that we eventually will get there and be able to accurately simulate an
artificial brain which is functionally indistinguishable from a real human
brain.&lt;/p&gt;
&lt;p&gt;&lt;img alt="Human brain" src="https://www.nowozin.net/sebastian/blog/images/ai-gauss-brain.png"&gt;&lt;/p&gt;
&lt;p&gt;Novel technology and approaches to study neural systems, such as
&lt;a href="http://edge.org/conversation/ed_boyden-how-the-brain-is-computing-the-mind"&gt;optogenetics&lt;/a&gt;,
&lt;a href="http://www.nature.com/nnano/journal/v8/n2/full/nnano.2012.265.html"&gt;multi-electrode arrays&lt;/a&gt;
and 
&lt;a href="https://en.wikipedia.org/wiki/Connectomics"&gt;connectomics&lt;/a&gt;, eventually will
enable us to obtain a high-fidelity understanding of the brain.
Likewise, increase in computation and custom hardware will allow accelerated
simulation of neural models.&lt;/p&gt;
&lt;p&gt;Most of the investments in this area of research are government funds, for
example through the large
US &lt;a href="https://en.wikipedia.org/wiki/BRAIN_Initiative"&gt;BRAIN initiative&lt;/a&gt; and the
&lt;a href="https://en.wikipedia.org/wiki/Human_Brain_Project"&gt;Human Brain Project&lt;/a&gt;, and
more general neuroscience funding.&lt;/p&gt;
&lt;h1&gt;3. Algorithmic Information Theory and Universal Intelligence&lt;/h1&gt;
&lt;p&gt;Whatever intelligence is, if we were to accept the possibility of a
mathematical theory for it, the closest contenders for such theory are found
in a field called algorithmic information theory.
If you have not heard of algorithmic information theory before, &lt;a href="https://en.wikipedia.org/wiki/Gregory_Chaitin"&gt;Gregory
Chaitin&lt;/a&gt; recently wrote &lt;a href="http://inference-review.com/article/doing-mathematics-differently"&gt;an
excellent essay on the conceptual roots of algorithmic information
theory&lt;/a&gt; and
the general history of notions of complexity in science and mathematics.&lt;/p&gt;
&lt;p&gt;One approach which leverages algorithmic information theory for general
artificial intelligence is the
&lt;a href="https://en.wikipedia.org/wiki/AIXI"&gt;AIXI agent&lt;/a&gt;, a
theory put forward by &lt;a href="http://www.hutter1.net/"&gt;Marcus Hutter&lt;/a&gt; that attempts
to be universal in the sense that it will successfully and optimally solve any
solvable tasks.
At its heart it is a &lt;a href="http://www.nowpublishers.com/article/Details/MAL-049"&gt;Bayesian reinforcement learning
agent&lt;/a&gt; where the
hypothesis space are possible programs of a &lt;a href="https://en.wikipedia.org/wiki/Turing_machine"&gt;Turing
machine&lt;/a&gt;.
It is an extension of an earlier idea to consider Turing machines for
predicting future symbols in an observed sequence.  This idea is
&lt;a href="https://en.wikipedia.org/wiki/Solomonoff's_theory_of_inductive_inference"&gt;Solomonoff induction&lt;/a&gt; proposed by &lt;a href="http://world.std.com/~rjs/tributes/vitanyi.html"&gt;Ray
Solomonoff&lt;/a&gt;.
Because Turing machines are universal any computable hypothesis can be
entertained.
AIXI extends this idea from mere prediction of symbols to acting in an unknown
environment, that is, to &lt;a href="https://en.wikipedia.org/wiki/Reinforcement_learning"&gt;reinforcement
learning&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;img alt="Alan Turing" src="https://www.nowozin.net/sebastian/blog/images/ai-turing.png"&gt;&lt;/p&gt;
&lt;p&gt;Grounding intelligence in Turing machines is very appealing: not only is it
universal, but allows the &lt;a href="http://arxiv.org/abs/0712.3329"&gt;formal &lt;em&gt;definition&lt;/em&gt; of universal
intelligence&lt;/a&gt; as well.
In essence, reasoning and acting intelligently is reduced to formal
manipulation of a notion of complexity defined by programs on a Turing
machine.  See also &lt;a href="http://people.idsia.ch/~juergen/"&gt;J&amp;uuml;rgen
Schmidhuber&lt;/a&gt;'s &lt;a href="http://citeseerx.ist.psu.edu/viewdoc/download;jsessionid=48FFC58A49C83119D49EB93C5AA2A975?doi=10.1.1.7.2717&amp;amp;rep=rep1&amp;amp;type=pdf"&gt;speed prior for Turing
machines&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Despite this promise, so far we do not see impressive results achieved by AIXI
agents.  Why not?
There are at least two obstacles:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Universal Turing machines are not practically implementable and
&lt;a href="https://arxiv.org/abs/1510.05572"&gt;approximating AIXI is hard&lt;/a&gt;; there have
been some approximation attempts, e.g. in the work of &lt;a href="http://www.aaai.org/Papers/JAIR/Vol40/JAIR-4004.pdf"&gt;(Veness et al., JAIR
2011)&lt;/a&gt;, but at best
results have matched other reinforcement learning methods without enabling
novel applications that were out of reach before.
More recently &lt;a href="http://people.idsia.ch/~juergen/"&gt;J&amp;uuml;rgen Schmidhuber&lt;/a&gt;
proposed a more practical integration of recurrent neural network models of
the world with algorithmic information theory in the form of &lt;a href="http://arxiv.org/abs/1511.09249"&gt;RNN-based
AIs&lt;/a&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;The choice of Turing machine is not clear.
There is an infinite set of possible universal Turing machines and we could
reasonably hope that the particular choice would not influence the agent
efficiency except perhaps for some small overhead.
(For a related example, the &lt;a href="https://en.wikipedia.org/wiki/Kolmogorov_complexity"&gt;Kolmogorov
complexity&lt;/a&gt; of a sequence
is defined through a Turing machine, but whatever the choice of a Turing
machine there is an invariance property in that only a constant overhead
introduced compared to any other Turing machine.)
&lt;a href="https://arxiv.org/abs/1510.04931"&gt;Unfortunately for AIXI this is not the
case&lt;/a&gt;: the choice of Turing machine
can determine the behaviour of the AIXI agent entirely.
(This may also affects Bayesian reinforcement learning more generally: when
using a non-parametric prior process the choice of prior may determine more
than intended.)&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;This recent negative result leaves AIXI in an interesting state at the moment.
It is clearly the most complete theory of universal agents we have at the
moment, see e.g. &lt;a href="https://arxiv.org/abs/1202.6153"&gt;Hutter's own review from
2012&lt;/a&gt;, but it may turn out to be entirely
subjective (if no "&lt;em&gt;natural&lt;/em&gt;" Turing machine can be identified) or practically
unworkable.&lt;/p&gt;
&lt;h1&gt;4. Artifical Life&lt;/h1&gt;
&lt;p&gt;In the above section on brain simulation I argued that by understanding the
human brain and then simulating it we will eventually be able to attain
human-level intelligence.
However, we can start at a more basic level: by understanding and simulating a
synthetic form of chemistry we may be able to simulate artificial life.
Given a sufficiently rich environment such life may evolve to become
intelligent.&lt;/p&gt;
&lt;p&gt;The field of &lt;em&gt;Artificial Life&lt;/em&gt; (ALife) studies the formation and dynamics of
life itself on top of artifical simulations of life.
This life does not need to be intelligent, and in fact, so far no such
simulation has produced life with the intelligence beyond that of a simple
organism.  But it is clear that &lt;a href="https://en.wikipedia.org/wiki/Tierra_%28computer_simulation%29"&gt;since the early
1990'ies&lt;/a&gt;, by
any generally plausible definition of life (of which there are many and there
is some controversy), artificial life does indeed spontaneously form in
computer simulations and complex evolutionary dynamics such as symbiosis and
parasites do occur in these simulations.&lt;/p&gt;
&lt;p&gt;For a dated but inspiring introduction to the field of artificial life
more generally, see &lt;a href="http://adamilab.msu.edu/"&gt;Christoph Adami&lt;/a&gt;'s &lt;a href="http://www.springer.com/us/book/9781461272311"&gt;book on
Artificial Life&lt;/a&gt;.
Adami also wrote a recent &lt;a href="http://adamilab.blogspot.co.uk/2015/12/evolving-intelligence-with-little-help.html"&gt;article on evolving artificial
intelligence&lt;/a&gt;
that highlights current research issues for the goal to evolve artificial
intelligence.&lt;/p&gt;
&lt;p&gt;More fundamentally, in &lt;a href="http://adamilab.blogspot.com/2013/02/your-conscious-you.html"&gt;another
article&lt;/a&gt; Adami
argues that from theoretical results in a field called &lt;a href="https://en.wikipedia.org/wiki/Integrated_information_theory"&gt;&lt;em&gt;integrated
information
theory&lt;/em&gt;&lt;/a&gt; (and
which I have not heard of before), one possible consequence may be that due to
the complexity of general intelligence it is not possible to design it but
instead an evolutionary approach is needed.&lt;/p&gt;
&lt;p&gt;Given that our goal is to evolve intelligence artifically, fundamentally there
are the following obstacles in producing useful general artificial
intelligence through artificial life:&lt;/p&gt;
&lt;p&gt;&lt;img alt="Anomalocaris" src="https://www.nowozin.net/sebastian/blog/images/ai-anomalocaris.png"&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;The &lt;em&gt;big intelligence filter&lt;/em&gt; hypothesis.
This hypothesis goes as follows: life may be abundant but intelligent life may
be exceedingly rare.
We currently do not know if intelligent life is rare or abundant in the
universe, but if it is rare, it may also be exceedingly rare in any simulation
of artificial life.
A related point is what is known as the &lt;em&gt;Fermi paradox&lt;/em&gt;, namely, that what
science tells us about astrophysics implies we should have likely observed alien
civilizations by now, but this has not happened yet.  (See Tim Urban's
wonderful article on the &lt;a href="http://waitbutwhy.com/2014/05/fermi-paradox.html"&gt;Fermi's
paradox&lt;/a&gt;.)
Even for life on our own planet we are not sure what triggered intelligence to
appear; one widely believed hypothesis is that it happened in a short time,
akin to a phase transition, due to a change in ocean oxygen levels 540 million
years ago, leading to the &lt;a href="http://www.nature.com/news/what-sparked-the-cambrian-explosion-1.19379"&gt;Cambrian
explosion&lt;/a&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Harnessing intelligence.
One of our closest genetic relatives, the chimpanzee, are clearly intelligent,
but harnessing this intelligence for something useful is difficult.
Now imagine a giant squid, swimming a kilometer deep within the ocean.
Likely they are also intelligent but we can hardly leverage this for anything
useful.
Who knows which form intelligent artificial life will take?
Will we be able to recognize this life as intelligent?
If we do, such life will likely be similar to encountering an alien species in
our universe: unlike anything you can imagine or predict beforehand.
That is to say, we may be able to achieve intelligent artificial life but may
still struggle to make it useful.
Even with full control over the simulation environment, a god-like state if
you will, it seems necessary that to make artificial intelligence life useful
we will at least have to decode its representation or ``language'' and
understand the incentives sufficiently well in order to communicate with such
intelligence and motivate it to work for us.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;img alt="Giant squid" src="https://www.nowozin.net/sebastian/blog/images/ai-octopus-drawing.png"&gt;&lt;/p&gt;
&lt;p&gt;In summary, the evolutionary approach to constructing AIs is promising in the
long run and there are now several labs working on it
(the labs of &lt;a href="http://adamilab.msu.edu/"&gt;Adami&lt;/a&gt;,
&lt;a href="http://www.evolvingai.org/"&gt;Clune&lt;/a&gt;, and &lt;a href="http://hintzelab.msu.edu/"&gt;Hintze&lt;/a&gt;).&lt;/p&gt;
&lt;h1&gt;5. Robotics and Autonomous Systems&lt;/h1&gt;
&lt;p&gt;Autonomous robots are rapidly conquering novel applications in industry and
consumer space, such as in self-driving cars, agricultural robotics,
&lt;a href="https://en.wikipedia.org/wiki/Industry_4.0"&gt;industry 4.0&lt;/a&gt;, and drones.&lt;/p&gt;
&lt;p&gt;The key enablers of this development are improved sensing technology (e.g.
low-cost depth sensors), increased compute and memory capacities, and improved
pattern recognition methods.
As a result of the maturity of basic required technologies significant
industry capital is invested in driving advanced autonomous robotics research.&lt;/p&gt;
&lt;p&gt;Beyond the natural urge to feel scared by autonomous machines, how could this
lead to a breakthrough in artificial intelligence that cannot be found in one
of the constituent technologies?&lt;/p&gt;
&lt;p&gt;&lt;img alt="Humanoid robot" src="https://www.nowozin.net/sebastian/blog/images/ai-robot.png"&gt;&lt;/p&gt;
&lt;p&gt;One line of thought in the field of &lt;a href="https://en.wikipedia.org/wiki/Embodied_cognition"&gt;embodied
cognition&lt;/a&gt; argues that
an intelligent system is conditioned on its environment in a fundamental way,
shaping the allocation of precious (evolutionary) resources in order to
maximally exploit the types of sensors and actuators available to it.
Therefore the specific nature of sensing and acting abilities is not ancillary
to intelligence but the main driving force that enables intelligence in the
first place.&lt;/p&gt;
&lt;p&gt;If the above thesis were true, autonomous robots with modern sensors and
actuators would provide a rich enough &lt;em&gt;embodiment&lt;/em&gt; for artificial
intelligence, and the lack of such an embodiment in other domains would likely
impede the emergence of general intelligence.&lt;/p&gt;
&lt;p&gt;In the past decade, the European Union, through its robotics programme in the
7th Framework Programme (FP7, totalling more than 50 billion Euro for
2007-2013) has placed an emphasis on &lt;em&gt;combining&lt;/em&gt; cognition with robotics at
the exclusion of funding research on artificial intelligence not involving
robotics.
However, many of the resulting &lt;a href="http://cordis.europa.eu/fp7/ict/robotics/projects/understanding/learning_en.html"&gt;large research projects of that
time&lt;/a&gt;
are more reflecting the ample funding availability rather than representing
progress on fundamental questions of cognition.&lt;/p&gt;
&lt;h1&gt;6. Game Playing&lt;/h1&gt;
&lt;p&gt;Games entertain humans; what could they do to enable artificial intelligence?&lt;/p&gt;
&lt;p&gt;The answer: quite a lot!
Games are designed to challenge our intellect, involve interactions
between multiple agents, and are sufficiently abstract to be formalized.
A computer-implemented game can be as simple and abstract as tic-tac-toe,
Chess, or Go, or as sophisticated and close to reality as the latest Grand
Theft Auto game.&lt;/p&gt;
&lt;p&gt;&lt;img alt="Dice" src="https://www.nowozin.net/sebastian/blog/images/ai-dice.png"&gt;&lt;/p&gt;
&lt;p&gt;Therefore games are an almost ideal research vehicle to drive artificial
intelligence research.
&lt;a href="http://engineering.nyu.edu/people/julian-togelius"&gt;Julian Togelius&lt;/a&gt; argues
this point eloquently in &lt;a href="http://togelius.blogspot.co.uk/2016/01/why-video-games-are-essential-for.html"&gt;a recent
article&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;In fact, there are now popular game playing competitions and platforms which
drive AI research:
the Stanford &lt;a href="http://games.stanford.edu/"&gt;general game playing competition&lt;/a&gt;,
the &lt;a href="http://www.computerpokercompetition.org/"&gt;Computer Poker Competition&lt;/a&gt;,
the &lt;a href="http://webdocs.cs.ualberta.ca/~cdavid/starcraftaicomp/report2015.shtml"&gt;StarCraft AI Competition&lt;/a&gt;,
the &lt;a href="http://www.arcadelearningenvironment.org/"&gt;Atari 2600 Arcade Learning Environment&lt;/a&gt;, and, most recently
&lt;a href="https://blogs.microsoft.com/next/2016/03/13/project-malmo-using-minecraft-build-intelligent-technology/"&gt;Microsoft's Minecraft AI environment
(Malmo)&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;It is likely that such platforms will provide diverse and challenging
environments for testing the abilities of artificial general intelligence
agents, thus accelerating research and enabling breakthroughs.  Perhaps the
next breakthrough will be in the form of mastering another game.&lt;/p&gt;
&lt;h1&gt;7. Knowledge Bases&lt;/h1&gt;
&lt;p&gt;A knowledge base is a discrete representation of basic facts and relations
about entities.
Large-scale knowledge bases constructed semi-automatically from the web are
already incredibly useful commercially and they power search engine results and
personal assistants.&lt;/p&gt;
&lt;p&gt;&lt;img alt="Couple" src="https://www.nowozin.net/sebastian/blog/images/ai-couple.png"&gt;&lt;/p&gt;
&lt;p&gt;In search results they provide highly accurate results for known entities in
all major search engines (e.g. &lt;a href="https://en.wikipedia.org/wiki/Knowledge_Graph"&gt;Knowledge
Graph&lt;/a&gt; and &lt;a href="https://en.wikipedia.org/wiki/Knowledge_Vault"&gt;Knowledge
Vault&lt;/a&gt; in Google,
&lt;a href="http://arstechnica.com/information-technology/2012/06/inside-the-architecture-of-googles-knowledge-graph-and-microsofts-satori/"&gt;Satori&lt;/a&gt; in Microsoft Bing).
To see an example, search for a well-known person, e.g. "Stanislaw Ulam"
(&lt;a href="http://www.bing.com/search?q=Stanislaw+Ulam&amp;amp;go=Submit+Query&amp;amp;qs=bs&amp;amp;form=QBLH"&gt;results from Bing&lt;/a&gt;, &lt;a href="https://www.google.com/?gws_rd=ssl#safe=off&amp;amp;q=Stanislaw+Ulam"&gt;results from Google&lt;/a&gt;) and observe that the details about the person displayed.&lt;/p&gt;
&lt;p&gt;In personal intelligent assistants such as
&lt;a href="http://www.apple.com/ios/siri/"&gt;Apple Siri&lt;/a&gt;,
&lt;a href="https://www.google.com/landing/now/"&gt;Google Now&lt;/a&gt;,
&lt;a href="https://www.microsoft.com/en-us/mobile/experiences/cortana/"&gt;Microsoft Cortana&lt;/a&gt;, or
&lt;a href="https://www.amazon.com/gp/help/customer/display.html?nodeId=201549800"&gt;Amazon Alexa&lt;/a&gt;
they are responsible for providing facts in basic reasoning abilities.  For
example, in order to answer queries such as "Who was the president following
Thomas Jefferson?" a basic natural language understanding ability and a large
knowledge base go a long way.&lt;/p&gt;
&lt;p&gt;But can knowledge bases provide the substrate for artificial intelligence?
The &lt;a href="https://en.wikipedia.org/wiki/Cyc"&gt;Cyc project&lt;/a&gt; started in 1984 and the
&lt;a href="https://en.wikipedia.org/wiki/Open_Mind_Common_Sense"&gt;Open Mind Common Sense
project&lt;/a&gt; started in
1999 are both based on the belief that in order to enable artificial
intelligence we need to encode common sense reasoning, particularly the
entities and relationships of everyday life.
The hope was that knowledge, encoded in this way, will make reasoning and
discovery of novel knowledge simpler.&lt;/p&gt;
&lt;p&gt;It is fair to say, that while the (commercial) usefulness of knowledge bases
for intelligent applications is now well established, it is too early to say
whether general artificial intelligence would require reasoning on top of an
explicit symbolic knowledge base.
Perhaps a more continuous and non-symbolic representation of knowledge that
supports reasoning is sufficient.&lt;/p&gt;
&lt;h1&gt;Conclusion&lt;/h1&gt;
&lt;p&gt;The goal of artificial general intelligence (AGI) is challenging and exciting
on many levels.
In all likelihood artificial intelligence will make rapid progress in the next
decade, perhaps along the directions we just discussed.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Acknowledgements&lt;/em&gt;.  I thank
&lt;a href="http://people.idsia.ch/~juergen/"&gt;J&amp;uuml;rgen Schmidhuber&lt;/a&gt;,
&lt;a href="http://inverseprobability.com/"&gt;Neil Lawrence&lt;/a&gt;,
&lt;a href="http://research.microsoft.com/en-us/um/people/pkohli/"&gt;Pushmeet Kohli&lt;/a&gt;,
&lt;a href="http://adamilab.msu.edu/"&gt;Chris Adami&lt;/a&gt;, and
&lt;a href="http://www.cs.rhul.ac.uk/home/chrisw/"&gt;Chris Watkins&lt;/a&gt;
for feedback, pointers to literature, and corrections on
a draft version of the article.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Image credits&lt;/em&gt;.
The tree image is licensed CC-BY-SA by
&lt;a href="http://adoomer.deviantart.com/art/Tree-of-life-190974117"&gt;adoomer&lt;/a&gt;.
The brain image is a drawing of the brain of Gauss and is &lt;a href="https://commons.wikimedia.org/wiki/File:PSM_V26_D768_Brain_of_gauss.jpg"&gt;public
domain&lt;/a&gt;.
The Anomalocaris image is CC-BY-3.0 licensed art by &lt;a href="https://commons.wikimedia.org/wiki/File:Anomalocaris_BW.jpg"&gt;Nobu
Tamura&lt;/a&gt;.
The octopus image is CC-BY-2.0 licensed art by &lt;a href="https://www.flickr.com/photos/bibliodyssey/"&gt;Paul
K&lt;/a&gt;.
The robot image is licensed CC-BY-2.0 by
&lt;a href="https://www.flickr.com/photos/striatic/245603625/"&gt;striatic&lt;/a&gt;.
The dice image is public domain by Personeoneste.
The couple image is &lt;a href="https://commons.wikimedia.org/wiki/File:Her-aide-de-camp-Early-19thc-Humorous.png"&gt;public
domain&lt;/a&gt;.&lt;/p&gt;</content><category term="Artificial Intelligence"/></entry><entry><title>The Best of Unpublished Machine Learning and Statistics Books</title><link href="https://www.nowozin.net/sebastian/blog/the-best-of-unpublished-machine-learning-and-statistics-books.html" rel="alternate"/><published>2016-02-09T23:00:00+00:00</published><updated>2016-02-09T23:00:00+00:00</updated><author><name>Sebastian Nowozin</name></author><id>tag:www.nowozin.net,2016-02-09:/sebastian/blog/the-best-of-unpublished-machine-learning-and-statistics-books.html</id><summary type="html">&lt;p&gt;Nowadays authors in the fields of statistics and machine learning often choose
to write their books openly by publishing early draft versions.
For popular books this creates a lot of feedback and in the end clearly
improves the final book when it is published.&lt;/p&gt;
&lt;p&gt;Here is a short list of …&lt;/p&gt;</summary><content type="html">&lt;p&gt;Nowadays authors in the fields of statistics and machine learning often choose
to write their books openly by publishing early draft versions.
For popular books this creates a lot of feedback and in the end clearly
improves the final book when it is published.&lt;/p&gt;
&lt;p&gt;Here is a short list of very promising draft books.
Because completing a book is difficult it is likely that some of these books
will never be finished.&lt;/p&gt;
&lt;h3&gt;&lt;a href="http://www.deeplearningbook.org/"&gt;"Deep Learning"&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;By Ian Goodfellow, Yoshua Bengio, and Aaron Courville.&lt;/p&gt;
&lt;p&gt;Deep learning has revolutionized multiple applied pattern recognition fields
since 2011.
If you want to get started in applying deep learning methods, now is the time.&lt;/p&gt;
&lt;p&gt;First, there are now &lt;a href="https://docs.google.com/spreadsheets/d/1XvGfi3TxWm7kuQ0DUqYrO6cxva196UJDxKTxccFqb9U/edit#gid=0"&gt;many well-engineered
frameworks&lt;/a&gt;
available that make learning and experimentation fun.&lt;/p&gt;
&lt;p&gt;Second, there are good learning resources available.  If you have a solid
background in basic machine learning and basic linear algebra, this book is
for you.
The field of deep learning is advancing very swiftly and likely this book will
not cover all the latest models and techniques used when it is published.
However, at the moment it is quite up-to-date and simply contains some of the
most organized material on the topic of deep learning.&lt;/p&gt;
&lt;h3&gt;&lt;a href="http://www.stat.cmu.edu/~cshalizi/ADAfaEPoV/"&gt;"Advanced Data Analysis from an Elementary Point of View"&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;By Cosma Rohilla Shalizi.&lt;/p&gt;
&lt;p&gt;This book is covering a lot of ground from classical statistics
(linear/additive/spline regression, resampling methods, density estimation,
dimensionality reduction), and some more recent topics (causality, graphical
models, models for dependent data).&lt;/p&gt;
&lt;p&gt;One feature of this book is highlighted by the addition ``from an elementary
point of view'' to the title:
it is quite accessible and the author genuinely cares about conveying
understanding, often in a delightfully casual tone.&lt;/p&gt;
&lt;p&gt;See also the unfinished but great book written by
&lt;a href="http://www.stat.cmu.edu/~cshalizi/"&gt;Cosma Shalizi&lt;/a&gt; and
&lt;a href="http://www.cs.bgu.ac.il/~karyeh/"&gt;Aryeh Kontorovich&lt;/a&gt;,
&lt;a href="http://www.stat.cmu.edu/~cshalizi/almost-none/"&gt;"Almost None of the Theory of Stochastic
Processes"&lt;/a&gt;.&lt;/p&gt;
&lt;h3&gt;&lt;a href="http://statweb.stanford.edu/~owen/mc/"&gt;"Monte Carlo theory, methods and examples"&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;By Art Owen.&lt;/p&gt;
&lt;p&gt;While Monte Carlo methods have advanced in the last decade, in particular
driven by the need for large scale Bayesian statistics, most comprehensive
textbooks (Liu, Robert and Casella, Rubinstein and Kroese) are now dated.&lt;/p&gt;
&lt;p&gt;Art Owen's book is a wonderful addition that will become a classic once it is
completed.
From first principles and with great depth Art Owen introduces the theory and
practice of Monte Carlo methods.
Chapters 8 to 10 contain a wealth of material not found in other textbook
treatments.
I am eagerly waiting for chapters 11 to 17.&lt;/p&gt;
&lt;h3&gt;&lt;a href="http://ciml.info/"&gt;"A Course in Machine Learning"&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;By Hal Daume III.&lt;/p&gt;
&lt;p&gt;A basic course on a broad set of machine learning methods including
(eventually, not yet) chapters on structured prediction and Bayesian learning.
Very accessible and lots of pseudo-code.&lt;/p&gt;
&lt;h3&gt;&lt;a href="http://alex.smola.org/drafts/thebook.pdf"&gt;"Introduction to Machine Learning"&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;By Alex Smola and SVN Vishwanathan.&lt;/p&gt;
&lt;p&gt;This draft was last updated in 2010 and probably will never be completed.
Chapter 3 however, covering continuous optimization methods, is complete and
nicely written.&lt;/p&gt;</content><category term="Machine Learning, Statistics"/></entry><entry><title>The Fair Price to Pay a Spy: An Introduction to the Value of Information</title><link href="https://www.nowozin.net/sebastian/blog/the-fair-price-to-pay-a-spy-an-introduction-to-the-value-of-information.html" rel="alternate"/><published>2016-01-09T22:30:00+00:00</published><updated>2016-01-09T22:30:00+00:00</updated><author><name>Sebastian Nowozin</name></author><id>tag:www.nowozin.net,2016-01-09:/sebastian/blog/the-fair-price-to-pay-a-spy-an-introduction-to-the-value-of-information.html</id><summary type="html">&lt;p&gt;&lt;img alt="Spy image" src="https://www.nowozin.net/sebastian/blog/images/voi-spy-illustration.png"&gt;&lt;/p&gt;
&lt;p&gt;(This article covers the decision-theoretic concept of &lt;em&gt;value of information&lt;/em&gt;
through a classic example.)&lt;/p&gt;
&lt;p&gt;What is the value of a piece of information?&lt;/p&gt;
&lt;p&gt;It depends.
Two factors determine the value of information:
first, whether the information is new to you;
second, whether the information causes you to change your decisions …&lt;/p&gt;</summary><content type="html">&lt;p&gt;&lt;img alt="Spy image" src="https://www.nowozin.net/sebastian/blog/images/voi-spy-illustration.png"&gt;&lt;/p&gt;
&lt;p&gt;(This article covers the decision-theoretic concept of &lt;em&gt;value of information&lt;/em&gt;
through a classic example.)&lt;/p&gt;
&lt;p&gt;What is the value of a piece of information?&lt;/p&gt;
&lt;p&gt;It depends.
Two factors determine the value of information:
first, whether the information is new to you;
second, whether the information causes you to change your decisions.&lt;/p&gt;
&lt;p&gt;The first point is immediately clear as you would be unwilling to pay a reward
for information which you already know.
Information is understood here in the sense of probabilistic knowledge
represented by a probability distribution.  As such, if the information keeps
your beliefs unchanged, it cannot have any value.&lt;/p&gt;
&lt;p&gt;The second point is more subtle.
Only decisions and actions can have value, information itself has only
indirect value through the decisions and actions that it influences.
The consequence of a decision is a realized utility which can be both positive
or negative.
As a simple monetary example, imagine you buy a share of a company.  Then the
utility is a function of the change in the share price.  Information such as
insider information can lead to a belief that the share price will drop, thus
leading to the decision to sell the share and realize the utility.
If the information I learn about the company does not change my decision
whether to sell the share or not, then it also cannot change the utility.
Therefore &lt;em&gt;value&lt;/em&gt; is understood as a subjective but quantitative utility that
is realized at decision time.&lt;/p&gt;
&lt;h2&gt;The Fair Price to Pay a Spy&lt;/h2&gt;
&lt;p&gt;The following example is from one of the important papers on decision theory
and decision analysis, now in its 50th anniversary year(!),
&lt;a href="http://dx.doi.org/10.1109/TSSC.1966.300074"&gt;(Howard, "Information Value Theory",
1966)&lt;/a&gt;.
Unfortunately the paper is behind a paywall, but I will keep the presentation
below self-contained and also took the liberty to update the exotic notation
used in the paper to a more modern form.&lt;/p&gt;
&lt;p&gt;Imagine you run a construction company and the government advertises a
contract to build a large development.
The bidding happens via a lowest price closed bidding, where every construction company submits a price for which they would construct the development in a technically acceptable manner.
You do not see any competing bids and the lowest-price bid wins.&lt;/p&gt;
&lt;p&gt;Leaving moral and legal concerns aside, how much would you pay a spy to reveal
to you the lowest competing bid prior to you making your bid?
We will follow &lt;a href="https://profiles.stanford.edu/ronald-howard"&gt;Ronald Howard&lt;/a&gt; in
answering this question using decision theory, thus putting a monetary value
on a piece of information.&lt;/p&gt;
&lt;p&gt;The following are the key quantities in this problem:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span class="math"&gt;\(E\)&lt;/span&gt;, the expense to your company in constructing the development.  It is a
  random variable.&lt;/li&gt;
&lt;li&gt;&lt;span class="math"&gt;\(L\)&lt;/span&gt;, the lowest price among all competing bids.  It is a random variable.&lt;/li&gt;
&lt;li&gt;&lt;span class="math"&gt;\(B\)&lt;/span&gt;, your bid.  It is a decision variable under your control, not a random
  variable.&lt;/li&gt;
&lt;li&gt;&lt;span class="math"&gt;\(V\)&lt;/span&gt;, the profit you realize, a random variable.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The situation is represented using &lt;a href="https://en.wikipedia.org/wiki/Influence_diagram"&gt;influence
diagrams&lt;/a&gt; in the following
figure.  (Incidentally influence diagrams were also first formally published
by Ronald Howard in (Howard and Matheson, "Influence diagrams", 1981), and a
nice historical piece on them is available from Judea Pearl in &lt;a href="http://ftp.cs.ucla.edu/pub/stat_ser/r326.pdf"&gt;(Pearl,
"Influence Diagrams - Historical and Personal Perspectives",
2005)&lt;/a&gt;.)&lt;/p&gt;
&lt;p&gt;&lt;img alt="Influence diagram for the construction company" src="https://www.nowozin.net/sebastian/blog/images/voi-spy.png"&gt;&lt;/p&gt;
&lt;p&gt;In the diagram the round nodes represent random variables, just like in
directed graphical models (Bayesian networks).
The rectangular node represents a decision node under our control, here the
bid &lt;span class="math"&gt;\(B\)&lt;/span&gt; we submit.
The diamond shaped utility node represents a value achieved, in our case the
profit &lt;span class="math"&gt;\(V\)&lt;/span&gt;.
The above diagram is not enough, we need to specify how our profit &lt;span class="math"&gt;\(V\)&lt;/span&gt; comes
about.&lt;/p&gt;
&lt;p&gt;The first step in applying decision theory is to assume that everything is
known.  So let us assume &lt;span class="math"&gt;\(B\)&lt;/span&gt;, &lt;span class="math"&gt;\(E\)&lt;/span&gt;, &lt;span class="math"&gt;\(L\)&lt;/span&gt; are known.
Then, it is easy to see whether we actually won the contract, i.e. whether
our bid is small enough, &lt;span class="math"&gt;\(B &amp;lt; L\)&lt;/span&gt;.  If &lt;span class="math"&gt;\(B \geq L\)&lt;/span&gt;, we do not obtain the
contract and the profit is zero.  (We assume here, for simplicity, that the
cost for making the bid is zero.)
If we won the bid, that is, if &lt;span class="math"&gt;\(B &amp;lt; L\)&lt;/span&gt; is true, then the profit is simply the
bid price minus our expenses, &lt;span class="math"&gt;\(B - E\)&lt;/span&gt;.
Therefore we have the profit as a function of &lt;span class="math"&gt;\(B\)&lt;/span&gt;, &lt;span class="math"&gt;\(E\)&lt;/span&gt;, and &lt;span class="math"&gt;\(L\)&lt;/span&gt; as
&lt;/p&gt;
&lt;div class="math"&gt;$$V = \left\{\begin{array}{cl}0,&amp;amp;\textrm{if $B \geq L$,}\\
B-E,&amp;amp;\textrm{if $B &amp;lt; L$.}\end{array}\right.$$&lt;/div&gt;
&lt;p&gt;
The above expression can also be written using indicator notation as
&lt;span class="math"&gt;\(V = \mathbb{1}_{\{B &amp;lt; L\}} \cdot (B-E)\)&lt;/span&gt;.&lt;/p&gt;
&lt;p&gt;But &lt;span class="math"&gt;\(B\)&lt;/span&gt;, &lt;span class="math"&gt;\(E\)&lt;/span&gt;, &lt;span class="math"&gt;\(L\)&lt;/span&gt; are not known.  The second step in applying decision theory
is therefore to take expectations with respect to everything that is unknown
(&lt;span class="math"&gt;\(E\)&lt;/span&gt; and &lt;span class="math"&gt;\(L\)&lt;/span&gt; in our case) and to maximize utility with respect to all
decisions (&lt;span class="math"&gt;\(B\)&lt;/span&gt; in our case).
We do this in two steps.  Let us first assume &lt;span class="math"&gt;\(B\)&lt;/span&gt; is fixed.  Then we take the
expectation of the above expression with respect to the unknown &lt;span class="math"&gt;\(E\)&lt;/span&gt; and &lt;span class="math"&gt;\(L\)&lt;/span&gt;,&lt;/p&gt;
&lt;div class="math"&gt;$$\mathbb{E}[V | B] = \mathbb{E}_{E,L}[\mathbb{1}_{\{B &amp;lt; L\}} \cdot (B-E)].$$&lt;/div&gt;
&lt;p&gt;Now we further assume independence of the cost &lt;span class="math"&gt;\(E\)&lt;/span&gt; and the lowest competing
bid &lt;span class="math"&gt;\(L\)&lt;/span&gt;, that is &lt;span class="math"&gt;\(P(E,L) = P(E) \, P(L)\)&lt;/span&gt;, a reasonable assumption.
Here is an example visualization of priors
&lt;span class="math"&gt;\(P(E) = \textrm{Gamma}(\textrm{Shape}=80,\textrm{Scale}=6)\)&lt;/span&gt; and
&lt;span class="math"&gt;\(P(L) = \mathcal{N}(\mu=1100, \sigma=120)\)&lt;/span&gt;.  &lt;/p&gt;
&lt;p&gt;&lt;img alt="Priors of cost and lowest bid" src="https://www.nowozin.net/sebastian/blog/images/voi-example.svg"&gt;&lt;/p&gt;
&lt;p&gt;Assuming independence we obtain&lt;/p&gt;
&lt;div class="math"&gt;\begin{eqnarray}
\mathbb{E}[V | B] &amp;amp; = &amp;amp; \mathbb{E}_{E,L}[\mathbb{1}_{\{B &amp;lt; L\}} \cdot (B-E)]\nonumber\\
&amp;amp; = &amp;amp; P(B &amp;lt; L) (B - \mathbb{E}_E[E]).\label{eqn:VgivenB}
\end{eqnarray}&lt;/div&gt;
&lt;p&gt;The expression (\ref{eqn:VgivenB}) is intuitive: the expected profit is given
by the probability of winning the bidding times the difference between bid and
expected cost.
Here is a visualization for the above priors, with our bid &lt;span class="math"&gt;\(B\)&lt;/span&gt; on the
horizontal axis.&lt;/p&gt;
&lt;p&gt;&lt;img alt="Expected profit as a function of our bid" src="https://www.nowozin.net/sebastian/blog/images/voi-expectedprofit.svg"&gt;&lt;/p&gt;
&lt;p&gt;You can see three regimes: 1. When &lt;span class="math"&gt;\(P(B &amp;lt; L)\)&lt;/span&gt; is very large (up to about
&lt;span class="math"&gt;\(B=850\)&lt;/span&gt;) the expected profit behaves linearly as &lt;span class="math"&gt;\(B-\mathbb{E}_E[E]\)&lt;/span&gt;, and if
we bid below our actual cost we realize a negative profit (loss).
2. When &lt;span class="math"&gt;\(P(B &amp;lt; L)\)&lt;/span&gt; is very small (above &lt;span class="math"&gt;\(B=1300\)&lt;/span&gt;) the expected profit drops to
zero.  3. Between &lt;span class="math"&gt;\(B=850\)&lt;/span&gt; and &lt;span class="math"&gt;\(B=1300\)&lt;/span&gt; we see the product expression resulting
in a nonlinear profit as a function of B.&lt;/p&gt;
&lt;p&gt;To finish the second step of applying decision theory we have to maximize
(\ref{eqn:VgivenB}) over our decision &lt;span class="math"&gt;\(B\)&lt;/span&gt;, yielding&lt;/p&gt;
&lt;div class="math"&gt;$$\mathbb{E}[V] = \max_{B} \mathbb{E}[V|B].$$&lt;/div&gt;
&lt;p&gt;This tells us how to bid without the help of a spy:
in the above example figures, we obtain an expected profit
&lt;span class="math"&gt;\(\mathbb{E}[V] = 421.8\)&lt;/span&gt; for a bid of &lt;span class="math"&gt;\(B=966.2\)&lt;/span&gt;.&lt;/p&gt;
&lt;p&gt;Revealing &lt;span class="math"&gt;\(L\)&lt;/span&gt; gives a large competitive advantage, but how much would we be
willing to pay a spy for this information?
To this end Howard introduces the concept of &lt;em&gt;clairvoyance&lt;/em&gt; and
&lt;em&gt;value of information&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;In &lt;em&gt;clairvoyance&lt;/em&gt; we consider what could happen if a clairvoyant appears and
offers us perfect information about &lt;span class="math"&gt;\(L\)&lt;/span&gt;.
If we would know &lt;span class="math"&gt;\(L\)&lt;/span&gt; we can compute as before&lt;/p&gt;
&lt;div class="math"&gt;\begin{eqnarray}
\mathbb{E}[V | B, L] &amp;amp; = &amp;amp; P(B &amp;lt; L) (B - \mathbb{E}_E[E])\nonumber\\
&amp;amp; = &amp;amp; \mathbb{1}_{\{B &amp;lt; L\}} (B - \mathbb{E}_E[E]),\nonumber
\end{eqnarray}&lt;/div&gt;
&lt;p&gt;
where the probability &lt;span class="math"&gt;\(P(B &amp;lt; L)\)&lt;/span&gt; is now deterministic one or zero as &lt;span class="math"&gt;\(B\)&lt;/span&gt; is
our decision and &lt;span class="math"&gt;\(L\)&lt;/span&gt; is known.
As &lt;span class="math"&gt;\(B\)&lt;/span&gt; is our decision we again maximize over it.
&lt;/p&gt;
&lt;div class="math"&gt;\begin{eqnarray}
\mathbb{E}[V | L] &amp;amp; = &amp;amp; \max_B \mathbb{E}[V | B,L]\nonumber\\
&amp;amp; = &amp;amp; \max_B \mathbb{1}_{\{B &amp;lt; L\}} (B - \mathbb{E}_E[E])\nonumber\\
&amp;amp; = &amp;amp; \left\{\begin{array}{cl}L - \mathbb{E}_E[E], &amp;amp; \textrm{if $L &amp;gt;
\mathbb{E}_E[E]$,}\\
0, &amp;amp; \textrm{otherwise (do not bid).}\end{array}\right.\nonumber
\end{eqnarray}&lt;/div&gt;
&lt;p&gt;
The last step can be seen as follows: our bid &lt;span class="math"&gt;\(B\)&lt;/span&gt; should be above
our expected expenses &lt;span class="math"&gt;\(\mathbb{E}_E[E]\)&lt;/span&gt; otherwise we would incur a negative
profit but &lt;span class="math"&gt;\(B\)&lt;/span&gt; should also be as high as possible just below &lt;span class="math"&gt;\(L\)&lt;/span&gt;.  Hence if
this is impossible (&lt;span class="math"&gt;\(L \leq \mathbb{E}_E[E]\)&lt;/span&gt;) we do not bid.  Otherwise we bid
&lt;span class="math"&gt;\(B=L-\epsilon\)&lt;/span&gt; and realize the expected profit &lt;span class="math"&gt;\(L-\mathbb{E}_E[E]\)&lt;/span&gt;.&lt;/p&gt;
&lt;p&gt;Ok, so this tells us how to bid when we know &lt;span class="math"&gt;\(L\)&lt;/span&gt;.  But we do not know &lt;span class="math"&gt;\(L\)&lt;/span&gt; yet.
Instead we would like to put a value on the information about &lt;span class="math"&gt;\(L\)&lt;/span&gt;.
We do this by integrating out &lt;span class="math"&gt;\(L\)&lt;/span&gt;,&lt;/p&gt;
&lt;div class="math"&gt;$$\mathbb{E}_L[\mathbb{E}[V|L]]$$&lt;/div&gt;
&lt;p&gt;(Howard introduces a special notation for
the above expression, but I am not a fan of it and will omit it here.)&lt;/p&gt;
&lt;p&gt;The &lt;em&gt;value of information&lt;/em&gt; (value of &lt;span class="math"&gt;\(L\)&lt;/span&gt;) is now defined as&lt;/p&gt;
&lt;div class="math"&gt;$$\textrm{EVPI}(L) = \mathbb{E}_L[\mathbb{E}[V|L]] - \mathbb{E}[V].$$&lt;/div&gt;
&lt;p&gt;This quantity is again intuitive: the value of knowing &lt;span class="math"&gt;\(L\)&lt;/span&gt; is the expected
difference between the utility achieved with knowledge of &lt;span class="math"&gt;\(L\)&lt;/span&gt; and the expected
utility achieved without such knowledge.&lt;/p&gt;
&lt;p&gt;The abbreviation &lt;span class="math"&gt;\(\textrm{EVPI}\)&lt;/span&gt; denotes the &lt;a href="https://en.wikipedia.org/wiki/Expected_value_of_perfect_information"&gt;&lt;em&gt;expected value of perfect
information&lt;/em&gt;&lt;/a&gt;,
a term that was introduced later and has become standard in decision analysis.&lt;/p&gt;
&lt;p&gt;So how much is the knowledge of &lt;span class="math"&gt;\(L\)&lt;/span&gt; worth in our example?
We compute &lt;/p&gt;
&lt;div class="math"&gt;$$\mathbb{E}_L[\mathbb{E}[V|L]] \approx 620.0$$&lt;/div&gt;
&lt;p&gt; with Monte Carlo
and we had &lt;span class="math"&gt;\(\mathbb{E}[V] = 421.8\)&lt;/span&gt; from earlier, hence
&lt;/p&gt;
&lt;div class="math"&gt;$$\textrm{EVPI}(L) \approx 620.0 - 421.8 = 198.2,$$&lt;/div&gt;
&lt;p&gt;
is the maximum price we should pay our spy for telling us &lt;span class="math"&gt;\(L\)&lt;/span&gt; exactly.&lt;/p&gt;
&lt;h2&gt;The Fair Price to Pay an Expert&lt;/h2&gt;
&lt;p&gt;The above was the original scenario described in Howard's paper.
In practice obtaining perfect knowledge is often infeasible.
But the above reasoning extends easily to the general case where we only
obtain partial information.&lt;/p&gt;
&lt;p&gt;Here is an example for our setup: consider that we can ask an expert to
provide us an estimate &lt;span class="math"&gt;\(L'\)&lt;/span&gt; of what the lowest bid &lt;span class="math"&gt;\(L\)&lt;/span&gt; could be.&lt;/p&gt;
&lt;p&gt;&lt;img alt="Expert advice" src="https://www.nowozin.net/sebastian/blog/images/voi-experts-lovelornpoets.jpg"&gt;&lt;/p&gt;
&lt;p&gt;By assuming a probability model &lt;span class="math"&gt;\(P(L' | L)\)&lt;/span&gt; we can relate the true unknown
lowest bid &lt;span class="math"&gt;\(L\)&lt;/span&gt; to the experts guess.&lt;/p&gt;
&lt;p&gt;The influence diagram looks as follows:&lt;/p&gt;
&lt;p&gt;&lt;img alt="Influence diagram for the construction company with expert advice" src="https://www.nowozin.net/sebastian/blog/images/voi-expert.png"&gt;&lt;/p&gt;
&lt;h3&gt;Recipe for Value of Information Computation&lt;/h3&gt;
&lt;p&gt;To understand how the above derivation extends to this case, let us state a
recipe of computing value of information:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;State the expected utility, conditioned on &lt;em&gt;decisions&lt;/em&gt; and the &lt;em&gt;information
to be valued&lt;/em&gt;.&lt;/li&gt;
&lt;li&gt;Maximize the expression of step 1 over all &lt;em&gt;decisions&lt;/em&gt;.&lt;/li&gt;
&lt;li&gt;Marginalize the expression of step 2 over the &lt;em&gt;information to be valued&lt;/em&gt;,
using your prior beliefs.  The resulting expression is the expected utility
with information.&lt;/li&gt;
&lt;li&gt;Start over: state the expected utility, conditioned only on &lt;em&gt;decisions&lt;/em&gt;.&lt;/li&gt;
&lt;li&gt;Maximize the expression of step 4 over all &lt;em&gt;decisions&lt;/em&gt;.  The resulting
expression is the expected utility without information.&lt;/li&gt;
&lt;li&gt;Compute the value of information as the difference between the two expected
utilities (step 3 minus step 5).&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;This recipe works for any single-step decision problem, and any potential
difficulties are computational.&lt;/p&gt;
&lt;h3&gt;Application of the Recipe to our Example&lt;/h3&gt;
&lt;p&gt;Here is its application to our generalized example:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;This is &lt;span class="math"&gt;\(\mathbb{E}[V | L', B]\)&lt;/span&gt; which is obtained by marginalizing over &lt;span class="math"&gt;\(E\)&lt;/span&gt;
and &lt;span class="math"&gt;\(L\)&lt;/span&gt; in &lt;span class="math"&gt;\(\mathbb{E}[V | L', B, E, L]\)&lt;/span&gt; and the marginal of &lt;span class="math"&gt;\(L\)&lt;/span&gt; is &lt;span class="math"&gt;\(P(L|L')\)&lt;/span&gt;
obtained by Bayes rule.&lt;/li&gt;
&lt;li&gt;Maximize over &lt;span class="math"&gt;\(B\)&lt;/span&gt;, obtaining &lt;span class="math"&gt;\(\max_B \mathbb{E}[V | L', B]\)&lt;/span&gt;.&lt;/li&gt;
&lt;li&gt;Take the expectation over &lt;span class="math"&gt;\(L'\)&lt;/span&gt;, which is defined via &lt;span class="math"&gt;\(P(L') = \mathbb{E}_{L}[P(L'|L)]\)&lt;/span&gt;, yielding
&lt;div class="math"&gt;\begin{equation}
\mathbb{E}_{L'}[\max_B \mathbb{E}[V | L', B]]\label{eqn:Ltick-withinfo}
\end{equation}&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;This is &lt;span class="math"&gt;\(\mathbb{E}[V | B]\)&lt;/span&gt; which is obtained by marginalizing over &lt;span class="math"&gt;\(E\)&lt;/span&gt; and
&lt;span class="math"&gt;\(L\)&lt;/span&gt;, here the marginal of &lt;span class="math"&gt;\(L\)&lt;/span&gt; is the prior &lt;span class="math"&gt;\(P(L)\)&lt;/span&gt;.&lt;/li&gt;
&lt;li&gt;Maximize over &lt;span class="math"&gt;\(B\)&lt;/span&gt;, obtaining
&lt;div class="math"&gt;\begin{equation}
\max_B \mathbb{E}[V | B].\label{eqn:Ltick-withoutinfo}
\end{equation}&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;The value of information is the difference between (\ref{eqn:Ltick-withinfo}) and (\ref{eqn:Ltick-withoutinfo}),
&lt;div class="math"&gt;$$
\textrm{EVPI}(L') = \mathbb{E}_{L'}[\max_B \mathbb{E}[V | L', B]] - \max_B \mathbb{E}[V | B].$$&lt;/div&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;To make the above example concrete, let us assume that our expert is unbiased
and we have
&lt;/p&gt;
&lt;div class="math"&gt;$$P(L'|L) = \mathcal{N}(L, \sigma),$$&lt;/div&gt;
&lt;p&gt;
where &lt;span class="math"&gt;\(\sigma &amp;gt; 0\)&lt;/span&gt; is the standard deviation.
Computing &lt;span class="math"&gt;\(\textrm{EVPI}(L')\)&lt;/span&gt; as a function of &lt;span class="math"&gt;\(\sigma\)&lt;/span&gt; is possible by solving
the maximization and integration problems.&lt;/p&gt;
&lt;p&gt;Using the same parameters as before and using Monte Carlo for the integration,
here is a visualization of the fair price to pay our expert.&lt;/p&gt;
&lt;p&gt;&lt;img alt="Price for expert advice as a function of expert reliability" src="https://www.nowozin.net/sebastian/blog/images/voi-expert-confidence.svg"&gt;&lt;/p&gt;
&lt;p&gt;We can see that for &lt;span class="math"&gt;\(\sigma \to 0\)&lt;/span&gt; we recover the previous case of perfect
information as the expert provides increasingly accurate knowledge about &lt;span class="math"&gt;\(L\)&lt;/span&gt;
when &lt;span class="math"&gt;\(\sigma\)&lt;/span&gt; decreases.
Conversely, with increasing expert uncertainty the value of his expert advice
decreases.&lt;/p&gt;
&lt;h2&gt;Computation&lt;/h2&gt;
&lt;p&gt;(This was added in April 2016 after the original article was published.)&lt;/p&gt;
&lt;p&gt;Computing the EVPI can be challenging because in many cases both the
maximization problem and the expectation are intractable analytically and
sample-based Monte Carlo approximations induce a non-negligible bias.&lt;/p&gt;
&lt;p&gt;The recent work of &lt;a href="http://arxiv.org/abs/1604.01120"&gt;(Takashi Goda, "Unbiased Monte Carlo estimation for the
expected value of partial perfect information",
arXiv:1604.01120)&lt;/a&gt; addresses part of the
computation diffulties by application of a randomly truncated series to
de-bias the ordinary Monte Carlo estimate.
I have not performed any experiments but it seems to be a potentially useful
method in the context of value of information computation problems.&lt;/p&gt;
&lt;h2&gt;Summary&lt;/h2&gt;
&lt;p&gt;From a formal decision theory point of view the &lt;em&gt;value of information&lt;/em&gt; does not
occupy a special place.  It just measures the difference between two different
expected utilities, given optimal decisions.&lt;/p&gt;
&lt;p&gt;But &lt;em&gt;value of information&lt;/em&gt; appears frequently in almost any statistical
decision task.
Here are two more examples.&lt;/p&gt;
&lt;p&gt;In &lt;em&gt;active learning&lt;/em&gt; we are interested in minimizing the amount of supervision
needed to learn to perform a task and we can obtain supervision (ground truth
class labels, for example) for instances of our choice at a cost.
By applying value of information we can select for supervision the instances
whose revealed label information brings the highest expected increase in
utility.&lt;/p&gt;
&lt;p&gt;In &lt;em&gt;experimental design&lt;/em&gt; we have to make choices about which information to
acquire, such as the number of patients to sample in a medical trial, or what
information to collect at different costs in a customer survey.
Value of information provides a way to make these choices, both statically, or
better, adaptively.&lt;/p&gt;
&lt;h3&gt;Limitations&lt;/h3&gt;
&lt;p&gt;While decision theory is rather uncontroversial, it is a normative theory,
that is, it tells you how to derive decisions which are optimal and coherent
(rational).
There are two main limitations I would like to point out:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;As a normative theory it cannot claim to be a description of how humans (or
other intelligent agents) make decisions.&lt;/li&gt;
&lt;li&gt;It assumes infinite reasoning resources on behalf of the acting agent.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Both limitations are related of course in that real intelligent agents may
deviate from normative decision theory precisely because they are limited in
their reasoning abilities.
There are both normative and descriptive theories to address these
limitations.
On the normative side we have for example &lt;a href="http://web.mit.edu/sjgershm/www/GershmanHorvitzTenenbaum15.pdf"&gt;computational
rationality&lt;/a&gt;,
taking into account the computational costs of reasoning and deriving optimal
decisions within these constraints.
On the descriptive side we have for example &lt;a href="https://en.wikipedia.org/wiki/Prospect_theory"&gt;prospect
theory&lt;/a&gt;, aiming to describe
human decision making.&lt;/p&gt;
&lt;h3&gt;Further Reading&lt;/h3&gt;
&lt;p&gt;A great introduction to decision theory, including value of information, is
the very accessible
&lt;a href="http://eu.wiley.com/WileyCDA/WileyTitle/productCd-047149657X.html"&gt;(Parmigiani and Inoue, "Decision Theory: Principles and Approaches",
2009)&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Three classic textbooks on decision theoretic topics are
&lt;a href="http://eu.wiley.com/WileyCDA/WileyTitle/productCd-047168029X.html"&gt;(DeGroot, "Optimal Statistical Decisions",
1970)&lt;/a&gt;,
&lt;a href="http://www.springer.com/us/book/9780387960982"&gt;(Berger, "Statistical Decision Theory and Bayesian Analysis",
1985)&lt;/a&gt;, and
&lt;a href="http://eu.wiley.com/WileyCDA/WileyTitle/productCd-047138349X.html"&gt;(Raiffa and Schlaifer, "Applied Statistical Decision Theory",
1961)&lt;/a&gt;
(available as outrageously priced reprint-paperback by Wiley).&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Acknowledgements&lt;/em&gt;.  The expert image is CC-BY-2.0 licensed art by
&lt;a href="https://www.flickr.com/photos/lovelornpoets/6214449310/"&gt;lovelornpoets&lt;/a&gt;.&lt;/p&gt;
&lt;script type="text/javascript"&gt;if (!document.getElementById('mathjaxscript_pelican_#%@#$@#')) {
    var align = "center",
        indent = "0em",
        linebreak = "false";

    if (false) {
        align = (screen.width &lt; 768) ? "left" : align;
        indent = (screen.width &lt; 768) ? "0em" : indent;
        linebreak = (screen.width &lt; 768) ? 'true' : linebreak;
    }

    var mathjaxscript = document.createElement('script');
    mathjaxscript.id = 'mathjaxscript_pelican_#%@#$@#';
    mathjaxscript.type = 'text/javascript';
    mathjaxscript.src = 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.3/latest.js?config=TeX-AMS-MML_HTMLorMML';

    var configscript = document.createElement('script');
    configscript.type = 'text/x-mathjax-config';
    configscript[(window.opera ? "innerHTML" : "text")] =
        "MathJax.Hub.Config({" +
        "    config: ['MMLorHTML.js']," +
        "    TeX: { extensions: ['AMSmath.js','AMSsymbols.js','noErrors.js','noUndefined.js'], equationNumbers: { autoNumber: 'none' } }," +
        "    jax: ['input/TeX','input/MathML','output/HTML-CSS']," +
        "    extensions: ['tex2jax.js','mml2jax.js','MathMenu.js','MathZoom.js']," +
        "    displayAlign: '"+ align +"'," +
        "    displayIndent: '"+ indent +"'," +
        "    showMathMenu: true," +
        "    messageStyle: 'normal'," +
        "    tex2jax: { " +
        "        inlineMath: [ ['\\\\(','\\\\)'] ], " +
        "        displayMath: [ ['$$','$$'] ]," +
        "        processEscapes: true," +
        "        preview: 'TeX'," +
        "    }, " +
        "    'HTML-CSS': { " +
        "        availableFonts: ['STIX', 'TeX']," +
        "        preferredFont: 'STIX'," +
        "        styles: { '.MathJax_Display, .MathJax .mo, .MathJax .mi, .MathJax .mn': {color: 'inherit ! important'} }," +
        "        linebreaks: { automatic: "+ linebreak +", width: '90% container' }," +
        "    }, " +
        "}); " +
        "if ('default' !== 'default') {" +
            "MathJax.Hub.Register.StartupHook('HTML-CSS Jax Ready',function () {" +
                "var VARIANT = MathJax.OutputJax['HTML-CSS'].FONTDATA.VARIANT;" +
                "VARIANT['normal'].fonts.unshift('MathJax_default');" +
                "VARIANT['bold'].fonts.unshift('MathJax_default-bold');" +
                "VARIANT['italic'].fonts.unshift('MathJax_default-italic');" +
                "VARIANT['-tex-mathit'].fonts.unshift('MathJax_default-italic');" +
            "});" +
            "MathJax.Hub.Register.StartupHook('SVG Jax Ready',function () {" +
                "var VARIANT = MathJax.OutputJax.SVG.FONTDATA.VARIANT;" +
                "VARIANT['normal'].fonts.unshift('MathJax_default');" +
                "VARIANT['bold'].fonts.unshift('MathJax_default-bold');" +
                "VARIANT['italic'].fonts.unshift('MathJax_default-italic');" +
                "VARIANT['-tex-mathit'].fonts.unshift('MathJax_default-italic');" +
            "});" +
        "}";

    (document.body || document.getElementsByTagName('head')[0]).appendChild(configscript);
    (document.body || document.getElementsByTagName('head')[0]).appendChild(mathjaxscript);
}
&lt;/script&gt;</content><category term="Decision Theory, Machine Learning"/></entry><entry><title>ICCV 2015, Day 4</title><link href="https://www.nowozin.net/sebastian/blog/iccv-2015-day-4.html" rel="alternate"/><published>2015-12-16T23:50:00+00:00</published><updated>2015-12-16T23:50:00+00:00</updated><author><name>Sebastian Nowozin</name></author><id>tag:www.nowozin.net,2015-12-16:/sebastian/blog/iccv-2015-day-4.html</id><summary type="html">&lt;p&gt;This article summarizes the fourth day of the &lt;a href="http://pamitc.org/iccv15/"&gt;ICCV
2015&lt;/a&gt; conference, the International Conference on
Computer Vision.
A summary of the &lt;a href="https://www.nowozin.net/sebastian/blog/iccv-2015-day-1.html"&gt;first day&lt;/a&gt;,
&lt;a href="https://www.nowozin.net/sebastian/blog/iccv-2015-day-2.html"&gt;second day&lt;/a&gt;, and
&lt;a href="https://www.nowozin.net/sebastian/blog/iccv-2015-day-3.html"&gt;third day&lt;/a&gt; is also available.&lt;/p&gt;
&lt;h2&gt;ICCV 2017 and 2019&lt;/h2&gt;
&lt;p&gt;ICCV 2017 will be in Venice, Italy.&lt;/p&gt;
&lt;p&gt;For ICCV 2019 there was an open voting …&lt;/p&gt;</summary><content type="html">&lt;p&gt;This article summarizes the fourth day of the &lt;a href="http://pamitc.org/iccv15/"&gt;ICCV
2015&lt;/a&gt; conference, the International Conference on
Computer Vision.
A summary of the &lt;a href="https://www.nowozin.net/sebastian/blog/iccv-2015-day-1.html"&gt;first day&lt;/a&gt;,
&lt;a href="https://www.nowozin.net/sebastian/blog/iccv-2015-day-2.html"&gt;second day&lt;/a&gt;, and
&lt;a href="https://www.nowozin.net/sebastian/blog/iccv-2015-day-3.html"&gt;third day&lt;/a&gt; is also available.&lt;/p&gt;
&lt;h2&gt;ICCV 2017 and 2019&lt;/h2&gt;
&lt;p&gt;ICCV 2017 will be in Venice, Italy.&lt;/p&gt;
&lt;p&gt;For ICCV 2019 there was an open voting between Seoul (Korea) and Shanghai
(China), with Seoul winning the election.
Both proposals were strong and because I have lived in Shanghai for two years I
favored that proposal, but I am confident that ICCV 2019 in Seoul will be
wonderful as well.&lt;/p&gt;
&lt;h2&gt;Parties&lt;/h2&gt;
&lt;p&gt;Computer vision is now fully recognized as having an impact in the industry.
All large tech companies invested heavily in the last three years or so, and
one of the visible results is the increased number of conference sponsors and
the conference parties.&lt;/p&gt;
&lt;p&gt;Conferences such as NIPS, CVPR, and ICCV now host invite-only open bar parties
with several hundred attendees; this year at ICCV there were parties by
Microsoft, Intel, Google, and Facebook.&lt;/p&gt;
&lt;p&gt;Interestingly they do not come across as recruiting events: there is a minimal
announcement perhaps, but otherwise people just chat with food and drinks.
It is more a show of strength and goodwill towards the community that computer
vision is taken seriously and the parties do demonstrate that the companies
are in good shape, much like banks invest in a marble floor and shiny glass
facades to gain the trust of their customers.&lt;/p&gt;
&lt;h2&gt;Interesting Papers&lt;/h2&gt;
&lt;h3&gt;Polarized 3D: High-Quality Depth Sensing with Polarization Cues&lt;/h3&gt;
&lt;p&gt;By Achuta Kadambi, Vage Taamazyan, Boxin Shi, and Ramesh Raskar.&lt;/p&gt;
&lt;p&gt;Polarization of light is a rarely exploited cue for 3D reconstruction.
This work revisits shape-from-polarization and shows fine detail 3D
reconstruction from polarization information (with non-trivial
post-processing).&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.cv-foundation.org/openaccess/content_iccv_2015/papers/Kadambi_Polarized_3D_High-Quality_ICCV_2015_paper.pdf"&gt;Paper&lt;/a&gt;.&lt;/p&gt;</content><category term="Computer Vision"/></entry><entry><title>ICCV 2015, Day 3</title><link href="https://www.nowozin.net/sebastian/blog/iccv-2015-day-3.html" rel="alternate"/><published>2015-12-16T01:00:00+00:00</published><updated>2015-12-16T01:00:00+00:00</updated><author><name>Sebastian Nowozin</name></author><id>tag:www.nowozin.net,2015-12-16:/sebastian/blog/iccv-2015-day-3.html</id><summary type="html">&lt;p&gt;This article summarizes the third day of the &lt;a href="http://pamitc.org/iccv15/"&gt;ICCV
2015&lt;/a&gt; conference, the International Conference on
Computer Vision.
A summary of the &lt;a href="https://www.nowozin.net/sebastian/blog/iccv-2015-day-1.html"&gt;first day&lt;/a&gt; and
&lt;a href="https://www.nowozin.net/sebastian/blog/iccv-2015-day-2.html"&gt;second day&lt;/a&gt; is also available.&lt;/p&gt;
&lt;h2&gt;Interesting Papers&lt;/h2&gt;
&lt;h3&gt;Registering Images to Untextured Geometry Using Average Shading Gradients&lt;/h3&gt;
&lt;p&gt;By Tobias Ploetz and Stefan Roth.&lt;/p&gt;
&lt;p&gt;This work considers the …&lt;/p&gt;</summary><content type="html">&lt;p&gt;This article summarizes the third day of the &lt;a href="http://pamitc.org/iccv15/"&gt;ICCV
2015&lt;/a&gt; conference, the International Conference on
Computer Vision.
A summary of the &lt;a href="https://www.nowozin.net/sebastian/blog/iccv-2015-day-1.html"&gt;first day&lt;/a&gt; and
&lt;a href="https://www.nowozin.net/sebastian/blog/iccv-2015-day-2.html"&gt;second day&lt;/a&gt; is also available.&lt;/p&gt;
&lt;h2&gt;Interesting Papers&lt;/h2&gt;
&lt;h3&gt;Registering Images to Untextured Geometry Using Average Shading Gradients&lt;/h3&gt;
&lt;p&gt;By Tobias Ploetz and Stefan Roth.&lt;/p&gt;
&lt;p&gt;This work considers the difficult problem of aligning an untextured 3D surface
to a real image of the same object, a challenging problem because of the
absence and presence of edges depending on texture and light.&lt;/p&gt;
&lt;p&gt;The authors propose an alignment procedure that uses efficiently computable
&lt;em&gt;average shading gradient&lt;/em&gt; images that capture expected visible edges due to
shadows despite unknown light direction.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.cv-foundation.org/openaccess/content_iccv_2015/papers/Plotz_Registering_Images_to_ICCV_2015_paper.pdf"&gt;Paper&lt;/a&gt;.&lt;/p&gt;
&lt;h3&gt;Robust Nonrigid Registration by Convex Optimization&lt;/h3&gt;
&lt;p&gt;By Qifeng Chen and Vladlen Koltun.&lt;/p&gt;
&lt;p&gt;The authors consider the problem of aligning two 3D shapes to each other, where
each shape may be corrupted by missing surfaces (non water-tight surfaces) and
undergo severe nonrigid deformations.
Previous work has proposed to minimize a specific geodesic distortion measure
over suitable classes of continuous transformations, however, this yields
difficult non-convex optimization problems.&lt;/p&gt;
&lt;p&gt;Because the distortion measure makes sense this work proposes a way to
approximate while simultaneously convexifying the problem.  This is achieved by
representing the transformation nonparametrically through correspondences on
randomly sampled points.
While the original problem was continuous and non-convex, now it is a discrete
energy minimization problem that can be approximately solved using a standard
LP-based relaxation approach, where the authors use TRW-S.&lt;/p&gt;
&lt;p&gt;What is surprising is how much the results improve on benchmark data sets; the
error is reduced by a factor of three compared to strong baseline methods.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.cv-foundation.org/openaccess/content_iccv_2015/papers/Chen_Robust_Nonrigid_Registration_ICCV_2015_paper.pdf"&gt;Paper&lt;/a&gt;.&lt;/p&gt;</content><category term="Computer Vision"/></entry><entry><title>ICCV 2015, Day 2</title><link href="https://www.nowozin.net/sebastian/blog/iccv-2015-day-2.html" rel="alternate"/><published>2015-12-15T01:20:00+00:00</published><updated>2015-12-15T01:20:00+00:00</updated><author><name>Sebastian Nowozin</name></author><id>tag:www.nowozin.net,2015-12-15:/sebastian/blog/iccv-2015-day-2.html</id><summary type="html">&lt;p&gt;This article summarizes the second day of the &lt;a href="http://pamitc.org/iccv15/"&gt;ICCV
2015&lt;/a&gt; conference, the International Conference on
Computer Vision.
A summary of the &lt;a href="https://www.nowozin.net/sebastian/blog/iccv-2015-day-1.html"&gt;first day&lt;/a&gt; is also available.&lt;/p&gt;
&lt;h2&gt;Awards&lt;/h2&gt;
&lt;p&gt;The following awards were given at ICCV 2015.&lt;/p&gt;
&lt;h3&gt;Achievement awards&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;PAMI Distinguished Researcher Award (1): &lt;strong&gt;Yann LeCun&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;PAMI Distinguished Researcher Award (2): &lt;strong&gt;David …&lt;/strong&gt;&lt;/li&gt;&lt;/ul&gt;</summary><content type="html">&lt;p&gt;This article summarizes the second day of the &lt;a href="http://pamitc.org/iccv15/"&gt;ICCV
2015&lt;/a&gt; conference, the International Conference on
Computer Vision.
A summary of the &lt;a href="https://www.nowozin.net/sebastian/blog/iccv-2015-day-1.html"&gt;first day&lt;/a&gt; is also available.&lt;/p&gt;
&lt;h2&gt;Awards&lt;/h2&gt;
&lt;p&gt;The following awards were given at ICCV 2015.&lt;/p&gt;
&lt;h3&gt;Achievement awards&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;PAMI Distinguished Researcher Award (1): &lt;strong&gt;Yann LeCun&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;PAMI Distinguished Researcher Award (2): &lt;strong&gt;David Lowe&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;PAMI Everingham Prize Winner (1): &lt;strong&gt;Andrea Vedaldi&lt;/strong&gt; for &lt;a href="http://www.vlfeat.org/"&gt;VLFeat&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;PAMI Everingham Prize Winner (2): &lt;strong&gt;Daniel Scharstein&lt;/strong&gt; and &lt;strong&gt;Rick Szeliski&lt;/strong&gt; for the &lt;a href="http://vision/middlebury.edu/stereo/data/"&gt;Middlebury Datasets&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;Paper awards&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;PAMI Helmholtz Prize (1): &lt;strong&gt;David Martin&lt;/strong&gt;, &lt;strong&gt;Charles Fowlkes&lt;/strong&gt;, &lt;strong&gt;Doron Tal&lt;/strong&gt;, and &lt;strong&gt;Jitendra Malik&lt;/strong&gt; for their ICCV 2001 paper "A database of human segmented natural images and its application to evaluating segmentation algorithms and measuring ecological statistics".&lt;/li&gt;
&lt;li&gt;PAMI Helmholtz Prize (2): &lt;strong&gt;Serge Belongie&lt;/strong&gt;, &lt;strong&gt;Jitendra Malik&lt;/strong&gt;, and &lt;strong&gt;Jan Puzicha&lt;/strong&gt;, for their ICCV 2001 paper "Matching Shapes".&lt;/li&gt;
&lt;li&gt;Marr Prize: &lt;strong&gt;Peter Kontschieder&lt;/strong&gt;, &lt;strong&gt;Madalina Fiterau&lt;/strong&gt;, &lt;strong&gt;Antonio Criminisi&lt;/strong&gt;, and &lt;strong&gt;Samual Rota Bulo&lt;/strong&gt;, for &lt;a href="http://www.cv-foundation.org/openaccess/content_iccv_2015/papers/Kontschieder_Deep_Neural_Decision_ICCV_2015_paper.pdf"&gt;"Deep Neural Decision Forests"&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Marr Prize honorable mention: &lt;strong&gt;Saining Xie&lt;/strong&gt; and &lt;strong&gt;Zhuowen Tu&lt;/strong&gt; for &lt;a href="http://www.cv-foundation.org/openaccess/content_iccv_2015/papers/Xie_Holistically-Nested_Edge_Detection_ICCV_2015_paper.pdf"&gt;"Holistically-Nested Edge Detection"&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;Interesting Papers&lt;/h2&gt;
&lt;p&gt;The above Marr prize winning papers are very nice, but here I also want to
highlight three other papers I found interesting today.&lt;/p&gt;
&lt;h3&gt;Fast R-CNN&lt;/h3&gt;
&lt;p&gt;By Ross Girshick.&lt;/p&gt;
&lt;p&gt;Since 2014 the standard object detection pipeline for natural images is the
R-CNN system which first extracts a set of object proposals then scores them
using a convolutional neural network.
The two key weaknesses of the approach are: first, the separation between
proposal generation and scoring, preventing joint training of model parameters;
and second the separate scoring of each hypothesis which leads to significant
runtime overhead.
This work and the follow-up work ("Faster R-CNNs" at NIPS this year) addresses
both issues by proposing a joint model that is trained end-to-end, including
proposal generation, leading to a new state of the art in object detection.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://github.com/rbgirshick/fast-rcnn"&gt;Code&lt;/a&gt;,
&lt;a href="http://www.cv-foundation.org/openaccess/content_iccv_2015/papers/Girshick_Fast_R-CNN_ICCV_2015_paper.pdf"&gt;paper&lt;/a&gt;.&lt;/p&gt;
&lt;h3&gt;Unsupervised Visual Representation Learning by Context Prediction&lt;/h3&gt;
&lt;p&gt;By Carl Doersch, Abhinav Gupta, and Alexei A. Efros.&lt;/p&gt;
&lt;p&gt;Supervised deep learning needs lots of labeled training data to achieve good performance.
This paper investigates whether we can create and train deep neural networks on
artificial tasks for which we can create large amounts of training data.  In
particular, the paper proposes to predict where a certain patch appears within
the image.  For this task, an almost infinite amount of training data is easily
created.
Perhaps surprisingly the resulting network, despite being trained on this
artificial task, has learned useful representations for real vision tasks such
as image classification.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.cv-foundation.org/openaccess/content_iccv_2015/papers/Doersch_Unsupervised_Visual_Representation_ICCV_2015_paper.pdf"&gt;Paper&lt;/a&gt;.&lt;/p&gt;
&lt;h3&gt;Deep Fried Convnets&lt;/h3&gt;
&lt;p&gt;By Zichao Yang, Marcin Moczulski, Misha Denil, Nando de Freitas, Alex Smola, Le Song,
and Ziyu Wang.&lt;/p&gt;
&lt;p&gt;In deep convolutional networks the last few densely connected layers have the
most parameters and thus most of the required memory during test time and
training.
This work proposes to leverage the &lt;em&gt;fastfood&lt;/em&gt; kernel approximation to replace
densely connected layers with specific efficient and low parameter operations.&lt;/p&gt;
&lt;p&gt;The empirical results are impressive and the fastfood justification is
plausible, but I wonder if this work may even provide a hint at a more general
approach to construct efficient neural network architectures by using arbitrary
dense but efficient matrix operations (FFT, DCT, Walsh-Hadamard, etcetera).&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.cv-foundation.org/openaccess/content_iccv_2015/papers/Yang_Deep_Fried_Convnets_ICCV_2015_paper.pdf"&gt;Paper&lt;/a&gt;.&lt;/p&gt;</content><category term="Computer Vision"/></entry><entry><title>ICCV 2015, Day 1</title><link href="https://www.nowozin.net/sebastian/blog/iccv-2015-day-1.html" rel="alternate"/><published>2015-12-14T23:00:00+00:00</published><updated>2015-12-14T23:00:00+00:00</updated><author><name>Sebastian Nowozin</name></author><id>tag:www.nowozin.net,2015-12-14:/sebastian/blog/iccv-2015-day-1.html</id><summary type="html">&lt;p&gt;&lt;a href="http://pamitc.org/iccv15/"&gt;ICCV 2015&lt;/a&gt;, the International Conference on
Computer Vision, is one of the premier venues for computer vision research,
together with the CVPR conference.
This ICCV is happening in Santiago, Chile, a beautiful city with amazing food.&lt;/p&gt;
&lt;p&gt;The computer vision community is growing, and this ICCV is the largest so far …&lt;/p&gt;</summary><content type="html">&lt;p&gt;&lt;a href="http://pamitc.org/iccv15/"&gt;ICCV 2015&lt;/a&gt;, the International Conference on
Computer Vision, is one of the premier venues for computer vision research,
together with the CVPR conference.
This ICCV is happening in Santiago, Chile, a beautiful city with amazing food.&lt;/p&gt;
&lt;p&gt;The computer vision community is growing, and this ICCV is the largest so far
(1460 attendees, 525 papers).  Since a few years computer vision is broadly
relevant for the industry and there are no less than 22 companies sponsoring
the conference.
The acceptance rate this year was 30.92%, with the acceptance for oral
presentations at 3.30%.
All papers of the conference are &lt;a href="http://www.cv-foundation.org/openaccess/ICCV2015.py"&gt;available as open-access PDF
here&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;There was a lot of interesting work presented on the first day, but here is my
subjective selection of interesting work.&lt;/p&gt;
&lt;h3&gt;Aligning Books and Movies&lt;/h3&gt;
&lt;p&gt;By Yukun Zhu, Ryan Kiros, Richard Zemel, Ruslan Salakhutdinov, Raquel
Urtasun, Antonio Torralba, and Sanja Fidler.&lt;/p&gt;
&lt;p&gt;Movies and the books they are based on form a rich paired data source.
In this work the authors propose a recurrent neural network model to align
these two sources semantically.
The challenge is that movies and books are often substantially different, but
apparently modern recurrent neural networks have enough semantic discrimination
ability to enable such alignment.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.cs.toronto.edu/~mbweb/"&gt;Project page&lt;/a&gt;,
&lt;a href="http://www.cv-foundation.org/openaccess/content_iccv_2015/papers/Zhu_Aligning_Books_and_ICCV_2015_paper.pdf"&gt;paper&lt;/a&gt;.&lt;/p&gt;
&lt;h3&gt;Convolutional Color Constancy&lt;/h3&gt;
&lt;p&gt;By Jonathan Barron.&lt;/p&gt;
&lt;p&gt;Color constancy deals with the correction of colors in digital images.  While
there have been a large number of works in this area, the issue remains
challenging and important.&lt;/p&gt;
&lt;p&gt;In this work the author convincingly demonstrates that common changes in colors
correspond to simple translation of a color histogram in a transformed 2D
histogram space.  Then, the problem of correcting for these translations can be
posed as simply recognizing the true center position of the observed color
histogram and undoing the translation.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.cv-foundation.org/openaccess/content_iccv_2015/papers/Barron_Convolutional_Color_Constancy_ICCV_2015_paper.pdf"&gt;Paper&lt;/a&gt;.&lt;/p&gt;
&lt;h3&gt;Self-Calibration of Optical Lenses&lt;/h3&gt;
&lt;p&gt;By Michael Hirsch and Bernhard Schoelkopf.&lt;/p&gt;
&lt;p&gt;Both cheap and expensive camera lenses suffer from many optical effects,
leading to deterioration in image quality.
This work proposes an automatic way to obtain non-parametric kernel estimates
of the point spread functions characterising a lens.
The resulting model can then be used to deblur images.
In effect, this allows better image quality even when using cheap lenses.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.cv-foundation.org/openaccess/content_iccv_2015/papers/Hirsch_Self-Calibration_of_Optical_ICCV_2015_paper.pdf"&gt;Paper&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;The &lt;a href="https://www.nowozin.net/sebastian/blog/iccv-2015-day-2.html"&gt;second day&lt;/a&gt; is available now.&lt;/p&gt;</content><category term="Computer Vision"/></entry><entry><title>Ten Tips for Writing CS Papers, Part 2</title><link href="https://www.nowozin.net/sebastian/blog/ten-tips-for-writing-cs-papers-part-2.html" rel="alternate"/><published>2015-12-10T22:30:00+00:00</published><updated>2015-12-10T22:30:00+00:00</updated><author><name>Sebastian Nowozin</name></author><id>tag:www.nowozin.net,2015-12-10:/sebastian/blog/ten-tips-for-writing-cs-papers-part-2.html</id><summary type="html">&lt;p&gt;This continues the &lt;a href="https://www.nowozin.net/sebastian/blog/ten-tips-for-writing-cs-papers-part-1.html"&gt;first part&lt;/a&gt; on tips to write
computer science papers.&lt;/p&gt;
&lt;h2&gt;6. Ideal Structure of a Paragraph&lt;/h2&gt;
&lt;p&gt;A paper has different levels of formal structure:
sections, subsections, paragraphs, sentences.
It is important to ensure that the structure of the content aligns well with
the formal structure because the formal …&lt;/p&gt;</summary><content type="html">&lt;p&gt;This continues the &lt;a href="https://www.nowozin.net/sebastian/blog/ten-tips-for-writing-cs-papers-part-1.html"&gt;first part&lt;/a&gt; on tips to write
computer science papers.&lt;/p&gt;
&lt;h2&gt;6. Ideal Structure of a Paragraph&lt;/h2&gt;
&lt;p&gt;A paper has different levels of formal structure:
sections, subsections, paragraphs, sentences.
It is important to ensure that the structure of the content aligns well with
the formal structure because the formal structure is readily perceived by the
reader, whereas the structure of the content is not.
With a good alignment we make it easy for the reader to have the right mental
model for the organization of the content; this enables a better navigation
and memory of the content.&lt;/p&gt;
&lt;p&gt;An important consequence of a well organized paper is to minimize the possible
surprise for the reader.
In general you may want to surprise readers with how amazing your method or
achievements are, but not through the organization of the paper.&lt;/p&gt;
&lt;p&gt;How to align the content with the formal structure?
There is more to say about this and I recommend the references at the end of
this article, but here I want to focus on the structure of one or multiple &lt;em&gt;paragraphs&lt;/em&gt;.
The basic rules are:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;One paragraph should contain only a single idea or a single point of
argumentation.&lt;/li&gt;
&lt;li&gt;The &lt;em&gt;beginning&lt;/em&gt; and the &lt;em&gt;end&lt;/em&gt; of a paragraph glue the paragraph into the
surrounding content.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;There is an ambiguity as to what constitutes a separate idea and indeed
paragraphs may be of quite different lengths.&lt;/p&gt;
&lt;p&gt;To achieve a good structure, here is a recipe that works for me.
For a section I would like to write I make a list of
bullet points of things I want to say, with one bullet point being a single
idea or important point.  Each point may have one or more dependencies on
other points and I use the dependencies to order the list.
Finally, I write one paragraph for each item on the list and I may add an
additional paragraph at the beginning and end of the section to connect the
section to the surrounding content.&lt;/p&gt;
&lt;p&gt;I found that this recipe also makes my job as a writer easier because it
overcomes my writing inhibition in two ways.
First, I can start by simply making a list and this does not feel like
writing.
Second, once the ordering of ideas is clear, the actual writing becomes a lot
simpler.&lt;/p&gt;
&lt;p&gt;Here is an example of a less-than-ideal paragraph from Section 2.3 in &lt;a href="http://www.nowozin.net/sebastian/papers/gehler2008ikl-tr.pdf"&gt;(Gehler
and Nowozin,
2008)&lt;/a&gt;.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;"As already mentioned to our knowledge (Argyriou et al., 2006) were the
first to note the possibility of an infinite set of base kernels and they
also stated the subproblem (Problem 1).  We will defer the discussion of the
subproblem to the next section and shortly comment on the differences of the
Algorithm of (Argyriou et al., 2006) and the IKL Algorithm.  We denote with
&lt;span class="math"&gt;\(g\)&lt;/span&gt; the objective value of a standard SVM classifier with loss function
&lt;span class="math"&gt;\(L\)&lt;/span&gt;."&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Let us reverse engineer the content of this paragraph, then restructure it.
The paragraph makes two points:
first, a connection to the work of (Argyriou et al., 2006).
Second, it establishes some notation.
So it should perhaps be split into two paragraphs.&lt;/p&gt;
&lt;p&gt;For the first point, the beginning is also less than ideal: "as already
mentioned to our knowledge"; it is a bit redundant and apologetic to point out
that we already mentioned it and that we may not know better.
The second point, the notation, is okay by itself, but it is unclear why it
follows the first: is it done in order to enable the comparison between
approaches?  We would need to read ahead to find out.  (This is indeed the
case.)
Here is a proposed improvement:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;(Argyriou et al., 2006) first recognized the possibility of an infinite set
of base kernels and we now discuss the connection to our work.&lt;/p&gt;
&lt;p&gt;To make the connection explicit we first establish the notation we will use
throughout the paper.  We use &lt;span class="math"&gt;\(g\)&lt;/span&gt; to denote the objective value of a
standard SVM classifier, where &lt;span class="math"&gt;\(L\)&lt;/span&gt; is the loss function.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;It is simpler to read and makes it clear why we introduce the notation.
Also note the end and beginning of the two short paragraphs: the end of the
first paragraph tells you what comes next ("the connection to our work"), the
beginning of the second paragraph tells you how this is done (through
notation).
The flow between the two paragraphs is natural now and they could almost be
merged into one again with the single point of the resulting paragraph being
"the connection between (Argyriou et al.) and our work".&lt;/p&gt;
&lt;h2&gt;7. Avoid Ambiguous Relative Pronouns (This, These, That, Which)&lt;/h2&gt;
&lt;p&gt;When used properly, a relative pronoun, such as "this", "these", "that",
"which", can effectively refer to a previously mentioned noun,
and &lt;em&gt;that&lt;/em&gt; has to be remembered by the reader.&lt;/p&gt;
&lt;p&gt;In the previous sentence, which entity did "&lt;em&gt;that&lt;/em&gt;" refer to?
Is it "a previously mentioned noun"?  Or is it "a relative pronoun"?
Or is it the proper use?&lt;/p&gt;
&lt;p&gt;Ambiguities of relative pronouns are common because the writer does not
experience the ambiguity.  After all, it is clear to the writer what he refers
to.
Train yourself to recognize any potentially ambiguous relative pronoun,
ideally by using a highlighter to mark them in a printout.&lt;/p&gt;
&lt;p&gt;To resolve the ambiguity the easiest solution is simply to add the noun it
refers to.  For the above example, "that" would become "that noun".&lt;/p&gt;
&lt;p&gt;(Another issue I ran into frequently is in deciding between "which" in cases
where "that" should have been used, such as in "We use an algorithm which is
efficient." I remember annoying a former American colleague of mine by using
"which" a bit too often.  &lt;a href="http://www.dailywritingtips.com/when-to-use-that-which-and-who/"&gt;Some advice is
available.&lt;/a&gt;)&lt;/p&gt;
&lt;p&gt;Here is a real example from an &lt;a href="http://www.nowozin.net/sebastian/papers/nowozin2008freqgeo.pdf"&gt;ICDM 2008
paper&lt;/a&gt; of
mine.  I highlight all relative pronouns.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Extracting such geometric patterns from molecular 3D
structures is one of the central topic in computational biology, and
numerous approaches have been proposed.  Most of them are optimization
methods, &lt;em&gt;which&lt;/em&gt; detect one pattern at a time by minimizing a loss function
(e.g., [14, 15, 6]).
&lt;em&gt;They&lt;/em&gt; are different from our approach enumerating all patterns satisfying a
certain geometric criterion.  In particular, &lt;em&gt;they&lt;/em&gt; do not have a minimum
support  constraint.  Instead &lt;em&gt;they&lt;/em&gt; try to find a motif that matches all
graphs.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;This is not the worst example but can be improved nevertheless.  The first
"which" is best removed, the other relative pronouns are best clarified.  Here
is a proposed improvement:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Extracting such geometric patterns from molecular 3D
structures is one of the central topic in computational biology, and
numerous approaches have been proposed.  Most of them are optimization
methods, &lt;em&gt;detecting&lt;/em&gt; one pattern at a time by minimizing a loss function
(e.g., [14, 15, 6]).
&lt;em&gt;These optimization methods&lt;/em&gt; are different from our approach enumerating all
patterns satisfying a certain geometric criterion.  In particular, &lt;em&gt;other
methods&lt;/em&gt; do not have a minimum support constraint &lt;em&gt;and instead&lt;/em&gt; try to find a
motif that matches all graphs.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2&gt;8. Provide Continuation Markers&lt;/h2&gt;
&lt;p&gt;&lt;em&gt;Continuation markers&lt;/em&gt; are sentences or paragraphs, typically at the beginning
of sections, to tell the reader what will be presented next and to tell the
reader how it is relevant or how it relates to what has been presented
already.  It provides structure and flow, connecting the different parts of
the paper.&lt;/p&gt;
&lt;p&gt;Here is an example, from an &lt;a href="http://www.nowozin.net/sebastian/papers/stuehmer2015toftracking.pdf"&gt;ICCV 2015
paper&lt;/a&gt;:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;"3. Method&lt;/p&gt;
&lt;p&gt;We now describe our model for tracking fast moving objects.  While the
motion model is standard, the observation model for raw ToF captures is a
novel contribution."&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Note two elements here: first, there is an explicit statement of what will be
presented next (the model for tracking fast moving objects).  Second, we
establish relevance with respect to the contribution.&lt;/p&gt;
&lt;p&gt;There are two reasons why thinking about natural continuation markers for
reading the paper is important.
First, it enables navigation through the paper by allowing the reader to skip
sections more efficiently.
Second, without the necessary background it may take a reader multiple
repeated readings to fully understand the paper.  If you lost the reader,
providing a natural re-entry point makes it easier to continue reading the
paper despite a lack of understanding of some parts.&lt;/p&gt;
&lt;p&gt;Both reasons are especially important for reviewers, a special type of reader.
Ideally the reviewer is an expert in the field already, so we would like to
make it easy for him to quickly navigate to relevant parts of the paper.
Less ideally, the reviewer is working under time pressure or without keen
interest in the work; in this case we would like to minimize misunderstanding
or missing important points during reading.&lt;/p&gt;
&lt;p&gt;It is important to co-locate the continuation markers with the actual text
itself.  It is not sufficient to provide a mini table-of-contents as part of
the introduction ("In Section 2 we present related work. In Section 3 we
present our method. etc.").&lt;/p&gt;
&lt;h2&gt;9. Multiple Authors&lt;/h2&gt;
&lt;p&gt;It is a reality that most computer science papers are authored by multiple
authors.
Coordinating the writing between multiple authors can be challenging on both
the level of content and in terms of technology.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;In terms of content&lt;/em&gt;, in my experience a recipe for disaster is to divide the
paper into parts and agree that "Author A will write the introduction, author
B will write the method, etcetera".  The resulting draft will be incoherent
and everyone has an excuse for delaying their part due to perceived
dependencies ("I will write the method once the notation is defined in the
introduction", "I will write the introduction when we have results").&lt;/p&gt;
&lt;p&gt;Also, when dividing up work this way the draft can be poorly balanced in terms
of relevant parts, as sub-authors tend to be assigned to the parts they have
contributed to the most, which provides an incentive to describe their own
contribution in too much detail (for example senior authors writing the
introduction will fill it discussing their past research agenda that led to
this work; the author writing about the implementation will want to go into
detail because it was really difficult to get it to work and people may miss
just how difficult it was, etcetera).&lt;/p&gt;
&lt;p&gt;It is better to assign responsibility to a single author to write a full
draft, then iterate together over this draft.
There are two reasons why it is better: &lt;em&gt;first&lt;/em&gt;, clear responsibility gets
stuff done; &lt;em&gt;second&lt;/em&gt;, the draft will be more coherent with a more linear
flow of arguments.&lt;/p&gt;
&lt;p&gt;The single author draft works best if the draft writer is an experienced
author because iterating on a poorly organized draft may take more effort than
a complete rewrite.
When iterating on a draft it is important to distinguish substantial from
minor changes.
&lt;em&gt;Minor changes&lt;/em&gt; are changes that fix issues locally, such as adding a
sentence for clarification, changes of word order, typos, etc.  These changes
are important but not urgent.  Most accomplished authors I know prefer to
make these changes in passes through the full paper, much like &lt;em&gt;polishing&lt;/em&gt;
the paper with each reading.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Substantial changes&lt;/em&gt; are things like addition or removal of sections,
changing the order of the presentation, enlarging or shrinking the claimed
contribution, etcetera.  Such changes can have large implications on the other
parts of the paper which need to be addressed and therefore such changes are
important and urgent because they require less time if made early.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;In terms of technology&lt;/em&gt;, I frequently experienced problems due to the
diversity of authors and their working style.  Often some authors will be
senior authors with a proven but dated work setup, for example, not using
basic version control systems and being stuck in an unflexible editor that
mangles LaTeX every time it opens a file.
To be fair, these authors are often most essential in terms of providing
feedback on the content of the paper and they may have little time available to
stay up to date with the latest tools.  For addressing this problem with
technology, my recommendations are the following:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Use a version control system: this should almost go without saying and even
if you are the sole author of a paper it is best to use a version control
system because it provides a simple method to back your work up.
But for multiple authors coordinating the writing of a paper without a version
control system is simply a waste of time and nerves of everyone involved.&lt;/li&gt;
&lt;li&gt;Use a &lt;em&gt;friendly&lt;/em&gt; version control system that provides a simple web
interface; &lt;a href="http://bitbucket.org/"&gt;Bitbucket&lt;/a&gt; is my favorite for paper
writing because it offers free private git repositories and allows you to
view changes in a neat timeline in the browser.  While hardly surprising to
any git user, this feature is readily appreciated by everyone.
Also, for minor changes Bitbucket actually allows editing from within the
browser.&lt;/li&gt;
&lt;li&gt;For yourself: when writing LaTeX write one sentence in a line and use
a line break after each sentence.  This makes merging conflicts easier and
leads to fewer surprises with strange editors breaking long lines.
(I also found that this helps me to improve the organization of a paragraph
because every sentence now starts at the beginning of a line.)&lt;/li&gt;
&lt;li&gt;When you need only high level feedback from your coauthors, sending them a
PDF for annotation via email may still be the most efficient way.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;10. Authorship and Author Ordering&lt;/h2&gt;
&lt;p&gt;Except for the writing itself, another common problem with multiple authors is
discussions about authorship and author ordering.  While not related to
writing papers per se, I do want to share some remarks on this topic.
There are only a few common situations where debates about author ordering
arise.  Here are a few common examples, with the more common cases first:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;A small contributor or someone involved in early discussions wants to be a
co-author, but other authors disagree based on the amount of time they
contributed.&lt;/li&gt;
&lt;li&gt;There is a PhD student, a post-doc, and a faculty author and in most
computer science venues the recognition is strongest for the first and last
author position.  The post-doc feels he guided the student the most so
deserves to be recognized, but the faculty member may feel different based
on seniority or being the source of funding.&lt;/li&gt;
&lt;li&gt;Two or more students contributed to a piece of work and see their
contribution as the strongest; this happens sometimes when a student
postpones a line of work and another student is continuing with the work,
directed by a joint supervisor.&lt;/li&gt;
&lt;li&gt;Two or more senior authors feel that they started or guided the project the
most.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Obviously there is no "right way" to handle all circumstances, and indeed
computer science handles authorship differently to, say, mathematics, for
example.
Of course everyone agrees that scientific authorship should imply substantial
contributions to the work, but that is about as ambiguous a statement as can
be made.
To be more concrete, here are some observations.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;First&lt;/em&gt;, some conflicts can be anticipated, for example the case of two
students.  Here, it is best to discuss a possible publication and authorship
as soon as the second student gets involved.  This discussion should be
summarized via email for future reference.  Likewise for the case of the small
contributor, as soon as it is clear the work will end up in a publication a
discussion should help to set expectations, for example to offer authorship
only if additional work is invested.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Second&lt;/em&gt;, as a young PhD student one naturally underestimates the implicit
future benefits that arise from co-authorship.  For example the senior
co-authors may present the work at venues otherwise inaccessible, or the work
will lead to substantial future collaborations with the original co-authors.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Third&lt;/em&gt;, when considering whether to include a small contributor as co-author,
the problem is most often not the co-authorship itself, but possible future
actions by the contributor after the paper is published (for example, giving
seminar talks about the paper).  The other authors may then feel that the
credit and opportunities are taken away from them.
By discussing not just the co-authorship itself early but instead also what
future paper-related actions are done by whom these problems can be avoided.
For example, all authors may agree that seminar and job talks about the work
should only be presented by the lead author.&lt;/p&gt;
&lt;h1&gt;Recommended Reading&lt;/h1&gt;
&lt;p&gt;I have bought many books on writing, especially when I started my PhD.
But there is one that stands above all others, and if you are writing papers I
can recommend this to you, no matter whether you just start out or have been
writing since decades.&lt;/p&gt;
&lt;p&gt;This book is &lt;a href="http://www.scientific-writing.com/cos/o.x?c=/wbn/pagetree&amp;amp;func=view&amp;amp;rid=10476"&gt;"Scientific Writing: A Reader and Writer's
Guide"&lt;/a&gt;
by &lt;a href="http://www.scientific-writing.com/"&gt;Jean-Luc Lebrun&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Acknowledgements&lt;/em&gt;.  Thanks to Jonathan Strahl for corrections to the article.
&lt;a href="http://www.cs.cmu.edu/~andrewgw/"&gt;Andrew Wilson&lt;/a&gt; was kind enough to point out
George Orwell's essay &lt;a href="http://georgeorwellnovels.com/essays/politics-and-the-english-language/"&gt;&lt;em&gt;Politics and the English
Language&lt;/em&gt;&lt;/a&gt;
as timeless advice on writing in English.&lt;/p&gt;
&lt;script type="text/javascript"&gt;if (!document.getElementById('mathjaxscript_pelican_#%@#$@#')) {
    var align = "center",
        indent = "0em",
        linebreak = "false";

    if (false) {
        align = (screen.width &lt; 768) ? "left" : align;
        indent = (screen.width &lt; 768) ? "0em" : indent;
        linebreak = (screen.width &lt; 768) ? 'true' : linebreak;
    }

    var mathjaxscript = document.createElement('script');
    mathjaxscript.id = 'mathjaxscript_pelican_#%@#$@#';
    mathjaxscript.type = 'text/javascript';
    mathjaxscript.src = 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.3/latest.js?config=TeX-AMS-MML_HTMLorMML';

    var configscript = document.createElement('script');
    configscript.type = 'text/x-mathjax-config';
    configscript[(window.opera ? "innerHTML" : "text")] =
        "MathJax.Hub.Config({" +
        "    config: ['MMLorHTML.js']," +
        "    TeX: { extensions: ['AMSmath.js','AMSsymbols.js','noErrors.js','noUndefined.js'], equationNumbers: { autoNumber: 'none' } }," +
        "    jax: ['input/TeX','input/MathML','output/HTML-CSS']," +
        "    extensions: ['tex2jax.js','mml2jax.js','MathMenu.js','MathZoom.js']," +
        "    displayAlign: '"+ align +"'," +
        "    displayIndent: '"+ indent +"'," +
        "    showMathMenu: true," +
        "    messageStyle: 'normal'," +
        "    tex2jax: { " +
        "        inlineMath: [ ['\\\\(','\\\\)'] ], " +
        "        displayMath: [ ['$$','$$'] ]," +
        "        processEscapes: true," +
        "        preview: 'TeX'," +
        "    }, " +
        "    'HTML-CSS': { " +
        "        availableFonts: ['STIX', 'TeX']," +
        "        preferredFont: 'STIX'," +
        "        styles: { '.MathJax_Display, .MathJax .mo, .MathJax .mi, .MathJax .mn': {color: 'inherit ! important'} }," +
        "        linebreaks: { automatic: "+ linebreak +", width: '90% container' }," +
        "    }, " +
        "}); " +
        "if ('default' !== 'default') {" +
            "MathJax.Hub.Register.StartupHook('HTML-CSS Jax Ready',function () {" +
                "var VARIANT = MathJax.OutputJax['HTML-CSS'].FONTDATA.VARIANT;" +
                "VARIANT['normal'].fonts.unshift('MathJax_default');" +
                "VARIANT['bold'].fonts.unshift('MathJax_default-bold');" +
                "VARIANT['italic'].fonts.unshift('MathJax_default-italic');" +
                "VARIANT['-tex-mathit'].fonts.unshift('MathJax_default-italic');" +
            "});" +
            "MathJax.Hub.Register.StartupHook('SVG Jax Ready',function () {" +
                "var VARIANT = MathJax.OutputJax.SVG.FONTDATA.VARIANT;" +
                "VARIANT['normal'].fonts.unshift('MathJax_default');" +
                "VARIANT['bold'].fonts.unshift('MathJax_default-bold');" +
                "VARIANT['italic'].fonts.unshift('MathJax_default-italic');" +
                "VARIANT['-tex-mathit'].fonts.unshift('MathJax_default-italic');" +
            "});" +
        "}";

    (document.body || document.getElementsByTagName('head')[0]).appendChild(configscript);
    (document.body || document.getElementsByTagName('head')[0]).appendChild(mathjaxscript);
}
&lt;/script&gt;</content><category term="Computer Science"/></entry><entry><title>Ten Tips for Writing CS Papers, Part 1</title><link href="https://www.nowozin.net/sebastian/blog/ten-tips-for-writing-cs-papers-part-1.html" rel="alternate"/><published>2015-11-29T21:00:00+00:00</published><updated>2015-11-29T21:00:00+00:00</updated><author><name>Sebastian Nowozin</name></author><id>tag:www.nowozin.net,2015-11-29:/sebastian/blog/ten-tips-for-writing-cs-papers-part-1.html</id><summary type="html">&lt;p&gt;As a non-native English speaker I can relate to the challenge of writing
concise and clear English.
Scientific writing is particularly challenging because the audience is only
partially known at the time of writing: at best, the paper will still be read
in 10 or 20 years from the time …&lt;/p&gt;</summary><content type="html">&lt;p&gt;As a non-native English speaker I can relate to the challenge of writing
concise and clear English.
Scientific writing is particularly challenging because the audience is only
partially known at the time of writing: at best, the paper will still be read
in 10 or 20 years from the time of writing by people from all over the world.&lt;/p&gt;
&lt;p&gt;Learning to write papers well takes a long time and is achieved mostly by
practice, that is, writing and publishing papers.
But to improve your writing at a faster pace you can actively reflect on
certain patterns and writing habits you may have.&lt;/p&gt;
&lt;p&gt;Below I compiled a short list of some best practices from my own experience
and preference, with more following in a second part.
This list is by no means exhaustive and has a certain bias towards computer
science publications.
However, I hope it will serve as an inspiration to improve your writing.&lt;/p&gt;
&lt;p&gt;I provide some examples of poor writing from published papers.
To avoid offending anyone, I select the examples from my own published papers.&lt;/p&gt;
&lt;h2&gt;1. Use Simple Language&lt;/h2&gt;
&lt;p&gt;Concepts and ideas in scientific papers can at times be complex but the
writing used to describe them should remain simple.
Simple writing has short sentences, a clear logical structure, and uses
minimal jargon.  Writing papers is not poetry but still requires you to pay
attention to the language you use.&lt;/p&gt;
&lt;p&gt;Computer science does not seem to have an overly large problem with complex
writing, possibly due to a large number of non-native English speakers.  Or
perhaps there is a strong desire to be understood by the writers;
&lt;a href="http://www.theatlantic.com/education/archive/2015/10/complex-academic-writing/412255/"&gt;other academic fields are more challenged&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Yet, I have frequently seen non-native English speaking junior authors,
perhaps when writing their first paper, who attempt to copy style from their
native language.  At least for native German speakers (like me)
this would often lead to comparatively complex writing in terms of sentence
lengths and less than optimal didactics in terms of presenting the abstract
before the concrete.&lt;/p&gt;
&lt;p&gt;If still in doubt whether using simple language is a good idea, check this
&lt;a href="http://www.improbable.com/ig/winners/#ig2015"&gt;Ig-Nobel-prize-winning&lt;/a&gt; work:
&lt;a href="http://www.ucd.ie/artspgs/semantics/ConsequencesErudite.pdf"&gt;(Oppenheimer, "Consequences of Erudite Vernacular Utilized Irrespective of Necessity:
Problems with Using Long Words
Needlessly", Applied Cognitive Psychology, 2006)&lt;/a&gt;.&lt;/p&gt;
&lt;h2&gt;2. State your Contribution&lt;/h2&gt;
&lt;p&gt;The key contribution of most published papers falls into exactly one out of
the following three categories.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;em&gt;Insight&lt;/em&gt;: you have an explanation for something that is already there.&lt;/li&gt;
&lt;li&gt;&lt;em&gt;Performance&lt;/em&gt;: you can do something better.&lt;/li&gt;
&lt;li&gt;&lt;em&gt;Capability&lt;/em&gt;: you can do something that could not be done before.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;If you know which category your paper falls into this, emphasize this aspect
early in the paper, ideally in the abstract.  This sets the tone and
expectations for the remainder of the paper.&lt;/p&gt;
&lt;h2&gt;3. See Everything as a Facet on the Contribution&lt;/h2&gt;
&lt;p&gt;Every scientific paper claims a contribution over previous work.
Once you have stated the contribution clearly, the rest of the paper is there
just to support the contribution:
The &lt;em&gt;introduction&lt;/em&gt; motivates the need for your contribution.
The &lt;em&gt;related work&lt;/em&gt; section differentiates prior work against your claimed
contribution.
The &lt;em&gt;method&lt;/em&gt; section typically provides a description of the contribution.
The &lt;em&gt;experiments&lt;/em&gt; verifies that your contribution works as advertised.
Etcetera.&lt;/p&gt;
&lt;p&gt;The point is: the contribution anchors everything else in the paper.
If the contribution is clear, every part of the paper should make sense and
become a different facet or view onto the contribution.&lt;/p&gt;
&lt;p&gt;There are two common ways how this simple structure is violated, leading
to a poorly written paper.
The first way is to not clearly state the contribution, leaving it ambiguous
during the whole paper.  In such papers some method may be described, some
experiments may be performed, but the higher goal does not emerge.  At the end
of the paper, the reader may agree with all statements of the paper and still
wonder what he should make of it.&lt;/p&gt;
&lt;p&gt;The second way to violate the structure is less severe: a long description of
another method or work is added to the paper.  I have seen this frequently
with junior authors who have just learned about a cool method and want to
showcase their understanding.  Such description may even be interesting to a
reader of the paper, but it is orthogonal to the contribution of the paper thus 
has negative value and is best removed.&lt;/p&gt;
&lt;h2&gt;4. Consider Using a Page-1 Figure&lt;/h2&gt;
&lt;p&gt;Consider using an explanatory figure on page one of the paper.
This was started in the SIGGRAPH community with the &lt;a href="http://ivizlab.sfu.ca/arya/Papers/ACM/SIGGRAPH-96/Storytelling%20in%20VR.pdf"&gt;work of Randy
Pausch&lt;/a&gt;,
but has slowly spread to other communities.&lt;/p&gt;
&lt;p&gt;The main purpose of a page one figure is to provide a gist of the paper, much
like a "visual abstract".
It highlights what is important and sets the right expectations.
It is also visually engaging and whets the appetite of the reader.&lt;/p&gt;
&lt;p&gt;What makes a good page one figure?
1. &lt;em&gt;Simplicity&lt;/em&gt;: You need to be able to understand it in 20 seconds or less.
2. &lt;em&gt;Being self-contained&lt;/em&gt;: All relevant information should be in the figure or
the figure caption.  The figure caption should be short.&lt;/p&gt;
&lt;p&gt;Many papers benefit from the addition of a page one figure, but there are some
exceptions, for example in theory papers it could appear out of place.&lt;/p&gt;
&lt;h2&gt;5. Avoid the Passive Voice&lt;/h2&gt;
&lt;p&gt;You can write clear English in both the active and passive voice.
A historical note on this is available in &lt;a href="http://www.biomedicaleditor.com/active-voice.html"&gt;this essay on active vs passive
voice in scientific
writing&lt;/a&gt;:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;"More than a century ago, scientists typically wrote in an active style that
included the first-person pronouns I and we. Beginning in about the 1920s,
however, these pronouns became less common as scientists adopted a passive
writing style.&lt;/p&gt;
&lt;p&gt;Considered to be objective, impersonal, and well suited to science writing,
the passive voice became the standard style for medical and scientific
journal publications for decades.&lt;/p&gt;
&lt;p&gt;...&lt;/p&gt;
&lt;p&gt;Nowadays, most medical and scientific style manuals support the active over
the passive voice."&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;The reason for this change is simple: most people find text written in the
active voice easier to read and more engaging.
Duke university published a guide on scientific writing that contains a &lt;a href="https://cgi.duke.edu/web/sciwriting/index.php?action=passive_voice"&gt;long
discussion on the active versus passive
voice&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;In my writing there are very few exceptions were a passive voice may be more
appropriate, for example when discussing prior work ("The relationship between
iron intake and lifespan of parrots was studied by Miller and Smith.")
or when discussing experimental results ("The test error remained small even
when the regularization strength was decreased."), but even for these two
examples we can find an alternative active formulation ("Miller and Smith
studied the relationship between iron intake and lifespan of parrots.") and
("Even when we decreased the regularization strength the test error remained
small.").
The use of the passive voice in these two exceptions conveys an impersonal
attitude that may be justified when discussing the work of others or reporting
(as opposed to interpreting) experimental results.&lt;/p&gt;
&lt;p&gt;Here is a real example from a &lt;a href="http://www.nowozin.net/sebastian/papers/nowozin2007actionclassification.pdf"&gt;ICCV 2007 paper&lt;/a&gt;
of mine (page 4):&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;The  dual problem has a limited number of variables,
but a huge number of constraints.  Such a linear program
&lt;em&gt;can be solved&lt;/em&gt; efficiently by the constraint generation
technique: Starting with an empty hypothesis set, the hypothesis whose
constraint (6) &lt;em&gt;is violated&lt;/em&gt; the most is identified and &lt;em&gt;added&lt;/em&gt; iteratively.
Each time a hypothesis &lt;em&gt;is added&lt;/em&gt;, the optimal solution &lt;em&gt;is updated&lt;/em&gt;
by solving the restricted dual problem.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;I highlight all the passive formulations.
Here is a rewrite of the paragraph using only the active voice:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;The dual problem has a limited number of variables,
but a huge number of constraints.
&lt;em&gt;We can solve&lt;/em&gt; such a linear program efficiently by the constraint generation
technique: Starting with an empty hypothesis set,
&lt;em&gt;we identify the hypothesis with the largest constraint violation in (6)&lt;/em&gt;
and &lt;em&gt;add the hypothesis to the hypothesis set&lt;/em&gt;.
Each time &lt;em&gt;we add&lt;/em&gt; a hypothesis, &lt;em&gt;we also update&lt;/em&gt; the optimal solution by
solving the restricted dual problem.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;I made a few minor changes such as changing the word order and adding the noun
("to the hypothesis set") for added clarity.  I hope you agree that the second
version is easier to read.&lt;/p&gt;
&lt;p&gt;The &lt;a href="https://www.nowozin.net/sebastian/blog/ten-tips-for-writing-cs-papers-part-2.html"&gt;next part&lt;/a&gt; is available now.&lt;/p&gt;</content><category term="Computer Science"/></entry><entry><title>History of Monte Carlo Methods - Part 3</title><link href="https://www.nowozin.net/sebastian/blog/history-of-monte-carlo-methods-part-3.html" rel="alternate"/><published>2015-11-13T21:30:00+00:00</published><updated>2015-11-13T21:30:00+00:00</updated><author><name>Sebastian Nowozin</name></author><id>tag:www.nowozin.net,2015-11-13:/sebastian/blog/history-of-monte-carlo-methods-part-3.html</id><summary type="html">&lt;p&gt;This is the third part of a three part post.
The &lt;a href="https://www.nowozin.net/sebastian/blog/history-of-monte-carlo-methods-part-1.html"&gt;first part&lt;/a&gt; covered the early history of Monte
Carlo and the rejection sampling method, the &lt;a href="https://www.nowozin.net/sebastian/blog/history-of-monte-carlo-methods-part-2.html"&gt;second
part&lt;/a&gt; covered sequential Monte Carlo.&lt;/p&gt;
&lt;h1&gt;Part 3&lt;/h1&gt;
&lt;p&gt;In this part we are going to look at Markov chain Monte Carlo.&lt;/p&gt;
&lt;p&gt;The video files …&lt;/p&gt;</summary><content type="html">&lt;p&gt;This is the third part of a three part post.
The &lt;a href="https://www.nowozin.net/sebastian/blog/history-of-monte-carlo-methods-part-1.html"&gt;first part&lt;/a&gt; covered the early history of Monte
Carlo and the rejection sampling method, the &lt;a href="https://www.nowozin.net/sebastian/blog/history-of-monte-carlo-methods-part-2.html"&gt;second
part&lt;/a&gt; covered sequential Monte Carlo.&lt;/p&gt;
&lt;h1&gt;Part 3&lt;/h1&gt;
&lt;p&gt;In this part we are going to look at Markov chain Monte Carlo.&lt;/p&gt;
&lt;p&gt;The video files &lt;a href="https://1drv.ms/u/s!AniEhJbTwIdrkuMvpGcjY3NR12xbuw?e=YvUIAn"&gt;are also available for offline
viewing&lt;/a&gt; in
MP4/H.264, WebM/VP8, and WebM/VP9 formats.&lt;/p&gt;
&lt;video width="639" controls&gt;
&lt;source src="https://onedrive.live.com/download?cid=6B87C0D396848478&amp;resid=6B87C0D396848478%21307640&amp;authkey=ALXIUk3FhLZCBFU"
    type="video/mp4"&gt;
Your browser does not support the video tag.
&lt;/video&gt;

&lt;p&gt;&lt;iframe
src="https://onedrive.live.com/embed?cid=6B87C0D396848478&amp;resid=6B87C0D396848478%21108438&amp;authkey=AD-c_aaKMW9BSFI&amp;em=2"
width="639" height="360" frameborder="0" scrolling="no"&gt;&lt;/iframe&gt;
&lt;/p&gt;
&lt;p&gt;(Click on the slide to advance, or use the previous/next buttons.)&lt;/p&gt;
&lt;p&gt;(Also note there are three additional video visualization below.)&lt;/p&gt;
&lt;h2&gt;Transcript&lt;/h2&gt;
&lt;p&gt;(This is a slightly edited and link-annotated transcript of the audio in the
above video.  As this is spoken text, it is not as polished as my writing.)&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Speaker&lt;/strong&gt;: So this was one of family of Monte Carlo methods. I have too few
time remaining but a little bit of time to talk about a completely different
family of Monte Carlo methods and you may have heard this abbreviation before.
It is called MCMC.&lt;/p&gt;
&lt;p&gt;MCMC stands for Markov chain Monte Carlo and it is completely different from
&lt;a href="http://statweb.stanford.edu/~owen/mc/Ch-var-is.pdf"&gt;importance sampling&lt;/a&gt;.
The basic difference is instead of growing a configuration or weighting
configurations, I always have a certain state and I manipulate that state
iteratively, and if I do this long enough then I have obtained a sample that
is uniformly distributed. I will get into the details in a minute. I first
want to talk briefly about the history.&lt;/p&gt;
&lt;p&gt;It was invented by &lt;a href="https://en.wikipedia.org/wiki/Marshall_Rosenbluth"&gt;Marshall
Rosenbluth&lt;/a&gt; but it is
called the Metropolis algorithm. Why is that? Well, there were five authors on
the paper. The first of which was Nicholas Metropolis. And I roughly sized the
pictures according to contributions to the paper.&lt;/p&gt;
&lt;p&gt;There are two different historical accounts of how the method came about and
they agree on that &lt;a href="https://en.wikipedia.org/wiki/Edward_Teller"&gt;Edward
Teller&lt;/a&gt; posed the mathematical
problem, and Marshall Rosenbluth solved it, and Arianna Rosenbluth implemented
it, and the other two authors did not do anything.  They ordered the author
names alphabetically and &lt;a href="https://en.wikipedia.org/wiki/Nicholas_Metropolis"&gt;Nicholas
Metropolis&lt;/a&gt; happened to be
head of the group at that time. In any case, two interesting things about it,
all of these authors did not use the method in their following research. Also
the method is now very, very popular.  Actually, Marshall Rosenbluth
afterwards founded the field of plasma physics, so he completely went into a
different direction. At the turn of the 21st century, Jack Dongarra and
Francis Sullivan, two researchers in scientific computing, were asking to
compile a &lt;a href="https://www.siam.org/pdf/news/637.pdf"&gt;list of the top 10 algorithms of the 20th
century&lt;/a&gt; and this was one
of them in their list. And quicksort was another one.  So it is really an
important algorithm. First, the intuition, then a little bit formalization and
how it applies to our problem.&lt;/p&gt;
&lt;p&gt;So, here is the intuition. What the method does: it constructs a directed
graph where each possible state is a node, and there are simple modifications
you can make indicated by these directed arcs to transform one state into
another state. For example, in our chain case, we could bend the chain at a
certain node or we could maybe change the last state a little bit or
something. Some simple transformations you can perform to transform one state
into another state. Only a few for each state, only a few arcs that leave each
state. And then it performs a random walk on this graph in such a way that if
you perform the random walk long enough and then stop it, you are uniformly
distributed across the whole graph, or according to some target probability
distribution.&lt;/p&gt;
&lt;p&gt;The graph is much too large to explicit construct, right? It has exponentially
many configurations on our case, but it still it is able to perform a random
walk on this graph. It is called Markov chain Monte Carlo because the basic
concept is a &lt;a href="https://en.wikipedia.org/wiki/Markov_chain"&gt;Markov chain&lt;/a&gt; and I
want to quickly introduce that concept to you.  So here is a simple graph with
just three states, &lt;em&gt;A&lt;/em&gt;, &lt;em&gt;B&lt;/em&gt;, and &lt;em&gt;C&lt;/em&gt;. And imagine that you are standing at
State &lt;em&gt;B&lt;/em&gt; and you follow the very simple rule of sequentially walking along
that graph.  You see all the edges that leave your current state. They have
numbers associated to them and these numbers sum up to one. So if you stand on
State &lt;em&gt;B&lt;/em&gt;, you have a 40% probability to move to State &lt;em&gt;A&lt;/em&gt;, a 50% probability
to move to State &lt;em&gt;C&lt;/em&gt;, and a 10% probability to stay in State &lt;em&gt;B&lt;/em&gt;. So you just
follow that rule in each time step and you arrive at a new state.&lt;/p&gt;
&lt;p&gt;(This is the video I showed, which is not visible in the slides above.  The
video file is also available as &lt;a href="/sebastian/videos/MarkovChain1.mp4"&gt;MP4/H.264 file&lt;/a&gt; (1MB).)&lt;/p&gt;
&lt;video id="markovchain1" class="video-js vjs-default-skin"
    controls preload="auto"
    width="600" height="450" data-setup="{}"&gt;
&lt;source src="/sebastian/videos/MarkovChain1.mp4" type='video/mp4'&gt;
&lt;p class="vjs-no-js"&gt;
To view this video please enable JavaScript, and
consider upgrading to a web browser that
&lt;a href="http://videojs.com/html5-video-support/" target="_blank"&gt;supports HTML5 video&lt;/a&gt;
&lt;/p&gt;
&lt;/video&gt;

&lt;p&gt;And when you do that and you record how often you reach a certain
state, then this is a histogram you would obtain. So it seems to converge to
some values after just a few hundred steps. And in fact, the limit
distribution that you obtain ultimately is given by these numbers here. And it
does not depend where you start, but it is completely independent of where you
start.&lt;/p&gt;
&lt;p&gt;The Metropolis algorithm solves the inverse problem. The inverse problem is
the following. So here we had the rules how to walk and we just recalled that
the limit distribution. What if you have a graph structure and you have some
target probabilities that you want to realize? How should you put numbers at
the edges to reach that limiting distribution? That was the problem that was
posed by Edward Teller in essence.&lt;/p&gt;
&lt;p&gt;Here we have that target distribution and the Metropolis algorithm is a
constructive way to choose its transition probabilities. It assumes that you
have a base Markov chain, so some basic random walk on the graph. So let us
say, just uniformly go over all outgoing edges on that graph. And we could
follow that random walk, right? It would not be the same limit distribution
that we are interested in but we could follow that random walk and we would
get a different limit distribution. And what it now does is whenever we
transition from one state to the other, in addition, modulates that decision
and has the option to reject that step. It can only accept or reject steps
proposed by the base Markov chain. The final Markov chain of the Metropolis
algorithm is this chain &lt;span class="math"&gt;\(T\)&lt;/span&gt; which is the base Markov chain multiplied with its
acceptance rate. And the acceptance rate is calculated according to that
formula which has a quite simple interpretation.&lt;/p&gt;
&lt;p&gt;The acceptance probability is high when the target probability, &lt;span class="math"&gt;\(\pi_j\)&lt;/span&gt;, is
high but your current probability is low, when it's more likely to be in a
target state or vice versa, if it is unlikely, you are more likely to stay at
the current configuration. Or if the base chain pushes you to some other
state, you divide by that probability to compensate for that bias of the base
chain. So that is sort of the numerator and denominator have the two effects.
And the remaining probability, everything that is sort of modulated down, that
is the reject probability to stay in the current state.&lt;/p&gt;
&lt;p&gt;(This is the video I showed, which is not visible in the slides above.  The
video file is also available as &lt;a href="/sebastian/videos/MarkovChain2.mp4"&gt;MP4/H.264 file&lt;/a&gt; (1MB).)&lt;/p&gt;
&lt;video id="markovchain2" class="video-js vjs-default-skin"
    controls preload="auto"
    width="600" height="450" data-setup="{}"&gt;
&lt;source src="/sebastian/videos/MarkovChain2.mp4" type='video/mp4'&gt;
&lt;p class="vjs-no-js"&gt;
To view this video please enable JavaScript, and
consider upgrading to a web browser that
&lt;a href="http://videojs.com/html5-video-support/" target="_blank"&gt;supports HTML5 video&lt;/a&gt;
&lt;/p&gt;
&lt;/video&gt;

&lt;p&gt;So let us do that simple calculation for our example here. For that limit
distribution, we would obtain that values. And let us take a look at whether
we converge to that limiting distribution. So the limiting distribution was
0.7, 0.1, 0.2, it converges slower than in the example before, but ultimately,
we are guaranteed to converge to the limit distribution that we setup. It is
not a unique way to construct such a Markov chain but it is a constructive way
to do so.&lt;/p&gt;
&lt;p&gt;In our (self-avoiding random walk) example, we want to walk on this graph. And
what we are going to do is we just allow simple transformations, we pick a
random element on that chain and bend it 90 degrees in a random fashion. So
that gives us the arcs on that graph and you can imagine for a chain of a
certain length, there are only so many ways which you can enumerate to bending
the elements by 90 degrees. And if we happen to bend it in such a way that it
is actually no longer self-avoiding, we can remove that and add that back to
the probability of staying in a certain state. And remember we wanted to
sample uniformly overall the states on the graph. So we just plug that into
the acceptance rate calculation of the Metropolis algorithm and the &lt;span class="math"&gt;\(\pi\)&lt;/span&gt;,
because it is uniformly distributed, just cancels out of that rate. So it is a
very simple calculation.&lt;/p&gt;
&lt;p&gt;And in practice, it is even simpler to implement that. We have a certain
state. We just initialize it with any state we want. We propose a random
modification and we accept or reject that, and then we have a new state, and
we iterate, we accept or reject that. So we keep doing that and after a
certain amount of time, we just keep the number of samples that we have
generated and we can compute our expectations with that sample that we have
generated. They are no longer independent samples because we have always
modified them a little bit but they are a set of samples that we have
generated. And this is the estimate, again, same curve that we had before,
this time, with the MCMC approach. And I am almost out time but I want to take
the last three slides here to show you our last method, the final method of
the talk. Any questions on MCMC so far?&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Attendee&lt;/strong&gt;: If we said we accept or reject. We make a bend and we accept
them. How do you decide whether to accept or reject, just whether it crosses
itself.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Speaker&lt;/strong&gt;: If it crosses itself, it is no longer a valid state, and we
immediately reject. If it does not cross itself, you compute the acceptance
probability by that formula and the acceptance probability maybe 0.8, and then
you roll a random number between zero and one, uniformly distributed, and if
that number is below the acceptance rate, then you &lt;em&gt;accept&lt;/em&gt;. If it is above the
acceptance rate that you have calculated, you &lt;em&gt;reject&lt;/em&gt;. So if the acceptance
rate is one, you always accept. If the acceptance rate is 0.5, you flip a coin
uniformly to accept or reject.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Attendee&lt;/strong&gt;: How would I calculate the acceptance rate in the self-avoiding
random walk problem?&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Speaker&lt;/strong&gt;: That depends on this graph structure here. So every state in the
graph has a certain set of allowed changes, right? For some state which is
very compact in number of allowed changes becomes smaller. For some longer
chain, you can basically bend it at any element, in any direction and it would
still be a self-avoiding work.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Attendee&lt;/strong&gt;: We have to check them all to count how many were
self-intersecting?&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Speaker&lt;/strong&gt;: Yes, in some case you can remove it, I mean, not in this case. In
some cases, you always have a probability mass everywhere and then not like a
hard constraint like self-avoiding, then it cancels out as well. But in this
case, we have to enumerate all of them.&lt;/p&gt;
&lt;p&gt;(A warning in this edit: I cannot recommend learning about the simulated
annealing by browsing the web as there is lots of misinformation around or
special cases are described as simulated annealing, or the base Markov chain
is not a reversible Markov chain, etc.  See the references at the end of this
transcript for good links if you want to learn about the method.)&lt;/p&gt;
&lt;p&gt;The final method is called &lt;em&gt;Simulated Annealing&lt;/em&gt;.
It is a method to convert a Markov chain into an optimization method. As
simple as that, a Markov chain into an optimization method. It was proposed in
1983 by &lt;a href="http://www.cs.huji.ac.il/~kirk/"&gt;Scott Kirkpatrick&lt;/a&gt; and co-workers
and it is a very simple and often quite effective optimization method. And
simple to implement. It can optimize over complex state spaces. And for that
reason, it is very popular. So this
&lt;a href="http://www.csb.pitt.edu/BBSI/2006/jc_talk/cheng.pdf"&gt;Science paper that they published in
1983&lt;/a&gt; has 28,000
citations (now 35,000, October 2015). And interestingly, Scott Kirkpatrick
later in the '90s worked at the IBM T.J.  Watson Research Center and there, at
least he writes this, he invented the first pen-based tablet computer. So it
is nice to see that he is innovative on quite different levels.&lt;/p&gt;
&lt;p&gt;So how does it work? Say we have a function that we want to optimize. A very
simple function here. There are only 40 possible inputs to that function. So
in that case, we could simply enumerate all the 40 possible states and pick
the one that is maximal, so we want to maximize that function. But imagine you
have a different problem with exponentially many states so we can no longer
list them and this is just for illustration. But imagine instead of 40, you
would have 2 to the power of 40 or something. What we are going to do is we
convert that function into a probability distribution and we do that by what
is called a Gibbs distribution. So just a simple formula, where &lt;span class="math"&gt;\(Z\)&lt;/span&gt; is a
normalizing constant and the formula depends on the parameter &lt;span class="math"&gt;\(T\)&lt;/span&gt;, the so called
temperature parameter. If the temperature parameter is very high, you divide
that function value by a very large value and the argument almost does not
matter. So the function value does not matter. In this case, the temperature
is 100 and you see that the resulting distribution is almost uniform. Maybe
hard to see but it is almost uniform because the temperature is quite high
compared to the function value.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Attendee&lt;/strong&gt;: What is &lt;span class="math"&gt;\(Z\)&lt;/span&gt;?&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Speaker&lt;/strong&gt;: &lt;span class="math"&gt;\(Z\)&lt;/span&gt; is a normalizing constant. So it is just a sum over all the
possible configurations. But it is a constant and it just depends on &lt;span class="math"&gt;\(T\)&lt;/span&gt;. And
interestingly, if we apply this Metropolis algorithm, the &lt;span class="math"&gt;\(Z\)&lt;/span&gt; constant cancels
out, it is not really important. You do not even need to write it down. You
can just write &lt;span class="math"&gt;\(P\)&lt;/span&gt; is proportional to &lt;span class="math"&gt;\(X\)&lt;/span&gt;, (&lt;span class="math"&gt;\(P \propto X\)&lt;/span&gt;) or something, the
constant is just a normalizing constant. If I decrease the temperature, you
see, so this is temperature 10, temperature 4, 1, and now I decrease it even
further, 0.1, the distribution puts more and more mass on the function values
that are higher; and basically, what the simulated annealing does it runs a
Markov chain, a Metropolis chain, for example. But, while it runs it, it
modifies it by decreasing the temperature.&lt;/p&gt;
&lt;p&gt;So it tries to shift all the probability mass in our current state as well to
the states that have high function value. And how it does it, well, it chooses
its schedule, a temperature schedule so on the x-axis here I have the steps
that I take with the Markov chain and on the y-axis I have the temperature
that I use, and I just decrease the temperature here, a geometric schedule so
I just modify the temperature on each step with 0.99 or something.&lt;/p&gt;
&lt;p&gt;For very high temperatures, the Markov chain is basically just a purely random
walk; it does not even look at the function value. For very low temperatures,
it basically is a local search algorithm; it only accepts improvements in the
function value. But, for intermediate temperature values, it is something in
between so it tries to optimize but it can still escape local minima.&lt;/p&gt;
&lt;p&gt;So that is intuition. There's some theory to it actually, in another famous
paper by &lt;a href="http://www.dam.brown.edu/people/geman/"&gt;Stuart&lt;/a&gt; and &lt;a href="http://cis.jhu.edu/people/faculty/geman/"&gt;Don Geman&lt;/a&gt;, a &lt;a href="http://www.csee.wvu.edu/~xinl/library/papers/infor/Geman_Geman.pdf"&gt;1984 paper&lt;/a&gt; which is actually famous for a
different reason because they proposed another famous Monte Carlo method they
&lt;a href="https://en.wikipedia.org/wiki/Gibbs_sampling"&gt;Gibbs sampler&lt;/a&gt; in that paper
but in that very paper they also have some theory of simulated annealing and
they prove that if you decrease the temperature slow enough the probability is
one to obtain the optimal state.  But that optimal schedule is too slow in
practice so you cannot use it and that is why we are still stuck with the
geometric schedule.&lt;/p&gt;
&lt;p&gt;Last minute, let us do simulated annealing and I go back to the more
complicated model where we actually have this two types of elements: the black
ones that attract each other and the white ones which are neutral. And you see
here I plotted whenever two black elements are close to each other on this 2-D
grid; I plotted a red line, and I am going to try to optimize the number of
red lines so I try to get as many red connections as possible.&lt;/p&gt;
&lt;p&gt;(This is the video I showed, which is not visible in the slides above.  The
video file is also available as &lt;a href="/sebastian/videos/SimulatedAnnealing-HP2D-48.mp4"&gt;MP4/H.264 file&lt;/a&gt; (5MB).)&lt;/p&gt;
&lt;video id="simulatedannealing" class="video-js vjs-default-skin"
    controls preload="auto"
    width="600" height="450" data-setup="{}"&gt;
&lt;source src="/sebastian/videos/SimulatedAnnealing-HP2D-48.mp4" type='video/mp4'&gt;
&lt;p class="vjs-no-js"&gt;
To view this video please enable JavaScript, and
consider upgrading to a web browser that
&lt;a href="http://videojs.com/html5-video-support/" target="_blank"&gt;supports HTML5 video&lt;/a&gt;
&lt;/p&gt;
&lt;/video&gt;

&lt;p&gt;And that is really a model for protein folding, folding in such a way that
there are many black to black noncovalent bonds. So here, is an animation of
performing simulated annealing exactly with that proposal that I had, bending
it at 90 degrees left or right at a random position and, I do 100,000 steps
and I show you every 100th step. At high temperatures, this is quite high
temperatures still you see it is very stretched out, there are not very many
compact structures but as the optimization proceeds the temperature decreases
and it favors more and more compact configuration. So I think already at a
step of, like now, you would see already quite some compact structures
appearing.&lt;/p&gt;
&lt;p&gt;So this is a purely random walk. I think it goes until 1,000. I can skip it in
the interest of time but, I can show you the result. This is the configuration
that we have obtained with 100,000 steps in our Markov chain in simulated
annealing and for that model problem there is a paper that analyzes different
model problems and the optimal configuration is known, the ground state is
known and the ground state is slightly better. It has 23 connections. We only
have 21 but actually, with such a simple method we have obtained a quite good
solution and that is really the essence of why simulated annealing is popular.&lt;/p&gt;
&lt;p&gt;We can often get quite far with allegedly fewer effort both in implementation
and runtime. Although, there may be a better method in a specific domain, that
is optimized for that. And let us reflect a little bit on what we did. We have
solved a rather complicated problem like folding this 2D protein with a very,
very simple method with just a random walk that accepts or rejects simple
modifications.&lt;/p&gt;
&lt;p&gt;And that is basically it. Before I have my last slide, I just want to say a
little bit about the literature if you are interested in the Monte Carlo
Methods I can highly recommend the first book and if you are interested in the
black and white pictures I showed of the people that are relevant to the
invention of the Monte Carlo method I can recommend the last book which is the
autobiography of Stanislaw Ulam, it is very interesting.&lt;/p&gt;
&lt;p&gt;So, thank you very much for your attention.&lt;/p&gt;
&lt;h2&gt;References&lt;/h2&gt;
&lt;p&gt;Here are some of the introductionary book references mentioned in the talk.&lt;/p&gt;
&lt;p&gt;The historical context and anecdotes are mostly from the autobiography of Stan
Ulam,
&lt;a href="http://www.ucpress.edu/book.php?isbn=9780520071544"&gt;Adventures of a
Mathematician&lt;/a&gt;.
The book is accessible to anyone with a basic high school math background.
See also this &lt;a href="http://projecteuclid.org/euclid.bams/1183540384"&gt;kind 1978 review of the
book&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;A great, now somewhat dated introduction to Monte Carlo methods is &lt;a href="http://www.people.fas.harvard.edu/~junliu/"&gt;Jun
Liu&lt;/a&gt;'s &lt;a href="http://www.springer.com/us/book/9780387763699"&gt;Monte Carlo Strategies in
Scientific Computing&lt;/a&gt;.  I
learned Monte Carlo through this book and it has a spot in my bookshelf that
is at arm-length from my desk.&lt;/p&gt;
&lt;p&gt;The Liu book is somewhat dated and it covers a lot of ground; a slightly more
formal but up-to-date Monte Carlo book is
&lt;a href="http://statweb.stanford.edu/~owen/"&gt;Art Owen&lt;/a&gt;'s upcoming book &lt;a href="http://statweb.stanford.edu/~owen/mc/"&gt;Monte Carlo
theory, methods and examples&lt;/a&gt;, which is
excellent.&lt;/p&gt;
&lt;p&gt;A highly accessible and very well written introduction to Markov chains and
simple Monte Carlo methods is
&lt;a href="http://www.math.chalmers.se/~olleh/"&gt;Olle H&amp;auml;ggstr&amp;ouml;m&lt;/a&gt;'s
&lt;a href="http://www.cambridge.org/catalogue/catalogue.asp?isbn=0521813573"&gt;Finite Markov Chains and Algorithmic Applications&lt;/a&gt;.
I recommend it if you want a most gentle introduction to the theory behind
MCMC.
Still the most authoritative reference on MCMC is the
&lt;a href="http://www.mcmchandbook.net/HandbookTableofContents.html"&gt;Handbook of Markov Chain Monte Carlo&lt;/a&gt;.
In particular, the first twelve chapters cover are on general methodology and
contain a wealth of information not found in other textbooks.&lt;/p&gt;
&lt;script type="text/javascript"&gt;if (!document.getElementById('mathjaxscript_pelican_#%@#$@#')) {
    var align = "center",
        indent = "0em",
        linebreak = "false";

    if (false) {
        align = (screen.width &lt; 768) ? "left" : align;
        indent = (screen.width &lt; 768) ? "0em" : indent;
        linebreak = (screen.width &lt; 768) ? 'true' : linebreak;
    }

    var mathjaxscript = document.createElement('script');
    mathjaxscript.id = 'mathjaxscript_pelican_#%@#$@#';
    mathjaxscript.type = 'text/javascript';
    mathjaxscript.src = 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.3/latest.js?config=TeX-AMS-MML_HTMLorMML';

    var configscript = document.createElement('script');
    configscript.type = 'text/x-mathjax-config';
    configscript[(window.opera ? "innerHTML" : "text")] =
        "MathJax.Hub.Config({" +
        "    config: ['MMLorHTML.js']," +
        "    TeX: { extensions: ['AMSmath.js','AMSsymbols.js','noErrors.js','noUndefined.js'], equationNumbers: { autoNumber: 'none' } }," +
        "    jax: ['input/TeX','input/MathML','output/HTML-CSS']," +
        "    extensions: ['tex2jax.js','mml2jax.js','MathMenu.js','MathZoom.js']," +
        "    displayAlign: '"+ align +"'," +
        "    displayIndent: '"+ indent +"'," +
        "    showMathMenu: true," +
        "    messageStyle: 'normal'," +
        "    tex2jax: { " +
        "        inlineMath: [ ['\\\\(','\\\\)'] ], " +
        "        displayMath: [ ['$$','$$'] ]," +
        "        processEscapes: true," +
        "        preview: 'TeX'," +
        "    }, " +
        "    'HTML-CSS': { " +
        "        availableFonts: ['STIX', 'TeX']," +
        "        preferredFont: 'STIX'," +
        "        styles: { '.MathJax_Display, .MathJax .mo, .MathJax .mi, .MathJax .mn': {color: 'inherit ! important'} }," +
        "        linebreaks: { automatic: "+ linebreak +", width: '90% container' }," +
        "    }, " +
        "}); " +
        "if ('default' !== 'default') {" +
            "MathJax.Hub.Register.StartupHook('HTML-CSS Jax Ready',function () {" +
                "var VARIANT = MathJax.OutputJax['HTML-CSS'].FONTDATA.VARIANT;" +
                "VARIANT['normal'].fonts.unshift('MathJax_default');" +
                "VARIANT['bold'].fonts.unshift('MathJax_default-bold');" +
                "VARIANT['italic'].fonts.unshift('MathJax_default-italic');" +
                "VARIANT['-tex-mathit'].fonts.unshift('MathJax_default-italic');" +
            "});" +
            "MathJax.Hub.Register.StartupHook('SVG Jax Ready',function () {" +
                "var VARIANT = MathJax.OutputJax.SVG.FONTDATA.VARIANT;" +
                "VARIANT['normal'].fonts.unshift('MathJax_default');" +
                "VARIANT['bold'].fonts.unshift('MathJax_default-bold');" +
                "VARIANT['italic'].fonts.unshift('MathJax_default-italic');" +
                "VARIANT['-tex-mathit'].fonts.unshift('MathJax_default-italic');" +
            "});" +
        "}";

    (document.body || document.getElementsByTagName('head')[0]).appendChild(configscript);
    (document.body || document.getElementsByTagName('head')[0]).appendChild(mathjaxscript);
}
&lt;/script&gt;</content><category term="Statistics"/></entry><entry><title>History of Monte Carlo Methods - Part 2</title><link href="https://www.nowozin.net/sebastian/blog/history-of-monte-carlo-methods-part-2.html" rel="alternate"/><published>2015-10-30T20:00:00+00:00</published><updated>2015-10-30T20:00:00+00:00</updated><author><name>Sebastian Nowozin</name></author><id>tag:www.nowozin.net,2015-10-30:/sebastian/blog/history-of-monte-carlo-methods-part-2.html</id><summary type="html">&lt;p&gt;This is the second part of a three part post.
The &lt;a href="https://www.nowozin.net/sebastian/blog/history-of-monte-carlo-methods-part-1.html"&gt;last part&lt;/a&gt; covered the early history of Monte
Carlo and the rejection sampling method.&lt;/p&gt;
&lt;h1&gt;Part 2&lt;/h1&gt;
&lt;p&gt;In this part we are going to look at importance sampling and sequential Monte
Carlo.&lt;/p&gt;
&lt;p&gt;The video files &lt;a href="https://1drv.ms/u/s!AniEhJbTwIdrkuMvpGcjY3NR12xbuw?e=YvUIAn"&gt;are also available for offline …&lt;/a&gt;&lt;/p&gt;</summary><content type="html">&lt;p&gt;This is the second part of a three part post.
The &lt;a href="https://www.nowozin.net/sebastian/blog/history-of-monte-carlo-methods-part-1.html"&gt;last part&lt;/a&gt; covered the early history of Monte
Carlo and the rejection sampling method.&lt;/p&gt;
&lt;h1&gt;Part 2&lt;/h1&gt;
&lt;p&gt;In this part we are going to look at importance sampling and sequential Monte
Carlo.&lt;/p&gt;
&lt;p&gt;The video files &lt;a href="https://1drv.ms/u/s!AniEhJbTwIdrkuMvpGcjY3NR12xbuw?e=YvUIAn"&gt;are also available for offline
viewing&lt;/a&gt; in
MP4/H.264, WebM/VP8, and WebM/VP9 formats.&lt;/p&gt;
&lt;video width="639" controls&gt;
&lt;source src="https://onedrive.live.com/download?cid=6B87C0D396848478&amp;resid=6B87C0D396848478%21307637&amp;authkey=ACYR7JYwYI_xH54"
    type="video/mp4"&gt;
Your browser does not support the video tag.
&lt;/video&gt;

&lt;p&gt;&lt;iframe
src="https://onedrive.live.com/embed?cid=6B87C0D396848478&amp;resid=6B87C0D396848478%21108434&amp;authkey=AJ6I7fTgWMVe7s8&amp;em=2"
width="639" height="360" frameborder="0" scrolling="no"&gt;&lt;/iframe&gt;
&lt;/p&gt;
&lt;p&gt;(Click on the slide to advance, or use the previous/next buttons.)&lt;/p&gt;
&lt;h2&gt;Transcript&lt;/h2&gt;
&lt;p&gt;(This is a slightly edited and link-annotated transcript of the audio in the
above video.  As this is spoken text, it is not as polished as my writing.)&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Speaker&lt;/strong&gt;: Okay, so rejection sampling works only for short chain lengths.
And then, in light of this finding the next method, sequential importance
sampling, was introduced independently by two groups.
&lt;a href="https://en.wikipedia.org/wiki/John_Hammersley"&gt;John Michael Hammersley&lt;/a&gt;,
who actually did his PhD here in Cambridge and then moved to Oxford to become
professor, and by &lt;a href="https://en.wikipedia.org/wiki/Marshall_Rosenbluth"&gt;Marshall
Rosenbluth&lt;/a&gt; and his wife
Arianna Rosenbluth. They did it independently. They called it different by
different names. I think Hammersley called it &lt;em&gt;inversely restricted sampling&lt;/em&gt;
and the Rosenbluth called it &lt;em&gt;biased sampling&lt;/em&gt; and both these names did not
really stick. So now, nowadays it is called &lt;em&gt;sequential importance sampling&lt;/em&gt;.
In different communities, it is also called the &lt;em&gt;growth method&lt;/em&gt; or the
&lt;em&gt;Rosenbluth method&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;How does this method work? It is based on the idea that was suggested by the
audience just before (in the first part). Remember when we are growing these
chains step by step and we make the step and we would have to reject the
sample? Well, we could just prevent making that step, all right. We could just
say, "Look, there are two possibilities but you would not reject that sample.
So why not just take one of these?"&lt;/p&gt;
&lt;p&gt;Of course the method is not fail-safe. So if we, in such a situation, no
matter what we do if we keep growing we will still run into trouble.
Right, so the method is still myopic. We still only make one inference at a
time. But the real problem with this method is that we no longer sample
uniformly from the set that interest us. In fact, we favor more compact
configurations and what Hammersley, and Morton, and the Rosenbluth's realized
is a method to systematically compensate for that bias. &lt;/p&gt;
&lt;p&gt;So let me first talk about how this in general is done and then how it is done
in our specific example. So in general, we have this expectation expression
that we want to approximate. And what they said is, well, we assign one weight
to each sample and if the weight would be one that would be the original
expectation. But we assign a weight to the sample and we choose the weight in
such a way that we compensate for that bias, that we favor some
configurations. So whenever we favor these configurations, we down-weight
them, and whenever some configurations is rare but we generate them, we
up-weight them.&lt;/p&gt;
&lt;p&gt;In practice, we would generate a few samples and if every sample would have a
weight, in this particular instance how it works is, well we just count the
number of possibilities we have in each step. So we basically decompose a
sampling distribution. So in the first step we have four possibilities, four
points free adjacent to it and the next one we have only three available. And
so we just unroll basically our decisions. Here we only have two available,
two choices available, all right? So because we grow the chain sequentially,
the probability of generating that particular configuration also decomposes
sequentially.  So the final chain would have this probability of being
generated. And what they simply do is say, "Okay, this is the distribution by
which we generate the sample, but we want to generate it at uniformly at
random so we also decompose the weight and just build the weight as a
inverse". So when we weight these samples by weights we will systematically
de-bias the sampling distribution, so we will get unbiased estimates of the
expectation that we are interested in.&lt;/p&gt;
&lt;p&gt;Let us take a look at where we were with the rejection sampler. So this is a
limit, what we could do with a rejection sampler. Now, with the growth method,
we can go to significantly longer chain length, to a chain length of 60 and
then again, the uncertainty estimates the confidence intervals blow up. So why
is this? I mean why do we say uncertainty intervals blow up in this improved
method? Well the thing is, the weights that we compute, they become very
unbalanced. And even though we generate maybe a few thousand samples, only few
of them will have significant share of the weights.&lt;/p&gt;
&lt;p&gt;So here is a visualization of that. So here, I grow 50 chains in parallel, one
step at a time, and I show you in each step the normalized weights. So in the
beginning, everything is uniform because in the beginning, everything has
equal number of possibilities. But over time, as I grow more and more, as
append more elements, the weights become very unbalanced so that after 100
steps, actually five elements have weights significantly different from zero.
And this means we actually do not have 50 samples on this case, we only have
five, and our estimates become very poor. And this only amplifies when you
have a few thousands ones. One way to measure the quality of the samples we
have generated is to ask, "Okay, I have generated, say 5,000 samples with
weights. How much are these worth in terms of computing expectations, in terms
of unweighted samples?"&lt;/p&gt;
&lt;p&gt;Because unweighted samples are optimal there is a quality measure that you can
compute that is an estimated quantity and it is called &lt;a href="http://www.nowozin.net/sebastian/blog/effective-sample-size-in-importance-sampling.html"&gt;effective sample
size&lt;/a&gt;,
which exactly measures the worthiness of a weighted sample set. And for this
plot I have shown you now with 5,000 samples, you see that it drops and drops
and drops until it is almost close to one. So that is a real problem.&lt;/p&gt;
&lt;p&gt;You guessed the next step would be another improved Monte Carlo method and
indeed it improves on that, and it is generally known as
&lt;a href="http://www.stats.ox.ac.uk/~doucet/doucet_defreitas_gordon_smcbookintro.pdf"&gt;&lt;em&gt;Sequential Monte Carlo Method&lt;/em&gt;&lt;/a&gt;.
The idea is quite simple and natural and it has been reinvented
many times in different communities. So the &lt;a href="http://scitation.aip.org/content/aip/journal/jcp/30/3/10.1063/1.1730021"&gt;original
paper&lt;/a&gt;
is from 1959 but has been reinvented in the signal processing community as
&lt;a href="https://en.wikipedia.org/wiki/Particle_filter"&gt;particle filter&lt;/a&gt;, it
has been reused and pioneered in computer vision by our Andrew Blake for
tracking objects and their contours. And it is used across many different
communities often under very different names. But generally, Sequential Monte
Carlo is the preferred name. And the basic idea here is quite simple. The
problem is unbalanced weights. We have to prevent getting unbalanced weights
in each step. So how we are going to do this is by introducing a process which
removes samples that have low weight and duplicate samples that have high
weight. That is called re-sampling.&lt;/p&gt;
&lt;p&gt;So say, in one certain timestamp, we grow all the chains in parallel, we grow
say 50 chains in parallel. On this example, it is only six chains in parallel.
And we have observed that the weights are unbalanced. Then remove some of the
low weight instances and we duplicate some of the high weight instances as
shown here. The algorithm that corresponds to that is the same as before just
weighted sequential importance sampling but we grow all the samples in
parallel and monitor the weights. And if the weights are in trouble, if the
weights become unbalanced, we enforce balanced weights again, by removing low
weight samples and duplicating other.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Attendee&lt;/strong&gt;: Question.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Speaker&lt;/strong&gt;: Yes.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Attendee&lt;/strong&gt;: In your little white chain example, the weights are going to be
high when at every step you can take three choices, right? Like three times
three times three. And that is going to get bigger. The long ones do not go
near each other. So this is going to bias in favor of things that just sort of
go off into the distance, all of them curly wurly things, is that right?&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Speaker&lt;/strong&gt;: Right, exactly, because the sampling distribution biases towards
compact configurations the weights have to undo that bias by favoring the
configurations that walk off and are no longer compact.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Attendee&lt;/strong&gt;: But isn't that bad because then essentially we'll you dominated by
all the ones that go off into the distance and we won't get any curly wurly
ones.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Speaker&lt;/strong&gt;: It would be bad but remember that the sampling distribution that
I had above the weight, the sampling distribution exactly has that opposing
bias. So we generate from that distribution and we want the weights to
compensate for that bias. So the extra samples that we get are more compact
than they should be. And that is why we have to downweight these to get a low
weight, right? And we have to upweight these samples that are not compact but
that go out into basically long chains.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Attendee&lt;/strong&gt;: I did not get that, sorry. But never mind. I believe you.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Speaker&lt;/strong&gt;: Okay. So if you do that re-sampling operation to compensate for
the unbalanced weight effect, and I plot again the effective sample size and
whenever we see that the effective sample size, in this case drops below
2,500, I perform this re-sampling operation and reset the weights to uniform
and I enforce this effective sample size to become 5,000 again. You see that
basically, I can control how unbalanced the weights become. Here is another
visualization in terms of the same plot that I had before and now with the red
arrows are indicated whenever I reset the weights to uniform, I perform his
re-sampling operation so I always can ensure that my weights are close to the
uniform distribution.&lt;/p&gt;
&lt;p&gt;So let us compare that again. This was a plot without re-sampling. You will
see that the uncertainty estimates indicate that our estimates are very
unreliable. And this is basically with re-sampling. The whole family of
Sequential Monte Carlo approaches are really state of the art methods. This
scales to almost no limits, so people have used generate chains with over a
million bonds. It is state of the art for any kind of probabilistic model
where you can sequentially decompose the model. For example, time series
models, hidden Markov models, state space models, dynamic Bayesian networks,
all these kind of models, these methods are applicable and highly efficient.&lt;/p&gt;</content><category term="Statistics"/></entry><entry><title>History of Monte Carlo Methods - Part 1</title><link href="https://www.nowozin.net/sebastian/blog/history-of-monte-carlo-methods-part-1.html" rel="alternate"/><published>2015-10-16T21:30:00+01:00</published><updated>2015-10-16T21:30:00+01:00</updated><author><name>Sebastian Nowozin</name></author><id>tag:www.nowozin.net,2015-10-16:/sebastian/blog/history-of-monte-carlo-methods-part-1.html</id><summary type="html">&lt;p&gt;Some time ago in June 2013 I gave a &lt;em&gt;lab tutorial&lt;/em&gt; on Monte Carlo methods at
Microsoft Research.  These tutorials are seminar-talk length (45 minutes) but
are supposed to be light, accessible to a general computer science audience,
and fun.&lt;/p&gt;
&lt;p&gt;In this tutorial I explain and illustrate a number of …&lt;/p&gt;</summary><content type="html">&lt;p&gt;Some time ago in June 2013 I gave a &lt;em&gt;lab tutorial&lt;/em&gt; on Monte Carlo methods at
Microsoft Research.  These tutorials are seminar-talk length (45 minutes) but
are supposed to be light, accessible to a general computer science audience,
and fun.&lt;/p&gt;
&lt;p&gt;In this tutorial I explain and illustrate a number of Monte Carlo methods
(rejection sampling, importance sampling, sequential Monte Carlo, Markov chain
Monte Carlo, and simulated annealing) on the same problem.
Although I am not exactly a comedian, in order to keep the tutorial fun I
peppered the talk with lots of historical anecdotes from the inventors of the
methods.&lt;/p&gt;
&lt;p&gt;This is the first of three parts.&lt;/p&gt;
&lt;h1&gt;Part 1&lt;/h1&gt;
&lt;p&gt;The first part (17 minutes) covers the history of modern Monte Carlo methods,
their use in scientific computation, and one of the most basic Monte Carlo
methods, &lt;em&gt;rejection sampling&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;The video files &lt;a href="https://1drv.ms/u/s!AniEhJbTwIdrkuMvpGcjY3NR12xbuw?e=YvUIAn"&gt;are also available for offline
viewing&lt;/a&gt; in
MP4/H.264, WebM/VP8, and WebM/VP9 formats.&lt;/p&gt;
&lt;video width="639" controls&gt;
&lt;source src="https://onedrive.live.com/download?cid=6B87C0D396848478&amp;resid=6B87C0D396848478%21307634&amp;authkey=AN2p0blkF_SVk2g"
    type="video/mp4"&gt;
Your browser does not support the video tag.
&lt;/video&gt;

&lt;p&gt;&lt;iframe
src="https://onedrive.live.com/embed?cid=6B87C0D396848478&amp;resid=6B87C0D396848478%21108435&amp;authkey=AHiRYMuM9wBIKos&amp;em=2"
width="639" height="360" frameborder="0" scrolling="no"&gt;&lt;/iframe&gt;
&lt;/p&gt;
&lt;p&gt;(Click on the slide to advance, or use the previous/next buttons.)&lt;/p&gt;
&lt;h2&gt;Transcript&lt;/h2&gt;
&lt;p&gt;(This is a slightly edited and link-annotated transcript of the audio in the
above video.  As this is spoken text, it is not as polished as my writing.)&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Speaker&lt;/strong&gt;: Thank you all for coming to this lab tutorial. I know many of you
have used Monte Carlo techniques in your research or in your projects. And
still I decide to keep the level of this tutorial very basic and I try to show
you a few different Monte Carlo methods and how they may be useful in your
research.  I hope that after the talk you basically understand how these
methods can be applied and what different limitations the different methods
have. And I will introduce these different methods in chronological order and
also say a little about the interesting history, how these methods have been
invented.&lt;/p&gt;
&lt;p&gt;But before I get to that, I first want to ask you, do you like to play
solitaire? I certainly do sometimes play solitaire and when you play a couple
of games, you realize that some games are actually not solvable. So some games
are just, no matter what you try, no matter what you do, they are just
provably not solvable. And so if you shuffle a random deck of 52 cards and put
it out as a solitaire deck, it's a valid question to ask is what probability
do you get a solvable game? That's the question. And it's precisely this
question, precisely this question for the game of &lt;a href="https://en.wikipedia.org/wiki/Canfield_%28solitaire%29"&gt;Canfield
Solitaire&lt;/a&gt; that has
led to the invention of the modern Monte Carlo methods.&lt;/p&gt;
&lt;p&gt;One way to attack this problem would be instead of trying analytic or
mathematical approaches, basically having to take into account all the rules
of the game, is to just take a random set of cards, play a hundred times after
randomly shuffling the cards and just looking at how many times you come up
with a solvable game. And that would give you a ballpark estimate on the
probability. And that's precisely what this man, &lt;a href="https://en.wikipedia.org/wiki/Stanislaw_Ulam"&gt;Stanislaw
Ulam&lt;/a&gt;, has
recognized, that this is possible.&lt;/p&gt;
&lt;p&gt;I want to say a few words about Stanislaw Ulam because he's so crucial to the
invention of Monte Carlo methods. So he was born in today's Ukraine in a town
called &lt;a href="https://en.wikipedia.org/wiki/Lviv"&gt;Lviv&lt;/a&gt; (formerly Lemberg,
in Austria-Hungary). And he was enjoying a very good education. His family had
a good background. And he very early discovered in his life that he likes to
do mathematics. He was part of the &lt;a href="https://en.wikipedia.org/wiki/Lw%C3%B3w_School_of_Mathematics"&gt;Lviv School of
Mathematics&lt;/a&gt;
who has done many contribution to the more abstract mathematics, vector
spaces. So he's known for some of the mathematical results. But then he had to
flee to the United States in the 1930s and there became professor in
Mathematics and was recruited to &lt;a href="http://www.atomicheritage.org/history/hydrogen-bomb-1950"&gt;Los
Alamos&lt;/a&gt; to do
research on the Hydrogen bomb. Not the first nuclear weapon but on the second
Hydrogen bomb design.&lt;/p&gt;
&lt;p&gt;During that time in 1946, working at Los Alamos, he had a breakdown. For
couple of days he had a headache and he had a breakdown and was delivered to a
hospital. The doctors performed an &lt;a href="https://en.wikipedia.org/wiki/Encephalitis"&gt;emergency
surgery&lt;/a&gt;, removed part of his
skull, because it turned out he had a brain infection, the brain has swollen
and he would have died if the doctors didn't perform his operation. And the
doctors told him "You have to recover, you have to stay at home for half a
year and don't do any mathematics."&lt;/p&gt;
&lt;p&gt;He was obsessed with Mathematics for his whole life. So instead of doing
mathematics, he tried to pass the time playing Canfield Solitaire. And while
playing Canfield Solitaire he asked the question, "&lt;a href="https://en.wikipedia.org/wiki/Canfield_%28solitaire%29#Solvability"&gt;Okay, what's probability to
solve this
game?&lt;/a&gt;"
and with his quite broad knowledge of Mathematics he tried a few different
analytic attempts to come up with the answer to that question.  But ultimately
he realized that it is much easier to get an estimate by just playing games
randomly.&lt;/p&gt;
&lt;p&gt;And at that time he was already doing research in Los Alamos. He recognized
that this has applications as well for studying different scientific problems
such as &lt;a href="https://en.wikipedia.org/wiki/Neutron_transport"&gt;Neutron Transport&lt;/a&gt;,
which is essential to understand when designing nuclear weapons. So he is also
the inventor of the &lt;a href="https://en.wikipedia.org/wiki/History_of_the_Teller%E2%80%93Ulam_design"&gt;first working Hydrogen bomb
design&lt;/a&gt;
together with &lt;a href="https://en.wikipedia.org/wiki/Edward_Teller"&gt;Edward Teller&lt;/a&gt;.
And the inventor of the Monte Carlo method, &lt;a href="http://www.amstat.org/misc/TheMonteCarloMethod.pdf"&gt;published a few years
later&lt;/a&gt; in
1949. And also he's known for having performed probably the most laborious
manual computation ever undertaken (with Cornelius Everett) to disprove Edward
Teller's earlier nuclear weapon design, to show that it is not possible. So
very interesting history. I will talk a little bit later about him some more.&lt;/p&gt;
&lt;p&gt;So nowadays, Monte Carlo methods, and with Monte Carlo methods, really, I
mean, any method where you perform some random experiment, which is typically
quite simple, and you aggregate this results into some inferences about a more
complex system. Today, Monte Carlo methods are very popular in simulating
complex systems. For example, models of physical or biological or chemical
processes, for example, weather forecasting, and of course, nuclear weapon
design.
But also just last week, it was used to &lt;a href="http://www.nature.com/nature/journal/v497/n7451/full/nature12162.html"&gt;simulate the HI Virus
capsid&lt;/a&gt;.
A simulation of 64 million atoms, a major breakthrough in understanding the HI
Virus. So it has huge applications in scientific simulations, it also has
applications in doing inference in probabilistic models. The most famous
system there would be the &lt;a href="http://www.mrc-bsu.cam.ac.uk/software/bugs/"&gt;BUGS
system&lt;/a&gt; also developed here in
Cambridge at the University, initially developed in the early '90s.
&lt;a href="http://research.microsoft.com/en-us/um/cambridge/projects/infernet/"&gt;Infer.NET&lt;/a&gt;
also supports Monte Carlo inference and here at MSRC also the &lt;a href="http://research.microsoft.com/en-us/projects/filzbach/"&gt;Filzbach
system&lt;/a&gt;
does. Also there's a quite popular system now, from the University of
Columbia, called &lt;a href="http://mc-stan.org/"&gt;STAN&lt;/a&gt;. It's actually named STAN because
of Stanislaw Ulam.&lt;/p&gt;
&lt;p&gt;Monte Carlo methods can also be used for optimization. So not just for
simulating but also for optimizing a cost function. We will see an example
later, but typically it is often used where very complicated systems are
optimized. So something like the circuit layout that has many interdependent
constraints. And it is also used for planning, for games, and for robotics,
where it is essential to approximate intractable quantities, to perform
planning under uncertainty or where measurement noise makes it essential to
represent uncertainty in a representative way. So these are many, many
different applications, too many to really list. I want to pick out one
application for the rest of the talk and illustrate this application with
different Monte Carlo methods.&lt;/p&gt;
&lt;p&gt;And that application is &lt;a href="https://en.wikipedia.org/wiki/Protein_folding"&gt;protein
folding&lt;/a&gt;. So protein folding
happens right now in your body, in every cell of your body. In every cell you
have a structure called the Ribosome and that's basically the factory in your
cell. It transforms information, encoded in the DNA into one linear long
structure, the protein. And that structure is such a long chain that folds
itself into very intricate three dimensional structures.  Very beautiful
structures arise, and it is really the three-dimensional shape that this long
chain folds into that determines the functional properties. It is really
essential to understand in order to make predictions about what these
molecules do. This can take anywhere between a few milliseconds and a few
hours. And I think the state of the art on a modern machine is to be able to
simulate accurately something like 60 nanoseconds per computer day. So we are
nowhere in reach of being able to accurately fold these structures. But there
is the &lt;a href="https://folding.stanford.edu/"&gt;Stanford Folding@home&lt;/a&gt; project which
uses Monte Carlo methods. And I think right now, they have something like a
hundred fifty thousand computers working right now on the problem of protein
folding. So it is quite essential to understand a couple of different
diseases.&lt;/p&gt;
&lt;p&gt;We are not going to solve protein folding in this talk but I am going to use a
slightly more simplified model. One thing to simplify is you still have a
chain. But you say, "Okay, first the chain does not live in three dimensions,
it only lives on the plane." And we do not have many different amino acids, we
only have two: the black ones and the white ones. And the white ones repel
water, the white ones like water and the black ones repel water and so they
fold into something that has a black core and a white surrounding. In fact, I
am going to make it even simpler. I say, "Okay, it lives on the plane but it
lives on the grid". So it is a further simplification. And now for the next
few slides, I even simplify this one step further: we only have the white
bonds. &lt;/p&gt;
&lt;p&gt;So that is a so-called &lt;a href="https://en.wikipedia.org/wiki/Self-avoiding_walk"&gt;2D lattice self-avoiding random walk&lt;/a&gt; model. So you have
a certain length. Say 48 bonds, 48 elements, and you have a self-avoiding
walk, so this walk is not allowed to cross onto itself. And this is a very
simplified model but already some questions which are interesting become very
hard or actually intractable. For example, if I fix a number of elements in
this walk, one question is, how many self-avoiding walks are there on the
plane? Another question is, okay the number is finite, while there are many
but finitely many possible combinations, how do I uniformly generate such
random walk? And the third question would be, okay, I am interested in some
average properties, for example, the average end-point distance between the
two ends, how do I compute an approximation to that average quantity?&lt;/p&gt;
&lt;p&gt;These are really typical problems that can be addressed with Monte Carlo
methods:
- &lt;em&gt;average quantities&lt;/em&gt;,
- &lt;em&gt;counting problems&lt;/em&gt;,
- &lt;em&gt;random sampling problems&lt;/em&gt;.
So that's what's going to be with us in the next few slides.&lt;/p&gt;
&lt;p&gt;The first method is a very simple one. It's called &lt;a href="https://en.wikipedia.org/wiki/Rejection_sampling"&gt;&lt;em&gt;rejection
sampling&lt;/em&gt;&lt;/a&gt; and the idea is
really very simple to explain. While we have this complicated set, the set of
all self-avoiding random walks of a certain lengths and we want to generate
one element uniformly at random from the set. This is hard. So what we do is
we instead consider a super set, the set of all random walks of a certain
lengths, and this is allowed to cross onto each other. And it is very easy to
simulate from that set. So we just simulate from this orange set, from this
larger set, and whenever we end up outside the blue set we discard that
sample. And whenever we are inside the blue sample set, then we keep the
sample. And because we uniformly generate samples, we can just keep doing this
and collect whenever we reach an element in the blue set.&lt;/p&gt;
&lt;p&gt;In practice this would work as follows: we start and we just keep appending in
a randomly chosen direction, one out of three say, and if we happen to cross
on ourselves we can already discard that sample and start over. And we would
keep all the sample set that we can grow to the full lengths we want and we
keep them and we maybe collect a thousand of them. And compute whatever
property we want from that sample set.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Attendee 1&lt;/strong&gt;: May I ask a question?&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Speaker&lt;/strong&gt;: Yes, sure.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Attendee 1&lt;/strong&gt;: What happens when instead you say, "Oh Dear, I shouldn't have
gone down, I should have gone-in in a different direction." Did you just get a
biased sample or something?&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Speaker&lt;/strong&gt;: You are anticipating the future. We are still in 1949.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Attendee 1&lt;/strong&gt;: But I thought this was the-- you said, right to begin with,
generating the ones that don't cross themselves is hard. &lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Speaker&lt;/strong&gt;: Yes and it would still be hard-- just bear with me for a few
slides, this is actually where it's leading to.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Attendee 1&lt;/strong&gt;: Okay.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Speaker&lt;/strong&gt;: But this is a simple method. And we can, once we have generated the
set of samples, we can compute average properties. For example, this squared
extension there where you compute the distance in the plane between the two
end points, that is a model problem that people considered. And more
generally, what we would like to do is to compute expectations. So we have a
distribution &lt;span class="math"&gt;\(\pi\)&lt;/span&gt; of &lt;span class="math"&gt;\(X\)&lt;/span&gt; over some state &lt;span class="math"&gt;\(X\)&lt;/span&gt; and we would like to evaluate some
quantity &lt;span class="math"&gt;\(\phi\)&lt;/span&gt; of &lt;span class="math"&gt;\(X\)&lt;/span&gt;.  For example, this distance between the two endpoints
of a certain state and we want to compute some sum and the sum contains
exponentially many terms in this case. We want to compute the sum as an
expectation and average quantity. And the Monte Carlo idea is to simply
replace it, approximate that huge sum with exponentially many terms with
something that has only say a thousand or 10,000 terms which is the samples we
generated.&lt;/p&gt;
&lt;p&gt;When we do that, when we actually do this rejection sampling here as a
function of the chain lengths. I do that and I generate here 10 million
samples, 10 million times I try and I keep all the samples at length that
helped me to be self-avoiding. Then I can plot this average distance and
because it is an average of many terms I know that the central limit theorem
applies so I can also plot &lt;a href="https://en.wikipedia.org/wiki/Binomial_proportion_confidence_interval#Wilson_score_interval"&gt;confidence
intervals&lt;/a&gt;.
So I not only get the inferences that I am interested in now, I also get an
estimate, a confidence interval that captures with a certain probability the
two value. &lt;/p&gt;
&lt;p&gt;Okay and it works until a chain length of thirty so already quite large chain
lengths. Then the confidence intervals become larger because I get less and
less samples accepted. I use 10 million attempts here but actually similar
methods are very useful even for a few hundred attempts. This is a picture
around that time in Los Alamos where they performed the simulation manually by
drawing with this drawing device, basically, on a sheet of paper, and whenever
they cross from one type of material to another type of material, they would
change the wheels and roll a new random number and then move it and turn it in
random directions and they do it a few hundred times and get a global picture
on how the neutrons are scattered in this matter. Because everything was named
MANIAC, ENIAC, etc., and this idea was from Enrico Fermi they called this
device a &lt;a href="https://en.wikipedia.org/wiki/FERMIAC"&gt;FERMIAC&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;But anyway, another thing we could do is solve the counting problem. So we can
estimate the acceptance rate. We have the number of attempts that we made and
the number of attempts that were accepted that happened to be self-avoiding.
It gives us the acceptance rate and we can estimate the number of
self-avoiding walks simply as a product of this acceptance rate with a total
number of 2D walks that are not necessarily self-avoiding. That is easy to
calculate as well because the first step was into right direction and we had
three possibilities in each step, so we could just have a formula for that one
and this gives an estimate of the number of self-avoiding walks. 
So here is a plot of that and in &lt;a href="http://arxiv.org/abs/cond-mat/0409355"&gt;this paper I found from
2005&lt;/a&gt; where people have exhaustively
computed that with clever enumeration methods up to a length of 59, but beyond
that the exact number is unknown. But it happens to agree very well with these
known ground truths.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Attendee 1&lt;/strong&gt;: Quick question. Is that what even with your early rejection
business?&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Speaker&lt;/strong&gt;: Yes, that's the one thing.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Attendee 1&lt;/strong&gt;: Okay.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Speaker&lt;/strong&gt;: It's exactly with the rejection sample here. So the acceptance
rate is from the rejection sample here.  &lt;span class="math"&gt;\(P\)&lt;/span&gt; is estimated from the rejection
sample.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Attendee 1&lt;/strong&gt;: What is the acceptance rate when you get to 30?&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Speaker&lt;/strong&gt;: Again, next slide here.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Speaker&lt;/strong&gt;: I am impressed. One second. Let us first enjoy what we have
achieved, let us take a look at Monte Carlo, enjoy some sunshine. So the name
Monte Carlo, I mean, what first comes to mind is all the casinos, right? And
the gambling and that is indeed one of the origins of the name. But the
particular reason and the person who suggested this was Nicholas Metropolis,
the colleague of Stanislaw Ulam, was very much amused about the stories Stan
was telling about his uncle, Michael Ulam, who was a wealthy businessman in
his hometown in Lviv. And then switched to the finance industry and spent the
rest of his life gambling away his fortune in Monte Carlo and Nicholas
Metropolis found this so amusing that he insisted the method being called,
Monte Carlo method. So that is the real reason why it is called Monte Carlo
method.&lt;/p&gt;
&lt;p&gt;And it is not all sunny and that is where we come to this slide, which is the
acceptance rate as a function of the chain lengths. And you see the simpler
rejection sample for long enough chains. I mean, intuitively you can
understand when you grow the chain very long, the probability to cross onto
yourself when you walk randomly becomes higher and higher. The acceptance rate
is very, very small. So I think for a million samples I had only like 15 walks
accepted at the lengths of 30. And that's why the confidence intervals have
been blowing up because the estimates become unreliable. &lt;/p&gt;
&lt;p&gt;The &lt;a href="https://www.nowozin.net/sebastian/blog/history-of-monte-carlo-methods-part-2.html"&gt;next part&lt;/a&gt; is available.&lt;/p&gt;
&lt;script type="text/javascript"&gt;if (!document.getElementById('mathjaxscript_pelican_#%@#$@#')) {
    var align = "center",
        indent = "0em",
        linebreak = "false";

    if (false) {
        align = (screen.width &lt; 768) ? "left" : align;
        indent = (screen.width &lt; 768) ? "0em" : indent;
        linebreak = (screen.width &lt; 768) ? 'true' : linebreak;
    }

    var mathjaxscript = document.createElement('script');
    mathjaxscript.id = 'mathjaxscript_pelican_#%@#$@#';
    mathjaxscript.type = 'text/javascript';
    mathjaxscript.src = 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.3/latest.js?config=TeX-AMS-MML_HTMLorMML';

    var configscript = document.createElement('script');
    configscript.type = 'text/x-mathjax-config';
    configscript[(window.opera ? "innerHTML" : "text")] =
        "MathJax.Hub.Config({" +
        "    config: ['MMLorHTML.js']," +
        "    TeX: { extensions: ['AMSmath.js','AMSsymbols.js','noErrors.js','noUndefined.js'], equationNumbers: { autoNumber: 'none' } }," +
        "    jax: ['input/TeX','input/MathML','output/HTML-CSS']," +
        "    extensions: ['tex2jax.js','mml2jax.js','MathMenu.js','MathZoom.js']," +
        "    displayAlign: '"+ align +"'," +
        "    displayIndent: '"+ indent +"'," +
        "    showMathMenu: true," +
        "    messageStyle: 'normal'," +
        "    tex2jax: { " +
        "        inlineMath: [ ['\\\\(','\\\\)'] ], " +
        "        displayMath: [ ['$$','$$'] ]," +
        "        processEscapes: true," +
        "        preview: 'TeX'," +
        "    }, " +
        "    'HTML-CSS': { " +
        "        availableFonts: ['STIX', 'TeX']," +
        "        preferredFont: 'STIX'," +
        "        styles: { '.MathJax_Display, .MathJax .mo, .MathJax .mi, .MathJax .mn': {color: 'inherit ! important'} }," +
        "        linebreaks: { automatic: "+ linebreak +", width: '90% container' }," +
        "    }, " +
        "}); " +
        "if ('default' !== 'default') {" +
            "MathJax.Hub.Register.StartupHook('HTML-CSS Jax Ready',function () {" +
                "var VARIANT = MathJax.OutputJax['HTML-CSS'].FONTDATA.VARIANT;" +
                "VARIANT['normal'].fonts.unshift('MathJax_default');" +
                "VARIANT['bold'].fonts.unshift('MathJax_default-bold');" +
                "VARIANT['italic'].fonts.unshift('MathJax_default-italic');" +
                "VARIANT['-tex-mathit'].fonts.unshift('MathJax_default-italic');" +
            "});" +
            "MathJax.Hub.Register.StartupHook('SVG Jax Ready',function () {" +
                "var VARIANT = MathJax.OutputJax.SVG.FONTDATA.VARIANT;" +
                "VARIANT['normal'].fonts.unshift('MathJax_default');" +
                "VARIANT['bold'].fonts.unshift('MathJax_default-bold');" +
                "VARIANT['italic'].fonts.unshift('MathJax_default-italic');" +
                "VARIANT['-tex-mathit'].fonts.unshift('MathJax_default-italic');" +
            "});" +
        "}";

    (document.body || document.getElementsByTagName('head')[0]).appendChild(configscript);
    (document.body || document.getElementsByTagName('head')[0]).appendChild(mathjaxscript);
}
&lt;/script&gt;</content><category term="Statistics"/></entry><entry><title>The Julia language for Scientific Computing</title><link href="https://www.nowozin.net/sebastian/blog/the-julia-language-for-scientific-computing.html" rel="alternate"/><published>2015-10-02T22:30:00+01:00</published><updated>2015-10-02T22:30:00+01:00</updated><author><name>Sebastian Nowozin</name></author><id>tag:www.nowozin.net,2015-10-02:/sebastian/blog/the-julia-language-for-scientific-computing.html</id><summary type="html">&lt;p&gt;&lt;a href="http://julialang.org/"&gt;Julia&lt;/a&gt; is a relatively new programming language with
the &lt;a href="http://julialang.org/blog/2012/02/why-we-created-julia/"&gt;declared goal&lt;/a&gt;
to become the leading language for scientific computing.&lt;/p&gt;
&lt;p&gt;I have probably annoyed half of my colleagues by raving about how great the
language is and what it is good at.
Before we get to this, and in my defense …&lt;/p&gt;</summary><content type="html">&lt;p&gt;&lt;a href="http://julialang.org/"&gt;Julia&lt;/a&gt; is a relatively new programming language with
the &lt;a href="http://julialang.org/blog/2012/02/why-we-created-julia/"&gt;declared goal&lt;/a&gt;
to become the leading language for scientific computing.&lt;/p&gt;
&lt;p&gt;I have probably annoyed half of my colleagues by raving about how great the
language is and what it is good at.
Before we get to this, and in my defense, let me provide some context.  I have
been developing using C and C++ for 20 years now, and have been using Matlab
and Python for over ten years now.  These are great languages and I can be
productive using each, infact I continue to use them regularly.&lt;/p&gt;
&lt;p&gt;Also, I tend to be quite conservative in terms of adopting new languages or
development tools: while learning a new language and environment is fun
it also takes a lot of effort and most languages/tools/libraries tend to come
and go rather quickly and every developer carries with him a graveyard of
tools and languages long gone.&lt;/p&gt;
&lt;p&gt;Because of this short-lived nature of software, when someone approaches me
with a new language or tool I am skeptical by default, and my litmus test
question is usually how confident they are that this tool will still be around
in five years time.  This is of course unfair, but I prefer to invest my time
in learning things that have long term value.  Which brings me to the point
that I firmly believe Julia is here to stay and in fact may even become a
popular language in scientific computing.&lt;/p&gt;
&lt;p&gt;Enough rambling, let's get to the good parts.&lt;/p&gt;
&lt;p&gt;I have been using Julia for the last 18 month now, both for work and pleasure.
Counting all code I wrote at work (just counting .jl files, no notebooks) I
see that I wrote more than 15k lines of Julia code in that time, including
several larger projects, ports of existing Matlab and C++ code, and interfaces
to C libraries.
Given my experience Julia is ready for production in internal projects (as
opposed to shipping executable code to a customer) and in particular is very
well suited to research-type projects.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://julialang.org/"&gt;&lt;img src="images/julia.svg" alt="Logo of the Julia language" style="width: 240px; display: block; margin-left: auto; margin-right: auto;"/&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;Julia&lt;/h1&gt;
&lt;p&gt;Developing code for research projects is in many ways similar to developing
other software, but the key difference for me is that I need a quick
turnaround time from idea to result not just once but in multiple iterations,
sometimes changing the idea and implementation drastically.&lt;/p&gt;
&lt;p&gt;In a very real sense most research projects should fail to achieve their
original goals; almost by definition research is beyond what is known to
work.  If you only attempt known-to-work ideas it is not research.
If your project fails it is important to learn as much as possible from the
failure, that is, increasing the understanding of the problem and finding
suitable new research ideas, and quick iterations make this process fun.
The new ideas are often variants of earlier ideas and thus can reuse code.  If
this code happens to be compact and flexible this translates directly into
productivity.&lt;/p&gt;
&lt;p&gt;Matlab, R, and Python achieve this tight cycle of iterations quite
successfully, but in all three languages there is a price towards the later
iterations in that for achieving a high performance implementation significant
parts of the code needs to be rewritten in a more basic language
such as C++, which then needs to be interfaced to the other code through some
interface specification.
For big high-value projects in industry with dedicated engineering support
the additional effort required is typically not a problem, but for individual
researchers it means hours and days spend writing additional code without
adding functionality.&lt;/p&gt;
&lt;p&gt;This process is cumbersome, errorprone, and creates a strong coupling, making
further iterations of changing ideas and implementations slower.
(As an example, in my &lt;a href="http://www.nowozin.net/sebastian/grante/"&gt;grante&lt;/a&gt;
library I prototyped many algorithms in Matlab, then programmed them in C++,
then wrote a Matlab interface which by itself is almost 2,000 lines of C++
code.)&lt;/p&gt;
&lt;p&gt;&lt;a href="http://julialang.org/"&gt;Julia&lt;/a&gt; also achieves this tight cycle, but does not
require you to resort to compiled statically-typed languages such as C++ in
order to achieve high performance.
Using a single language maintains productivity both at the very beginning
(prototyping) and towards the later iterations (productization).&lt;/p&gt;
&lt;p&gt;Productivity in Julia (roughly "scientific results per wallclock developer
time") is achieved through a number of features:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;em&gt;compact syntax&lt;/em&gt;, for example I can declare a function using &lt;code&gt;f(x) = 2x+5&lt;/code&gt;.
As mentioned above, I see the advantage of a compact syntax not in the
keystrokes saved initially, but in lowering the barrier to future
understanding and modification as the code evolves.&lt;/li&gt;
&lt;li&gt;&lt;em&gt;optional type annotation&lt;/em&gt;, the above function will work for &lt;code&gt;x&lt;/code&gt; being an
integer, or a float, or anything that has a multiplication and addition with
integer arguments defined; in fact, I could write &lt;code&gt;f(x::Float64) = 2x+5&lt;/code&gt; to
require that &lt;code&gt;x&lt;/code&gt; is a float, but performance-wise they both yield the same
code.  This means that I can be strict about types when I need to be, but have
the feel of a &lt;a href="https://en.wikipedia.org/wiki/Dynamic_programming_language"&gt;dynamic programming
language&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;&lt;a href="http://jupyter.org/"&gt;&lt;em&gt;Jupyter notebook interface&lt;/em&gt;&lt;/a&gt; for quick
think-implement-results cycles.&lt;/li&gt;
&lt;li&gt;&lt;em&gt;excellent default choices of numerical libraries&lt;/em&gt;, dense linear algebra,
sparse linear algebra,
&lt;a href="http://juliaopt.org/"&gt;numerical optimization libraries&lt;/a&gt;,
&lt;a href="http://julia.readthedocs.org/en/latest/stdlib/numbers/#bigfloats"&gt;arbitrary precision computation&lt;/a&gt;,
&lt;a href="http://julia.readthedocs.org/en/latest/stdlib/math/?highlight=bessel#mathematical-functions"&gt;special functions&lt;/a&gt;,
&lt;a href="http://julia.readthedocs.org/en/latest/stdlib/math/?highlight=fft#signal-processing"&gt;FFT&lt;/a&gt;, etcetera, most of what you can wish for
in a technical computing environment is already there by default or in the
many numerical packages available.  In terms of numerical optimization codes
Julia is probably one of the &lt;a href="http://www.juliaopt.org/"&gt;best environments&lt;/a&gt;
available.  All these libraries are carefully chosen to be the best-in-class
for the functions that they implement.&lt;/li&gt;
&lt;li&gt;&lt;a href="https://en.wikipedia.org/wiki/Foreign_function_interface"&gt;&lt;em&gt;foreign function interfaces&lt;/em&gt;&lt;/a&gt;
to a number of languages:
&lt;a href="http://docs.julialang.org/en/release-0.3/stdlib/c/"&gt;C and Fortran&lt;/a&gt;,
&lt;a href="https://github.com/Keno/Cxx.jl"&gt;C++&lt;/a&gt; (unfortunately planned only for Julia 0.5),
&lt;a href="https://github.com/stevengj/PyCall.jl"&gt;Python&lt;/a&gt;,
&lt;a href="https://github.com/lgautier/Rif.jl"&gt;R&lt;/a&gt;,
&lt;a href="https://github.com/JuliaLang/MATLAB.jl"&gt;Matlab&lt;/a&gt;.  This makes it relatively
easy to use code in any of these languages and I have used several Python
libraries without issues.&lt;/li&gt;
&lt;li&gt;&lt;a href="http://julialang.org/benchmarks/"&gt;&lt;em&gt;high performance&lt;/em&gt;&lt;/a&gt;, I regularly find my
first-attempt Julia code for a problem to be an order of magnitude faster
than the equivalent Matlab code.  Infact, I &lt;em&gt;unlearned&lt;/em&gt; a number of bad Matlab
programming patterns such as using &lt;code&gt;bsxfun&lt;/code&gt; and vectorizing all code.  Last
year I wrote Julia code for a &lt;a href="https://en.wikipedia.org/wiki/R-tree"&gt;R-tree data
structure&lt;/a&gt; to maintain a dynamic spatial
index.  Doing this in Matlab/R/Python in a reasonably performant way would be
unthinkable!  Instead you have to resort to &lt;a href="https://pypi.python.org/pypi/Rtree/"&gt;wrapping native
libraries&lt;/a&gt;.
In Julia it was fun to write and it is fast, and I could add the required
methods I needed for my application easily, including fancy filtering
iterators.&lt;/li&gt;
&lt;li&gt;&lt;em&gt;no separation between user and developer&lt;/em&gt;, almost all of the base library
is implemented in Julia itself, and it is easy to find where things are.  For
example, if you want to find out how two complex numbers are multiplied in
Julia's base library? Enter &lt;code&gt;methods(*)&lt;/code&gt; and &lt;a href="https://github.com/JuliaLang/julia/blob/c8ceeefcc1dc25953a644622a895a3adcbc80dad/base/complex.jl#L112"&gt;have a
look!&lt;/a&gt;
This transparency makes it easy to learn good Julian style and extends further
to how code is run:
Want to see what machine code is executed when you call the &lt;code&gt;sqrt&lt;/code&gt; function on
a single precision float?
Enter &lt;code&gt;code_native(sqrt, (Float32,))&lt;/code&gt; and see&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="na"&gt;.text&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nl"&gt;Filename:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nf"&gt;math.jl&lt;/span&gt;
&lt;span class="nf"&gt;Source&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="no"&gt;line&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;132&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="no"&gt;RBP&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nf"&gt;mov&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="no"&gt;RBP&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="no"&gt;RSP&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nf"&gt;xorps&lt;/span&gt;&lt;span class="w"&gt;   &lt;/span&gt;&lt;span class="no"&gt;XMM1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="no"&gt;XMM1&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nf"&gt;ucomiss&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="no"&gt;XMM1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="no"&gt;XMM0&lt;/span&gt;
&lt;span class="nf"&gt;Source&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="no"&gt;line&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;132&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nf"&gt;ja&lt;/span&gt;&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="mi"&gt;6&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nf"&gt;sqrtss&lt;/span&gt;&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="no"&gt;XMM0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="no"&gt;XMM0&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nf"&gt;pop&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="no"&gt;RBP&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nf"&gt;ret&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nf"&gt;movabs&lt;/span&gt;&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="no"&gt;RAX&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;140269793784104&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nf"&gt;mov&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="no"&gt;RDI&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="no"&gt;QWORD&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="no"&gt;PTR&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="no"&gt;RAX&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nf"&gt;movabs&lt;/span&gt;&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="no"&gt;RAX&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;140269778958624&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nf"&gt;mov&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="no"&gt;ESI&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;132&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nf"&gt;call&lt;/span&gt;&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="no"&gt;RAX&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Almost nothing is hidden from the eyes of the user and this makes it easy and
fun to look into the implementation.&lt;/p&gt;
&lt;h2&gt;Weak parts&lt;/h2&gt;
&lt;p&gt;Julia, while ready for serious use, is not yet at version 1.0 and lacks
several important features.
In my work, I found the following pieces missing (as of version 0.4).&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;em&gt;Simple single machine parallelism&lt;/em&gt;.  In C/C++/Fortran this would be
&lt;a href="http://openmp.org/wp/"&gt;OpenMP&lt;/a&gt; and in Matlab it is &lt;code&gt;parfor&lt;/code&gt;.
While Julia does have good support for &lt;a href="http://julia.readthedocs.org/en/latest/manual/parallel-computing/"&gt;distributed parallel
computing&lt;/a&gt;,
it currently does not have simple single-machine parallelism.
In my experience using the distributed computing abstractions for single
machine parallelism has severe performance overheads because all data is
serialized and remote method invocations are used to execute code.
(Also, I found the use of &lt;code&gt;@everywhere&lt;/code&gt; macros cumbersome.)
Apparently a simpler single machine parallelism is difficult to implement but
in the works, as shown in this &lt;a href="https://www.youtube.com/watch?v=GvLhseZ4D8M"&gt;recent work by
Intel&lt;/a&gt; presented at JuliaCon
2015.&lt;/li&gt;
&lt;li&gt;&lt;em&gt;Debugger&lt;/em&gt;.  Quite simply, a debugger is essential for larger projects where
errors can arise that are difficult to understand and debug without being able
to interactively inspect the context in which the error appeared.
Currently Julia has &lt;a href="https://github.com/toivoh/Debug.jl"&gt;Debug.jl&lt;/a&gt; which
provides debugging at &lt;a href="http://www.gnu.org/software/gdb/"&gt;gdb&lt;/a&gt; level in terms
of functionality.
But Julia lacks an interactive debugging capability on par with what is
available in Matlab or most C/C++ environments (actually, I am not sure about
&lt;a href="https://wiki.python.org/moin/PythonDebuggingTools"&gt;Python debuggers&lt;/a&gt; here, is
there a single popular tool?).
As far as I understand, this is planned for the 0.5 version of Julia.&lt;/li&gt;
&lt;li&gt;&lt;em&gt;Shipping/productization/static-compilation&lt;/em&gt;.  With this I mean the ability
to select the distribution mechanism for the software, in particular to select
whether all dependencies are included so that the software "will just run" on
the target system, and whether binaries or source code is delivered.
For most researchers and open-source programmers this is not an issue and the
Julia package system caters for all their needs, but I found it relevant in a
company environment because explaining to someone how they install Julia and a
piece of code takes a while, whereas for C++ I can typically easily send an
executable file and some library dependencies.
As far as I understand, static compilation is planned for a future version of
Julia.&lt;/li&gt;
&lt;/ul&gt;
&lt;h1&gt;Further Reading&lt;/h1&gt;
&lt;p&gt;If you want to give Julia a spin, here are a few links:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://julialang.org/downloads/"&gt;Official installer&lt;/a&gt;, go for the 0.4
release (or the release candidates until the final release is available).&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/stevengj/julia-mit/"&gt;Julia at MIT&lt;/a&gt; helpful
  getting-started information, including the best way to install it on Windows.&lt;/li&gt;
&lt;li&gt;&lt;a href="http://tinyurl.com/JuliaLang"&gt;Julia cheat sheet&lt;/a&gt;, courtesy of Ian
  Hellstroem.&lt;/li&gt;
&lt;li&gt;&lt;a href="https://gist.github.com/gizmaa/7214002"&gt;Basic plotting examples&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/playlist?list=PLP8iPy9hna6Sdx4soiGrSefrmOPdUWixM"&gt;JuliaCon 2015 talk recordings&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Packages which I use frequently and can recommend:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="https://github.com/stevengj/PyPlot.jl"&gt;PyPlot.jl&lt;/a&gt;, wrapper around
&lt;a href="http://matplotlib.org/"&gt;matplotlib&lt;/a&gt; for all your plotting needs.&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/JuliaStats/Distributions.jl"&gt;Distributions.jl&lt;/a&gt;, common
probability distributions.&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/JuliaLang/IJulia.jl"&gt;IJulia.jl&lt;/a&gt; for interactive
browser notebooks.&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/JuliaStats/DataFrames.jl"&gt;DataFrames.jl&lt;/a&gt; for processing
tabular data.&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/goedman/Stan.jl"&gt;Stan.jl&lt;/a&gt;, an interface for the &lt;a href="http://mc-stan.org/"&gt;Stan
probabilistic programming language&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/JuliaOpt/JuMP.jl"&gt;JuMP.jl&lt;/a&gt; a high-performance
mathematical modeling language with excellent solver integration.&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/JuliaOpt/NLopt.jl"&gt;NLopt.jl&lt;/a&gt; state-of-the-art
optimization solvers for non-linear minimization (L-BFGS and gradient-free
methods).&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/JuliaGPU/OpenCL.jl"&gt;OpenCL.jl&lt;/a&gt; an interface for
&lt;a href="https://www.khronos.org/opencl/"&gt;OpenCL&lt;/a&gt; similar to PyOpenCL.  Not
feature-complete yet (e.g. images are missing).&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The &lt;a href="http://pkg.julialang.org/pulse.html"&gt;Julia package ecosystem&lt;/a&gt; has a lot
more packages, so if you are looking for a particular thing, have a look
there.&lt;/p&gt;</content><category term="Programming"/></entry><entry><title>How good are your beliefs? Part 2: The Quiz</title><link href="https://www.nowozin.net/sebastian/blog/how-good-are-your-beliefs-part-2-the-quiz.html" rel="alternate"/><published>2015-09-18T21:00:00+01:00</published><updated>2015-09-18T21:00:00+01:00</updated><author><name>Sebastian Nowozin</name></author><id>tag:www.nowozin.net,2015-09-18:/sebastian/blog/how-good-are-your-beliefs-part-2-the-quiz.html</id><summary type="html">&lt;p&gt;This post continues the previous post, &lt;a href="https://www.nowozin.net/sebastian/blog/how-good-are-your-beliefs-part-1-scoring-rules.html"&gt;part 1&lt;/a&gt; on
scoring rules.  However, today we will be more hands on, testing your skill of
making good and well-calibrated predictions.&lt;/p&gt;
&lt;p&gt;To this end, I will ask you several questions about numerical quantities and I
would like to hear an answer stated as …&lt;/p&gt;</summary><content type="html">&lt;p&gt;This post continues the previous post, &lt;a href="https://www.nowozin.net/sebastian/blog/how-good-are-your-beliefs-part-1-scoring-rules.html"&gt;part 1&lt;/a&gt; on
scoring rules.  However, today we will be more hands on, testing your skill of
making good and well-calibrated predictions.&lt;/p&gt;
&lt;p&gt;To this end, I will ask you several questions about numerical quantities and I
would like to hear an answer stated as a belief interval.
First, we consider scoring rules for intervals.&lt;/p&gt;
&lt;h2&gt;Interval Scoring Rules&lt;/h2&gt;
&lt;p&gt;Often the prediction or elicitation of a full probability distribution is
cumbersome due to the many degrees of freedom a distribution has.&lt;/p&gt;
&lt;p&gt;Therefore, in practice we can instead ask our model or users for intervals.
This carries the implicit assumption of unimodal beliefs, which may not be
satisfied in important tasks, but has the advantage of requiring only two
numbers to be elicited.&lt;/p&gt;
&lt;p&gt;Given an interval forecast &lt;span class="math"&gt;\([L,U]\)&lt;/span&gt;, where &lt;span class="math"&gt;\(U &amp;gt; L &amp;gt; 0\)&lt;/span&gt;, and &lt;span class="math"&gt;\(x &amp;gt; 0\)&lt;/span&gt; is a
realization, &lt;a href="https://www.csss.washington.edu/~raftery/Research/PDF/Gneiting2007jasa.pdf"&gt;(Gneiting and Raftery,
2007)&lt;/a&gt;
define the following interval scoring rule for &lt;span class="math"&gt;\(\alpha \in (0,\frac{1}{2})\)&lt;/span&gt;,&lt;/p&gt;
&lt;div class="math"&gt;$$S_{\textrm{int}}(L,U,x,\alpha) = (U-L) + 1_{\{x &amp;lt; L\}} \, \alpha (L-X)
+ 1_{\{x &amp;gt; U\}} \, \alpha (X-U).$$&lt;/div&gt;
&lt;p&gt;This is a proper scoring rule for intervals constructed from the sum of two
quantile losses at the &lt;span class="math"&gt;\(\alpha\)&lt;/span&gt;-quantile and the &lt;span class="math"&gt;\((1-\alpha)\)&lt;/span&gt;-quantile.
However, it has the problem that if the score is used in different contexts
where the quantities &lt;span class="math"&gt;\(x\)&lt;/span&gt; are of very different scales, then the resulting
scores also carry this scale and are not comparable.&lt;/p&gt;
&lt;p&gt;To achieve a scale-free interval scoring rule, we propose the following
&lt;em&gt;scale-free interval scoring rule&lt;/em&gt;.&lt;/p&gt;
&lt;div class="math"&gt;$$S_{\textrm{sf}}(L,U,x,\alpha) = \alpha \log(U/L)
+ 1_{\{x &amp;lt; L\}} \log(L/x) + 1_{\{x &amp;gt; U\}} \log(x/U).$$&lt;/div&gt;
&lt;p&gt;The rule is negatively oriented, thus acting as a loss function.
This scoring rule is &lt;em&gt;proper&lt;/em&gt; and is minimized in expectation over &lt;span class="math"&gt;\(X\)&lt;/span&gt;
if we set &lt;span class="math"&gt;\(L = F^{-1}(\alpha)\)&lt;/span&gt; and &lt;span class="math"&gt;\(U = F^{-1}(1-\alpha)\)&lt;/span&gt; where &lt;span class="math"&gt;\(F\)&lt;/span&gt; is the
cummulative distribution function of &lt;span class="math"&gt;\(X\)&lt;/span&gt; so that &lt;span class="math"&gt;\(L\)&lt;/span&gt; and &lt;span class="math"&gt;\(U\)&lt;/span&gt; become the
&lt;span class="math"&gt;\(\alpha\)&lt;/span&gt;-quantile and the &lt;span class="math"&gt;\((1-\alpha)\)&lt;/span&gt;-quantile.  (You can find a short proof
that this is a proper scoring rule in an appendix to this article.)&lt;/p&gt;
&lt;h2&gt;Quiz&lt;/h2&gt;
&lt;p&gt;The following quiz tests your ability to make well-calibrated but uncertain
assessments.
(This also means that the quiz becomes somewhat pointless if you resort to
Google or Wikipedia searches.)
The quiz contains twelve items, and each item asks for a number, assuming there
is a single true answer.  Please pay attention to the units being asked for.
Your knowledge regarding the different items is likely quite variable and for
some questions you may have a good idea (your beliefs are concentrated),
whereas for some other questions you may be more uncertain.&lt;/p&gt;
&lt;p&gt;Because of this uncertainty the quiz does not ask you for your best guess but
instead asks for an interval in an attempt to elicit your subjective beliefs.
The lower number should be chosen such that you
consider it 10 percent likely that the truth is below this number.  The upper
number is a 90 percent quantile and should be chosen such that there is a 10
percent chance that the truth is above this number.&lt;/p&gt;
&lt;p&gt;For example, say the question is "Maximum horsepower of an 2015 Audi R8 car
(horsepower)".  Given my limited knowledge of cars I know that the Audi R8 is
likely a quite powerful car so I would provide maybe an interval of 200 to
510.  How I arrive at this is up to me, for example, I may consider that a car
manufacturer may want to break the magic "500 horsepower" mark for marketing
purposes.  Fixing this interval, the truth is revealed.  The truth is 570
horsepower, and the above scale-free interval loss would be 0.205.&lt;/p&gt;
&lt;p&gt;For the interval score a &lt;em&gt;lower score is better&lt;/em&gt;, that is, the score is
negatively-oriented and behaves like a loss function.
Here is an illustration of different intervals and their scores for the
example.  I plot the true value 570 as a solid green vertical line, and the
intervals are green if they cover the truth and red otherwise.  The score is
shown next to each interval.&lt;/p&gt;
&lt;p&gt;&lt;a href="https://www.nowozin.net/sebastian/blog/images/interval-rule.svg"&gt;&lt;img alt="Example interval predictions" src="https://www.nowozin.net/sebastian/blog/images/interval-rule.png"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Have fun, and feel free to comment or suggest new questions/answer in the
comment field.&lt;/p&gt;
&lt;style&gt;
#calibform label { width:auto; }
#calibform label.error,#calibform input.submit { margin-left:253px; }
table.calibration {
    table-layout: auto;
    border-collapse: collapse;
    width: 660px;
}
#calibrationform form { border: none; }
form.calibration tr, td { padding:7px; border:0px; }
tr.row0 { background-color:#cccccc; border:0px; }
tr.row1 { background-color:#909090; border:0px; }
tr.correctRow { background-color:#90ff90; border:0px; }
tr.incorrectRow { background-color:#ff9090; border:0px; }
.row-question { width: 400px; }
.row-q10 { width: 80px; }
.row-q90 { width: 80px; }
.row-score { width: 40px; }
&lt;/style&gt;
&lt;iframe name="hidden_iframe" id="hidden_iframe" style="display:none;"&gt;&lt;/iframe&gt;
&lt;div id="calibformdiv"&gt;&lt;/div&gt;
&lt;div id="calibresultdiv"&gt;&lt;/div&gt;
&lt;script src="http://code.jquery.com/jquery-1.11.1.min.js"&gt;&lt;/script&gt;
&lt;script src="http://jqueryvalidation.org/files/dist/jquery.validate.min.js"&gt;&lt;/script&gt;
&lt;!--&lt;script src="http://jqueryvalidation.org/files/dist/additional-methods.min.js"&gt;&lt;/script&gt;--&gt;
&lt;script&gt;
$.validator.addMethod("positive", function(value, element) {
    return this.optional(element) || parseFloat(value) &gt; 0.0;
}, "Please enter a positive scalar");
$.validator.addMethod("largerThan", function(value, element, param) {
    var target = $( param );
    if (this.settings.onfocusout) {
        target.off( ".validate-equalTo" ).on( "blur.validate-equalTo",
            function() { $( element ).valid(); });
    }
    return parseFloat(value) &gt; parseFloat(target.val());
}, "90% quantile must be strictly larger than 10% quantile");

/* List of question/answer pairs */
var calibquestions = [
{
    "Q": "Height of the Mount Everest above sea level (meters)",
    "A": 8850.0
},
{
    "Q": "Year the first album of The Beatles has been released (four digit year)",
    "A": 1963.0
},
{
    "Q": "World record distance achieved in the longest human throw of an object without any velocity-aiding features (meters)",
    "A": 406.3
},
{
    "Q": "Most recent (2013) scientific estimate for the number of cells in an average adult human body (in trillions, 10 to the power of 12)",
    "A": 37.2
},
{
    "Q": "Gold price on the 7th September 1977 (US dollar per kg)",
    "A": 4747.06
},
{
    "Q": "Birth year of Sir Isaac Newton (four digit year)",
    "A": 1643.0
},
{
    "Q": "Scientific estimate for the average number of eggs a industrial hen lays during its life time (number of eggs)",
    "A": 530.0
},
{
    "Q": "Current scientific estimate (2013) of the age of the universe (billion years)",
    "A": 13.82
},
{
    "Q": "Mass of a Bee hummingbird, the lightest known bird (grams)",
    "A": 2.0
},
{
    "Q": "Guinness world record for the longest kiss as of 2015, rounded to the nearest hour (hours)",
    "A": 59.0
},
{
    "Q": "World population in 2050 as projected by the UN (as of 2015, in billions)",
    "A": 9.7
},
{
    "Q": "Number of officially confirmed moons in our solar system (as of 2015, count)",
    "A": 146
}
];

// Scale-free interval scoring function (proper)
// This function is a special case of the general family proposed in
// (Gneiting and Raftery, 2007).
function score_sfi(alpha, L, U, x) {
    var res = - alpha * Math.log(U/L);
    if (x &lt; L) {
        res += Math.log(x/L);
    } else if (x &gt; U) {
        res += Math.log(U/x);
    }
    return -res;
}

$.validator.setDefaults({
    submitHandler: function() {
        // Disable submit button
        $("input#submitbutton").prop('disabled', true);
        $("th#Qmsg").append("Score");

        // 1. Compute scoring function
        var avg_score = 0.0;
        for (i = 0; i &lt; calibquestions.length; ++i) {
            var L = parseFloat($('input#Qlow'+i).val());
            var U = parseFloat($('input#Qhigh'+i).val());
            var x = calibquestions[i].A;
            var score = score_sfi(0.1, L, U, x);
            avg_score += score;

            $("tr#RowQ"+i).removeClass(i % 2 == 0 ? "row0" : "row1");
            if (x &gt;= L &amp;&amp; x &lt;= U) {
                $("tr#RowQ"+i).addClass("correctRow");
            } else {
                $("tr#RowQ"+i).addClass("incorrectRow");
            }

            $('td#Qmsg'+i).append(" " + score.toFixed(4));
        }
        avg_score /= calibquestions.length;
        $("#calibresultdiv").append($("&lt;p/&gt;",
            { text: "Average score: " + avg_score.toFixed(4) }));

        return true;
    }
});

function randperm(n) {
    var rsort = new Array(n);
    for (var i = 0; i &lt; rsort.length; ++i) {
        rsort[i] = i;
    }
    for (var i = 0; i &lt; rsort.length; ++i) {
        var si = i + Math.floor(Math.random() * (rsort.length - i));
        var tmp = rsort[i];
        rsort[i] = rsort[si];
        rsort[si] = tmp;
    }
    return rsort;
}

$().ready(function() {
var form = $("&lt;form/&gt;", {
    name: "calibrationform",
    action: "https://script.google.com/macros/s/AKfycbzK161Q-fZCqRZzOtpO03-qJCWhYaBheNtR2Vt7iWd_Xt6R_rg/exec",
    method: "get",
    target: "hidden_iframe"
});
var fieldset = $("&lt;fieldset/&gt;");
rulelist = {};

var tab = $("&lt;table/&gt;", { class: "calibration" });
var thead = $("&lt;thead/&gt;");
var th_row = thead.append($("&lt;tr/&gt;"));
th_row.append($("&lt;th/&gt;", { class: "row-question" }).append("Question"));
th_row.append($("&lt;th/&gt;", { class: "row-q10" }).append("10% quantile"));
th_row.append($("&lt;th/&gt;", { class: "row-q90" }).append("90% quantile"));
th_row.append($("&lt;th/&gt;", { id: "Qmsg" }));
tab.append(thead);

var tbody = tab.append($("&lt;tbody/&gt;"));
P = randperm(calibquestions.length);
for (var i1 = 0; i1 &lt; calibquestions.length; ++i1) {
    var i = P[i1];
    var trow = $("&lt;tr/&gt;", {
        class: i1 % 2 == 0 ? "row0" : "row1",
        id: "RowQ"+i });

    trow.append($("&lt;td/&gt;").append($("&lt;label/&gt;",
        { class: "row-question", for: "Qlow"+i, text: calibquestions[i].Q })));
    trow.append($("&lt;td/&gt;").append($("&lt;input/&gt;",
        { class: "row-q10", type: "text", name: "Qlow"+i, id: "Qlow"+i })));
    trow.append($("&lt;td/&gt;").append($("&lt;input/&gt;",
        { class: "row-q90", type: "text", name: "Qhigh"+i, id: "Qhigh"+i })));
    trow.append($("&lt;td/&gt;", { class: "row-score", id: "Qmsg"+i }));

    tbody.append(trow);

    rulelist["Qlow"+i] = { required: true, number: true, positive: true };
    rulelist["Qhigh"+i] = { required: true, number: true, positive: true,
        largerThan: "#Qlow"+i };
}
fieldset.append(tab);
fieldset.append($("&lt;p/&gt;", { text: "Optional comment" }).append(
    $("&lt;input/&gt;", { type: "text", name: "Comment", id: "Comment" })));
fieldset.append($("&lt;input/&gt;",
    { id: "submitbutton", type: "submit", value: "Check answers" }));
form.append(fieldset);
$("#calibformdiv").append(form);
form.validate({
    errorPlacement: function(error, element) {
        //error.appendTo(element.parent().next());
        error.appendTo(element.parent());
    },
    highlight: function(element, errorClass) {
        $(element).addClass(errorClass).parent().prev().children("select").addClass(errorClass);
    },
    rules: rulelist
});

});
&lt;/script&gt;

&lt;p&gt;Based on my informal testing with a few volunteers, for the above questionaire
the following seems like a reasonable subjective scale for the average score:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span class="math"&gt;\(0\)&lt;/span&gt; to &lt;span class="math"&gt;\(0.1\)&lt;/span&gt;, expert&lt;/li&gt;
&lt;li&gt;&lt;span class="math"&gt;\(0.1\)&lt;/span&gt; to &lt;span class="math"&gt;\(0.2\)&lt;/span&gt;, proficient&lt;/li&gt;
&lt;li&gt;&lt;span class="math"&gt;\(0.2\)&lt;/span&gt; to &lt;span class="math"&gt;\(0.5\)&lt;/span&gt;, good&lt;/li&gt;
&lt;li&gt;&lt;span class="math"&gt;\(0.5\)&lt;/span&gt; to &lt;span class="math"&gt;\(1.0\)&lt;/span&gt;, medium&lt;/li&gt;
&lt;li&gt;above &lt;span class="math"&gt;\(1\)&lt;/span&gt;, fair&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;As for calibration, you should ideally have around eight to ten out of the
twelve questions showing as green, because the quantile range should have 80
percent coverage.
(Most persons who do not work with probability on a regular basis will have a
lower coverage because of overconfidence.)&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Acknowledgements&lt;/em&gt;.  I thank &lt;a href="http://johnwinn.org/"&gt;&lt;em&gt;John Winn&lt;/em&gt;&lt;/a&gt; for the
original calibration experiment he conducted in 2014 which inspired this
article, &lt;a href="https://www.stat.washington.edu/tilmann/"&gt;&lt;em&gt;Tilmann Gneiting&lt;/em&gt;&lt;/a&gt; for
commenting on the scale-free quantile score, &lt;a href="http://files.is.tue.mpg.de/pgehler/"&gt;&lt;em&gt;Peter
Gehler&lt;/em&gt;&lt;/a&gt; for feedback and providing
further questions,
&lt;a href="http://www.ong-home.my/"&gt;&lt;em&gt;Cheng Soon Ong&lt;/em&gt;&lt;/a&gt; for comments that improved clarity
of the article,
&lt;a href="http://research.microsoft.com/en-us/people/iankash/"&gt;&lt;em&gt;Ian Kash&lt;/em&gt;&lt;/a&gt; for
explaining scoring rules, &lt;a href="http://cdann.net/"&gt;&lt;em&gt;Christoph Dann&lt;/em&gt;&lt;/a&gt; and &lt;em&gt;Juan Gao&lt;/em&gt;
for feedback on the questionnaire.&lt;/p&gt;
&lt;h3&gt;Appendix: Propriety of the Scale-free Interval Scoring Rule&lt;/h3&gt;
&lt;p&gt;The following is a proof that the scale-free interval scoring rule is proper.
We will use the result from &lt;a href="https://www.csss.washington.edu/~raftery/Research/PDF/Gneiting2007jasa.pdf"&gt;(Gneiting and Raftery,
2007)&lt;/a&gt; and show that our scoring rule is a special case.&lt;/p&gt;
&lt;p&gt;First, consider the general form of a scoring rule for an &lt;span class="math"&gt;\(\alpha\)&lt;/span&gt;-quantile
from &lt;em&gt;Theorem 6&lt;/em&gt; in Gneiting and Raftery; for a choice &lt;span class="math"&gt;\(r\)&lt;/span&gt; and realization &lt;span class="math"&gt;\(x\)&lt;/span&gt;
this takes the form&lt;/p&gt;
&lt;div class="math"&gt;\begin{equation}
S(r,x,\alpha) = \alpha s(r) + (s(x) - s(r)) \, 1_{\{x \leq r\}} + h(x).
\label{eqn:Squantile}
\end{equation}&lt;/div&gt;
&lt;p&gt;Gneiting and Raftery show that for any nondecreasing function &lt;span class="math"&gt;\(s\)&lt;/span&gt; and an
arbitrary function &lt;span class="math"&gt;\(h\)&lt;/span&gt; this yields a proper scoring rule for quantiles.
Infact, it is known that any proper scoring rule for quantile has to be of the
form &lt;span class="math"&gt;\((\ref{eqn:Squantile})\)&lt;/span&gt;, see Theorem 3.3 in &lt;a href="http://arxiv.org/abs/0912.0902"&gt;(Gneiting,
2009)&lt;/a&gt;.
In the Gneiting and Raftery JASA paper the authors propose the choices
&lt;span class="math"&gt;\(s(y)=y\)&lt;/span&gt; and &lt;span class="math"&gt;\(h(y)=-\alpha y\)&lt;/span&gt;.
But here, in order to achieve a scale-free rule we propose to use&lt;/p&gt;
&lt;div class="math"&gt;$$s(y) = \log y,\qquad h(y) = -\alpha \log y.$$&lt;/div&gt;
&lt;p&gt;We obtain the specialization of &lt;span class="math"&gt;\((\ref{eqn:Squantile})\)&lt;/span&gt; as&lt;/p&gt;
&lt;div class="math"&gt;\begin{eqnarray}
S_{\textrm{q}}(r,x,\alpha)
    &amp;amp; = &amp;amp; \alpha \log r + (\log x - \log r) \,1_{\{x \leq r\}} - \alpha \log x\nonumber\\
    &amp;amp; = &amp;amp; \alpha \log (r/x) + 1_{\{x \leq r\}} \, \log (x/r).\label{eqn:qscore}
\end{eqnarray}&lt;/div&gt;
&lt;p&gt;Because &lt;span class="math"&gt;\(s\)&lt;/span&gt; is a non-decreasing function this is a proper scoring rule for
quantiles.
This quantile loss looks as follows (compare to the check loss figure
earlier), for different quantiles (&lt;span class="math"&gt;\(x=5\)&lt;/span&gt; is the sample realization, and the
horizontal axis denotes our quantile estimate).&lt;/p&gt;
&lt;p&gt;&lt;img alt="Scale-free quantile loss" src="https://www.nowozin.net/sebastian/blog/images/scoringrules-quantile-rule-scalefree.svg"&gt;&lt;/p&gt;
&lt;p&gt;The expected risk plot has a different shape compared to the check loss that
we have seen earlier, but note that the minimizer again corresponds to the
right quantiles of the &lt;span class="math"&gt;\(N(5,1)\)&lt;/span&gt; belief distribution.&lt;/p&gt;
&lt;p&gt;&lt;img alt="Integrated risk under the scale-free quantile loss" src="https://www.nowozin.net/sebastian/blog/images/scoringrules-quantile-rule-scalefree-example.svg"&gt;&lt;/p&gt;
&lt;p&gt;By using &lt;em&gt;Corollary 1&lt;/em&gt; in (Gneiting and Raftery, 2007) the sum of multiple
quantile scoring rules remains a proper scoring rule.  To obtain a scoring
rule for intervals we use the &lt;span class="math"&gt;\(\alpha\)&lt;/span&gt;-quantile and the &lt;span class="math"&gt;\((1-\alpha)\)&lt;/span&gt;-quantile
to obtain (after some rewriting of terms)&lt;/p&gt;
&lt;div class="math"&gt;\begin{eqnarray}
S_{\textrm{sf}}(L,U,x,\alpha)
    &amp;amp; = &amp;amp; -S_{\textrm{q}}(L,x,\alpha) - S_{\textrm{q}}(U,x,1-\alpha)\nonumber\\
    &amp;amp; = &amp;amp; \alpha \log(U/L) + 1_{\{x &amp;lt; L\}} \log(L/x) + 1_{\{x &amp;gt; U\}} \log(x/U).\nonumber
\end{eqnarray}&lt;/div&gt;
&lt;script type="text/javascript"&gt;if (!document.getElementById('mathjaxscript_pelican_#%@#$@#')) {
    var align = "center",
        indent = "0em",
        linebreak = "false";

    if (false) {
        align = (screen.width &lt; 768) ? "left" : align;
        indent = (screen.width &lt; 768) ? "0em" : indent;
        linebreak = (screen.width &lt; 768) ? 'true' : linebreak;
    }

    var mathjaxscript = document.createElement('script');
    mathjaxscript.id = 'mathjaxscript_pelican_#%@#$@#';
    mathjaxscript.type = 'text/javascript';
    mathjaxscript.src = 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.3/latest.js?config=TeX-AMS-MML_HTMLorMML';

    var configscript = document.createElement('script');
    configscript.type = 'text/x-mathjax-config';
    configscript[(window.opera ? "innerHTML" : "text")] =
        "MathJax.Hub.Config({" +
        "    config: ['MMLorHTML.js']," +
        "    TeX: { extensions: ['AMSmath.js','AMSsymbols.js','noErrors.js','noUndefined.js'], equationNumbers: { autoNumber: 'none' } }," +
        "    jax: ['input/TeX','input/MathML','output/HTML-CSS']," +
        "    extensions: ['tex2jax.js','mml2jax.js','MathMenu.js','MathZoom.js']," +
        "    displayAlign: '"+ align +"'," +
        "    displayIndent: '"+ indent +"'," +
        "    showMathMenu: true," +
        "    messageStyle: 'normal'," +
        "    tex2jax: { " +
        "        inlineMath: [ ['\\\\(','\\\\)'] ], " +
        "        displayMath: [ ['$$','$$'] ]," +
        "        processEscapes: true," +
        "        preview: 'TeX'," +
        "    }, " +
        "    'HTML-CSS': { " +
        "        availableFonts: ['STIX', 'TeX']," +
        "        preferredFont: 'STIX'," +
        "        styles: { '.MathJax_Display, .MathJax .mo, .MathJax .mi, .MathJax .mn': {color: 'inherit ! important'} }," +
        "        linebreaks: { automatic: "+ linebreak +", width: '90% container' }," +
        "    }, " +
        "}); " +
        "if ('default' !== 'default') {" +
            "MathJax.Hub.Register.StartupHook('HTML-CSS Jax Ready',function () {" +
                "var VARIANT = MathJax.OutputJax['HTML-CSS'].FONTDATA.VARIANT;" +
                "VARIANT['normal'].fonts.unshift('MathJax_default');" +
                "VARIANT['bold'].fonts.unshift('MathJax_default-bold');" +
                "VARIANT['italic'].fonts.unshift('MathJax_default-italic');" +
                "VARIANT['-tex-mathit'].fonts.unshift('MathJax_default-italic');" +
            "});" +
            "MathJax.Hub.Register.StartupHook('SVG Jax Ready',function () {" +
                "var VARIANT = MathJax.OutputJax.SVG.FONTDATA.VARIANT;" +
                "VARIANT['normal'].fonts.unshift('MathJax_default');" +
                "VARIANT['bold'].fonts.unshift('MathJax_default-bold');" +
                "VARIANT['italic'].fonts.unshift('MathJax_default-italic');" +
                "VARIANT['-tex-mathit'].fonts.unshift('MathJax_default-italic');" +
            "});" +
        "}";

    (document.body || document.getElementsByTagName('head')[0]).appendChild(configscript);
    (document.body || document.getElementsByTagName('head')[0]).appendChild(mathjaxscript);
}
&lt;/script&gt;</content><category term="Statistics, Machine Learning"/></entry><entry><title>How good are your beliefs? Part 1: Scoring Rules</title><link href="https://www.nowozin.net/sebastian/blog/how-good-are-your-beliefs-part-1-scoring-rules.html" rel="alternate"/><published>2015-09-04T22:00:00+01:00</published><updated>2015-09-04T22:00:00+01:00</updated><author><name>Sebastian Nowozin</name></author><id>tag:www.nowozin.net,2015-09-04:/sebastian/blog/how-good-are-your-beliefs-part-1-scoring-rules.html</id><summary type="html">&lt;p&gt;This article is the first of two on &lt;em&gt;proper scoring rules&lt;/em&gt;,
a specific type of loss function defined on probability distributions or
functions of probability distributions.&lt;/p&gt;
&lt;p&gt;If this article sparks your interest, I recommend the gentle introduction to
scoring rules in the context of decision theory in Chapter 10 of …&lt;/p&gt;</summary><content type="html">&lt;p&gt;This article is the first of two on &lt;em&gt;proper scoring rules&lt;/em&gt;,
a specific type of loss function defined on probability distributions or
functions of probability distributions.&lt;/p&gt;
&lt;p&gt;If this article sparks your interest, I recommend the gentle introduction to
scoring rules in the context of decision theory in Chapter 10 of &lt;a href="http://eu.wiley.com/WileyCDA/WileyTitle/productCd-047149657X.html"&gt;Parmigiani
and Inoue's "Decision Theory"
book&lt;/a&gt;,
which is a great book to have on your data science bookshelf in any case and
it deservedly won the &lt;a href="https://bayesian.org/awards/DeGrootPrize.html"&gt;DeGroot
prize&lt;/a&gt; in 2009.&lt;/p&gt;
&lt;h2&gt;Scoring Rules&lt;/h2&gt;
&lt;p&gt;Consider the following forecasting setting.
Given a set of possible outcomes &lt;span class="math"&gt;\(\mathcal{X}\)&lt;/span&gt; and a class of probability
measures &lt;span class="math"&gt;\(\mathcal{P}\)&lt;/span&gt; defined on a suitably constructed &lt;span class="math"&gt;\(\sigma\)&lt;/span&gt;-algebra,
we consider a &lt;em&gt;forecaster&lt;/em&gt; which makes a forecast in the form of a probability
distribution &lt;span class="math"&gt;\(P \in \mathcal{P}\)&lt;/span&gt;.
After the forecast is fixed, a realization &lt;span class="math"&gt;\(x \in \mathcal{X}\)&lt;/span&gt; is revealed and
we would like to assess quality of the prediction made by the forecaster.&lt;/p&gt;
&lt;p&gt;A &lt;em&gt;scoring rule&lt;/em&gt; is a function &lt;span class="math"&gt;\(S\)&lt;/span&gt; such that &lt;span class="math"&gt;\(S(P,x)\)&lt;/span&gt; is taken to mean the
&lt;em&gt;quality&lt;/em&gt; of the forecast.  Hence the function has the form
&lt;span class="math"&gt;\(S: \mathcal{P} \times \mathcal{X} \to \mathbb{R} \cup \{-\infty,\infty\}\)&lt;/span&gt;.
There are two variants popular in the literature: the &lt;em&gt;positively-orientied&lt;/em&gt;
scoring rules assign higher values to better forecasts, the
&lt;em&gt;negatively-oriented&lt;/em&gt; scoring rules behave like loss functions, taking smaller
values for better forecasts.&lt;/p&gt;
&lt;p&gt;A &lt;em&gt;proper&lt;/em&gt; scoring rule has desirable behaviour, to be made precise shortly.
Let us first think what could be desirable in a scoring rule.  Intuitively we
would like to make "cheating" difficult, that is, if we really subjectively
believe in &lt;span class="math"&gt;\(P\)&lt;/span&gt;, we should have no incentive to report any deviation from &lt;span class="math"&gt;\(P\)&lt;/span&gt;
in order to achieve a better score.
Formally, we first define the &lt;em&gt;expected score&lt;/em&gt; under distribution &lt;span class="math"&gt;\(Q\)&lt;/span&gt;,&lt;/p&gt;
&lt;div class="math"&gt;$$S(P,Q) = \mathbb{E}_{x \sim Q}[S(P,x)].$$&lt;/div&gt;
&lt;p&gt;So that if we believe in any prediction &lt;span class="math"&gt;\(P \in \mathcal{P}\)&lt;/span&gt;, then we should
demand that (for negatively-oriented scores)&lt;/p&gt;
&lt;div class="math"&gt;$$S(Q,Q) \leq S(P,Q),\qquad \forall P,Q \in \mathcal{P}.$$&lt;/div&gt;
&lt;p&gt;For &lt;em&gt;strictly proper&lt;/em&gt; scoring rules the above inequality holds strictly except
for &lt;span class="math"&gt;\(Q=P\)&lt;/span&gt;.
For a proper scoring rule the above inequality means that in expectation the
lowest possible score can be achieved by faithfully reporting our true
beliefs.  Therefore, a rational forecaster who aims to minimize expected score
(loss) is going to report his beliefs.&lt;/p&gt;
&lt;p&gt;Key uses of scoring rules are:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Evaluating the predictive performance of a model;&lt;/li&gt;
&lt;li&gt;Eliciting probabilities;&lt;/li&gt;
&lt;li&gt;Using them for parameter estimation.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Let us look briefly at the different uses.&lt;/p&gt;
&lt;h3&gt;Model Evaluation&lt;/h3&gt;
&lt;p&gt;For &lt;em&gt;assessing the model performance&lt;/em&gt;, we simply use the scoring rule as a loss
function and measure the predictive performance on a holdout data set.&lt;/p&gt;
&lt;h3&gt;Probability Elicitation&lt;/h3&gt;
&lt;p&gt;For &lt;em&gt;probability elicitation&lt;/em&gt; we can use a scoring rule as follows: we ask a
user to make predictions and we tell him that we will reward him
proportionally to the value achieved by the scoring rule once the prediction
can be scored.  Assuming that the user is &lt;em&gt;rational&lt;/em&gt; and aims to maximize his
reward, if we use a proper scoring rule, then he can maximize his expected
reward by making predictions according to the true beliefs he holds.
However, while the existence of a strictly proper scoring rule roughly means
that elicitation of a quantity is possible, more efficient methods for
probability elicitation may exist.  Infact, &lt;a href="http://www2.warwick.ac.uk/fac/sci/statistics/staff/academic-research/french/"&gt;Simon
French&lt;/a&gt; and &lt;a href="http://www.davidriosinsua.org/"&gt;David Rios Insua&lt;/a&gt;
argue in their book &lt;a href="http://eu.wiley.com/WileyCDA/WileyTitle/productCd-0470711051.html"&gt;Statistical Decision
Theory&lt;/a&gt;,
page 76, that&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;"de Finetti (1974; 1975) and others have championed the use of &lt;em&gt;scoring
rules&lt;/em&gt; to elicit probabilities of events. ...
Scoring rules are important in de Finetti's development of subjective
probability, but it is not clear that they have a practical use in
statistical or decision analysis. ...
Scoring rules could provide a very expensive method of eliciting
probabilities.  In training probability assessors, however, they can have a
practical use."&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;If you wonder what more efficient alternatives French and Insua have in mind,
they do propose several methods to elicit probabilities, such as an idealized
"probability wheel" the user can configure and spin, and a sequence of
proposed gambles in order to find a fair value accepted by the user.&lt;/p&gt;
&lt;p&gt;In general it seems to me (as an outsider of this field), that probability
elicitation is as much about theoretically sound methods as it is about human
psychology and biases, and how to avoid them.  The human aspect of probability
elicitation is discussed in the &lt;a href="http://www.rff.org/people/profile/roger-m-cooke"&gt;Roger
Cooke&lt;/a&gt;'s &lt;a href="https://books.google.com/books?isbn=0195362373"&gt;book-length
monograph&lt;/a&gt; on the topic, and
the recent study of &lt;a href="http://journal.sjdm.org/13/131029/jdm131029.pdf"&gt;(Goldstein and Rothschild, "Lay understanding of
probability distributions",
2014)&lt;/a&gt; (thanks to Ian Kash
for pointing me to this study!).&lt;/p&gt;
&lt;h3&gt;Estimation&lt;/h3&gt;
&lt;p&gt;For &lt;em&gt;parameter estimation&lt;/em&gt; we perform empirical risk minimization on a
probabilistic model using the scoring rule as a loss function, an approach
dating back to &lt;a href="http://link.springer.com/article/10.1007/BF02613654"&gt;(Pfanzagl,
1969)&lt;/a&gt;.  This is a
special case of &lt;a href="https://en.wikipedia.org/wiki/M-estimator"&gt;M-estimation&lt;/a&gt; but
generalizes maximum likelihood estimation (MLE), where the log-probability
scoring rule is used.&lt;/p&gt;
&lt;p&gt;If the model class contains the true generating model this yields a
&lt;a href="https://en.wikipedia.org/wiki/Consistent_estimator"&gt;&lt;em&gt;consistent estimator&lt;/em&gt;&lt;/a&gt;
but for misspecified models this can yield answers different from the MLE, and
these answers may be preferable; for example, if model assumptions are
violated and for any choice of parameter the model would put have a low
density on some observations these tend to influence the MLE severely because
the log-prob scoring rule assigns a large penalty to these observations.
Using a suitable scoring rule cannot prevent misspecification of course but
the consequences can be made less severe.&lt;/p&gt;
&lt;p&gt;It should also be said that for estimation problems the log-prob scoring rule
is the most principled in that it is the only one that can be justified from
the &lt;a href="https://projecteuclid.org/euclid.lnms/1215466210#toc"&gt;likelihood principle&lt;/a&gt;.&lt;/p&gt;
&lt;h2&gt;Scoring Rule Examples&lt;/h2&gt;
&lt;p&gt;Here are a few examples of common and not so common scoring rules both for
discrete and continuous outcomes.&lt;/p&gt;
&lt;h3&gt;Scoring Rule Example: Brier Score&lt;/h3&gt;
&lt;p&gt;This scoring rule was historically the first, proposed by
&lt;a href="http://imsc.pacificclimate.org/awards_brier.shtml"&gt;Glenn Wilson Brier&lt;/a&gt;
(1913-1998) in his seminal work
&lt;a href="http://docs.lib.noaa.gov/rescue/mwr/078/mwr-078-01-0001.pdf"&gt;(Brier, "Verification of Forecasts Expressed in Terms of Probability",
1950)&lt;/a&gt;
as a means to verify weather forecasts.&lt;/p&gt;
&lt;p&gt;Given a discrete outcome set &lt;span class="math"&gt;\(\{1,2,\dots,K\}\)&lt;/span&gt; the forecaster specifies a
distribution &lt;span class="math"&gt;\(P=(p_1,\dots,p_K)\)&lt;/span&gt; with &lt;span class="math"&gt;\(p_i \geq 0\)&lt;/span&gt; and &lt;span class="math"&gt;\(\sum_i p_i = 1\)&lt;/span&gt;.
Then, when an outcome &lt;span class="math"&gt;\(j\)&lt;/span&gt; is realized we score the forecaster according to
the &lt;em&gt;Brier score&lt;/em&gt;,&lt;/p&gt;
&lt;div class="math"&gt;$$S_B(P,j) = \sum_{i=1}^K (1_{\{i=j\}} - p_i)^2.$$&lt;/div&gt;
&lt;p&gt;The Brier score is extensively discussed in &lt;a href="http://www.dtic.mil/cgi-bin/GetTRDoc?AD=ADA121924"&gt;(DeGroot and Fienberg,
1983)&lt;/a&gt; and they show that
it can be decomposed into two terms measuring &lt;em&gt;calibration&lt;/em&gt; and &lt;em&gt;refinement&lt;/em&gt;,
respectively.  Here, &lt;em&gt;refinement&lt;/em&gt; measures the information
available to discriminate between different outcomes that is contained in the
prediction.&lt;/p&gt;
&lt;p&gt;For the case with binary classes, the definite work is &lt;a href="http://www-stat.wharton.upenn.edu/~buja/PAPERS/paper-proper-scoring.pdf"&gt;(Buja, Stuetzle, Shen,
2005)&lt;/a&gt;
in which a class of scoring rules is proposed based on the Beta distribution
which generalizes both the Brier score and the log-probability score.&lt;/p&gt;
&lt;h3&gt;Scoring Rule Example: Log-Probability&lt;/h3&gt;
&lt;p&gt;The most common scoring rule in estimation problems is the log-probability,
also known as the log-loss in machine learning.
Maximum likelihood estimation can be seen as optimizing the log-probability
scoring rule.&lt;/p&gt;
&lt;p&gt;For the discrete outcome case it is given simply by&lt;/p&gt;
&lt;div class="math"&gt;$$S_{\textrm{log}}(P,i) = -\log p_i.$$&lt;/div&gt;
&lt;p&gt;If &lt;span class="math"&gt;\(p_i = 0\)&lt;/span&gt; the score &lt;span class="math"&gt;\(S_{\textrm{log}}(P,i) = \infty\)&lt;/span&gt;.
The log-probability is a proper scoring rule, but what really distinguishes it
is that it is &lt;em&gt;local&lt;/em&gt; in that when outcome &lt;span class="math"&gt;\(j\)&lt;/span&gt; realizes only the predicted
value &lt;span class="math"&gt;\(p_j\)&lt;/span&gt; is used to compute the score.
Intuitively this is a desirable property because if &lt;span class="math"&gt;\(j\)&lt;/span&gt; happens, why should we
care about the precise distribution of probability mass for the other events?&lt;/p&gt;
&lt;p&gt;It turns out that this &lt;em&gt;local&lt;/em&gt; property is unique to the log-probability
scoring rule.  (For the result and proof see Theorem 10.1 in Parmigiani and
Inoue's book.)&lt;/p&gt;
&lt;h3&gt;Scoring Rule Example: Energy Statistic&lt;/h3&gt;
&lt;p&gt;This scoring rule is for predicting a distribution in &lt;span class="math"&gt;\(\mathbb{R}^d\)&lt;/span&gt; and is
defined for &lt;span class="math"&gt;\(\beta \in (0,2)\)&lt;/span&gt;, realization &lt;span class="math"&gt;\(x \in \mathbb{R}^d\)&lt;/span&gt;, and distribution &lt;span class="math"&gt;\(P\)&lt;/span&gt; on &lt;span class="math"&gt;\(\mathbb{R}^d\)&lt;/span&gt; as&lt;/p&gt;
&lt;div class="math"&gt;$$S_E(P,x) = \mathbb{E}_{X \sim P}[\|X-x\|^\beta] - \frac{1}{2} \mathbb{E}_{X,X' \sim P}[\|X-X'\|^\beta].$$&lt;/div&gt;
&lt;p&gt;This score has an intuitive interpretation: the score is the expected distance
to the realization minus half the expected pairwise sample distance.
Let us think about a few cases: if &lt;span class="math"&gt;\(P\)&lt;/span&gt; is a point mass, then the first term is
just the distance to the realization and the second term is zero; in
particular for &lt;span class="math"&gt;\(\beta \to 2\)&lt;/span&gt; the score recovers the squared Euclidean norm
loss.
The original definition is from &lt;a href="https://www.csss.washington.edu/~raftery/Research/PDF/Gneiting2007jasa.pdf"&gt;(Gneiting and Raftery,
2007)&lt;/a&gt; except for the sign change, but is based on
Szekely's &lt;a href="http://personal.bgsu.edu/~mrizzo/energy.htm"&gt;energy statistic&lt;/a&gt;
which also independently found its way into machine learning through the
&lt;a href="http://kyb.mpg.de/fileadmin/user_upload/files/publications/attachments/indepHS140_3437%5B0%5D.pdf"&gt;Hilbert-Schmidt independence
criterion&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;For &lt;span class="math"&gt;\(\beta \in (0,2)\)&lt;/span&gt; the energy score is a strictly proper scoring function
for all Borel measures with finite moment &lt;span class="math"&gt;\(\mathbb{E}_P[\|X\|^\beta]
&amp;lt; \infty\)&lt;/span&gt;.&lt;/p&gt;
&lt;p&gt;Here is a visualization, where &lt;span class="math"&gt;\(P = \mathcal{N}([0,0]^T, \textrm{diag}([1/2,
5/2]))\)&lt;/span&gt; is given by the 10k samples and the red marker corresponds to the
realization &lt;span class="math"&gt;\(x\)&lt;/span&gt;.  Here we have &lt;span class="math"&gt;\(\beta=1\)&lt;/span&gt;.  We can see that the Euclidean
nature of the scoring rule seems to dominate the anisotropic distribution &lt;span class="math"&gt;\(P\)&lt;/span&gt;,
that is, a realization that is unlikely under our belief distribution
(leftmost plot) achieves a lower score than a sample with higher density
(second leftmost plot).&lt;/p&gt;
&lt;p&gt;&lt;img alt="Energy score for beta equal to
one" src="https://www.nowozin.net/sebastian/blog/images/scoringrules-energyscore-beta10-80dpi.png"&gt;&lt;/p&gt;
&lt;p&gt;As a practical manner, the energy score is simple to evaluate even when you
have only predictive Monte Carlo realizations of your model, compared to the
log-probability rule which requires the normalizer of the predictive
distribution.&lt;/p&gt;
&lt;h3&gt;Scoring Rule: Check Loss&lt;/h3&gt;
&lt;p&gt;The &lt;em&gt;check loss&lt;/em&gt;, also known as &lt;em&gt;quantile loss&lt;/em&gt; or &lt;em&gt;tick loss&lt;/em&gt;, is a loss
function used for &lt;a href="https://en.wikipedia.org/wiki/Quantile_regression"&gt;quantile
regression&lt;/a&gt;, where we would
like to learn a model that directly predicts a
&lt;a href="https://en.wikipedia.org/wiki/Quantile"&gt;quantile&lt;/a&gt; of a distribution, but we
are given only samples of the distribution at training time.&lt;/p&gt;
&lt;p&gt;This scoring rule is somewhat different in that a specific property of a
belief distribution is scored, namely the quantile of the distribution.
Being &lt;em&gt;proper&lt;/em&gt; here means that the lowest expected loss is achieved by
predicting the corresponding quantile of your belief.
(Interestingly proper scoring rules exist only for some functions of the
distribution, see &lt;a href="http://arxiv.org/abs/0912.0902"&gt;(Gneiting, 2009)&lt;/a&gt;.)&lt;/p&gt;
&lt;p&gt;You may know a special case of the check loss already:
when using an absolute value loss, your expected risk is minimized by taking
the median of your belief distribution, that is, the &lt;span class="math"&gt;\(\frac{1}{2}\)&lt;/span&gt;-quantile.
The &lt;em&gt;check loss&lt;/em&gt; generalizes this to a richer family of loss functions such
that the expected minimizer corresponds to arbitrary quantiles, not just the
median.
Thus, instead of scoring an entire belief distribution &lt;span class="math"&gt;\(P\)&lt;/span&gt; we only score its
quantile statistics.&lt;/p&gt;
&lt;p&gt;The check loss is defined as&lt;/p&gt;
&lt;div class="math"&gt;$$S_{\textrm{c}}(r,x,\alpha) = (x-r) (1_{\{x \leq r\}} - \alpha),$$&lt;/div&gt;
&lt;p&gt;where &lt;span class="math"&gt;\(r\)&lt;/span&gt; is our predicted &lt;span class="math"&gt;\(\alpha\)&lt;/span&gt;-quantile and &lt;span class="math"&gt;\(x \sim Q\)&lt;/span&gt; is a sample from
the true unknown distribution &lt;span class="math"&gt;\(Q\)&lt;/span&gt;.&lt;/p&gt;
&lt;p&gt;Plotting this loss explains the name &lt;em&gt;check loss&lt;/em&gt; and &lt;em&gt;tick loss&lt;/em&gt;, because it
looks like two tilted lines.
I show it for a sample realization of &lt;span class="math"&gt;\(x=5\)&lt;/span&gt;, and the horizontal axis denotes
the quantile estimate.&lt;/p&gt;
&lt;p&gt;&lt;img alt="Check loss, a popular quantile loss" src="https://www.nowozin.net/sebastian/blog/images/scoringrules-quantile-rule.svg"&gt;&lt;/p&gt;
&lt;p&gt;For any belief distribution, taking the minimum expected risk decision yields
the matching quantile.
For example, if your beliefs are distributed according to &lt;span class="math"&gt;\(X \sim N(5,1)\)&lt;/span&gt;,
then you would consider the expected risk&lt;/p&gt;
&lt;div class="math"&gt;$$R_{\alpha}(r,\alpha) = \mathbb{E}_{X \sim N(5,1)}[-S_c(r,X,\alpha)].$$&lt;/div&gt;
&lt;p&gt;This convolves the check loss function with the belief distribution, in this
case corresponding to a Gaussian kernel.
The minimizer over &lt;span class="math"&gt;\(r\)&lt;/span&gt; of this expected risk function would correspond to your
optimal decision.&lt;/p&gt;
&lt;p&gt;&lt;img alt="Integrated risk under the check loss" src="https://www.nowozin.net/sebastian/blog/images/scoringrules-quantile-rule-example.svg"&gt;&lt;/p&gt;
&lt;p&gt;The above plot marks the 10/50/90 quantiles and these correspond to the
minimizers of the expected risks of the respective check losses.&lt;/p&gt;
&lt;h2&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;The above is only a small peek into the vast literature on scoring rules.
If you are mathematically inclined, I highly recommend &lt;a href="https://www.csss.washington.edu/~raftery/Research/PDF/Gneiting2007jasa.pdf"&gt;(Gneiting and Raftery,
2007)&lt;/a&gt;
as an enjoyable further read and &lt;a href="http://www.cs.colorado.edu/~raf/media/papers/vec-props.pdf"&gt;(Frongillo and Kash,
2015)&lt;/a&gt; for the
most recent general results; everyone else may enjoy the book mentioned in the
introduction.&lt;/p&gt;
&lt;p&gt;In the second part we are going to put your forecasting skills to the test via
an interactive quiz!&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Acknowledgements&lt;/em&gt;.  I thank &lt;a href="http://research.microsoft.com/en-us/people/iankash/"&gt;&lt;em&gt;Ian
Kash&lt;/em&gt;&lt;/a&gt; for further
insightful discussions on scoring rules and pointing me to relevant
literature.  I thank &lt;em&gt;Aidan Campbell&lt;/em&gt; for a correction to the definition of
properness.&lt;/p&gt;
&lt;script type="text/javascript"&gt;if (!document.getElementById('mathjaxscript_pelican_#%@#$@#')) {
    var align = "center",
        indent = "0em",
        linebreak = "false";

    if (false) {
        align = (screen.width &lt; 768) ? "left" : align;
        indent = (screen.width &lt; 768) ? "0em" : indent;
        linebreak = (screen.width &lt; 768) ? 'true' : linebreak;
    }

    var mathjaxscript = document.createElement('script');
    mathjaxscript.id = 'mathjaxscript_pelican_#%@#$@#';
    mathjaxscript.type = 'text/javascript';
    mathjaxscript.src = 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.3/latest.js?config=TeX-AMS-MML_HTMLorMML';

    var configscript = document.createElement('script');
    configscript.type = 'text/x-mathjax-config';
    configscript[(window.opera ? "innerHTML" : "text")] =
        "MathJax.Hub.Config({" +
        "    config: ['MMLorHTML.js']," +
        "    TeX: { extensions: ['AMSmath.js','AMSsymbols.js','noErrors.js','noUndefined.js'], equationNumbers: { autoNumber: 'none' } }," +
        "    jax: ['input/TeX','input/MathML','output/HTML-CSS']," +
        "    extensions: ['tex2jax.js','mml2jax.js','MathMenu.js','MathZoom.js']," +
        "    displayAlign: '"+ align +"'," +
        "    displayIndent: '"+ indent +"'," +
        "    showMathMenu: true," +
        "    messageStyle: 'normal'," +
        "    tex2jax: { " +
        "        inlineMath: [ ['\\\\(','\\\\)'] ], " +
        "        displayMath: [ ['$$','$$'] ]," +
        "        processEscapes: true," +
        "        preview: 'TeX'," +
        "    }, " +
        "    'HTML-CSS': { " +
        "        availableFonts: ['STIX', 'TeX']," +
        "        preferredFont: 'STIX'," +
        "        styles: { '.MathJax_Display, .MathJax .mo, .MathJax .mi, .MathJax .mn': {color: 'inherit ! important'} }," +
        "        linebreaks: { automatic: "+ linebreak +", width: '90% container' }," +
        "    }, " +
        "}); " +
        "if ('default' !== 'default') {" +
            "MathJax.Hub.Register.StartupHook('HTML-CSS Jax Ready',function () {" +
                "var VARIANT = MathJax.OutputJax['HTML-CSS'].FONTDATA.VARIANT;" +
                "VARIANT['normal'].fonts.unshift('MathJax_default');" +
                "VARIANT['bold'].fonts.unshift('MathJax_default-bold');" +
                "VARIANT['italic'].fonts.unshift('MathJax_default-italic');" +
                "VARIANT['-tex-mathit'].fonts.unshift('MathJax_default-italic');" +
            "});" +
            "MathJax.Hub.Register.StartupHook('SVG Jax Ready',function () {" +
                "var VARIANT = MathJax.OutputJax.SVG.FONTDATA.VARIANT;" +
                "VARIANT['normal'].fonts.unshift('MathJax_default');" +
                "VARIANT['bold'].fonts.unshift('MathJax_default-bold');" +
                "VARIANT['italic'].fonts.unshift('MathJax_default-italic');" +
                "VARIANT['-tex-mathit'].fonts.unshift('MathJax_default-italic');" +
            "});" +
        "}";

    (document.body || document.getElementsByTagName('head')[0]).appendChild(configscript);
    (document.body || document.getElementsByTagName('head')[0]).appendChild(mathjaxscript);
}
&lt;/script&gt;</content><category term="Statistics, Machine Learning"/></entry><entry><title>Machine Learning for Intelligent Image and Video Processing (ICCV 2015 Workshop)</title><link href="https://www.nowozin.net/sebastian/blog/machine-learning-for-intelligent-image-and-video-processing-iccv-2015-workshop.html" rel="alternate"/><published>2015-09-02T23:30:00+01:00</published><updated>2015-09-02T23:30:00+01:00</updated><author><name>Sebastian Nowozin</name></author><id>tag:www.nowozin.net,2015-09-02:/sebastian/blog/machine-learning-for-intelligent-image-and-video-processing-iccv-2015-workshop.html</id><summary type="html">&lt;p&gt;&lt;a href="http://ei.is.tuebingen.mpg.de/person/mhirsch"&gt;Michael Hirsch&lt;/a&gt; and myself are
organizing a &lt;a href="http://ml4ip-iccv2015.is.tuebingen.mpg.de"&gt;workshop on the topic of machine learning for image and video
processing&lt;/a&gt;
as part of the &lt;a href="http://pamitc.org/iccv15/"&gt;ICCV 2015 programme&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;The workshop takes place on the 17th December 2015 in Santiago, Chile, right
after the main ICCV conference.&lt;/p&gt;
&lt;h2&gt;Call for Contributions&lt;/h2&gt;
&lt;p&gt;Image processing methods …&lt;/p&gt;</summary><content type="html">&lt;p&gt;&lt;a href="http://ei.is.tuebingen.mpg.de/person/mhirsch"&gt;Michael Hirsch&lt;/a&gt; and myself are
organizing a &lt;a href="http://ml4ip-iccv2015.is.tuebingen.mpg.de"&gt;workshop on the topic of machine learning for image and video
processing&lt;/a&gt;
as part of the &lt;a href="http://pamitc.org/iccv15/"&gt;ICCV 2015 programme&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;The workshop takes place on the 17th December 2015 in Santiago, Chile, right
after the main ICCV conference.&lt;/p&gt;
&lt;h2&gt;Call for Contributions&lt;/h2&gt;
&lt;p&gt;Image processing methods are highly relevant in a large variety of
industrial and consumer applications. Traditionally some of the
successful methods have been derived based on a careful consideration
of the particular imaging modality and task, or on an adhoc basis by
image processing practitioners. More recently statistical machine
learning models have been proposed for tasks such as denoising,
deblurring, inpainting, etc., often leading to significant gains in
image quality. Machine learning methods require training data to learn
about the image statistics and the task, and challenges arise in how
this data should be collected and how ground truth is obtained.&lt;/p&gt;
&lt;p&gt;The goal of this workshop is to bring together researchers from the
image processing and machine learning community to discuss all issues
related to machine learning models for image processing applications.&lt;/p&gt;
&lt;p&gt;We invite submission of papers on relevant topics including, but not
limited to the following areas:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Statistical modelling of image processing tasks&lt;/li&gt;
&lt;li&gt;Runtime and data efficiency&lt;/li&gt;
&lt;li&gt;Tractable estimation&lt;/li&gt;
&lt;li&gt;Deep learning for image processing applications&lt;/li&gt;
&lt;li&gt;Procedures to obtain ground truth data sets&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;In all aspects the ICCV community has been at the forefront of developing
new ideas and we hope to continue this development through this workshop.&lt;/p&gt;
&lt;h3&gt;Keynote Speakers&lt;/h3&gt;
&lt;p&gt;Join us for an exciting program including invited talks by:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="https://users.soe.ucsc.edu/~milanfar/"&gt;Peyman Milanfar&lt;/a&gt;, Google&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.visinf.tu-darmstadt.de/vi_people/sroth/sroth.en.jsp"&gt;Stefan Roth&lt;/a&gt;, TU Darmstadt&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;Important Dates&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Submission deadline: Friday, September 25th, 2015&lt;/li&gt;
&lt;li&gt;Author Notification: Friday, October 16th, 2015&lt;/li&gt;
&lt;li&gt;Final version of submission: Friday, October 23rd, 2015&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;Submission Instructions&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Papers should be in ICCV style&lt;/li&gt;
&lt;li&gt;Maximum paper length is 6 pages&lt;/li&gt;
&lt;li&gt;Papers will be reviewed in a double blind process&lt;/li&gt;
&lt;li&gt;Accepted papers are not published as part of IEEE Proceedings but
  inofficially on the workshop website&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Accepted papers will be presented at the poster session with an
additional poster spotlight presentation. One author of every accepted
paper has to attend the workshop to present poster and spotlight talk.&lt;/p&gt;
&lt;h3&gt;Organizers&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Sebastian Nowozin, Microsoft Research, Cambridge, UK&lt;/li&gt;
&lt;li&gt;Michael Hirsch, Max Planck Institute for Intelligent Systems, Germany&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Please find further details at the &lt;a href="http://ml4ip-iccv2015.is.tuebingen.mpg.de"&gt;workshop
website&lt;/a&gt; or send me an email in
case you have any questions.&lt;/p&gt;</content><category term="Computer Vision, Image Processing, Machine Learning"/></entry><entry><title>Effective Sample Size in Importance Sampling</title><link href="https://www.nowozin.net/sebastian/blog/effective-sample-size-in-importance-sampling.html" rel="alternate"/><published>2015-08-21T21:30:00+01:00</published><updated>2015-08-21T21:30:00+01:00</updated><author><name>Sebastian Nowozin</name></author><id>tag:www.nowozin.net,2015-08-21:/sebastian/blog/effective-sample-size-in-importance-sampling.html</id><summary type="html">&lt;p&gt;In this article we will look at a practically important measure of efficiency
in importance sampling, the so called &lt;em&gt;effective sample size&lt;/em&gt; (ESS) estimate.
This measure was proposed by &lt;a href="http://www.decode.com/management/"&gt;Augustine
Kong&lt;/a&gt; in 1992 in a technical report which
until recently has been difficult to locate online, but after getting in …&lt;/p&gt;</summary><content type="html">&lt;p&gt;In this article we will look at a practically important measure of efficiency
in importance sampling, the so called &lt;em&gt;effective sample size&lt;/em&gt; (ESS) estimate.
This measure was proposed by &lt;a href="http://www.decode.com/management/"&gt;Augustine
Kong&lt;/a&gt; in 1992 in a technical report which
until recently has been difficult to locate online, but after getting in
contact with the University of Chicago I am pleased that the report is now
available (again):&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Augustine Kong, "A Note on Importance Sampling using Standardized Weights",
Technical Report 348,
&lt;a href="https://galton.uchicago.edu/techreports/tr348.pdf"&gt;PDF&lt;/a&gt;,
Department of Statistics, University of Chicago, July 1992.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Before we discuss the usefulness of the effective sample size, let us first
define the notation and context for importance sampling.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://en.wikipedia.org/wiki/Importance_sampling"&gt;Importance sampling&lt;/a&gt; is one
of the most generally applicable method to sample from otherwise intractable
distributions.
In machine learning and statistics importance sampling is regularly used for
sampling from distributions in low dimensions (say, up to maybe 20
dimensions).
The general idea of importance sampling has been extended since the 1950s
to the sequential setting and the resulting class of modern
&lt;a href="http://www.stats.ox.ac.uk/~doucet/doucet_defreitas_gordon_smcbookintro.pdf"&gt;&lt;em&gt;Sequential Monte Carlo&lt;/em&gt; (SMC) methods&lt;/a&gt;
constitute the state of the art Monte Carlo methods in many important time
series modeling applications.&lt;/p&gt;
&lt;p&gt;The general idea of importance sampling is as follows.
We are interested in computing an expectation,
&lt;/p&gt;
&lt;div class="math"&gt;$$\mu = \mathbb{E}_{X \sim p}[h(X)] = \int h(x) p(x) \,\textrm{d}x.$$&lt;/div&gt;
&lt;p&gt;
If we can sample from &lt;span class="math"&gt;\(p\)&lt;/span&gt; directly, the standard Monte Carlo estimate is
possible, and we draw &lt;span class="math"&gt;\(X_i \sim p\)&lt;/span&gt;, &lt;span class="math"&gt;\(i=1,\dots,n\)&lt;/span&gt;, then use
&lt;/p&gt;
&lt;div class="math"&gt;$$\hat{\mu} = \frac{1}{n} \sum_{i=1}^n h(X_i).$$&lt;/div&gt;
&lt;p&gt;In many applications we cannot directly sample from &lt;span class="math"&gt;\(p\)&lt;/span&gt;.
In this case importance sampling can still be applied by sampling from a
tractable proposal distribution &lt;span class="math"&gt;\(q\)&lt;/span&gt;, with &lt;span class="math"&gt;\(X_i \sim q\)&lt;/span&gt;, &lt;span class="math"&gt;\(i=1,\dots,n\)&lt;/span&gt;, then
reweighting the sample using the ratio &lt;span class="math"&gt;\(p(X_i)/q(X_i)\)&lt;/span&gt;, leading to the
standard importance sampling estimate
&lt;/p&gt;
&lt;div class="math"&gt;$$\tilde{\mu} = \frac{1}{n} \sum_{i=1}^n \frac{p(X_i)}{q(X_i)} h(X_i).$$&lt;/div&gt;
&lt;p&gt;In case &lt;span class="math"&gt;\(p\)&lt;/span&gt; is known only up to an unknown normalizing constant, the so called
&lt;em&gt;self-normalized importance sampling estimate&lt;/em&gt; can be used.
Denoting the weights by &lt;span class="math"&gt;\(w(X_i) = \frac{p(X_i)}{q(X_i)}\)&lt;/span&gt; it is defined as
&lt;/p&gt;
&lt;div class="math"&gt;$$\bar{\mu} = \frac{\frac{1}{n} \sum_{i=1}^n w(X_i) h(X_i)}{
    \frac{1}{n} \sum_{i=1}^n w(X_i)}.$$&lt;/div&gt;
&lt;p&gt;The quality of this estimate chiefly depends on how good the proposal
distribution &lt;span class="math"&gt;\(q\)&lt;/span&gt; matches the form of &lt;span class="math"&gt;\(p\)&lt;/span&gt;.  Because &lt;span class="math"&gt;\(p\)&lt;/span&gt; is difficult to sample
from, it typically is also difficult to make a precise statement about the
quality of approximation of &lt;span class="math"&gt;\(q\)&lt;/span&gt;.&lt;/p&gt;
&lt;p&gt;The effective sample size solves this issue: it can be used after or during
importance sampling to provide a quantitative measure of the quality of the
estimated mean.
Even better, the estimate is provided on a natural scale of worth in samples
from &lt;span class="math"&gt;\(p\)&lt;/span&gt;, that is, if we use &lt;span class="math"&gt;\(n=1000\)&lt;/span&gt; samples &lt;span class="math"&gt;\(X_i \sim q\)&lt;/span&gt; and obtain an ESS
of say 350 then this indicates that the quality of our estimate is about the
same as if we would have used 350 direct samples &lt;span class="math"&gt;\(X_i \sim p\)&lt;/span&gt;.  This justifies
the name &lt;em&gt;effective sample size&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;Since the late 1990s the effective sample size is popularly used as a reliable
diagnostic in importance sampling and sequential Monte Carlo applications.
Sometimes it even informs the algorithm during sampling; for example, one can
continue an importance sampling method until a certain ESS has been reached.
Another example is during SMC where the ESS is often used to decide whether
operations such as resampling or rejuvenation are performed.&lt;/p&gt;
&lt;h2&gt;Definition&lt;/h2&gt;
&lt;p&gt;Two alternative but equivalent definitions exist.  Assume normalized weights
&lt;span class="math"&gt;\(w_i \geq 0\)&lt;/span&gt; with &lt;span class="math"&gt;\(\sum_{i=1}^n w_i = 1\)&lt;/span&gt;.  Then, the original definition of
the effective sample size estimate is by Kong, popularized by &lt;a href="http://www.people.fas.harvard.edu/~junliu/"&gt;Jun
Liu&lt;/a&gt; in
&lt;a href="https://stat.duke.edu/~scs/Courses/Stat376/Papers/ConvergeRates/LiuMetropolized1996.pdf"&gt;this
paper&lt;/a&gt;, as
&lt;/p&gt;
&lt;div class="math"&gt;$$\textrm{ESS} = \frac{n}{1 + \textrm{Var}_q(W)},$$&lt;/div&gt;
&lt;p&gt;
where &lt;span class="math"&gt;\(\textrm{Var}_q(W) = \frac{1}{n-1} \sum_{i=1}^n (w_i - \frac{1}{n})^2\)&lt;/span&gt;.
The alternative form emerged later (I did not manage to find its first use
precisely), and has the form
&lt;/p&gt;
&lt;div class="math"&gt;$$\textrm{ESS} = \frac{1}{\sum_{i=1}^n w_i^2}.$$&lt;/div&gt;
&lt;p&gt;When the weights are unnormalized, we define &lt;span class="math"&gt;\(\tilde{w}_i = w_i /
(\sum_{i=1}^n w_i)\)&lt;/span&gt; and see that
&lt;/p&gt;
&lt;div class="math"&gt;$$\textrm{ESS} = \frac{1}{\sum_{i=1}^n \tilde{w}_i^2}
= \frac{(\sum_{i=1}^n w_i)^2}{\sum_{i=1}^n w_i^2}.$$&lt;/div&gt;
&lt;p&gt;As is often the case in numerical computation in probabilistic models the
quantities are often stored in log-domain, i.e. we would store &lt;span class="math"&gt;\(\log w_i\)&lt;/span&gt;
instead of &lt;span class="math"&gt;\(w_i\)&lt;/span&gt;, and compute the above equations in log-space.&lt;/p&gt;
&lt;h2&gt;Example&lt;/h2&gt;
&lt;p&gt;As a simple example we set the target distribution to be a
&lt;span class="math"&gt;\(\textrm{StudentT}(0,\nu)\)&lt;/span&gt; with &lt;span class="math"&gt;\(\nu=8\)&lt;/span&gt; degrees of freedom, and the proposal
to be a Normal &lt;span class="math"&gt;\(\mathcal{N}(\mu,16)\)&lt;/span&gt;.
We then visualize the ESS as a function of the shift &lt;span class="math"&gt;\(\mu\)&lt;/span&gt; of the Normal
proposal.  The sample size should decrease away from the true mean (zero) and
be highest at zero.&lt;/p&gt;
&lt;p&gt;&lt;img alt="ESS example, StudentT target, Normal proposal" src="https://www.nowozin.net/sebastian/blog/images/ess-demo-1.svg"&gt;&lt;/p&gt;
&lt;p&gt;This is indeed what happens in the above plot and, not shown, the estimated
variance from the ESS agrees with the variance over many replicates.&lt;/p&gt;
&lt;h2&gt;Derivation&lt;/h2&gt;
&lt;p&gt;The following derivation is from Kong's technical report, however, to make it
self-contained and accessible I fleshed out some details and give explanations
inline.&lt;/p&gt;
&lt;p&gt;We start with an expression for &lt;span class="math"&gt;\(\textrm{Var}(\bar{\mu})\)&lt;/span&gt;.
This is a variance of a ratio expression with positive denominator; hence we
can apply the multivariate delta method for ratio expressions (see appendix
below) to obtain an asymptotic approximation.
Following Kong's original notation we define &lt;span class="math"&gt;\(W_i = w(X_i)\)&lt;/span&gt; and &lt;span class="math"&gt;\(W=W_1\)&lt;/span&gt;, as
well as &lt;span class="math"&gt;\(Z_i = h(X_i) w(X_i)\)&lt;/span&gt; and &lt;span class="math"&gt;\(Z = Z_1\)&lt;/span&gt;.
Then we have the asymptotic delta method approximation
&lt;/p&gt;
&lt;div class="math"&gt;\begin{eqnarray}
\textrm{Var}_q(\bar{\mu}) &amp;amp; \approx &amp;amp;
    \frac{1}{n}\left[\frac{\textrm{Var}_q(Z)}{(\mathbb{E}_q W)^2}
        - 2 \frac{\mathbb{E}_q Z}{(\mathbb{E}_q W)^3} \textrm{Cov}_q(Z,W)
        + \frac{(\mathbb{E}_q Z)^2}{(\mathbb{E}_q W)^4}
            \textrm{Var}_q(W)\right].\label{eqn:delta1}
\end{eqnarray}&lt;/div&gt;
&lt;p&gt;
We can simplify this somewhat intimidating expression by realizing that
&lt;/p&gt;
&lt;div class="math"&gt;$$\mathbb{E}_q W = \int \frac{p(x)}{q(x)} q(x) \,\textrm{d}x
    = \int p(x) \,\textrm{d}x = 1.$$&lt;/div&gt;
&lt;p&gt;
(For the unnormalized case the derivation result is the same because the ratio
&lt;span class="math"&gt;\(\bar{\mu}\)&lt;/span&gt; does not depend on the normalization constant.)
Then we can simplify &lt;span class="math"&gt;\((\ref{eqn:delta1})\)&lt;/span&gt; to
&lt;/p&gt;
&lt;div class="math"&gt;\begin{eqnarray}
    &amp;amp; = &amp;amp;
    \frac{1}{n}\left[\textrm{Var}_q(Z)
        - 2 (\mathbb{E}_q Z) \textrm{Cov}_q(Z,W)
        + (\mathbb{E}_q Z)^2 \textrm{Var}_q(W)\right].\label{eqn:delta2}
\end{eqnarray}&lt;/div&gt;
&lt;p&gt;
The next step is to realize that
&lt;span class="math"&gt;\(\mathbb{E}_q Z = \int w(x) h(x) q(x) \,\textrm{d}x
    = \int \frac{p(x)}{q(x)} q(x) h(x) \,\textrm{d}x
    = \int h(x) p(x) \,\textrm{d}x = \mu.\)&lt;/span&gt;
Thus &lt;span class="math"&gt;\((\ref{eqn:delta2})\)&lt;/span&gt; further simplifies to
&lt;/p&gt;
&lt;div class="math"&gt;\begin{eqnarray}
    &amp;amp; = &amp;amp;
    \frac{1}{n}\big[\underbrace{\textrm{Var}_q(Z)}_{\textrm{(B)}}
        - 2 \mu \underbrace{\textrm{Cov}_q(Z,W)}_{\textrm{(A)}}
        + \mu^2 \textrm{Var}_q(W)\big].
    \label{eqn:delta3}
\end{eqnarray}&lt;/div&gt;
&lt;p&gt;This is great progress, but we need to nibble on this expression some more.
Let us consider the parts (A) and (B), in this order.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;(A)&lt;/strong&gt;.  To simplify this expression we can leverage the &lt;a href="http://en.wikipedia.org/wiki/Covariance#Definition"&gt;definition of the
covariance&lt;/a&gt; and then apply
the known relations of our special expectations.
This yields.
&lt;/p&gt;
&lt;div class="math"&gt;\begin{eqnarray}
\textrm{(A)} = \textrm{Cov}_q(Z,W) &amp;amp; = &amp;amp;
    \mathbb{E}_q[\underbrace{Z}_{= W H} W]
        - \underbrace{(\mathbb{E}_q Z)}_{= \mu}
            \underbrace{(\mathbb{E}_q W)}_{= 1}\nonumber\\
    &amp;amp; = &amp;amp; \mathbb{E}_q[H W^2] - \mu\nonumber\\
    &amp;amp; = &amp;amp; \mathbb{E}_p[H W] - \mu.\label{eqn:A1}
\end{eqnarray}&lt;/div&gt;
&lt;p&gt;
Note the change of measure from &lt;span class="math"&gt;\(q\)&lt;/span&gt; to &lt;span class="math"&gt;\(p\)&lt;/span&gt; in the last step.
To break down the expectation of the product further we use the known rules
about expectations, namely &lt;span class="math"&gt;\(\textrm{Cov}(X,Y) = \mathbb{E}[XY] -
(\mathbb{E}X)(\mathbb{E}Y)\)&lt;/span&gt;, which leds us to
&lt;/p&gt;
&lt;div class="math"&gt;\begin{eqnarray}
\textrm{(A)} = \textrm{Cov}_q(Z,W) &amp;amp; = &amp;amp;
    \textrm{Cov}_p(H,W) + \mu \mathbb{E}_p W - \mu.\label{eqn:A2}
\end{eqnarray}&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;(B)&lt;/strong&gt;.  First we expand the variance by its definition, then simplify.
&lt;/p&gt;
&lt;div class="math"&gt;$$\textrm{Var}_q(Z) = \textrm{Var}_q(W H)
    = \mathbb{E}_q[W^2 H^2] - (\underbrace{\mathbb{E}_q[WH]}_{= \mu})^2
    = \mathbb{E}_p[W H^2] - \mu^2.$$&lt;/div&gt;
&lt;p&gt;For approaching &lt;span class="math"&gt;\(\mathbb{E}_p[W H^2]\)&lt;/span&gt; we need to leverage the second-order
delta method (see appendix) which gives the following approximation,
&lt;/p&gt;
&lt;div class="math"&gt;\begin{eqnarray}
\mathbb{E}_p[W H^2] &amp;amp; \approx &amp;amp;
    (\mathbb{E}_p W)\underbrace{(\mathbb{E}_p H)^2}_{= \mu^2}
    + 2 \underbrace{\mathbb{E}_p[H]}_{\mu} \textrm{Cov}_p(W,H)
    + (\mathbb{E}_p W) \textrm{Var}_p(H)\nonumber\\
    &amp;amp; = &amp;amp; (\mathbb{E}_p W) \mu^2 + 2 \mu \textrm{Cov}_p(W,H)
        + (\mathbb{E}_p W) \textrm{Var}_p(H).
    \label{eqn:B1}
\end{eqnarray}&lt;/div&gt;
&lt;p&gt;Ok, almost done.  We now leverage our work to harvest:
&lt;/p&gt;
&lt;div class="math"&gt;\begin{eqnarray}
\textrm{Var}_q(\bar{\mu}) &amp;amp; \approx &amp;amp;
    \frac{1}{n}\big[\underbrace{\textrm{Var}_q(Z)}_{\textrm{(B)}}
        - 2 \mu \underbrace{\textrm{Cov}_q(Z,W)}_{\textrm{(A)}}
        + \mu^2 \textrm{Var}_q(W)\big]\nonumber\\
    &amp;amp; \approx &amp;amp; \frac{1}{n}\big[
        \left(
            (\mathbb{E}_p W) \mu^2 + 2 \mu \textrm{Cov}_p(W,H)
            + (\mathbb{E}_p W) \textrm{Var}_p(H) - \mu^2
        \right)\nonumber\\
    &amp;amp; &amp;amp; \qquad
        - 2 \mu \left(\textrm{Cov}_p(H,W) + \mu\mathbb{E}_p W - \mu\right)
        \nonumber\\
    &amp;amp; &amp;amp; \qquad + \mu^2 \textrm{Var}_q(W)
        \big]\nonumber\\
    &amp;amp; = &amp;amp; \frac{1}{n}\left[\mu^2 \left(
            1 + \textrm{Var}_q(W) - \mathbb{E}_p W\right)
        + (\mathbb{E}_p W) \textrm{Var}_p(H)\right].\label{eqn:H1}
\end{eqnarray}&lt;/div&gt;
&lt;p&gt;Finally, we can reduce &lt;span class="math"&gt;\((\ref{eqn:H1})\)&lt;/span&gt; further by
&lt;/p&gt;
&lt;div class="math"&gt;$$\mathbb{E}_p W = \mathbb{E}_q[W^2]
    = \textrm{Var}_q(W) + (\mathbb{E}_q W)^2
    = \textrm{Var}_q(W) + 1.$$&lt;/div&gt;
&lt;p&gt;
For the other term we have
&lt;/p&gt;
&lt;div class="math"&gt;$$\frac{1}{n} \textrm{Var}_p(H) = \textrm{Var}_p(\hat{\mu}).$$&lt;/div&gt;
&lt;p&gt;
This simplifies &lt;span class="math"&gt;\((\ref{eqn:H1})\)&lt;/span&gt; to the following satisfying expression.
&lt;/p&gt;
&lt;div class="math"&gt;$$\textrm{Var}_q(\bar{\mu}) \approx \textrm{Var}_p(\hat{\mu})
    (1 + \textrm{Var}_q(W)).$$&lt;/div&gt;
&lt;p&gt;
This reads as "the variance of the self-normalized importance sampling
estimate is approximately equal to the variance of the simple Monte Carlo
estimate times &lt;span class="math"&gt;\(1 + \textrm{Var}_q(W)\)&lt;/span&gt;."&lt;/p&gt;
&lt;p&gt;Therefore, when taking &lt;span class="math"&gt;\(n\)&lt;/span&gt; samples to compute &lt;span class="math"&gt;\(\bar{\mu}\)&lt;/span&gt; the &lt;em&gt;effective
sample size&lt;/em&gt; is estimated as
&lt;/p&gt;
&lt;div class="math"&gt;$$\textrm{ESS} = \frac{n}{1 + \textrm{Var}_q(W)}.$$&lt;/div&gt;
&lt;p&gt;Two comments:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;We can estimate &lt;span class="math"&gt;\(\textrm{Var}_q(W)\)&lt;/span&gt; by the sample variance of the
normalized importance weights.&lt;/li&gt;
&lt;li&gt;This estimate does not depend on the integrand &lt;span class="math"&gt;\(h\)&lt;/span&gt;.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;The simpler form of the ESS estimate can be obtained by estimating
&lt;/p&gt;
&lt;div class="math"&gt;\begin{eqnarray}
\textrm{Var}_q(W) &amp;amp; \approx &amp;amp; \frac{1}{n} \sum_{i=1}^n (w_i - \frac{1}{n})^2
    \nonumber\\
    &amp;amp; = &amp;amp; \frac{1}{n} \sum_{i=1}^n w_i^2 - \frac{1}{n^2}.\nonumber
\end{eqnarray}&lt;/div&gt;
&lt;p&gt;
which yields
&lt;/p&gt;
&lt;div class="math"&gt;$$\textrm{ESS} = \frac{n}{1 + \frac{1}{n} \sum_i w_i^2 - \frac{1}{n^2}}
    = \frac{1}{\sum_{i=1}^n w_i^2}.$$&lt;/div&gt;
&lt;h2&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;Monte Carlo methods such as importance sampling and Markov chain Monte Carlo
can fail in case the proposal distribution is not suitable chosen.  Therefore,
we should always employ diagnostics, and for importance sampling the effective
sampling size diagnostic has become the standard due to its simplicity,
intuitive interpretation, and its robustness in practical applications.&lt;/p&gt;
&lt;p&gt;However, the effective sample size can fail, for example when all proposal
samples are in a region where the target distribution has few probability mass.
In that case, the weights would be approximately equal and the ESS close to
optimal, failing to diagnose the mismatch between proposal and target
distribution.  This is, in a way, unavoidable: if we never get to see a high
probability region of the target distribution, the low value of our samples is
hard to recognize.&lt;/p&gt;
&lt;p&gt;For another discussion on importance sampling diagnostics and an alternative
derivation, see &lt;a href="http://statweb.stanford.edu/~owen/mc/Ch-var-is.pdf"&gt;Section 9.3 in Art Owen's upcoming Monte Carlo
book&lt;/a&gt;.
Among many interesting things in that chapter, he proposes an effective sample
size statistic specific to the particular integrand &lt;span class="math"&gt;\(h\)&lt;/span&gt;.  For this, redefine
the weights as
&lt;/p&gt;
&lt;div class="math"&gt;$$w_h(X_i) = \frac{\frac{p(X_i)}{q(X_i)} |h(X_i)|}{
    \sum_{i=1}^n \frac{p(X_i)}{q(X_i)} |h(X_i)|},$$&lt;/div&gt;
&lt;p&gt;
then use the normal &lt;span class="math"&gt;\(1/\sum_i w_h(X_i)^2\)&lt;/span&gt; estimate.  This variant is more
accurate because it takes the integrand into account.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Addendum:&lt;/em&gt; &lt;a href="http://arxiv.org/abs/1602.03572"&gt;This paper&lt;/a&gt; by Martino, Elvira,
and Louzada, takes a detailed look at variations of the effective sample size
statistic.&lt;/p&gt;
&lt;h2&gt;Appendix: The Multivariate Delta Method&lt;/h2&gt;
&lt;p&gt;The &lt;a href="http://en.wikipedia.org/wiki/Delta_method"&gt;&lt;em&gt;delta method&lt;/em&gt;&lt;/a&gt; is a classic
method using in asymptotic statistics to obtain limiting expressions for the
mean and variance of functions of random variables.  It can be seen as the
statistical analog of the Taylor approximation to a function.&lt;/p&gt;
&lt;p&gt;The multivariate extension is also classic, and the following theorem can be
found in many works, I picked the one given as Theorem 3.7 in
&lt;a href="http://www.stat.purdue.edu/~dasgupta/"&gt;DasGupta's&lt;/a&gt;
&lt;a href="http://www.springer.com/mathematics/probability/book/978-0-387-75970-8"&gt;book on asymptotic
statistics&lt;/a&gt;
(by the way, this book is a favorite of mine for its accessible presentation
of many practical result in classical statistics).
A more advanced and specialized book on expansions beyond the delta method is
&lt;a href="https://math.uwaterloo.ca/statistics-and-actuarial-science/people-profiles/christopher-small"&gt;Christopher
Small&lt;/a&gt;'s
&lt;a href="https://books.google.co.uk/books?id=uXexXLoZnZAC"&gt;book on the topic&lt;/a&gt;.&lt;/p&gt;
&lt;h3&gt;Delta Method for Distributions&lt;/h3&gt;
&lt;p&gt;&lt;em&gt;&lt;strong&gt;Theorem&lt;/strong&gt; (Multivariate Delta Method for Distributions).&lt;/em&gt;  Suppose
&lt;span class="math"&gt;\(\{T_n\}\)&lt;/span&gt; is a sequence of &lt;span class="math"&gt;\(k\)&lt;/span&gt;-dimensional random vectors such that
&lt;/p&gt;
&lt;div class="math"&gt;$$\sqrt{n}(T_n - \theta) \stackrel{\mathcal{L}}{\rightarrow}
    \mathcal{N}_k(0,\Sigma(\theta)).$$&lt;/div&gt;
&lt;p&gt;
Let &lt;span class="math"&gt;\(g:\mathbb{R}^k \to \mathbb{R}^m\)&lt;/span&gt; be once differentiable at &lt;span class="math"&gt;\(\theta\)&lt;/span&gt; with
the gradient vector &lt;span class="math"&gt;\(\nabla g(\theta)\)&lt;/span&gt;.  Then
&lt;/p&gt;
&lt;div class="math"&gt;$$\sqrt{n}(g(T_n) - g(\theta)) \stackrel{\mathcal{L}}{\rightarrow}
    \mathcal{N}_m(0, \nabla g(\theta)^T \Sigma(\theta) \nabla g(\theta))$$&lt;/div&gt;
&lt;p&gt;
provided &lt;span class="math"&gt;\(\nabla g(\theta)^T \Sigma(\theta) \nabla g(\theta)\)&lt;/span&gt; is positive
definite.&lt;/p&gt;
&lt;p&gt;This simply says that if we have a vector &lt;span class="math"&gt;\(T\)&lt;/span&gt; of random variables and we know
that &lt;span class="math"&gt;\(T\)&lt;/span&gt; converges asymptotically to a Normal, then we can make a similar
statement about the convergence of &lt;span class="math"&gt;\(g(T)\)&lt;/span&gt;.&lt;/p&gt;
&lt;p&gt;For the effective sample size derivation we will need to instantiate this
theorem for a special case of &lt;span class="math"&gt;\(g\)&lt;/span&gt;, namely where &lt;span class="math"&gt;\(g: \mathbb{R}^2 \to
\mathbb{R}\)&lt;/span&gt; and &lt;span class="math"&gt;\(g(x,y) = \frac{x}{y}\)&lt;/span&gt;.  Let's quickly do that.
We have
&lt;/p&gt;
&lt;div class="math"&gt;$$\nabla g(x,y) = \left(\begin{array}{c}
    \frac{1}{y} \\
    -\frac{x}{y^2}\end{array}\right).$$&lt;/div&gt;
&lt;p&gt;
We further define &lt;span class="math"&gt;\(X_i \sim P_X\)&lt;/span&gt;, &lt;span class="math"&gt;\(Y_i \sim P_Y\)&lt;/span&gt; iid, &lt;span class="math"&gt;\(X=X_1\)&lt;/span&gt;, &lt;span class="math"&gt;\(Y=Y_1\)&lt;/span&gt;,
&lt;/p&gt;
&lt;div class="math"&gt;$$T_n=\left(\begin{array}{c} \frac{1}{n}\sum_{i=1}^n X_i\\
    \frac{1}{n} \sum_{i=1}^n Y_i\end{array}\right),\qquad
    \theta=\left(\begin{array}{c} \mathbb{E}X\\
        \mathbb{E}Y\end{array}\right),$$&lt;/div&gt;
&lt;p&gt;
assuming our sequence &lt;span class="math"&gt;\(\frac{1}{n} \sum_{i=1}^n X_i \to \mathbb{E}X\)&lt;/span&gt; and
&lt;span class="math"&gt;\(\frac{1}{n} \sum_{i=1}^n Y_i \to \mathbb{E}Y\)&lt;/span&gt;.
For the covariance matrix we know that the empirical average of &lt;span class="math"&gt;\(n\)&lt;/span&gt; iid
samples has a variance as &lt;span class="math"&gt;\(1/n\)&lt;/span&gt;, that is
&lt;/p&gt;
&lt;div class="math"&gt;$$\textrm{Var}(\frac{1}{n}\sum_{i=1}^n X_i)
    = \frac{1}{n^2} \textrm{Var}(\sum_{i=1}^n X_i)
    = \frac{1}{n^2} \sum_{i=1}^n \textrm{Var}(X_i)
    = \frac{1}{n} \textrm{Var}(X),$$&lt;/div&gt;
&lt;p&gt;
and &lt;a href="http://en.wikipedia.org/wiki/Covariance#Properties"&gt;similar for the
covariance&lt;/a&gt;, so we have
&lt;/p&gt;
&lt;div class="math"&gt;$$\Sigma(\theta) = \frac{1}{n} \left(\begin{array}{cc}
    \textrm{Var}(X) &amp;amp; \textrm{Cov}(X,Y)\\
    \textrm{Cov}(X,Y) &amp;amp; \textrm{Var}(Y)\end{array}\right).$$&lt;/div&gt;
&lt;p&gt;
Applying the above theorem we have for the resulting one-dimensional
transformed variance
&lt;/p&gt;
&lt;div class="math"&gt;\begin{eqnarray}
B(\theta) &amp;amp; := &amp;amp; \nabla g(\theta)^T \Sigma(\theta) \nabla g(\theta)\nonumber\\
    &amp;amp; = &amp;amp; \frac{1}{n} \left(\begin{array}{c}
        \frac{1}{\mathbb{E}Y} \\
        -\frac{\mathbb{E}X}{(\mathbb{E}Y)^2}\end{array}\right)^T
        \left(\begin{array}{cc}
            \textrm{Var}(X) &amp;amp; \textrm{Cov}(X,Y)\\
            \textrm{Cov}(X,Y) &amp;amp; \textrm{Var}(Y)\end{array}\right)
        \left(\begin{array}{c}
        \frac{1}{\mathbb{E}Y} \\
        -\frac{\mathbb{E}X}{(\mathbb{E}Y)^2}\end{array}\right)\nonumber\\
    &amp;amp; = &amp;amp; \frac{1}{n} \left[
        \frac{1}{(\mathbb{E}Y)^2} \textrm{Var}(X)
            - 2 \frac{\mathbb{E}X}{(\mathbb{E}Y)^3} \textrm{Cov}(X,Y)
            + \frac{(\mathbb{E}X)^2}{(\mathbb{E}Y)^4} \textrm{Var}(Y)
        \right].\nonumber
\end{eqnarray}&lt;/div&gt;
&lt;p&gt;One way to interpret the quantity &lt;span class="math"&gt;\(B(\theta)\)&lt;/span&gt; is that the limiting variance of
the ratio &lt;span class="math"&gt;\(X/Y\)&lt;/span&gt; depends both on the variances of &lt;span class="math"&gt;\(X\)&lt;/span&gt; and of &lt;span class="math"&gt;\(Y\)&lt;/span&gt;, but crucially
it depends most sensitively on &lt;span class="math"&gt;\(\mathbb{E}Y\)&lt;/span&gt; because this quantity appears in
the denominator: small values of &lt;span class="math"&gt;\(Y\)&lt;/span&gt; have large effects on &lt;span class="math"&gt;\(X/Y\)&lt;/span&gt;.&lt;/p&gt;
&lt;p&gt;This is an asymptotic expression which is based on the assumption that both
&lt;span class="math"&gt;\(X\)&lt;/span&gt; and &lt;span class="math"&gt;\(Y\)&lt;/span&gt; are concentrated around the mean so that the linearization of &lt;span class="math"&gt;\(g\)&lt;/span&gt;
around the mean will incur a small error.  As such, this approximation may
deteriorate if the variance of &lt;span class="math"&gt;\(X\)&lt;/span&gt; or &lt;span class="math"&gt;\(Y\)&lt;/span&gt; is large so that the linear
approximation of &lt;span class="math"&gt;\(g\)&lt;/span&gt; deviates from the actual values of &lt;span class="math"&gt;\(g\)&lt;/span&gt;.&lt;/p&gt;
&lt;p&gt;(For an exact expansion of the expectation of a ratio, see &lt;a href="http://www.faculty.biol.ttu.edu/Rice/ratio-derive.pdf"&gt;this 2009
note&lt;/a&gt; by &lt;a href="http://www.faculty.biol.ttu.edu/Rice/"&gt;Sean
Rice&lt;/a&gt;.)&lt;/p&gt;
&lt;h3&gt;Second-order Delta Method&lt;/h3&gt;
&lt;p&gt;The above delta method can be extended to higher-order by a &lt;a href="http://en.wikipedia.org/wiki/Taylor%27s_theorem#Taylor.27s_theorem_for_multivariate_functions"&gt;multivariate
Taylor
expansion&lt;/a&gt;.
I give the following result without proof.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;&lt;strong&gt;Theorem&lt;/strong&gt; (Second-order Multivariate Delta Method).&lt;/em&gt;  Let &lt;span class="math"&gt;\(T\)&lt;/span&gt; be a
&lt;span class="math"&gt;\(k\)&lt;/span&gt;-dimensional random vectors such that &lt;span class="math"&gt;\(\mathbb{E} T = \theta\)&lt;/span&gt;.  Let
&lt;span class="math"&gt;\(g:\mathbb{R}^k \to \mathbb{R}\)&lt;/span&gt; be twice differentiable at &lt;span class="math"&gt;\(\theta\)&lt;/span&gt; with
&lt;a href="http://en.wikipedia.org/wiki/Hessian_matrix"&gt;Hessian&lt;/a&gt; &lt;span class="math"&gt;\(H(\theta)\)&lt;/span&gt;.  Then
&lt;/p&gt;
&lt;div class="math"&gt;$$\mathbb{E} g(T) \approx
    g(\theta) + \frac{1}{2} \textrm{tr}(\textrm{Cov}(T) \: H(\theta)).$$&lt;/div&gt;
&lt;p&gt;For the proof of the effective sample size we need to apply this theorem to
the function &lt;span class="math"&gt;\(g(X,Y)=XY^2\)&lt;/span&gt; so that
&lt;/p&gt;
&lt;div class="math"&gt;$$H(X,Y)=\left[\begin{array}{cc} 0 &amp;amp; 2Y\\ 2Y &amp;amp; 2X\end{array}\right].$$&lt;/div&gt;
&lt;p&gt;
Then the above result gives
&lt;/p&gt;
&lt;div class="math"&gt;$$\mathbb{E} g(X,Y) \approx
    (\mathbb{E}X)(\mathbb{E}Y)^2 + 2 (\mathbb{E}Y) \textrm{Cov}(X,Y)
    + (\mathbb{E}X) \textrm{Var}(Y).$$&lt;/div&gt;
&lt;script type="text/javascript"&gt;if (!document.getElementById('mathjaxscript_pelican_#%@#$@#')) {
    var align = "center",
        indent = "0em",
        linebreak = "false";

    if (false) {
        align = (screen.width &lt; 768) ? "left" : align;
        indent = (screen.width &lt; 768) ? "0em" : indent;
        linebreak = (screen.width &lt; 768) ? 'true' : linebreak;
    }

    var mathjaxscript = document.createElement('script');
    mathjaxscript.id = 'mathjaxscript_pelican_#%@#$@#';
    mathjaxscript.type = 'text/javascript';
    mathjaxscript.src = 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.3/latest.js?config=TeX-AMS-MML_HTMLorMML';

    var configscript = document.createElement('script');
    configscript.type = 'text/x-mathjax-config';
    configscript[(window.opera ? "innerHTML" : "text")] =
        "MathJax.Hub.Config({" +
        "    config: ['MMLorHTML.js']," +
        "    TeX: { extensions: ['AMSmath.js','AMSsymbols.js','noErrors.js','noUndefined.js'], equationNumbers: { autoNumber: 'none' } }," +
        "    jax: ['input/TeX','input/MathML','output/HTML-CSS']," +
        "    extensions: ['tex2jax.js','mml2jax.js','MathMenu.js','MathZoom.js']," +
        "    displayAlign: '"+ align +"'," +
        "    displayIndent: '"+ indent +"'," +
        "    showMathMenu: true," +
        "    messageStyle: 'normal'," +
        "    tex2jax: { " +
        "        inlineMath: [ ['\\\\(','\\\\)'] ], " +
        "        displayMath: [ ['$$','$$'] ]," +
        "        processEscapes: true," +
        "        preview: 'TeX'," +
        "    }, " +
        "    'HTML-CSS': { " +
        "        availableFonts: ['STIX', 'TeX']," +
        "        preferredFont: 'STIX'," +
        "        styles: { '.MathJax_Display, .MathJax .mo, .MathJax .mi, .MathJax .mn': {color: 'inherit ! important'} }," +
        "        linebreaks: { automatic: "+ linebreak +", width: '90% container' }," +
        "    }, " +
        "}); " +
        "if ('default' !== 'default') {" +
            "MathJax.Hub.Register.StartupHook('HTML-CSS Jax Ready',function () {" +
                "var VARIANT = MathJax.OutputJax['HTML-CSS'].FONTDATA.VARIANT;" +
                "VARIANT['normal'].fonts.unshift('MathJax_default');" +
                "VARIANT['bold'].fonts.unshift('MathJax_default-bold');" +
                "VARIANT['italic'].fonts.unshift('MathJax_default-italic');" +
                "VARIANT['-tex-mathit'].fonts.unshift('MathJax_default-italic');" +
            "});" +
            "MathJax.Hub.Register.StartupHook('SVG Jax Ready',function () {" +
                "var VARIANT = MathJax.OutputJax.SVG.FONTDATA.VARIANT;" +
                "VARIANT['normal'].fonts.unshift('MathJax_default');" +
                "VARIANT['bold'].fonts.unshift('MathJax_default-bold');" +
                "VARIANT['italic'].fonts.unshift('MathJax_default-italic');" +
                "VARIANT['-tex-mathit'].fonts.unshift('MathJax_default-italic');" +
            "});" +
        "}";

    (document.body || document.getElementsByTagName('head')[0]).appendChild(configscript);
    (document.body || document.getElementsByTagName('head')[0]).appendChild(mathjaxscript);
}
&lt;/script&gt;</content><category term="Statistics, Machine Learning"/></entry><entry><title>Reverse Search</title><link href="https://www.nowozin.net/sebastian/blog/reverse-search.html" rel="alternate"/><published>2015-08-07T21:30:00+01:00</published><updated>2015-08-07T21:30:00+01:00</updated><author><name>Sebastian Nowozin</name></author><id>tag:www.nowozin.net,2015-08-07:/sebastian/blog/reverse-search.html</id><summary type="html">&lt;p&gt;One of my all-time favorite algorithms is &lt;em&gt;reverse search&lt;/em&gt; proposed by
&lt;a href="http://cgm.cs.mcgill.ca/~avis/"&gt;David Avis&lt;/a&gt; and
&lt;a href="http://www.inf.ethz.ch/personal/fukudak/"&gt;Komei Fukuda&lt;/a&gt; in 1992,
&lt;a href="http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.26.4487&amp;amp;rep=rep1&amp;amp;type=pdf"&gt;PDF&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Reverse search is an algorithm to solve enumeration problems, that is,
problems where you would like to list a finite set of typically
combinatorially related elements.
Reverse search is not quite …&lt;/p&gt;</summary><content type="html">&lt;p&gt;One of my all-time favorite algorithms is &lt;em&gt;reverse search&lt;/em&gt; proposed by
&lt;a href="http://cgm.cs.mcgill.ca/~avis/"&gt;David Avis&lt;/a&gt; and
&lt;a href="http://www.inf.ethz.ch/personal/fukudak/"&gt;Komei Fukuda&lt;/a&gt; in 1992,
&lt;a href="http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.26.4487&amp;amp;rep=rep1&amp;amp;type=pdf"&gt;PDF&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Reverse search is an algorithm to solve enumeration problems, that is,
problems where you would like to list a finite set of typically
combinatorially related elements.
Reverse search is not quite an algorithm, rather it is a general construction
principle that is applicable to a wide variety of problems and often leads to
optimal algorithms for enumeration problems.&lt;/p&gt;
&lt;p&gt;Problems in which reverse search is applicable often have the flavour where
the elements have a &lt;em&gt;natural partial order&lt;/em&gt; (such as sets, sequences, graphs
where we can define subsets, subsequences, and subgraphs), or where there is a
natural neighborhood relation between elements which can be used to traverse
from one element to the other (such as the linear programming bases considered
in the Avis and Fukuda examples).&lt;/p&gt;
&lt;p&gt;The reverse search construction leads to a structured search space that is
also suitable for combinatorial search and optimization algorithms.  For
example, we can often readily use the resulting enumeration tree in
&lt;a href="http://en.wikipedia.org/wiki/Branch_and_bound"&gt;branch-and-bound search&lt;/a&gt;
methods.
I made heavy use of this possibility during my PhD a few years ago during my
work with Koji Tsuda, and reverse search is the working horse in my CVPR 2007,
ICCV 2007, and ICDM 2008 papers.  (Needless to say, I have fond memories of
it, but even now I regularly see applications of the reverse search idea.)
In the following, my presentation will differ quite a bit from the Avis and
Fukuda paper.&lt;/p&gt;
&lt;h2&gt;Basic Idea&lt;/h2&gt;
&lt;p&gt;At its core reverse search is a method to organize all elements to be
enumerated into a tree where the nodes in the tree each represent a single
element.
Each element appears exactly once in the tree and by traversing the tree from
the root we can enumerate all elements exactly once.&lt;/p&gt;
&lt;p&gt;Here is the &lt;em&gt;recipe&lt;/em&gt;:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Define a ``reduction'' operation which takes an enumeration element and
reduces it to a simpler one.  This defines an enumeration tree.&lt;/li&gt;
&lt;li&gt;Invert the reduction operation.&lt;/li&gt;
&lt;li&gt;Enumerate all elements, starting from the root.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Let us illustrate this recipe first on a simple example: enumerating subsets
of a given set.  Say we are given the set &lt;span class="math"&gt;\(\{1,2,3\}\)&lt;/span&gt; and would like to
enumerate subsets.  To define the reduction operation we simply say ``remove
the largest integer from the set''.  Formally, this defines defines a function
&lt;span class="math"&gt;\(f\)&lt;/span&gt; from the set of sets to the set of sets.  Here is an illustration:&lt;/p&gt;
&lt;p&gt;&lt;img alt="Set of three integers and reduction operation" src="https://www.nowozin.net/sebastian/blog/images/rsearch-123set-f.svg"&gt;&lt;/p&gt;
&lt;p&gt;Now we consider the inverse map &lt;span class="math"&gt;\(f^{-1}\)&lt;/span&gt;, from the set of sets to the set of
powersets.  Here is an illustration:&lt;/p&gt;
&lt;p&gt;&lt;img alt="Inverse reduction operation" src="https://www.nowozin.net/sebastian/blog/images/rsearch-123set-finv.svg"&gt;&lt;/p&gt;
&lt;p&gt;The inverse defines an enumeration strategy: we start at &lt;span class="math"&gt;\(\emptyset\)&lt;/span&gt; and
evaluate &lt;span class="math"&gt;\(f^{-1}(\emptyset) = \{\{1\}, \{2\}, \{3\}\}\)&lt;/span&gt;.  For each set element
we now recurse.  This enumerates all elements in the tree exactly once.&lt;/p&gt;
&lt;p&gt;The above recipe has the following practical advantages:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Reverse search often yields a simple algorithm.&lt;/li&gt;
&lt;li&gt;Typically there is no additional memory or bookkeeping required beyond the
   recursion call stack, so that the total memory required is &lt;span class="math"&gt;\(O(r)\)&lt;/span&gt; where &lt;span class="math"&gt;\(r\)&lt;/span&gt;
   is the recursion depth.&lt;/li&gt;
&lt;li&gt;Yields a &lt;em&gt;output-linear&lt;/em&gt; &lt;em&gt;polynomial-delay&lt;/em&gt; enumeration algorithms, which
   means that the total time complexity is linear in the number of items
   enumerated and for each item only polynomial time is needed.  (This slightly
   unconventional notion of complexity makes sense for enumeration problems
   because the answer is often exponential in the size of the input.)&lt;/li&gt;
&lt;li&gt;Often yields optimal enumeration algorithms in terms of memory and runtime.&lt;/li&gt;
&lt;li&gt;The resulting algorithms are trivially parallelizable over the enumeration
   tree.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Ok, the above was a trivial example, let us look at a more complicated example.&lt;/p&gt;
&lt;h2&gt;Example: Enumerating all Connected Subgraphs&lt;/h2&gt;
&lt;p&gt;Let us consider a non-trivial application of the reverse search idea:
enumerating all connected subgraphs of a given graph.&lt;/p&gt;
&lt;p&gt;To apply the recipe, how could the &lt;em&gt;reduction operation&lt;/em&gt; look like?
Intuitively, we are given a connected graph and we could remove a single
vertex from the graph, thereby making it smaller.  By removing one vertex at a
time we would eventually arrive at the empty graph.&lt;/p&gt;
&lt;p&gt;But given a graph, how do we determine which vertex to remove?
For this, let us assume all vertices in the given graph have a unique integer
index.  Then, given such a graph we can then attempt to remove the highest
integer vertex, just as in the set example above.  Here we hit a complication:
upon removal of the vertex the graph may become disconnected.
For example, consider the chain graph &lt;span class="math"&gt;\(1-3-2\)&lt;/span&gt;.  Here the vertex labeled &lt;span class="math"&gt;\(3\)&lt;/span&gt;
would be removed, yielding two disconnected components, which violates the
requirement of enumerating only connected subgraphs.  Therefore we simply say:
``Remove the highest-index vertex such that the resulting graph remains
connected''.&lt;/p&gt;
&lt;p&gt;Here is an example of the reduction operation in action on the following
simple cycle graph:&lt;/p&gt;
&lt;p&gt;&lt;img alt="Cycle graph with four nodes" src="https://www.nowozin.net/sebastian/blog/images/rsearch-1324.svg"&gt;&lt;/p&gt;
&lt;p&gt;The enumeration tree of all fourteen connected subgraphs (counting the empty
graph as well) looks as follows.  Here each arrow is the application of one
reduction operation.&lt;/p&gt;
&lt;p&gt;&lt;img alt="All connected subgraphs of the cycle graph with four nodes" src="https://www.nowozin.net/sebastian/blog/images/rsearch-enumtree-1324.svg"&gt;&lt;/p&gt;
&lt;p&gt;Looking at the above tree, you can note the following:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The graph &lt;span class="math"&gt;\(1-4-2\)&lt;/span&gt; has the highest vertex &lt;span class="math"&gt;\(4\)&lt;/span&gt; but this cannot be removed
  because it would yield a disconnected subgraph; therefore the reduction
  operation removes &lt;span class="math"&gt;\(2\)&lt;/span&gt; instead.&lt;/li&gt;
&lt;li&gt;By construction, there is a unique path from every graph to the root.&lt;/li&gt;
&lt;li&gt;By construction only connected subgraphs are present in the tree, and each
  such graph is present exactly once.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;In order to enumerate all connected subgraphs, we have to &lt;em&gt;invert&lt;/em&gt; the
arrows of this graph.  That is, we have to invert the reduction operation and
given a graph we have to generate all child nodes in the reversed graph.
This reversion is what gives &lt;em&gt;reverse search&lt;/em&gt; its name.&lt;/p&gt;
&lt;p&gt;The inverse operation is described as follows: ``given a connected subgraph,
add a vertex which will become the highest-index vertex and whose removal
retains a connected graph."  This is quite a mouthful but luckily
the actual implementation is simple.&lt;/p&gt;
&lt;p&gt;Here is a &lt;a href="http://julialang.org/"&gt;Julia&lt;/a&gt; implementation.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="k"&gt;using&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;LightGraphs&lt;/span&gt;

&lt;span class="n"&gt;is_connected1&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;g&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="kt"&gt;Graph&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;nv&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;g&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;&amp;lt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;true&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;is_connected&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;g&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;is_removable&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;g&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="kt"&gt;Graph&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;vset&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="kt"&gt;IntSet&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;rmv&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;is_connected1&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;induced_subgraph&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;g&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;setdiff&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;vset&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;rmv&lt;/span&gt;&lt;span class="p"&gt;)))&lt;/span&gt;
&lt;span class="n"&gt;rm_vertex&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;g&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="kt"&gt;Graph&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;vset&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="kt"&gt;IntSet&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;maximum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;rmv&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;is_removable&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;g&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;vset&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;rmv&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;vset&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;

&lt;span class="k"&gt;function&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;connsubgraphs&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;g&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="kt"&gt;Graph&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="k"&gt;function&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;_connsubgraphs&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;vset&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="kt"&gt;IntSet&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="n"&gt;produce&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;copy&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;vset&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;&lt;span class="w"&gt;   &lt;/span&gt;&lt;span class="c"&gt;# output current subgraph vertex set&lt;/span&gt;

&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="c"&gt;# Generate child nodes of the current subgraph.&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="c"&gt;# Consider all vertices not yet in graph&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;add_vi&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="k"&gt;in&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;vset&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;vertices&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;g&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;span class="w"&gt;            &lt;/span&gt;&lt;span class="n"&gt;push!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;vset&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;add_vi&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt;     &lt;/span&gt;&lt;span class="c"&gt;# Add new vertex&lt;/span&gt;
&lt;span class="w"&gt;            &lt;/span&gt;&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;is_connected1&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;induced_subgraph&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;g&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;vset&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt;
&lt;span class="w"&gt;                &lt;/span&gt;&lt;span class="n"&gt;add_vi&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;==&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;rm_vertex&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;g&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;vset&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="w"&gt;                &lt;/span&gt;&lt;span class="c"&gt;# Recurse&lt;/span&gt;
&lt;span class="w"&gt;                &lt;/span&gt;&lt;span class="n"&gt;_connsubgraphs&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;vset&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="w"&gt;            &lt;/span&gt;&lt;span class="k"&gt;end&lt;/span&gt;
&lt;span class="w"&gt;            &lt;/span&gt;&lt;span class="n"&gt;setdiff!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;vset&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;add_vi&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="c"&gt;# Remove new vertex&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="k"&gt;end&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="k"&gt;end&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="k"&gt;function&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;_connsubgraphs&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="n"&gt;_connsubgraphs&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;IntSet&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="k"&gt;end&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="kt"&gt;Task&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;_connsubgraphs&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;

&lt;span class="n"&gt;g&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;Graph&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;add_edge!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;g&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;add_edge!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;g&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;add_edge!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;g&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;add_edge!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;g&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;S&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;collect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;connsubgraphs&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;g&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Note the key statements between the &lt;code&gt;push!&lt;/code&gt; and &lt;code&gt;setdiff!&lt;/code&gt; lines that
govern the recursion.
In the if-condition we check that the new graph remains connected and the
added vertex would be the one that would be removed.&lt;/p&gt;
&lt;p&gt;The above code uses the Julia
&lt;a href="http://julia.readthedocs.org/en/latest/manual/control-flow/#tasks-aka-coroutines"&gt;producer-consumer&lt;/a&gt;
pattern.
When run, it produces the following output, identical to the above diagram.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="mi"&gt;14&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;element&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kt"&gt;Array&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="kt"&gt;Any&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;
&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;IntSet&lt;/span&gt;&lt;span class="p"&gt;([])&lt;/span&gt;&lt;span class="w"&gt;          &lt;/span&gt;
&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;IntSet&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;&lt;span class="w"&gt;         &lt;/span&gt;
&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;IntSet&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;&lt;span class="w"&gt;      &lt;/span&gt;
&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;IntSet&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;&lt;span class="w"&gt;   &lt;/span&gt;
&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;IntSet&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;IntSet&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;&lt;span class="w"&gt;   &lt;/span&gt;
&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;IntSet&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;&lt;span class="w"&gt;      &lt;/span&gt;
&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;IntSet&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;&lt;span class="w"&gt;   &lt;/span&gt;
&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;IntSet&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;&lt;span class="w"&gt;         &lt;/span&gt;
&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;IntSet&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;&lt;span class="w"&gt;      &lt;/span&gt;
&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;IntSet&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;&lt;span class="w"&gt;   &lt;/span&gt;
&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;IntSet&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;&lt;span class="w"&gt;      &lt;/span&gt;
&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;IntSet&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;&lt;span class="w"&gt;         &lt;/span&gt;
&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;IntSet&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;&lt;span class="w"&gt;         &lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;h2&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;Reverse search is a general recipe to construct tree-structured enumeration
methods useful for enumerating combinatorial sets and optimization over them.&lt;/p&gt;
&lt;p&gt;In fact, it is so useful that some authors have reinvented reverse search
without noticing.  For example, the popular &lt;a href="http://cs.ucsb.edu/~xyan/papers/gSpan-short.pdf"&gt;gSpan
algorithm&lt;/a&gt; of Yan and Han
published in 2003 defines a clever total ordering on labeled graphs
essentially in order to be able to define the reduction operation needed in
reverse search.&lt;/p&gt;
&lt;p&gt;So, check it out, the &lt;a href="http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.26.4487&amp;amp;rep=rep1&amp;amp;type=pdf"&gt;Avis and Fukuda
paper&lt;/a&gt;
is very rich and well worth a read!  (If you prefer a different presentation
similar to the one above but more technical, have a look at my PhD thesis.)&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Acknowledgements&lt;/em&gt;.  I thank &lt;a href="http://tsudalab.org/en/member/koji_tsuda/"&gt;Koji
Tsuda&lt;/a&gt; for reading a draft version
of the article and providing feedback.&lt;/p&gt;
&lt;script type="text/javascript"&gt;if (!document.getElementById('mathjaxscript_pelican_#%@#$@#')) {
    var align = "center",
        indent = "0em",
        linebreak = "false";

    if (false) {
        align = (screen.width &lt; 768) ? "left" : align;
        indent = (screen.width &lt; 768) ? "0em" : indent;
        linebreak = (screen.width &lt; 768) ? 'true' : linebreak;
    }

    var mathjaxscript = document.createElement('script');
    mathjaxscript.id = 'mathjaxscript_pelican_#%@#$@#';
    mathjaxscript.type = 'text/javascript';
    mathjaxscript.src = 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.3/latest.js?config=TeX-AMS-MML_HTMLorMML';

    var configscript = document.createElement('script');
    configscript.type = 'text/x-mathjax-config';
    configscript[(window.opera ? "innerHTML" : "text")] =
        "MathJax.Hub.Config({" +
        "    config: ['MMLorHTML.js']," +
        "    TeX: { extensions: ['AMSmath.js','AMSsymbols.js','noErrors.js','noUndefined.js'], equationNumbers: { autoNumber: 'none' } }," +
        "    jax: ['input/TeX','input/MathML','output/HTML-CSS']," +
        "    extensions: ['tex2jax.js','mml2jax.js','MathMenu.js','MathZoom.js']," +
        "    displayAlign: '"+ align +"'," +
        "    displayIndent: '"+ indent +"'," +
        "    showMathMenu: true," +
        "    messageStyle: 'normal'," +
        "    tex2jax: { " +
        "        inlineMath: [ ['\\\\(','\\\\)'] ], " +
        "        displayMath: [ ['$$','$$'] ]," +
        "        processEscapes: true," +
        "        preview: 'TeX'," +
        "    }, " +
        "    'HTML-CSS': { " +
        "        availableFonts: ['STIX', 'TeX']," +
        "        preferredFont: 'STIX'," +
        "        styles: { '.MathJax_Display, .MathJax .mo, .MathJax .mi, .MathJax .mn': {color: 'inherit ! important'} }," +
        "        linebreaks: { automatic: "+ linebreak +", width: '90% container' }," +
        "    }, " +
        "}); " +
        "if ('default' !== 'default') {" +
            "MathJax.Hub.Register.StartupHook('HTML-CSS Jax Ready',function () {" +
                "var VARIANT = MathJax.OutputJax['HTML-CSS'].FONTDATA.VARIANT;" +
                "VARIANT['normal'].fonts.unshift('MathJax_default');" +
                "VARIANT['bold'].fonts.unshift('MathJax_default-bold');" +
                "VARIANT['italic'].fonts.unshift('MathJax_default-italic');" +
                "VARIANT['-tex-mathit'].fonts.unshift('MathJax_default-italic');" +
            "});" +
            "MathJax.Hub.Register.StartupHook('SVG Jax Ready',function () {" +
                "var VARIANT = MathJax.OutputJax.SVG.FONTDATA.VARIANT;" +
                "VARIANT['normal'].fonts.unshift('MathJax_default');" +
                "VARIANT['bold'].fonts.unshift('MathJax_default-bold');" +
                "VARIANT['italic'].fonts.unshift('MathJax_default-italic');" +
                "VARIANT['-tex-mathit'].fonts.unshift('MathJax_default-italic');" +
            "});" +
        "}";

    (document.body || document.getElementsByTagName('head')[0]).appendChild(configscript);
    (document.body || document.getElementsByTagName('head')[0]).appendChild(mathjaxscript);
}
&lt;/script&gt;</content><category term="Algorithms"/></entry><entry><title>Stochastic Computation Graphs</title><link href="https://www.nowozin.net/sebastian/blog/stochastic-computation-graphs.html" rel="alternate"/><published>2015-07-24T22:00:00+01:00</published><updated>2015-07-24T22:00:00+01:00</updated><author><name>Sebastian Nowozin</name></author><id>tag:www.nowozin.net,2015-07-24:/sebastian/blog/stochastic-computation-graphs.html</id><summary type="html">&lt;p&gt;This post is about a recent arXiv submission entitled
&lt;a href="http://arxiv.org/abs/1506.05254"&gt;Gradient Estimation Using Stochastic Computation
Graphs&lt;/a&gt;, and authored by
&lt;a href="http://www.eecs.berkeley.edu/~joschu/"&gt;John Schulman&lt;/a&gt;,
Nicolas Heess,
&lt;a href="http://thphn.com/"&gt;Theophane Weber&lt;/a&gt;, and
&lt;a href="http://www.cs.berkeley.edu/~pabbeel/"&gt;Pieter Abbeel&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;In a nutshell this paper generalizes the &lt;a href="https://en.wikipedia.org/wiki/Backpropagation"&gt;backpropagation
algorithm&lt;/a&gt; to allow
&lt;em&gt;differentiation through expectations&lt;/em&gt;, that is, to compute unbiased estimates
of&lt;/p&gt;
&lt;div class="math"&gt;$$\frac{\partial …&lt;/div&gt;</summary><content type="html">&lt;p&gt;This post is about a recent arXiv submission entitled
&lt;a href="http://arxiv.org/abs/1506.05254"&gt;Gradient Estimation Using Stochastic Computation
Graphs&lt;/a&gt;, and authored by
&lt;a href="http://www.eecs.berkeley.edu/~joschu/"&gt;John Schulman&lt;/a&gt;,
Nicolas Heess,
&lt;a href="http://thphn.com/"&gt;Theophane Weber&lt;/a&gt;, and
&lt;a href="http://www.cs.berkeley.edu/~pabbeel/"&gt;Pieter Abbeel&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;In a nutshell this paper generalizes the &lt;a href="https://en.wikipedia.org/wiki/Backpropagation"&gt;backpropagation
algorithm&lt;/a&gt; to allow
&lt;em&gt;differentiation through expectations&lt;/em&gt;, that is, to compute unbiased estimates
of&lt;/p&gt;
&lt;div class="math"&gt;$$\frac{\partial}{\partial \theta} \mathbb{E}_{x \sim q(x|\theta)}[f(x,\theta)].$$&lt;/div&gt;
&lt;p&gt;The paper also provides a nice calculus on directed graphs that allows quick
derivation of unbiased gradient estimates.
The basic technical results in the paper have been known and used in various
communities before and the arXiv submission properly discusses these.&lt;/p&gt;
&lt;p&gt;But dismissing the paper as non novel would miss the point in a similar way as
missing the point when stating that backpropagation is ``just an application
of the chain rule of differentiation''.
Instead, the contribution of the current paper is in the practical utility of
the graphical calculus and a rich catalogue of machine learning problems where
the computation of unbiased gradients of expectations is useful.&lt;/p&gt;
&lt;p&gt;In typical statistical point estimation tasks
&lt;a href="https://en.wikipedia.org/wiki/Bias_of_an_estimator"&gt;&lt;em&gt;unbiasedness&lt;/em&gt;&lt;/a&gt; is often
not quite as important compared to expected risk.
However, here it is crucial.
This is because the applications where stochastic computation graphs are
useful involve &lt;em&gt;optimization&lt;/em&gt; over &lt;span class="math"&gt;\(\theta\)&lt;/span&gt; and &lt;a href="https://en.wikipedia.org/wiki/Stochastic_approximation"&gt;stochastic
approximation&lt;/a&gt;
methods such as &lt;a href="https://en.wikipedia.org/wiki/Stochastic_gradient_descent"&gt;stochastic gradient
methods&lt;/a&gt; can only
be justified theoretically in the case of unbiased gradient estimates.&lt;/p&gt;
&lt;h3&gt;A Neat Derivative Trick&lt;/h3&gt;
&lt;p&gt;To get an idea of the flavour of derivatives involving expectations, let us
look at a simpler case explained in Section 2.1 of the paper.
The proof of that case also contains a neat trick worth knowing.
The case is as above but inside the expectation we have only &lt;span class="math"&gt;\(f(x)\)&lt;/span&gt; instead of &lt;span class="math"&gt;\(f(x,\theta)\)&lt;/span&gt;.
The ``trick'' is in the identity (obvious in retrospect),
&lt;/p&gt;
&lt;div class="math"&gt;$$\frac{\partial}{\partial \theta} p(x|\theta) =
p(x|\theta) \frac{\partial}{\partial \theta} \log p(x|\theta).$$&lt;/div&gt;
&lt;p&gt;This allows to establish
&lt;/p&gt;
&lt;div class="math"&gt;\begin{eqnarray}
\frac{\partial}{\partial \theta} \mathbb{E}_{x \sim p(x|\theta)}[f(x)]
&amp;amp; = &amp;amp; \frac{\partial}{\partial \theta} \int p(x|\theta) f(x) \,\textrm{d}x\nonumber\\
&amp;amp; = &amp;amp; \int \frac{\partial}{\partial \theta} p(x|\theta) f(x) \,\textrm{d}x\nonumber\\
&amp;amp; = &amp;amp; \int p(x|\theta) f(x) \frac{\partial}{\partial \theta} \log p(x|\theta) \,\textrm{d}x\nonumber\\
&amp;amp; = &amp;amp; \mathbb{E}_{x \sim p(x|\theta)}[f(x) \frac{\partial}{\partial \theta} \log p(x|\theta)].\nonumber
\end{eqnarray}&lt;/div&gt;
&lt;p&gt;In this case the derivation was straightforward but for multiple expectations
a derivation based on this elementary definition of the expectation is
cumbersome and error-prone.  Stochastic computation graphs allow a much
quicker derivation of the derivative.&lt;/p&gt;
&lt;h2&gt;Stochastic Computation Graphs&lt;/h2&gt;
&lt;p&gt;Stochastic computation graphs are directed acyclic graphs that encode the
dependency structure of computation to be performed.  The graphical notation
generalizes directed graphical models.
Here is an example graph.&lt;/p&gt;
&lt;p&gt;&lt;img alt="Stochastic computation graph of problem (1) in Schulman et al." src="https://www.nowozin.net/sebastian/blog/images/stochastic-computation-graphs-example1.svg"&gt;&lt;/p&gt;
&lt;p&gt;There are three (or four) types of nodes in a stochastic computation graph:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;em&gt;Input nodes&lt;/em&gt;.  These are the fixed parameters we would like to compute the
derivative of.  In the example graph, this is the &lt;span class="math"&gt;\(\theta\)&lt;/span&gt; node and they are
drawn without any container.  While technically it is possible to have graphs
without input nodes, in order to compute gradients the graph should include at
least one input node.&lt;/li&gt;
&lt;li&gt;&lt;em&gt;Deterministic nodes&lt;/em&gt;.  These compute a deterministic function of their
parents.  In the above graph this is the case for the &lt;span class="math"&gt;\(x\)&lt;/span&gt; and &lt;span class="math"&gt;\(f\)&lt;/span&gt; nodes.&lt;/li&gt;
&lt;li&gt;&lt;em&gt;Stochastic nodes&lt;/em&gt;.  These nodes specify a random variable through a
distribution conditional on their parents.  In the above graph this is true
for the &lt;span class="math"&gt;\(y\)&lt;/span&gt; node, and the circle mirrors the notation used in directed
graphical models.&lt;/li&gt;
&lt;li&gt;&lt;em&gt;Cost nodes&lt;/em&gt;.  These are a subset of the deterministic nodes in the graph
whose range are the real numbers.  In the above graph the node &lt;span class="math"&gt;\(f\)&lt;/span&gt; is a cost
node.  I draw them shaded, this is not the case in the original paper.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;The entire stochastic computation graph specifies a single objective function
whose domain are the input nodes and whose scalar objective is the sum of all
cost nodes.
The sum of all cost nodes is taken as an expectation over all stochastic nodes
in the graph.&lt;/p&gt;
&lt;p&gt;Therefore the above graph has the objective function
&lt;/p&gt;
&lt;div class="math"&gt;$$F(\theta) = \mathbb{E}_{y \sim p(y|x(\theta))}[f(y)].$$&lt;/div&gt;
&lt;h3&gt;Derivative Calculus&lt;/h3&gt;
&lt;p&gt;The notation used in the paper is a bit heavy and (for my taste at least) a
bit too custom, but here it is.
Let &lt;span class="math"&gt;\(\Theta\)&lt;/span&gt; be the set of input nodes, &lt;span class="math"&gt;\(\mathcal{C}\)&lt;/span&gt; the set of cost nodes,
and &lt;span class="math"&gt;\(\mathcal{S}\)&lt;/span&gt; be the set of stochastic nodes.
The notation &lt;span class="math"&gt;\(u \prec v\)&lt;/span&gt; denotes that there exist a directed path from &lt;span class="math"&gt;\(u\)&lt;/span&gt; to
&lt;span class="math"&gt;\(v\)&lt;/span&gt; in the graph.
The notation &lt;span class="math"&gt;\(u \prec^D v\)&lt;/span&gt; denotes that there exist a path whose nodes are all
deterministic with the exception of the last node &lt;span class="math"&gt;\(v\)&lt;/span&gt; which may be of any
type.
We write &lt;span class="math"&gt;\(\hat{c}\)&lt;/span&gt; for a sample realization of a cost node &lt;span class="math"&gt;\(c\)&lt;/span&gt;.
The final notation needed for the result is
&lt;/p&gt;
&lt;div class="math"&gt;$$\textrm{DEPS}_v = \{ w \in \Theta \cup \mathcal{S} | w \prec^D v\}.$$&lt;/div&gt;
&lt;p&gt;The key result of the paper, Theorem 1, is now stated as follows:
&lt;/p&gt;
&lt;div class="math"&gt;$$\frac{\partial}{\partial \theta} \mathbb{E}\left[\sum_{c \in \mathcal{C}} c\right]
= \mathbb{E}\Bigg[\underbrace{\sum_{w \in \mathcal{S}, \theta \prec^D w} \left(
\frac{\partial}{\partial \theta} \log p(w|\textrm{DEPS}_w)
\right) \sum_{c \in \mathcal{C}, w \prec c} \hat{c}}_{\textrm{(A)}}
+ \underbrace{\sum_{c \in \mathcal{C}, \theta \prec^D c} \frac{\partial}{\partial \theta}
c(\textrm{DEPS}_c)}_{\textrm{(B)}}\Bigg].$$&lt;/div&gt;
&lt;p&gt;The two parts, (A) and (B) can be interpreted as follows.  If we only have
deterministic computation so that &lt;span class="math"&gt;\(\mathcal{S} = \emptyset\)&lt;/span&gt;, as in an ordinary
feedforward neural network for example, the part (B) is just the ordinary
derivative and we have to apply the chain rule to that expression.
The part (A) originates from each stochastic node and the consequences that
originate from the stochastic nodes is absorbed in the sample realizations
&lt;span class="math"&gt;\(\hat{c}\)&lt;/span&gt;.&lt;/p&gt;
&lt;p&gt;It takes a bit of practice to apply Theorem 1 quickly to a given graph, and I
found it easier to instead manually, on a piece of paper, executing
Algorithm 1 of the paper, which generalizes backpropagation and builds the
derivative node by node by traversing the graph backwards.&lt;/p&gt;
&lt;h2&gt;Example&lt;/h2&gt;
&lt;p&gt;To understand the basic technique I illustrate the stochastic computation
graph technique on the concrete graph above, which is problem (1) in the paper
(Section 2.3), but I make the example concrete.&lt;/p&gt;
&lt;p&gt;&lt;img alt="Stochastic computation graph of problem (1) in Schulman et al." src="https://www.nowozin.net/sebastian/blog/images/stochastic-computation-graphs-example1.svg"&gt;&lt;/p&gt;
&lt;div class="math"&gt;$$x(\theta) = (\theta-1)^2,$$&lt;/div&gt;
&lt;div class="math"&gt;$$y(x) \sim \mathcal{N}(x,1),$$&lt;/div&gt;
&lt;div class="math"&gt;$$f(y) = \left(y-\frac{5}{2}\right)^2.$$&lt;/div&gt;
&lt;p&gt;Before we apply Theorem 1 to the graph, here is how the problem actually looks
like.  First, the objective &lt;span class="math"&gt;\(F(\theta) = \mathbb{E}_{y \sim p(y|x(\theta))}[f(y)]\)&lt;/span&gt;.
This objective is just an ordinary one-dimensional deterministic function.&lt;/p&gt;
&lt;p&gt;&lt;img alt="True objective to be minimized" src="https://www.nowozin.net/sebastian/blog/images/stochastic-computation-graphs-Ef.svg"&gt;&lt;/p&gt;
&lt;p&gt;The true gradient of the objective is also just an ordinary function.
You can see three zero-crossings at approximately -0.6, 1, and 2.6,
corresponding to two local minima and a saddle-point of the objective function.&lt;/p&gt;
&lt;p&gt;&lt;img alt="True gradient of objective" src="https://www.nowozin.net/sebastian/blog/images/stochastic-computation-graphs-grad.svg"&gt;&lt;/p&gt;
&lt;p&gt;For this simple example we can find a closed form expression for &lt;span class="math"&gt;\(F(\theta)\)&lt;/span&gt;,
but in general stochastic computation graphs we are not able to evaluate
&lt;span class="math"&gt;\(F(\theta)\)&lt;/span&gt; and instead only sample values &lt;span class="math"&gt;\(\hat{F}_1, \hat{F}_2, \dots\)&lt;/span&gt; which
are unbiased estimates of the true &lt;span class="math"&gt;\(F(\theta)\)&lt;/span&gt;.
By taking averages of a few samples, say of a 100 samples, we can improve the
accuracy of our estimates.
In order to minimize &lt;span class="math"&gt;\(F(\theta)\)&lt;/span&gt; over &lt;span class="math"&gt;\(\theta\)&lt;/span&gt; our goal is to sample unbiased
gradients as well.
The unbiased sample gradients look as follows, for &lt;span class="math"&gt;\(1\)&lt;/span&gt; sample (shown in green)
and for averages of a &lt;span class="math"&gt;\(100\)&lt;/span&gt; samples (shown in red), evaluated at a 100 points
equispaced along the &lt;span class="math"&gt;\(\theta\)&lt;/span&gt; axis shown.&lt;/p&gt;
&lt;p&gt;&lt;img alt="Sample gradient of objective" src="https://www.nowozin.net/sebastian/blog/images/stochastic-computation-graphs-gradsample.svg"&gt;&lt;/p&gt;
&lt;p&gt;To derive the unbiased gradient estimate we apply Theorem 1.
From the summation (A) we will only have one term because our graph contains
only one stochastic node, namely &lt;span class="math"&gt;\(y\)&lt;/span&gt;.
We will not have any term from (B) as there is no deterministic path from
&lt;span class="math"&gt;\(\theta\)&lt;/span&gt; to &lt;span class="math"&gt;\(f\)&lt;/span&gt;.
Therefore we have&lt;/p&gt;
&lt;div class="math"&gt;$$\frac{\partial}{\partial \theta} \mathbb{E}_{y \sim p(y|x(\theta))}[f(y)]
= \mathbb{E}_{y \sim p(y|x(\theta))}\left[\frac{\partial}{\partial \theta}
\log p(y|x(\theta)) \hat{f}\right].$$&lt;/div&gt;
&lt;p&gt;For the logarithm we need to differentiate the log-likelihood of the Normal
distribution and compute 
&lt;/p&gt;
&lt;div class="math"&gt;\begin{eqnarray}
\frac{\partial x}{\partial \theta} \frac{\partial}{\partial x} \log p(y|x(\theta))
&amp;amp; = &amp;amp;
\frac{\partial x}{\partial \theta} \frac{\partial}{\partial x} \left[
- \frac{(y-x(\theta))^2}{2} - \frac{1}{2} \log 2\pi \right]\nonumber\\
&amp;amp; = &amp;amp;
\frac{\partial x}{\partial \theta} (y-x(\theta))\nonumber\\
&amp;amp; = &amp;amp;
2(\theta - 1)(y - x(\theta)).\nonumber
\end{eqnarray}&lt;/div&gt;
&lt;p&gt;So the overall unbiased gradient estimator is
&lt;/p&gt;
&lt;div class="math"&gt;$$\mathbb{E}\left[\frac{\partial}{\partial \theta} \log p(y|x(\theta)) \hat{f}\right]
= \mathbb{E}[2(\theta-1)(\hat{y}-\hat{x}) \hat{f}].$$&lt;/div&gt;
&lt;p&gt;
And the last expression in the expectation is the estimate for a single sample
realization.&lt;/p&gt;
&lt;h2&gt;Variational Bayesian Neural Networks&lt;/h2&gt;
&lt;p&gt;One important application of being able to compute gradients of expectation
objectives is the approximate variational Bayesian posterior inference of
neural network parameters.&lt;/p&gt;
&lt;p&gt;The original pioneering work of applying variational Bayes (aka mean field
inference) to neural network learning is &lt;a href="http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.119.5194"&gt;this 1993 paper of Hinton and van
Kamp&lt;/a&gt;.
Recently this has made a revival in particular through the appearance of
&lt;a href="http://www.cs.princeton.edu/courses/archive/fall11/cos597C/reading/Blei2011.pdf"&gt;stochastic variational inference
methods&lt;/a&gt;
around 2011, including a &lt;a href="http://papers.nips.cc/paper/4329-practical-variational-inference-for-neural-networks-spotlight.pdf"&gt;paper of Alex
Graves&lt;/a&gt;.
Many works followed up on this lead, for example &lt;a href="http://dpkingma.com/wordpress/wp-content/uploads/2014/10/iclr14_vae.pdf"&gt;Kingma and
Welling&lt;/a&gt;,
&lt;a href="http://arxiv.org/abs/1401.4082"&gt;Rezende et al., ICML 2014&lt;/a&gt;, &lt;a href="http://arxiv.org/abs/1505.05424"&gt;Blundell et al.,
ICML 2015&lt;/a&gt;, and &lt;a href="http://arxiv.org/abs/1402.0030"&gt;Mnih and
Gregor&lt;/a&gt;.  They use different estimators of the
gradient with varying quality and the SCG paper provides a nice overview of
the bigger picture.&lt;/p&gt;
&lt;p&gt;In any case, here is a visualization of prototypical variational Bayes
learning for feedforward neural networks.  A normal feedforward neural network
training objective yields the following computation graph, without any
stochastic nodes.&lt;/p&gt;
&lt;p&gt;&lt;img alt="Feedforward neural network training objective computation graph" src="https://www.nowozin.net/sebastian/blog/images/scg-nn1.svg"&gt;&lt;/p&gt;
&lt;p&gt;Here we have a fixed weight vector &lt;span class="math"&gt;\(w\)&lt;/span&gt; with a regularizer &lt;span class="math"&gt;\(R(w)\)&lt;/span&gt;.
We have &lt;span class="math"&gt;\(n\)&lt;/span&gt; training instances and each input &lt;span class="math"&gt;\(x_i\)&lt;/span&gt; produces a network output,
&lt;span class="math"&gt;\(P_i(x_i,w)\)&lt;/span&gt;, for example a distribution over class labels.  Together with a
known ground truth label &lt;span class="math"&gt;\(y_i\)&lt;/span&gt; this yields a loss &lt;span class="math"&gt;\(\ell_i(P_i,y_i)\)&lt;/span&gt;, for
example the cross-entropy loss.
If we use a likelihood based loss and a regularizer derived from a prior, i.e.
&lt;span class="math"&gt;\(R(w)=-\log P(w)\)&lt;/span&gt; the training objective becomes just regularized maximum
likelihood estimation.&lt;/p&gt;
&lt;div class="math"&gt;$$F(w) = -\log P(w) - \sum_{i=1}^n \log P(y_i|x_i;w).$$&lt;/div&gt;
&lt;p&gt;The &lt;a href="https://en.wikipedia.org/wiki/Variational_Bayesian_methods"&gt;variational
Bayes&lt;/a&gt; training
objective yields the following slightly extended &lt;em&gt;stochastic&lt;/em&gt; computation
graph.&lt;/p&gt;
&lt;p&gt;&lt;img alt="Variational Bayes neural network training objective stochastic computation graph" src="https://www.nowozin.net/sebastian/blog/images/scg-nn2.svg"&gt;&lt;/p&gt;
&lt;p&gt;Here &lt;span class="math"&gt;\(w\)&lt;/span&gt; is still a network parameter, but it is now a stochastic vector, &lt;span class="math"&gt;\(w
\sim Q(w|\theta)\)&lt;/span&gt; and &lt;span class="math"&gt;\(\theta\)&lt;/span&gt; becomes the parameter we would like to learn.
The additional cost node &lt;span class="math"&gt;\(H\)&lt;/span&gt; arises from the entropy of the approximating
posterior distribution &lt;span class="math"&gt;\(Q\)&lt;/span&gt;.  (An interesting detail: in principle we would not
need an arrow &lt;span class="math"&gt;\(w \to H\)&lt;/span&gt; because we can compute &lt;span class="math"&gt;\(H(Q)\)&lt;/span&gt;.  However, if we allow
this arrow, then we can use a Monte Carlo approximation of the entropy for
approximating families which do not have an analytic entropy expression.)
The training objective becomes:&lt;/p&gt;
&lt;div class="math"&gt;$$F(\theta) = \mathbb{E}_{w \sim Q(w|\theta)}\left[-\log P(w) + \log Q(w|\theta) - \sum_{i=1}^n \log P(y_i|x_i;w)\right].$$&lt;/div&gt;
&lt;p&gt;The stochastic computation graph rules can now be used to derive the unbiased
gradient estimate.&lt;/p&gt;
&lt;div class="math"&gt;$$\frac{\partial}{\partial \theta} F(\theta) =
\mathbb{E}_{w \sim Q(w|\theta)}\left[
\frac{\partial}{\partial \theta} \log Q(w|\theta) \left(
-\log P(w) + \log Q(w|\theta) - \sum_{i=1}^n \log P(y_i|x_i;w)
\right)\right].$$&lt;/div&gt;
&lt;p&gt;This is now quite practical: the expectation can be approximated using simple
Monte Carlo samples of &lt;span class="math"&gt;\(w\)&lt;/span&gt; values using the current approximating posterior
&lt;span class="math"&gt;\(Q(w|\theta)\)&lt;/span&gt;.  Because the gradient is unbiased we can improve the
approximation by running standard stochastic gradient methods.&lt;/p&gt;
&lt;h2&gt;Additional Applications&lt;/h2&gt;
&lt;p&gt;The paper contains a large number of machine learning applications, but there
are many others.
Here is one I find useful.&lt;/p&gt;
&lt;p&gt;&lt;img alt="Experimental design stochastic computation graph" src="https://www.nowozin.net/sebastian/blog/images/scg-experimental-design.svg"&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Experimental design.&lt;/em&gt;  In &lt;a href="http://eu.wiley.com/WileyCDA/WileyTitle/productCd-047149657X.html"&gt;Bayesian experimental
design&lt;/a&gt; we
make a choice that influences our future measurements and we would like to
make these choices in such a way that we will maximize the future expected
utility or minimize expected loss.
For this we use a model of how our choices relate to the information we will
capture and to how valuable these information will be.  Because this is just
decision theory and the idea is general, let me be more concrete.  Let us
assume the objective function
&lt;/p&gt;
&lt;div class="math"&gt;$$\mathbb{E}_{z \sim p(z)}[\mathbb{E}_{x \sim p(x|z,\theta)}[\ell(\tilde{z}(x,\theta), z)]].$$&lt;/div&gt;
&lt;p&gt;
Here &lt;span class="math"&gt;\(\theta\)&lt;/span&gt; is our design parameter, &lt;span class="math"&gt;\(z\)&lt;/span&gt; is the true state we are interested
in with a prior &lt;span class="math"&gt;\(p(z)\)&lt;/span&gt;.
The measurement process produces &lt;span class="math"&gt;\(x \sim p(x|z,\theta)\)&lt;/span&gt;.
We have an estimator &lt;span class="math"&gt;\(\tilde{z}(x,\theta)\)&lt;/span&gt; and a loss function which compares
the estimated value against the true state.
The full objective function is then the expected loss of our estimator
&lt;span class="math"&gt;\(\tilde{z}\)&lt;/span&gt; as a function of the design parameters &lt;span class="math"&gt;\(\theta\)&lt;/span&gt;.
The above expression looks a bit convoluted but this structure appears
frequently when the type of information that is collected can be controlled.
One example application of this: &lt;span class="math"&gt;\(z\)&lt;/span&gt; could represent user behaviour and
&lt;span class="math"&gt;\(\theta\)&lt;/span&gt; some subset of questions we could ask that user to learn more about
his behaviour.  We then assume a model &lt;span class="math"&gt;\(p(x|z,\theta)\)&lt;/span&gt; of how the user would
provide answers &lt;span class="math"&gt;\(x\)&lt;/span&gt; given questions &lt;span class="math"&gt;\(\theta\)&lt;/span&gt; and behaviour &lt;span class="math"&gt;\(z\)&lt;/span&gt;.  This allows
us to build an estimator &lt;span class="math"&gt;\(\tilde{z}(x,\theta)\)&lt;/span&gt;.  The design objective then tries
to find the most informative set of questions to ask.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Acknowledgements&lt;/em&gt;.  I thank &lt;a href="http://ei.is.tuebingen.mpg.de/person/mschober"&gt;Michael
Schober&lt;/a&gt; for discussions about
the paper and Nicolas Heess for feedback on this article.&lt;/p&gt;
&lt;script type="text/javascript"&gt;if (!document.getElementById('mathjaxscript_pelican_#%@#$@#')) {
    var align = "center",
        indent = "0em",
        linebreak = "false";

    if (false) {
        align = (screen.width &lt; 768) ? "left" : align;
        indent = (screen.width &lt; 768) ? "0em" : indent;
        linebreak = (screen.width &lt; 768) ? 'true' : linebreak;
    }

    var mathjaxscript = document.createElement('script');
    mathjaxscript.id = 'mathjaxscript_pelican_#%@#$@#';
    mathjaxscript.type = 'text/javascript';
    mathjaxscript.src = 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.3/latest.js?config=TeX-AMS-MML_HTMLorMML';

    var configscript = document.createElement('script');
    configscript.type = 'text/x-mathjax-config';
    configscript[(window.opera ? "innerHTML" : "text")] =
        "MathJax.Hub.Config({" +
        "    config: ['MMLorHTML.js']," +
        "    TeX: { extensions: ['AMSmath.js','AMSsymbols.js','noErrors.js','noUndefined.js'], equationNumbers: { autoNumber: 'none' } }," +
        "    jax: ['input/TeX','input/MathML','output/HTML-CSS']," +
        "    extensions: ['tex2jax.js','mml2jax.js','MathMenu.js','MathZoom.js']," +
        "    displayAlign: '"+ align +"'," +
        "    displayIndent: '"+ indent +"'," +
        "    showMathMenu: true," +
        "    messageStyle: 'normal'," +
        "    tex2jax: { " +
        "        inlineMath: [ ['\\\\(','\\\\)'] ], " +
        "        displayMath: [ ['$$','$$'] ]," +
        "        processEscapes: true," +
        "        preview: 'TeX'," +
        "    }, " +
        "    'HTML-CSS': { " +
        "        availableFonts: ['STIX', 'TeX']," +
        "        preferredFont: 'STIX'," +
        "        styles: { '.MathJax_Display, .MathJax .mo, .MathJax .mi, .MathJax .mn': {color: 'inherit ! important'} }," +
        "        linebreaks: { automatic: "+ linebreak +", width: '90% container' }," +
        "    }, " +
        "}); " +
        "if ('default' !== 'default') {" +
            "MathJax.Hub.Register.StartupHook('HTML-CSS Jax Ready',function () {" +
                "var VARIANT = MathJax.OutputJax['HTML-CSS'].FONTDATA.VARIANT;" +
                "VARIANT['normal'].fonts.unshift('MathJax_default');" +
                "VARIANT['bold'].fonts.unshift('MathJax_default-bold');" +
                "VARIANT['italic'].fonts.unshift('MathJax_default-italic');" +
                "VARIANT['-tex-mathit'].fonts.unshift('MathJax_default-italic');" +
            "});" +
            "MathJax.Hub.Register.StartupHook('SVG Jax Ready',function () {" +
                "var VARIANT = MathJax.OutputJax.SVG.FONTDATA.VARIANT;" +
                "VARIANT['normal'].fonts.unshift('MathJax_default');" +
                "VARIANT['bold'].fonts.unshift('MathJax_default-bold');" +
                "VARIANT['italic'].fonts.unshift('MathJax_default-italic');" +
                "VARIANT['-tex-mathit'].fonts.unshift('MathJax_default-italic');" +
            "});" +
        "}";

    (document.body || document.getElementsByTagName('head')[0]).appendChild(configscript);
    (document.body || document.getElementsByTagName('head')[0]).appendChild(mathjaxscript);
}
&lt;/script&gt;</content><category term="Statistics, Machine Learning"/></entry><entry><title>Multilevel Splitting</title><link href="https://www.nowozin.net/sebastian/blog/multilevel-splitting.html" rel="alternate"/><published>2015-07-10T22:50:00+01:00</published><updated>2015-07-10T22:50:00+01:00</updated><author><name>Sebastian Nowozin</name></author><id>tag:www.nowozin.net,2015-07-10:/sebastian/blog/multilevel-splitting.html</id><summary type="html">&lt;p&gt;This article is about &lt;em&gt;multilevel splitting&lt;/em&gt;, a method for estimating the
probability of rare events.&lt;/p&gt;
&lt;p&gt;Estimating the probability of &lt;em&gt;rare events&lt;/em&gt; is important in many fields.
One vivid example is in the study of reliability of systems; imagine for
example, that we are responsible for building a mechanical structure such …&lt;/p&gt;</summary><content type="html">&lt;p&gt;This article is about &lt;em&gt;multilevel splitting&lt;/em&gt;, a method for estimating the
probability of rare events.&lt;/p&gt;
&lt;p&gt;Estimating the probability of &lt;em&gt;rare events&lt;/em&gt; is important in many fields.
One vivid example is in the study of reliability of systems; imagine for
example, that we are responsible for building a mechanical structure such as a
bridge and we aim to design it to last one hundred years.
To provide any kind of guarantee we need to have a model of what could happen
in these 100 years, for example how the bridge will be used during that time,
what weight it will have to bear, how strong winds and floods may be, how
corrosion and other processes deteriorate the structure, etc.
Considering all these factors may only be possible approximately via a
&lt;em&gt;simulation&lt;/em&gt; of the structure under different effects.&lt;/p&gt;
&lt;p&gt;For concreteness let's say we denote by &lt;span class="math"&gt;\(X\)&lt;/span&gt; the random variable that represents the
maximum force that is applied to the bridge during the 100 years lifetime.
Each simulation allows us to obtain a sample &lt;span class="math"&gt;\(X_i \sim P\)&lt;/span&gt; of this force, where
&lt;span class="math"&gt;\(P\)&lt;/span&gt; is a probabilistic model of everything that can happen during the 100
years.
Given that we designed the bridge to widthstand a certain force, the question
is now to make statements of the form
&lt;/p&gt;
&lt;div class="math"&gt;$$P(X \geq \delta) \leq \epsilon.$$&lt;/div&gt;
&lt;p&gt;
Often we want the probability of something bad happening (the event &lt;span class="math"&gt;\(X \geq
\delta\)&lt;/span&gt;) to be exceptionally small, say &lt;span class="math"&gt;\(\epsilon = 10^{-9}\)&lt;/span&gt;.&lt;/p&gt;
&lt;p&gt;Another common example is the &lt;a href="https://www.nowozin.net/sebastian/blog/bayesian-p-values.html"&gt;computation of P-values&lt;/a&gt;,
where we observe a sample &lt;span class="math"&gt;\(x\)&lt;/span&gt; and compute a &lt;em&gt;test statistic&lt;/em&gt; &lt;span class="math"&gt;\(t=T(x)\)&lt;/span&gt;.  Given
a &lt;em&gt;null model&lt;/em&gt; in the form of a distribution &lt;span class="math"&gt;\(P(X)\)&lt;/span&gt; we are interested in the
&lt;em&gt;P-value&lt;/em&gt;, that is, the probability of the event &lt;span class="math"&gt;\(P(T(X) \geq t)\)&lt;/span&gt;.  This
number is the probability under the null of observing a test statistic at
least as extreme as the one actually observed.
Using the multilevel splitting idea we can hope to accurately compute the
P-value as long as we can run an MCMC chain on the null model.
Also, more general P-values for composite null models, such as the &lt;a href="https://www.nowozin.net/sebastian/blog/bayesian-p-values.html"&gt;&lt;em&gt;posterior
predictive P-value&lt;/em&gt;&lt;/a&gt; are computable.
So if this sounds good, how does multilevel splitting work and why is it
needed in the first place?&lt;/p&gt;
&lt;p&gt;In the absence of an analytic form for &lt;span class="math"&gt;\(P\)&lt;/span&gt;, a naive simulation approach is to
repeatedly draw samples &lt;span class="math"&gt;\(X_i \sim P\)&lt;/span&gt; and to count how often the bad event
happens.  For rare events as the one above this does not work very well and if
we would exactly meet the guarantee of the above example, &lt;span class="math"&gt;\(\epsilon =
10^{-9}\)&lt;/span&gt;, then we would on average have to draw around &lt;span class="math"&gt;\(1/\epsilon = 10^9\)&lt;/span&gt;
samples just to see a single bad event.
But because we would like to estimate the rare event probability we need even
more samples.&lt;/p&gt;
&lt;p&gt;There are a number of custom methods for accurate estimation of rare event
probabilities.  The remainder of the article discusses &lt;em&gt;multilevel splitting&lt;/em&gt;,
but at this point I would like to mention that another popular set of methods
for rare events is based on adaptive importance sampling which is described in
detail in &lt;a href="http://eu.wiley.com/WileyCDA/WileyTitle/productCd-0470177942.html"&gt;Rubinstein and Kroese's
book on Monte Carlo
methods&lt;/a&gt;.&lt;/p&gt;
&lt;h1&gt;Multilevel Splitting&lt;/h1&gt;
&lt;p&gt;&lt;a href="http://en.wikipedia.org/wiki/John_von_Neumann"&gt;John von Neumann&lt;/a&gt; had an idea
better than naive simulation on how to address the problem of estimating rare
event probabilities.  He named his solution &lt;em&gt;multilevel splitting&lt;/em&gt;.  The first
published description of multilevel splitting is due to &lt;a href="https://dornsifecms.usc.edu/assets/sites/520/docs/kahnharris.pdf"&gt;Kahn and Harris in
1951&lt;/a&gt; (who
attribute it to John von Neumann).&lt;/p&gt;
&lt;p&gt;The basic idea of multilevel splitting is to steer an iterative simulation
process towards the rare event region by removing samples far away from the
rare event and &lt;em&gt;splitting&lt;/em&gt; samples closer to the rare event.&lt;/p&gt;
&lt;p&gt;The application considered in the 1951 paper is interesting in this regard in
that it clearly relates to nuclear weapon research:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;"We wish to estimate the probability that a particle is transmitted through a
shield, when this probability is of the order of &lt;span class="math"&gt;\(10^{-6}\)&lt;/span&gt; to &lt;span class="math"&gt;\(10^{-10}\)&lt;/span&gt;, and
we wish to do this by sampling about a thousand life histories."
...
"In one method of applying this, one defines regions of importance in the
space being studied, and, when the sampled particle goes from a less
important to a more important region, it is split into two independent
particles, each one-half the weight of the original."&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Back in 1951 the algorithm was somewhat adhoc but effective.
In a recent 2011 &lt;a href="http://perso.univ-rennes2.fr/system/files/users/guyader_a/ghm2.pdf"&gt;paper by Guyader, Hengartner, and
Matzner-Lober&lt;/a&gt;
the authors propose a more practical variant of the same idea and provide
theoretical results.&lt;/p&gt;
&lt;h2&gt;Setup&lt;/h2&gt;
&lt;p&gt;The general setup is as follows.  We have a distribution &lt;span class="math"&gt;\(P\)&lt;/span&gt; defining our system.
We have &lt;span class="math"&gt;\(X \in \mathcal{X}\)&lt;/span&gt; for the realizations &lt;span class="math"&gt;\(X \sim P\)&lt;/span&gt;.
A continuous map &lt;span class="math"&gt;\(\phi: \mathcal{X} \to \mathbb{R}\)&lt;/span&gt; defines the quantity of interest.
We are interested in computing the probability &lt;span class="math"&gt;\(P(\phi(X) \geq q)\)&lt;/span&gt;.
To this end we assume we can approximately simulate from &lt;span class="math"&gt;\(P\)&lt;/span&gt; using a &lt;a href="http://en.wikipedia.org/wiki/Markov_chain_Monte_Carlo"&gt;Markov
chain&lt;/a&gt;, which is
typically possible even in complex models.&lt;/p&gt;
&lt;p&gt;The basic idea of the original 1951 algorithm is to fix a set of levels
&lt;span class="math"&gt;\(-\infty = L_0 &amp;lt; L_1 &amp;lt; L_2 &amp;lt; \dots &amp;lt; L_k = q\)&lt;/span&gt;.  Then we can formally write
&lt;/p&gt;
&lt;div class="math"&gt;$$P(\phi(X) \geq q) = \prod_{i=1}^k P(\phi(X) \geq L_i \:|\: \phi(X) \geq L_{i-1}).$$&lt;/div&gt;
&lt;p&gt;The above product can be estimated term-by-term as follows: we use a set of
&lt;span class="math"&gt;\(N\)&lt;/span&gt; particles &lt;span class="math"&gt;\((X_1,\dots,X_N)\)&lt;/span&gt; and simulate these according to &lt;span class="math"&gt;\(X_i \sim P(X)\)&lt;/span&gt;.
Then we estimate the fraction
&lt;/p&gt;
&lt;div class="math"&gt;$$P(\phi(X) \geq L_1 \:|\: \phi(X) \geq L_0) = P(\phi(X) \geq L_1)
    \approx \frac{\sum_{i=1}^N 1_{\{\phi(X_i) \geq L_1\}}}{N}.$$&lt;/div&gt;
&lt;p&gt;
Afterwards we discard all particles with &lt;span class="math"&gt;\(\phi(X_i) &amp;lt; L_1\)&lt;/span&gt; and use the remaining
particles to resample a set of &lt;span class="math"&gt;\(N\)&lt;/span&gt; particles (the &lt;em&gt;splitting&lt;/em&gt;).
Finally, we update all particles using a number of steps of our MCMC kernel,
but this time restricted to &lt;span class="math"&gt;\(\phi(X_i) \geq L_1\)&lt;/span&gt;, that is, we reject all
proposals that would violate this condition.
This is one level, and for the multilevel scheme we repeat the above procedure
with the next level.  Eventually, when we reach the final level &lt;span class="math"&gt;\(L_k\)&lt;/span&gt;, we take
the product of the estimated probabilities as the estimate of the rare event
probability.  Upon reaching the final level the surviving particles are
properly distributed conditional on the restriction &lt;span class="math"&gt;\(\phi(X) \geq q\)&lt;/span&gt;.&lt;/p&gt;
&lt;p&gt;The above algorithm is effective but has the major drawback of having to fix a
ladder of levels apriori.  It would be more practical to instead have an
automatic method to create these levels or to get rid of them entirely.  The
algorithm of &lt;em&gt;Guyader et al.&lt;/em&gt; achieves this automatic selection by keeping the
particles sorted according to &lt;span class="math"&gt;\(\phi\)&lt;/span&gt;, with the lowest particle defining the
current level, at the cost of having a random runtime of the algorithm.&lt;/p&gt;
&lt;p&gt;The 2011 paper is quite rich in that it also contains an approximate
confidence interval for the true probability as well as an analysis of the
random runtime and an interesting application of estimating the false positive
rate of watermark detection schemes (which ideally should be very small).
Also, a variant of their method can solve for the &lt;em&gt;quantile&lt;/em&gt;, that is, given
&lt;span class="math"&gt;\(p\)&lt;/span&gt; in &lt;span class="math"&gt;\(p = P(\phi(X) \geq q)\)&lt;/span&gt;, solve for &lt;span class="math"&gt;\(q\)&lt;/span&gt;.
(Unfortunately, in the paper, as is often the case with many statistics and
applied math papers, the algorithm (in Section 3.2) is not presented very
clearly compared to a typical CS or ML paper.)&lt;/p&gt;
&lt;h2&gt;Example&lt;/h2&gt;
&lt;p&gt;The following is an implementation in the &lt;a href="http://julialang.org/"&gt;Julia
language&lt;/a&gt; that estimates &lt;span class="math"&gt;\(P(X \geq 16.5)\)&lt;/span&gt; where &lt;span class="math"&gt;\(X \sim
\mathcal{N}(0,1)\)&lt;/span&gt; is a standard Normal random variable.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="k"&gt;using&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;Distributions&lt;/span&gt;

&lt;span class="n"&gt;N&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;2000&lt;/span&gt;&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="c"&gt;# number of particles&lt;/span&gt;
&lt;span class="n"&gt;T&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="w"&gt;   &lt;/span&gt;&lt;span class="c"&gt;# number of MCMC steps&lt;/span&gt;
&lt;span class="n"&gt;q&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mf"&gt;16.5&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="c"&gt;# quantile&lt;/span&gt;
&lt;span class="n"&gt;target&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;Normal&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;0.0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mf"&gt;1.0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;K&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;Normal&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;0.0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mf"&gt;0.2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="c"&gt;# Markov kernel&lt;/span&gt;

&lt;span class="n"&gt;m&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;
&lt;span class="n"&gt;X&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;sort&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;rand&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;target&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;N&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;span class="n"&gt;L&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;X&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="k"&gt;while&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;L&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;q&lt;/span&gt;&lt;span class="w"&gt;   &lt;/span&gt;&lt;span class="c"&gt;# as long as there are particles below q&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;X&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;X&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;rand&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="n"&gt;N&lt;/span&gt;&lt;span class="p"&gt;)]&lt;/span&gt;

&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="c"&gt;# Run a Markov chain on the lowermost sample&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="n"&gt;T&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;X&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;rand&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;K&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="n"&gt;log_alpha&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;logpdf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;target&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;logpdf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;target&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;X&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;rand&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;&amp;lt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;log_alpha&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;L&lt;/span&gt;
&lt;span class="w"&gt;            &lt;/span&gt;&lt;span class="n"&gt;X&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;y&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="k"&gt;end&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="k"&gt;end&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;X&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;sort&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;X&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;L&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;X&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;m&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;+=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;span class="n"&gt;phat&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;1.0&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mf"&gt;1.0&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;N&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;^&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;m&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c"&gt;# Estimate, Truth&lt;/span&gt;
&lt;span class="n"&gt;phat&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;ccdf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;target&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;q&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Giving the output&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;(1.4581487078794118e-61,1.8344630031647276e-61)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;where the first number is the estimate and the second number is the ground
truth, known in this case analytically.
The relative estimation accuracy in this case is remarkably, given that this
event occurs on average only once every &lt;span class="math"&gt;\(10^{61}\)&lt;/span&gt; samples.  For this
simulation a total of &lt;span class="math"&gt;\(m=280,092\)&lt;/span&gt; sample updates have been performed until the
algorithm stopped.&lt;/p&gt;
&lt;h2&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;Multilevel splitting is a useful algorithm for estimating the probability of
rare events and the recent algorithm of Guyader et al. is practical in that it
can be implemented on top of an arbitrary MCMC sampler.&lt;/p&gt;
&lt;p&gt;There are caveats, however.  In the above example, the problem structure is
almost ideal for the application of multilevel splitting: a slowly varying
continuous function &lt;span class="math"&gt;\(\phi\)&lt;/span&gt; whose level sets are topologically connected.  This
means that the MCMC sampler can mix easily in the restricted subsets and the
resulting rare event probabilities can be accurately estimated.
If these assumptions are not satisfied the algorithm may fail to work, and
current research addresses these more general situations, see, for example
&lt;a href="http://arxiv.org/abs/1507.00919"&gt;this recent paper by Walter&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;In summary, although some care is required for the application of multilevel
splitting to real problems it is likely to be orders of magnitude more
efficient than naive approaches.&lt;/p&gt;
&lt;script type="text/javascript"&gt;if (!document.getElementById('mathjaxscript_pelican_#%@#$@#')) {
    var align = "center",
        indent = "0em",
        linebreak = "false";

    if (false) {
        align = (screen.width &lt; 768) ? "left" : align;
        indent = (screen.width &lt; 768) ? "0em" : indent;
        linebreak = (screen.width &lt; 768) ? 'true' : linebreak;
    }

    var mathjaxscript = document.createElement('script');
    mathjaxscript.id = 'mathjaxscript_pelican_#%@#$@#';
    mathjaxscript.type = 'text/javascript';
    mathjaxscript.src = 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.3/latest.js?config=TeX-AMS-MML_HTMLorMML';

    var configscript = document.createElement('script');
    configscript.type = 'text/x-mathjax-config';
    configscript[(window.opera ? "innerHTML" : "text")] =
        "MathJax.Hub.Config({" +
        "    config: ['MMLorHTML.js']," +
        "    TeX: { extensions: ['AMSmath.js','AMSsymbols.js','noErrors.js','noUndefined.js'], equationNumbers: { autoNumber: 'none' } }," +
        "    jax: ['input/TeX','input/MathML','output/HTML-CSS']," +
        "    extensions: ['tex2jax.js','mml2jax.js','MathMenu.js','MathZoom.js']," +
        "    displayAlign: '"+ align +"'," +
        "    displayIndent: '"+ indent +"'," +
        "    showMathMenu: true," +
        "    messageStyle: 'normal'," +
        "    tex2jax: { " +
        "        inlineMath: [ ['\\\\(','\\\\)'] ], " +
        "        displayMath: [ ['$$','$$'] ]," +
        "        processEscapes: true," +
        "        preview: 'TeX'," +
        "    }, " +
        "    'HTML-CSS': { " +
        "        availableFonts: ['STIX', 'TeX']," +
        "        preferredFont: 'STIX'," +
        "        styles: { '.MathJax_Display, .MathJax .mo, .MathJax .mi, .MathJax .mn': {color: 'inherit ! important'} }," +
        "        linebreaks: { automatic: "+ linebreak +", width: '90% container' }," +
        "    }, " +
        "}); " +
        "if ('default' !== 'default') {" +
            "MathJax.Hub.Register.StartupHook('HTML-CSS Jax Ready',function () {" +
                "var VARIANT = MathJax.OutputJax['HTML-CSS'].FONTDATA.VARIANT;" +
                "VARIANT['normal'].fonts.unshift('MathJax_default');" +
                "VARIANT['bold'].fonts.unshift('MathJax_default-bold');" +
                "VARIANT['italic'].fonts.unshift('MathJax_default-italic');" +
                "VARIANT['-tex-mathit'].fonts.unshift('MathJax_default-italic');" +
            "});" +
            "MathJax.Hub.Register.StartupHook('SVG Jax Ready',function () {" +
                "var VARIANT = MathJax.OutputJax.SVG.FONTDATA.VARIANT;" +
                "VARIANT['normal'].fonts.unshift('MathJax_default');" +
                "VARIANT['bold'].fonts.unshift('MathJax_default-bold');" +
                "VARIANT['italic'].fonts.unshift('MathJax_default-italic');" +
                "VARIANT['-tex-mathit'].fonts.unshift('MathJax_default-italic');" +
            "});" +
        "}";

    (document.body || document.getElementsByTagName('head')[0]).appendChild(configscript);
    (document.body || document.getElementsByTagName('head')[0]).appendChild(mathjaxscript);
}
&lt;/script&gt;</content><category term="Statistics"/></entry><entry><title>Bayesian P-Values</title><link href="https://www.nowozin.net/sebastian/blog/bayesian-p-values.html" rel="alternate"/><published>2015-06-27T00:15:00+01:00</published><updated>2015-06-27T00:15:00+01:00</updated><author><name>Sebastian Nowozin</name></author><id>tag:www.nowozin.net,2015-06-27:/sebastian/blog/bayesian-p-values.html</id><summary type="html">&lt;p&gt;&lt;a href="https://en.wikipedia.org/wiki/P-value"&gt;P-Values&lt;/a&gt; (see also &lt;a href="https://stat.duke.edu/~berger/p-values.html"&gt;Jim Berger's page
on p-values&lt;/a&gt;) are probably one of
the most misunderstood concepts in statistics and certainly have been abused
in statistical practice.
Originally proposed as an informal diagnostic by &lt;a href="http://en.wikipedia.org/wiki/Ronald_Fisher"&gt;Ronald Fisher&lt;/a&gt;, there are many
reasons for the bad reputation of p-values, and in many relevant situations …&lt;/p&gt;</summary><content type="html">&lt;p&gt;&lt;a href="https://en.wikipedia.org/wiki/P-value"&gt;P-Values&lt;/a&gt; (see also &lt;a href="https://stat.duke.edu/~berger/p-values.html"&gt;Jim Berger's page
on p-values&lt;/a&gt;) are probably one of
the most misunderstood concepts in statistics and certainly have been abused
in statistical practice.
Originally proposed as an informal diagnostic by &lt;a href="http://en.wikipedia.org/wiki/Ronald_Fisher"&gt;Ronald Fisher&lt;/a&gt;, there are many
reasons for the bad reputation of p-values, and in many relevant situations
good alternatives such as &lt;a href="http://amstat.tandfonline.com/doi/abs/10.1080/01621459.1995.10476572"&gt;Bayes
factors&lt;/a&gt;
can and should be used instead.
One key objection to p-values is that although they provide statistical
evidence against an assumed hypothesis, this does not imply that the deviation
from the hypothesis is large or relevant.
In practice, the largest criticisms are not related to the p-value itself but
related to the widespread misunderstanding of p-values and the arbitrariness
of accepting formal tests of significance based on p-values in
scientific discourse.&lt;/p&gt;
&lt;p&gt;In this article I am not going to defend p-values, also because others have
done a good job at giving a modern explanation of their benefits in context,
as well as refuting some common criticisms, for example the article &lt;a href="http://www.dcscience.net/Senn-Two-cheers-2001.pdf"&gt;Two
cheers for P-values?&lt;/a&gt; by
&lt;a href="http://www.gla.ac.uk/schools/mathematicsstatistics/staff/stephensenn/"&gt;Stephen
Senn&lt;/a&gt;
and the more recent &lt;a href="http://science.oregonstate.edu/~murtaugh/files/ecol-2014.pdf"&gt;In defense of P
values&lt;/a&gt; by &lt;a href="http://stat.oregonstate.edu/content/murtaugh-paul"&gt;Paul
Murtaugh&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Instead, I will consider a situation which often arises in practice.&lt;/p&gt;
&lt;h2&gt;Setup&lt;/h2&gt;
&lt;p&gt;Suppose you have decided on a probabilistic model &lt;span class="math"&gt;\(P(X)\)&lt;/span&gt; or &lt;span class="math"&gt;\(P(X|\theta)\)&lt;/span&gt;,
where &lt;span class="math"&gt;\(\theta\)&lt;/span&gt; is some unknown parameter.
With &lt;em&gt;decided&lt;/em&gt; I mean that we actually commit and ship our model and we no
longer entertain alternative models.
Alternatives could be too expensive computationally or it could be too
difficult to accurately specify these alternative models.  (For example, a
more complicated model may involve additional latent variables for which it is
difficult to elicit prior beliefs.)&lt;/p&gt;
&lt;p&gt;Given such a model but no assumed alternative, and some observed data &lt;span class="math"&gt;\(X\)&lt;/span&gt;, can
we identify whether "the model fits the data"?
This problem is the classic &lt;a href="https://en.wikipedia.org/wiki/Goodness_of_fit"&gt;goodness of
fit&lt;/a&gt; problem and classical
statistics has a repertoire of methods for standard models.  These methods
have their own problems in that they are often unsatisfactory case-by-case
studies or strong results are obtained only in asymptotia.
However, it would be too easy to just criticise these methods.
The real question is whether the problem they address is an important one, and
what alternatives should be used, especially from a Bayesian viewpoint.&lt;/p&gt;
&lt;h2&gt;Prediction versus Scientific Theories&lt;/h2&gt;
&lt;p&gt;In &lt;em&gt;machine learning&lt;/em&gt;, at least in its widespread current industrial use, we
are most often concerned with building predictive models that automatically
make decisions such as showing the right advertisements, classifying spam
emails, etcetera.&lt;/p&gt;
&lt;p&gt;This current focus on prediction may shift in the future, for example due to a
revival in artificial intelligence systems or in general more autonomous agent
type systems which do not have a single clearly defined prediction task.&lt;/p&gt;
&lt;p&gt;But as it currently stands, model checking and goodness of fit is not so
relevant for building predictive models.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;First&lt;/em&gt;, even when the observation does not comply with model assumptions, your
prediction may still be correct, in which case the non-compliance does not
matter.  I.e. the p-value does not use a decision-theoretic viewpoint that
includes a task-dependent utility; cf. &lt;a href="http://arxiv.org/abs/1402.6118"&gt;Watson and
Holmes&lt;/a&gt;.
To know whether the model is "correct" or not may not be important at all for
prediction, but even likewise within science, as summarized by Bruce Hill in
&lt;a href="http://www3.stat.sinica.edu.tw/statistica/oldpdf/A6n41.pdf"&gt;this comment&lt;/a&gt;,&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;"A major defect of the classical view of hypothesis testing, [...],
is that it attempts to test only whether the model is true.
This came out of the tradition in physics, where models such as Newtonian
mechanics, the gas laws, fluid dynamics, and so on, come so close to being
"true" in the sense of fitting (much of) the data, that one tends to neglect
issues about the use of the model. However, in typical statistical problems
(especially in the biological and social sciences but not exclusively so)
one is almost certain a priori that the model taken literally is false in a
non-trivial way, and so one is instead concerned whether the magnitude of
discrepancies is sufficiently small so that the model can be employed for
some specific purpose."&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;&lt;em&gt;Second&lt;/em&gt;, if the deviation from modelling assumptions leads to incorrect
predictions you would detect this through simple analysis of incorrect
predictions using ground truth holdout data, not through fancy model checking.
Checking accuracy of predictions is easy with annotated ground truth data, and
is the bread-and-butter basic tool of machine learning.&lt;/p&gt;
&lt;p&gt;The only useful application of model checking for predictive systems that I
could think of are systems in which a conservative "prefer-not-to-predict"
option exists, so that observations which are violating model assumptions
could be excluded from further automated processing.  Yet, much of this
potential benefit may already be accessible through posterior uncertainty of
the model.  Only the subset of instances for which the model is certain but
its predictions are wrong could profit from this special treatment.&lt;/p&gt;
&lt;p&gt;In contrast to prediction, in science we build models not purely for
prediction, but as a formal approximation to reality.  Here I see that model
checking is crucial, because it allows falsification of &lt;em&gt;scientific&lt;/em&gt;
hypotheses, leading hopefully to improved scientific understanding in the form
of new models.
One historically efficient method to falsify a scientific model is to check
the predictions it makes, so a scientific model must normally also be a
"predictive model".
This viewpoint of establishing a model not just for making good predictions
but also to understand mechanisms of reality also seems closer to the field of
statistics.&lt;/p&gt;
&lt;p&gt;The above separation of prediction versus science is of course not a
simple dichotomy, but just a preference of the practitioner.&lt;/p&gt;
&lt;h2&gt;Bayesian Viewpoints?&lt;/h2&gt;
&lt;p&gt;So then, what is the Bayesian viewpoint here?
The answer is that some well respected figures in the field accept frequentist
tests and p-values as a method to criticise and attempt to falsify Bayesian
models.
One example can be seen in a &lt;a href="http://www.stat.columbia.edu/~gelman/research/published/philosophy_chapter.pdf"&gt;recent article&lt;/a&gt;
by &lt;a href="http://andrewgelman.com/"&gt;Andrew Gelman&lt;/a&gt; and &lt;a href="http://www.stat.cmu.edu/~cshalizi/"&gt;Cosma
Shalizi&lt;/a&gt; where mechanisms to falsify a
Bayesian model a discussed, stating&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;"The main point where we disagree with many Bayesians is that we do not
think that Bayesian methods are generally useful for giving the posterior
probability that a model is true, or the probability for preferring model A
over model &lt;em&gt;B&lt;/em&gt;, or whatever.  Bayesian inference is good for deductive
inference within a model, but for evaluating a model, we prefer to compare
it to data (what Cox and Hinkley , 1974, call "pure significance testing")
without requiring that a new model be there to beat it."&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;(They use pure significance tests and frequentist predictive checks, but no
p-values in that paper.)&lt;/p&gt;
&lt;p&gt;Another example is &lt;a href="http://amstat.tandfonline.com/doi/abs/10.1080/01621459.2000.10474309"&gt;an
article&lt;/a&gt;
by &lt;a href="http://www.uv.es/bayarri/"&gt;Susie Bayarri&lt;/a&gt; and &lt;a href="https://stat.duke.edu/~berger/"&gt;James
Berger&lt;/a&gt;, where "Bayesian p-values" are
discussed.&lt;/p&gt;
&lt;p&gt;A third and maybe more popular pragmatic Bayesian stance is summarized in
Bruce Hill's comment on &lt;a href="http://www3.stat.sinica.edu.tw/statistica/oldpdf/A6n41.pdf"&gt;Gelman, Meng, and Stern's article on posterior
predictive
testing&lt;/a&gt;,&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;"Like many others, I have come to regard the classical p-value as a useful
diagnostic device, particularly in screening large numbers of possibly
meaningful treatment comparisons. It is one of many ways quickly to alert
oneself to some of the important features of a data set. However, in my
opinion it is not particularly suited for careful decision-making in serious
problems, or even for hypothesis testing.  Its primary function is to
alert one to the need for making such a more careful analysis, and
perhaps to search for better models. Whether one wishes actually to go
beyond the p-value depends upon, among other things, the importance of the
problem, whether the quality of the data and information about the model and
a priori distributions is sufficiently high for such an analysis to be
worthwhile, and ultimately upon the perceived utility of such an analysis."&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Not arguing by reference to authorities, but given the broad spectrum of
contributions of Andrew Gelman, Bruce Hill, and James Berger (many of us
learned Bayesian methods from the books &lt;a href="http://www.stat.columbia.edu/~gelman/book/"&gt;Bayesian Data
Analysis&lt;/a&gt; and &lt;a href="http://www.springer.com/us/book/9780387960982"&gt;Statistical
Decision Theory and Bayesian
Analysis&lt;/a&gt;), it should be clear
that if they take frequentist tests and p-values seriously in statistical
practice, they may actually be useful.&lt;/p&gt;
&lt;p&gt;So let's look again at our goodness-of-fit problem.&lt;/p&gt;
&lt;h2&gt;Simple Models (simple null model)&lt;/h2&gt;
&lt;p&gt;The p-value can provide a useful diagnostic of goodness of fit.
For the case of a simple model &lt;span class="math"&gt;\(P(X)\)&lt;/span&gt; with an observation &lt;span class="math"&gt;\(X \in \mathcal{X}\)&lt;/span&gt;
we can pick a test statistic &lt;span class="math"&gt;\(T: \mathcal{X} \to \mathbb{R}\)&lt;/span&gt; where high values
indicate unlikely outcomes, and then compute
&lt;/p&gt;
&lt;div class="math"&gt;$$p_{\textrm{classic}} = \textrm{Pr}_{X' \sim P}(T(X') \geq T(X)),$$&lt;/div&gt;
&lt;p&gt;
that is, the probability of observing a &lt;span class="math"&gt;\(T(X')\)&lt;/span&gt; greater than the actually
observed &lt;span class="math"&gt;\(T(X)\)&lt;/span&gt;, given the assumed model &lt;span class="math"&gt;\(P(X)\)&lt;/span&gt;.
This probability is the p-value and if the probability of observing a more
extreme test statistic is small we should righly be suspicious of the assumed
model.
The choice of test statistic &lt;span class="math"&gt;\(T\)&lt;/span&gt; is the only degree of freedom and has to be
made given the model.&lt;/p&gt;
&lt;p&gt;This is the classic p-value and its formal definition is completely
unambiguous.
One important observation is that if we assume the null hypothesis is true and
we treat the p-value as a random variable, then this random variable is
uniformly distributed, for any sample size.&lt;/p&gt;
&lt;h2&gt;Latent Variable Models (composite null model)&lt;/h2&gt;
&lt;p&gt;Now assume a slightly more general setting, where we have a model
&lt;span class="math"&gt;\(P(X|\theta)\)&lt;/span&gt;, and &lt;span class="math"&gt;\(\theta \in \Theta\)&lt;/span&gt; is some unknown parameter of the model
which is not observed.&lt;/p&gt;
&lt;p&gt;Because it is not observed, the above definition does not apply.
We could apply the definition only if we knew &lt;span class="math"&gt;\(\theta\)&lt;/span&gt;.
Classic methods assume that we have an estimator &lt;span class="math"&gt;\(\hat{\theta}\)&lt;/span&gt; so that we can
evaluate the p-value on &lt;span class="math"&gt;\(P(X|\hat{\theta})\)&lt;/span&gt;, fixing the parameter to a value
hopefully close to it's true value.
The key problem with this approach is that the p-value in general will no
longer be uniformly distributed.
This diminishes its value as a diagnostic for model misspecification.
(Another alternative is to take the supremum probability over all possible
parameters, again yielding a non-uniformly distributed p-value under the
null.)&lt;/p&gt;
&lt;p&gt;Bayesians to the rescue!  Twice!&lt;/p&gt;
&lt;p&gt;First, assume we would like to compute a p-value in the above setting.  What
would a Bayesian do?  Of course, he would integrate over the unknown
parameter, using a prior.
This yields the so called &lt;a href="http://projecteuclid.org/euclid.aos/1176325622"&gt;posterior predictive
p-value&lt;/a&gt; going back to
the &lt;a href="http://www.jstor.org/stable/2984569"&gt;work of Guttman&lt;/a&gt;.
Assuming a prior &lt;span class="math"&gt;\(P(\theta)\)&lt;/span&gt; we compute the &lt;em&gt;posterior predictive p-value&lt;/em&gt; as
&lt;/p&gt;
&lt;div class="math"&gt;$$p_{\textrm{post}} = \mathbb{E}_{\theta \sim P(\theta|X)}[
    \textrm{Pr}_{X' \sim P(X'|\theta)}(T(X') \geq T(X))],$$&lt;/div&gt;
&lt;p&gt;
where &lt;span class="math"&gt;\(P(\theta|X) \propto P(X|\theta) P(\theta)\)&lt;/span&gt; is the proper posterior.
The definition is simple: take the expectation of the ordinary p-value
weighted by the parameter posterior.
This definition is very general and typically easy to compute during posterior
inference, i.e. it is quite practical computationally.&lt;/p&gt;
&lt;p&gt;Unfortunately, it is also overly conservative, as explained in the JASA paper
&lt;a href="http://www.biostat.harvard.edu/robins/p-values.pdf"&gt;``Asymptotic Distribution of P Values in Composite Null
Models''&lt;/a&gt; by Robins, van
der Vaart, and Ventura from 2000.
Intuitively this is because the observed data &lt;span class="math"&gt;\(X\)&lt;/span&gt; is used twice, a violation
of the &lt;a href="https://projecteuclid.org/euclid.lnms/1215466210#toc"&gt;likelihood principle of Bayesian
statistics&lt;/a&gt;:
first it is used to obtain the posterior &lt;span class="math"&gt;\(P(\theta|X)\)&lt;/span&gt;, and then it is used
again to compute the p-value.&lt;/p&gt;
&lt;p&gt;Bayesians to the rescue again!
This time it is Susie Bayarri and Jim Berger, and in their JASA paper &lt;a href="http://amstat.tandfonline.com/doi/abs/10.1080/01621459.2000.10474309"&gt;P
values for Composite Null
Models&lt;/a&gt;
they introduce two alternative p-values which exactly "undo" the effect of
using the data twice by conditioning on the information already observed.
(I will not discuss the &lt;em&gt;U-conditional predictive p-value&lt;/em&gt; proposed by Bayarri
and Berger.)
Here is the basic idea: let &lt;span class="math"&gt;\(X\)&lt;/span&gt; be the observed data and &lt;span class="math"&gt;\(t=T(X)\)&lt;/span&gt; the test
statistic.  We then define the &lt;em&gt;partial posterior&lt;/em&gt;,
&lt;/p&gt;
&lt;div class="math"&gt;$$P(\theta|X \setminus t) \propto \frac{P(X|\theta) P(\theta)}{P(t|\theta)}.$$&lt;/div&gt;
&lt;p&gt;
To understand this definition remember that random variables are functions
from the sample space to another set.  Hence, conditioning on &lt;span class="math"&gt;\(t\)&lt;/span&gt; means that
we condition on the event &lt;span class="math"&gt;\(\{X' \in \mathcal{X} | T(X') = t\}\)&lt;/span&gt;.
The partial posterior predictive p-value is now defined as
&lt;/p&gt;
&lt;div class="math"&gt;$$p_{\textrm{ppost}} = \mathbb{E}_{\theta \sim P(\theta|X \setminus t)}[
    \textrm{Pr}_{X' \sim P(X'|\theta)}(T(X') \geq T(X))].$$&lt;/div&gt;
&lt;p&gt;
Bayarri and Berger, as well as Robins, van der Vaart, and Ventura analyze the
properties of this particular p-value and show that is asymptotically
uniformly distributed and thus is neither conservative nor anti-conservative.&lt;/p&gt;
&lt;p&gt;If you are a Bayesian and consider providing a general model-fit diagnostic in
the absence of a formal alternative hypothesis this partial posterior
predictive p-value is the method to use.&lt;/p&gt;
&lt;p&gt;However, there are two drawbacks I can see that have affected it's usefulness
for me:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;It is much harder to compute.  Whereas the posterior predictive p-value can
   be well approximated even with naive Monte Carlo as soon as normal
   posterior inference is achieved, this is not the case for the partial
   posterior predictive p-value.  The reason is that &lt;span class="math"&gt;\(P(t|\theta)\)&lt;/span&gt;, although
   typically an univariate density in the test statistic, is the integral over
   potentially complicated sets in &lt;span class="math"&gt;\(\mathcal{X}\)&lt;/span&gt;, that is
   &lt;span class="math"&gt;\(P(t|\theta) = \int_{\mathcal{X}} 1_{\{T(X)=t\}} P(X|\theta) \,\textrm{d}X\)&lt;/span&gt;.
   I have not seen generally applicable methods to compute
   &lt;span class="math"&gt;\(p_{\textrm{ppost}}\)&lt;/span&gt; efficiently so far.&lt;/li&gt;
&lt;li&gt;The nice results of Bayarri and Berger do not extend to so called
   &lt;em&gt;discrepancy statistics&lt;/em&gt; as proposed by Xiaoli Meng in his &lt;a href="http://projecteuclid.org/euclid.aos/1176325622"&gt;1994
   paper&lt;/a&gt;.  These more general
   test statistics include the parameter, i.e. we use &lt;span class="math"&gt;\(T(X,\theta)\)&lt;/span&gt; instead of
   just &lt;span class="math"&gt;\(T(X)\)&lt;/span&gt;.  Why is this useful?  For example, and I found this a very
   useful test statistic, you can directly use the likelihood of the model
   itself as a test statistic: &lt;span class="math"&gt;\(T(X,\theta) = -P(X|\theta)\)&lt;/span&gt;.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Enough thoughts, let's get our hands dirty with a simple experiment.&lt;/p&gt;
&lt;h2&gt;Experiment&lt;/h2&gt;
&lt;p&gt;We take a simple composite null setting as follows.  Our assumed model is
&lt;/p&gt;
&lt;div class="math"&gt;$$X_i \sim \mathcal{N}(\mu, \sigma^2),\qquad i=1,\dots,n.$$&lt;/div&gt;
&lt;p&gt;
We get to observe &lt;span class="math"&gt;\(X=(X_1,\dots,X_n)\)&lt;/span&gt; and know &lt;span class="math"&gt;\(\sigma\)&lt;/span&gt; but consider &lt;span class="math"&gt;\(\mu\)&lt;/span&gt;
unknown.&lt;/p&gt;
&lt;p&gt;After some observations we would like to assess whether our model is accurate
in light of the data.
To this end we would like to use the P-values described above.
We will need two ingredients: we need to define a test statistic and we need
to work out the posterior inference in our model.&lt;/p&gt;
&lt;p&gt;For the test statistic we actually use a generalized test statistic
(discrepancy variable in Meng's vocabulary) as
&lt;/p&gt;
&lt;div class="math"&gt;$$T(X,\mu) = - \prod_{i=1}^n p(X_i|\mu)
    = -\prod_{i=1}^n \mathcal{N}(X_i ; \mu, \sigma^2).$$&lt;/div&gt;
&lt;p&gt;For the posterior inference, as Bayesians we place a prior on &lt;span class="math"&gt;\(\mu\)&lt;/span&gt; and we
select
&lt;/p&gt;
&lt;div class="math"&gt;$$\mu \sim \mathcal{N}(\mu_0, \sigma_0).$$&lt;/div&gt;
&lt;p&gt;
The Bayesian analysis is particularly straightforward in this case, as this
&lt;a href="http://www.cs.ubc.ca/~murphyk/Papers/bayesGauss.pdf"&gt;note by Kevin Murphy&lt;/a&gt;
details.
In particular, after observing &lt;span class="math"&gt;\(n\)&lt;/span&gt; samples &lt;span class="math"&gt;\(X=(X_1,\dots,X_n)\)&lt;/span&gt; the posterior
on &lt;span class="math"&gt;\(\mu\)&lt;/span&gt; has a simple closed form as
&lt;/p&gt;
&lt;div class="math"&gt;$$p(\mu|X) = \mathcal{N}(\mu_n, \sigma^2_n),$$&lt;/div&gt;
&lt;p&gt;
with
&lt;/p&gt;
&lt;div class="math"&gt;$$\sigma^2_n = \frac{1}{\frac{n}{\sigma^2}+\frac{1}{\sigma^2_0}},$$&lt;/div&gt;
&lt;p&gt;
and
&lt;/p&gt;
&lt;div class="math"&gt;$$\mu_n = \sigma^2_n \left(\frac{\mu_0}{\sigma^2_0} +
    \frac{n \bar{x}}{\sigma^2}\right),$$&lt;/div&gt;
&lt;p&gt;
where &lt;span class="math"&gt;\(\bar{x} = \frac{1}{n} \sum_i X_i\)&lt;/span&gt; is the sample average.&lt;/p&gt;
&lt;p&gt;From this simple form of the posterior distribution we can derive the closed
form partial posterior &lt;span class="math"&gt;\(P(\mu|X\setminus t)\)&lt;/span&gt; as well (not shown here, but
essentially using known properties of the &lt;span class="math"&gt;\(\chi^2\)&lt;/span&gt; distribution).
Here is a picture of the posterior &lt;span class="math"&gt;\(P(\mu|X)\)&lt;/span&gt; and the partial posterior
&lt;span class="math"&gt;\(P(\mu | X \setminus t)\)&lt;/span&gt;, where the data &lt;span class="math"&gt;\(X\)&lt;/span&gt; actually
comes from the assumed model with true &lt;span class="math"&gt;\(\mu=4.5\)&lt;/span&gt; and &lt;span class="math"&gt;\(n=10\)&lt;/span&gt;.
Interestingly the partial posterior is more concentrated (which makes sense
from the theory derived in Robins et al.).&lt;/p&gt;
&lt;p&gt;&lt;img alt="Posterior and partial posterior in mu" src="https://www.nowozin.net/sebastian/blog/images/pvalue-posterior.svg"&gt;&lt;/p&gt;
&lt;p&gt;Let us generate data from the assumed prior and model and see how our p-values
behave.  Because the null model is then correct, we can hope that the
resulting p-values will be uniformly distributed.
Indeed, if they were perfectly uniformly distributed they would be proper
frequentist p-values.
Because of the paper of Robins et al. we know that they will only be
asymptotically uniformly distributed as &lt;span class="math"&gt;\(n \to \infty\)&lt;/span&gt;.  But here we are also
outside the theory because our test statistic &lt;span class="math"&gt;\(T(X,\mu)\)&lt;/span&gt; includes the unknown
parameter &lt;span class="math"&gt;\(\mu\)&lt;/span&gt;.
So, walking on thin theory, let's verify the distribution for &lt;span class="math"&gt;\(n=10\)&lt;/span&gt; by taking
a histogram over &lt;span class="math"&gt;\(10^6\)&lt;/span&gt; replicates.&lt;/p&gt;
&lt;p&gt;&lt;img alt="Distribution over P-values" src="https://www.nowozin.net/sebastian/blog/images/pvalue-histogram.svg"&gt;&lt;/p&gt;
&lt;p&gt;This looks good, and the partial posterior predictive p-value is more
uniformly distributed obtaining better frequentist properties, in line with
the claims in Bayarri and Berger and in Robins et al.&lt;/p&gt;
&lt;p&gt;Finally, let us check with data from a model that is different from the
assumed model.  Here I sample from &lt;span class="math"&gt;\(\mathcal{N}(\mu, s^2)\)&lt;/span&gt;, where &lt;span class="math"&gt;\(s \in
[0,2]\)&lt;/span&gt;.  For &lt;span class="math"&gt;\(s=1\)&lt;/span&gt; this is the assumed model, but ideally we can refute the
model for values that differ from one by detecting this deviation through a
p-value close to zero.
The plot below shows, for each &lt;span class="math"&gt;\(s\)&lt;/span&gt;, the average p-value over 1000 replicates.&lt;/p&gt;
&lt;p&gt;&lt;img alt="Deviation experiment" src="https://www.nowozin.net/sebastian/blog/images/pvalue-deviation-sensitivity.svg"&gt;&lt;/p&gt;
&lt;p&gt;Clearly for &lt;span class="math"&gt;\(s &amp;lt; 0.6\)&lt;/span&gt; or so we can reliably discover that our assumed model is
problematic.  Interestingly the partial posterior predictive p-value has
significantly more power, in line with the theory.&lt;/p&gt;
&lt;p&gt;For &lt;span class="math"&gt;\(s &amp;gt; 1\)&lt;/span&gt; however, our p-value goes to one!  How can this be?
Well, remember that the choice of test statistic determines which deviations
from our assumptions we can detect and that the p-value cannot verify the
correctness of our assumed model but instead may only provide one-sided
evidence against the model.
With our current test statistic clearly this significant deviation passes
undetected.
We could replace our test statistic using the negative of our current test
statistic and would be able detect the above deviation for &lt;span class="math"&gt;\(s &amp;gt; 1\)&lt;/span&gt;, but this
implicitly more or less starts the process of &lt;em&gt;thinking about alternative
models&lt;/em&gt;, a point Bruce Hill mentioned above.&lt;/p&gt;
&lt;p&gt;If we would like to consider alternative models we should ideally consider
them in a formal way, and as a result we would be better off using a fully
Bayesian approach over an enlarged model class.&lt;/p&gt;
&lt;script type="text/javascript"&gt;if (!document.getElementById('mathjaxscript_pelican_#%@#$@#')) {
    var align = "center",
        indent = "0em",
        linebreak = "false";

    if (false) {
        align = (screen.width &lt; 768) ? "left" : align;
        indent = (screen.width &lt; 768) ? "0em" : indent;
        linebreak = (screen.width &lt; 768) ? 'true' : linebreak;
    }

    var mathjaxscript = document.createElement('script');
    mathjaxscript.id = 'mathjaxscript_pelican_#%@#$@#';
    mathjaxscript.type = 'text/javascript';
    mathjaxscript.src = 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.3/latest.js?config=TeX-AMS-MML_HTMLorMML';

    var configscript = document.createElement('script');
    configscript.type = 'text/x-mathjax-config';
    configscript[(window.opera ? "innerHTML" : "text")] =
        "MathJax.Hub.Config({" +
        "    config: ['MMLorHTML.js']," +
        "    TeX: { extensions: ['AMSmath.js','AMSsymbols.js','noErrors.js','noUndefined.js'], equationNumbers: { autoNumber: 'none' } }," +
        "    jax: ['input/TeX','input/MathML','output/HTML-CSS']," +
        "    extensions: ['tex2jax.js','mml2jax.js','MathMenu.js','MathZoom.js']," +
        "    displayAlign: '"+ align +"'," +
        "    displayIndent: '"+ indent +"'," +
        "    showMathMenu: true," +
        "    messageStyle: 'normal'," +
        "    tex2jax: { " +
        "        inlineMath: [ ['\\\\(','\\\\)'] ], " +
        "        displayMath: [ ['$$','$$'] ]," +
        "        processEscapes: true," +
        "        preview: 'TeX'," +
        "    }, " +
        "    'HTML-CSS': { " +
        "        availableFonts: ['STIX', 'TeX']," +
        "        preferredFont: 'STIX'," +
        "        styles: { '.MathJax_Display, .MathJax .mo, .MathJax .mi, .MathJax .mn': {color: 'inherit ! important'} }," +
        "        linebreaks: { automatic: "+ linebreak +", width: '90% container' }," +
        "    }, " +
        "}); " +
        "if ('default' !== 'default') {" +
            "MathJax.Hub.Register.StartupHook('HTML-CSS Jax Ready',function () {" +
                "var VARIANT = MathJax.OutputJax['HTML-CSS'].FONTDATA.VARIANT;" +
                "VARIANT['normal'].fonts.unshift('MathJax_default');" +
                "VARIANT['bold'].fonts.unshift('MathJax_default-bold');" +
                "VARIANT['italic'].fonts.unshift('MathJax_default-italic');" +
                "VARIANT['-tex-mathit'].fonts.unshift('MathJax_default-italic');" +
            "});" +
            "MathJax.Hub.Register.StartupHook('SVG Jax Ready',function () {" +
                "var VARIANT = MathJax.OutputJax.SVG.FONTDATA.VARIANT;" +
                "VARIANT['normal'].fonts.unshift('MathJax_default');" +
                "VARIANT['bold'].fonts.unshift('MathJax_default-bold');" +
                "VARIANT['italic'].fonts.unshift('MathJax_default-italic');" +
                "VARIANT['-tex-mathit'].fonts.unshift('MathJax_default-italic');" +
            "});" +
        "}";

    (document.body || document.getElementsByTagName('head')[0]).appendChild(configscript);
    (document.body || document.getElementsByTagName('head')[0]).appendChild(mathjaxscript);
}
&lt;/script&gt;</content><category term="Machine Learning, Statistics"/></entry><entry><title>The Entropy of a Normal Distribution</title><link href="https://www.nowozin.net/sebastian/blog/the-entropy-of-a-normal-distribution.html" rel="alternate"/><published>2015-06-13T23:30:00+01:00</published><updated>2015-06-13T23:30:00+01:00</updated><author><name>Sebastian Nowozin</name></author><id>tag:www.nowozin.net,2015-06-13:/sebastian/blog/the-entropy-of-a-normal-distribution.html</id><summary type="html">&lt;p&gt;The &lt;a href="http://en.wikipedia.org/wiki/Multivariate_normal_distribution"&gt;multivariate normal
distribution&lt;/a&gt;
is one of the most important probability distributions for multivariate data.
In this post we will look at the entropy of this distribution and how to
estimate the entropy given an iid sample.&lt;/p&gt;
&lt;p&gt;For a multivariate normal distribution in &lt;span class="math"&gt;\(k\)&lt;/span&gt; dimensions in standard form with
mean …&lt;/p&gt;</summary><content type="html">&lt;p&gt;The &lt;a href="http://en.wikipedia.org/wiki/Multivariate_normal_distribution"&gt;multivariate normal
distribution&lt;/a&gt;
is one of the most important probability distributions for multivariate data.
In this post we will look at the entropy of this distribution and how to
estimate the entropy given an iid sample.&lt;/p&gt;
&lt;p&gt;For a multivariate normal distribution in &lt;span class="math"&gt;\(k\)&lt;/span&gt; dimensions in standard form with
mean vector &lt;span class="math"&gt;\(\mathbf{\mu} \in \mathbb{R}^k\)&lt;/span&gt; and covariance matrix
&lt;span class="math"&gt;\(\mathbf{\Sigma}\)&lt;/span&gt; we have the density function&lt;/p&gt;
&lt;div class="math"&gt;$$f(\mathbb{x};\mathbf{\mu},\mathbf{\Sigma}) =
    \frac{1}{\sqrt{(2\pi)^k |\mathbf{\Sigma}|}}
    \exp\left(-\frac{1}{2} (\mathbf{x}-\mathbf{\mu})^T
        \mathbf{\Sigma}^{-1} (\mathbf{x}-\mathbf{\mu})\right).$$&lt;/div&gt;
&lt;p&gt;For this density, the differential entropy takes the simple form&lt;/p&gt;
&lt;div class="math"&gt;\begin{equation}
H = \frac{k}{2} + \frac{k}{2} \log(2\pi)
    + \frac{1}{2} \log |\mathbf{\Sigma}|.\label{eqn:Hnormal}
\end{equation}&lt;/div&gt;
&lt;p&gt;In practice we are often provided with a sample&lt;/p&gt;
&lt;div class="math"&gt;$$\mathbf{x}_i \sim \mathcal{N}(\mathbf{\mu},\mathbf{\Sigma}),
    \quad i=1,\dots,n,$$&lt;/div&gt;
&lt;p&gt;without knowledge of &lt;span class="math"&gt;\(\mathbf{\mu}\)&lt;/span&gt; nor &lt;span class="math"&gt;\(\mathbf{\Sigma}\)&lt;/span&gt;.
We are then interested in estimating the entropy of the distribution from the
sample.&lt;/p&gt;
&lt;h2&gt;Plugin Estimator&lt;/h2&gt;
&lt;p&gt;The simplest method to estimate the entropy is to first estimate the mean as
the empirical mean,&lt;/p&gt;
&lt;div class="math"&gt;$$\hat{\mathbf{\mu}} =
    \frac{1}{n} \sum_{i=1}^n \mathbf{x}_i,$$&lt;/div&gt;
&lt;p&gt;and the sample covariance as&lt;/p&gt;
&lt;div class="math"&gt;$$\hat{\mathbf{\Sigma}} =
    \frac{1}{n-1} \sum_{i=1}^n (\mathbf{x}_i - \hat{\mathbf{\mu}})
        (\mathbf{x}_i - \hat{\mathbf{\mu}})^T.$$&lt;/div&gt;
&lt;p&gt;Given these two estimates we simply use equation &lt;span class="math"&gt;\((\ref{eqn:Hnormal})\)&lt;/span&gt; on
&lt;span class="math"&gt;\(\mathcal{N}(\hat{\mathbf{\mu}},\hat{\mathbf{\Sigma}})\)&lt;/span&gt;.  (We can also use
&lt;span class="math"&gt;\(\mathcal{N}(\mathbf{0},\hat{\mathbf{\Sigma}})\)&lt;/span&gt; instead as the entropy is
invariant under translation.)&lt;/p&gt;
&lt;p&gt;This is called a &lt;em&gt;plugin estimate&lt;/em&gt; because we first estimate parameters of a
distribution, then plug these into the analytic expression for the quantity of
interest.&lt;/p&gt;
&lt;p&gt;It turns out that the plugin estimator systematically underestimates the true
entropy and that one can use improved estimators.
This is not special and plugin estimates are often biased or otherwise
deficient.
In case of the problem of estimating the entropy of an unknown normal
distribution however, the known results are especially beautiful.
In particular,&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;there exist unbiased estimators,&lt;/li&gt;
&lt;li&gt;there exist an estimator that is a &lt;a href="http://en.wikipedia.org/wiki/Minimum-variance_unbiased_estimator"&gt;uniformly minimum variance unbiased
  estimator&lt;/a&gt;
  (within a restricted class, see below),&lt;/li&gt;
&lt;li&gt;this estimator is also a (generalized) Bayesian estimator under the
  squared-loss, with an improper prior distribution.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Hence, for this case, a single estimator is satisfactory from both a Bayesian
and frequentist viewpoint, and moreover it is easily computable.&lt;/p&gt;
&lt;p&gt;Great, we will look at this estimator, but first look at an earlier work that
studies a simpler case.&lt;/p&gt;
&lt;h2&gt;Ahmed and Gokhale, 1989&lt;/h2&gt;
&lt;p&gt;An optimal &lt;a href="http://en.wikipedia.org/wiki/Minimum-variance_unbiased_estimator"&gt;UMVUE
estimator&lt;/a&gt;
for the problem of a zero-mean Normal distribution
&lt;span class="math"&gt;\(\mathcal{N}(\mathbf{0},\Sigma)\)&lt;/span&gt; has been found by &lt;a href="http://ee364b.googlecode.com/svn-history/r24/trunk/references/00030996.pdf"&gt;(Ahmed and Gokhale,
1989)&lt;/a&gt;.
This is a restricted case: while the entropy does not depend on the mean of
the distribution, it does affect the estimation of the sample covariance
matrix.&lt;/p&gt;
&lt;p&gt;For a sample their estimator is&lt;/p&gt;
&lt;div class="math"&gt;$$\hat{H}_{\textrm{AG}} =
    \frac{k}{2} \log(e\pi)
    + \frac{1}{2} \log \left|\sum_{i=1}^n \mathbf{x}_i \mathbf{x}_i^T\right|
    - \frac{1}{2} \sum_{j=1}^d \psi\left(\frac{n+1-j}{2}\right),$$&lt;/div&gt;
&lt;p&gt;where &lt;span class="math"&gt;\(\psi\)&lt;/span&gt; is the &lt;a href="http://en.wikipedia.org/wiki/Digamma_function"&gt;digamma
function&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;If you know the mean of your distribution (so you can center your data to
ensure &lt;span class="math"&gt;\(\mu=0\)&lt;/span&gt;), this estimator provides a big improvement over the plugin
estimate.  Here is an example in mean squared error and bias, were &lt;span class="math"&gt;\(\Sigma
\sim \textrm{Wishart}(\nu,I_k)\)&lt;/span&gt; and &lt;span class="math"&gt;\(\mathbf{x}_i \sim
\mathcal{N}(\mathbf{0},\Sigma)\)&lt;/span&gt;, with &lt;span class="math"&gt;\(k=3\)&lt;/span&gt; and &lt;span class="math"&gt;\(n=20\)&lt;/span&gt;.
The plot below shows a Monte Carlo result with &lt;span class="math"&gt;\(80,000\)&lt;/span&gt; replicates.&lt;/p&gt;
&lt;p&gt;&lt;img alt="Ahmed and Gokhale estimator" src="https://www.nowozin.net/sebastian/blog/images/normal-entropy-ag.svg"&gt;&lt;/p&gt;
&lt;p&gt;As promised, we can observe a big improvement over the plugin estimate, and we
also see that the Ahmed Gokhale estimator is indeed unbiased.&lt;/p&gt;
&lt;p&gt;Here is a &lt;a href="http://julialang.org/"&gt;Julia&lt;/a&gt; implementation.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="k"&gt;function&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;entropy_ag&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;X&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="c"&gt;# X is a (k,n) matrix, samples in columns&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;k&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;size&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;X&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;size&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;X&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;C&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;zeros&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;k&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;k&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="n"&gt;C&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;+=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;X&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;X&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;&amp;#39;&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="k"&gt;end&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;H&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mf"&gt;0.5&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;k&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;1.0&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;pi&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mf"&gt;0.5&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;logdet&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;C&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="n"&gt;k&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="n"&gt;H&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;-=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mf"&gt;0.5&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;digamma&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;0.5&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="k"&gt;end&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;H&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Because the case of a known mean is maybe less interesting, we go
straight to the general case.&lt;/p&gt;
&lt;h2&gt;Misra, Singh, and Demchuk, 2005&lt;/h2&gt;
&lt;p&gt;In &lt;a href="http://www.sciencedirect.com/science/article/pii/S0047259X03001787"&gt;(Misra, Singh, and Demchuk,
2005)&lt;/a&gt;
(here is the
&lt;a href="http://www.researchgate.net/profile/Neeraj_Misra4/publication/23644689_Estimation_of_the_entropy_of_a_multivariate_normal_distribution/links/00b7d51df6ad392c72000000.pdf"&gt;PDF&lt;/a&gt;)
the authors do a thorough job of analyzing the general case.
Beside a detailed bias and risk analysis the paper proposes two estimators for
the general case:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;An UMVUE estimator in a restricted class of estimators, that is a slight
  variation of the Ahmed and Gokhale estimator;&lt;/li&gt;
&lt;li&gt;A shrinkage estimator in a larger class, which is proven to dominate the
  UMVUE estimator in the restricted class.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The authors are apparently unaware of the work of Ahmed and Gokhale.
For their UMVUE estimator &lt;span class="math"&gt;\(\hat{H}_{\textrm{MSD}}\)&lt;/span&gt; they use the matrix&lt;/p&gt;
&lt;div class="math"&gt;$$S = \sum_{i=1}^n (\mathbf{x}_i-\hat{\mu})(\mathbf{x}_i-\hat{\mu})^T$$&lt;/div&gt;
&lt;p&gt;and define&lt;/p&gt;
&lt;div class="math"&gt;\begin{equation}
\hat{H}_{\textrm{MSD}} =
    \frac{k}{2} \log(e\pi)
    + \frac{1}{2} \log |S|
    - \frac{1}{2} \sum_{j=1}^d \psi\left(\frac{n-j}{2}\right).
    \label{Hmsd}
\end{equation}&lt;/div&gt;
&lt;p&gt;Can you spot the difference to the Ahmed and Gokhale estimator?  There are
two: the matrix &lt;span class="math"&gt;\(S\)&lt;/span&gt; is centered using the &lt;em&gt;sample mean&lt;/em&gt; &lt;span class="math"&gt;\(\hat{\mu}\)&lt;/span&gt;, and, to
adjust for the use of the sample mean for centering, the argument to the
digamma function is shifted by &lt;span class="math"&gt;\(1/2\)&lt;/span&gt;.&lt;/p&gt;
&lt;p&gt;Here is a &lt;a href="http://julialang.org/"&gt;Julia&lt;/a&gt; implementation.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="k"&gt;function&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;entropy_msd&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;X&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="c"&gt;# X is a (k,n) matrix, samples in columns&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;k&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;size&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;X&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;size&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;X&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;Xbar&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;mean&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;X&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;Xs&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;sqrt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;Xbar&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;S&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;zeros&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;k&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;k&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="n"&gt;S&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;+=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;X&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;Xbar&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;X&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;Xbar&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;&amp;#39;&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="k"&gt;end&lt;/span&gt;

&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mf"&gt;0.5&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;k&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;1.0&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;pi&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mf"&gt;0.5&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;logdet&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;S&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="n"&gt;k&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;-=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mf"&gt;0.5&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;digamma&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;0.5&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="k"&gt;end&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;res&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;h3&gt;Outline of Derivation&lt;/h3&gt;
&lt;p&gt;The key result that is used for deriving both the MSD and the AG estimator is
a lemma due to &lt;a href="http://www.stat.illinois.edu/statnews/wijsman_memoriam.htm"&gt;Robert
Wijsman&lt;/a&gt; from 1957
(&lt;a href="http://projecteuclid.org/euclid.aoms/1177706969"&gt;PDF&lt;/a&gt;).&lt;/p&gt;
&lt;p&gt;Wijsman proved a result relating the determinants of two matrices:
the covariance matrix &lt;span class="math"&gt;\(\Sigma\)&lt;/span&gt; of a multivariate Normal distribution, and
the empirical outer product matrix &lt;span class="math"&gt;\(X X^T\)&lt;/span&gt; of a sample &lt;span class="math"&gt;\(X \in
\mathbb{R}^{n\times k}\)&lt;/span&gt; from that Normal.
In Lemma 3 of the above paper he showed&lt;/p&gt;
&lt;div class="math"&gt;$$\frac{|X X^T|}{|\Sigma|} = \prod_{i=1}^k \chi_{n-i+1}^2.$$&lt;/div&gt;
&lt;p&gt;By taking the logarithm of this equation we can relate the central quantity in
the differential entropy, namely &lt;span class="math"&gt;\(\log |\Sigma|\)&lt;/span&gt; to the log-determinant of the
sample outer product matrix.&lt;/p&gt;
&lt;p&gt;The sample outer product matrix of a zero-mean multivariate Normal sample with
&lt;span class="math"&gt;\(n \geq k\)&lt;/span&gt; is known to be distributed according to a Wishart distribution,
with many known analytic properties.
By using the known properties of the Wishart and &lt;span class="math"&gt;\(\chi^2\)&lt;/span&gt; distributions this
allows the derivation and proving unbiasedness of the AG and MSD estimators.&lt;/p&gt;
&lt;h3&gt;Generalized Bayes&lt;/h3&gt;
&lt;p&gt;Misra, Singh, and Demchuk also show that their MSD estimator is the mean of a
posterior that arises from a full Bayesian treatment with an improper prior.
This prior is shown to be, in (Theorem 2.3 in Misra et al., 2005),&lt;/p&gt;
&lt;div class="math"&gt;$$\pi(\mu,\Sigma) = \frac{1}{|\Sigma|^{(k+1)/2}}$$&lt;/div&gt;
&lt;p&gt;This is a most satisfying result: a frequentist-optimal estimator in large
class of possible estimators is shown to be also a Bayes estimator for a
suitable matching prior.&lt;/p&gt;
&lt;p&gt;Because the posterior is proper for &lt;span class="math"&gt;\(n \geq k\)&lt;/span&gt;, one could also use the
proposed prior to derive posterior credible regions for the entropy, and most
likely this is a good choice in that it could achieve good coverage
properties.&lt;/p&gt;
&lt;h2&gt;Brewster-Zidek estimator&lt;/h2&gt;
&lt;p&gt;Going even further, Misra and coauthors also show that while the MSD estimator
is optimal in the class of &lt;em&gt;affine-equivariant&lt;/em&gt; estimators, when one enlarges
the class of possible estimators there exist estimators which uniformly
dominate the MSD estimator by achieving a lower risk.&lt;/p&gt;
&lt;p&gt;They propose a shrinkage estimator, termed &lt;em&gt;Brewster-Zidek estimator&lt;/em&gt; which I
give here without further details.&lt;/p&gt;
&lt;div class="math"&gt;$$\hat{H}_{BZ} = \frac{k}{2} \log(2 e \pi)
    + \frac{1}{2} \log |S + YY^T| + \frac{1}{2}(\log T - d(T))$$&lt;/div&gt;
&lt;div class="math"&gt;$$d(r) = \frac{\int_r^1 t^{\frac{n-k}{2}-1} (1-t)^{\frac{k}{2}-1}
    \left[\log t + k \log 2 + \sum_{i=1}^k \psi\left(\frac{n-i+1}{2}\right)
        \right]
    \textrm{d}t}{\int_r^1 t^{\frac{n-k}{2}-1}(1-t)^{\frac{k}{2}-1}
    \textrm{d}t}$$&lt;/div&gt;
&lt;div class="math"&gt;$$T = |S| |S+YY^T|^{-1}$$&lt;/div&gt;
&lt;div class="math"&gt;$$Y = \sqrt{n} \hat{\mu}$$&lt;/div&gt;
&lt;p&gt;Here is a Julia implementation using numerical integration for evaluating
&lt;span class="math"&gt;\(d(r)\)&lt;/span&gt;.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="k"&gt;function&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;entropy_bz&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;X&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="c"&gt;# X is a (p,n) matrix, samples in columns&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;size&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;X&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;size&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;X&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;Bfun&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="o"&gt;^&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;^&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="k"&gt;function&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;Afun&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="n"&gt;p&lt;/span&gt;
&lt;span class="w"&gt;            &lt;/span&gt;&lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;+=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;digamma&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;0.5&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="k"&gt;end&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;Bfun&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="k"&gt;end&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;A&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="kt"&gt;Float64&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;quadgk&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Afun&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mf"&gt;1.0&lt;/span&gt;&lt;span class="p"&gt;)[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;B&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="kt"&gt;Float64&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;quadgk&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Bfun&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mf"&gt;1.0&lt;/span&gt;&lt;span class="p"&gt;)[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;d&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;A&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;B&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;Xbar&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;mean&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;X&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;Xs&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;sqrt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;Xbar&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;S&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;zeros&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="n"&gt;S&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;+=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;X&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;Xbar&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;X&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;Xbar&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;&amp;#39;&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="k"&gt;end&lt;/span&gt;

&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;T&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;det&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;S&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;det&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;S&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="n"&gt;Xs&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;Xs&lt;/span&gt;&lt;span class="o"&gt;&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;dBZ&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;logdet&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;S&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;Xs&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;Xs&lt;/span&gt;&lt;span class="o"&gt;&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;d&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;T&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;T&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="mf"&gt;0.5&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="n"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="nb"&gt;pi&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="n"&gt;dBZ&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;h2&gt;Shoot-out&lt;/h2&gt;
&lt;p&gt;Remember the zero-mean case?  Let us start with this case.
I use &lt;span class="math"&gt;\(k=3\)&lt;/span&gt; and &lt;span class="math"&gt;\(n=20\)&lt;/span&gt; as before, and &lt;span class="math"&gt;\(\Sigma \sim \textrm{Wishart}(\nu,I_k)\)&lt;/span&gt;.
Then samples are generated as
&lt;span class="math"&gt;\(\mathbf{x}_i \sim \mathcal{N}(\mathbf{0},\Sigma)\)&lt;/span&gt;.
All numbers are from &lt;span class="math"&gt;\(80,000\)&lt;/span&gt; replications of the full procedure.&lt;/p&gt;
&lt;p&gt;&lt;img alt="Four estimators" src="https://www.nowozin.net/sebastian/blog/images/normal-entropy-all-zeromean.svg"&gt;&lt;/p&gt;
&lt;p&gt;What you can see from the above plot is that the AG estimator which is UMVUE
for this special case dominates the MSD estimator.
Both unbiased estimators are indeed unbiased.
In terms of risk the Brewster-Zidek estimator is indistinguishable from the
MSD estimator.&lt;/p&gt;
&lt;p&gt;Now, what about &lt;span class="math"&gt;\(\mu \neq \mathbf{0}\)&lt;/span&gt;?
Here, for the simulation the setting is as before, but the mean is
&lt;span class="math"&gt;\(\mu \sim \mathcal{N}(\mathbf{0},2I)\)&lt;/span&gt;, so that samples are distributed as
&lt;span class="math"&gt;\(\mathbf{x}_i \sim \mathcal{N}(\mu,\Sigma)\)&lt;/span&gt;.&lt;/p&gt;
&lt;p&gt;&lt;img alt="Four estimators" src="https://www.nowozin.net/sebastian/blog/images/normal-entropy-all.svg"&gt;&lt;/p&gt;
&lt;p&gt;The result shows that the AG estimator becomes useless if its assumption is
violated, as is to be expected.  (Interestingly, if we were to try using the
scaled sample covariance matrix &lt;span class="math"&gt;\(n \hat{\Sigma}\)&lt;/span&gt; with the AG estimator it is
reasonable but biased, that is, it has lost its UMVUE property.)
The MSD estimator and the Brewster-Zidek estimators are virtually
indistinguishable and seem to be both unbiased in this case.&lt;/p&gt;
&lt;h2&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;Estimating the entropy of a multivariate Normal distribution from a sample has
a satisfying solution, the MSD estimator &lt;span class="math"&gt;\((\ref{Hmsd})\)&lt;/span&gt;, which can be robustly
used in all circumstances.  It is computationally efficient, and with
sufficient samples, &lt;span class="math"&gt;\(n \geq k\)&lt;/span&gt;, the Bayesian interpretation also provides a
proper posterior distribution over &lt;span class="math"&gt;\(\mu\)&lt;/span&gt; and &lt;span class="math"&gt;\(\Sigma\)&lt;/span&gt; which can be used to
derive a posterior distribution over the entropy.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Acknowledgements&lt;/em&gt;.  I thank
&lt;a href="http://ei.is.tuebingen.mpg.de/person/jpeters"&gt;Jonas Peters&lt;/a&gt; for reading a
draft version of the article and providing feedback.&lt;/p&gt;
&lt;script type="text/javascript"&gt;if (!document.getElementById('mathjaxscript_pelican_#%@#$@#')) {
    var align = "center",
        indent = "0em",
        linebreak = "false";

    if (false) {
        align = (screen.width &lt; 768) ? "left" : align;
        indent = (screen.width &lt; 768) ? "0em" : indent;
        linebreak = (screen.width &lt; 768) ? 'true' : linebreak;
    }

    var mathjaxscript = document.createElement('script');
    mathjaxscript.id = 'mathjaxscript_pelican_#%@#$@#';
    mathjaxscript.type = 'text/javascript';
    mathjaxscript.src = 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.3/latest.js?config=TeX-AMS-MML_HTMLorMML';

    var configscript = document.createElement('script');
    configscript.type = 'text/x-mathjax-config';
    configscript[(window.opera ? "innerHTML" : "text")] =
        "MathJax.Hub.Config({" +
        "    config: ['MMLorHTML.js']," +
        "    TeX: { extensions: ['AMSmath.js','AMSsymbols.js','noErrors.js','noUndefined.js'], equationNumbers: { autoNumber: 'none' } }," +
        "    jax: ['input/TeX','input/MathML','output/HTML-CSS']," +
        "    extensions: ['tex2jax.js','mml2jax.js','MathMenu.js','MathZoom.js']," +
        "    displayAlign: '"+ align +"'," +
        "    displayIndent: '"+ indent +"'," +
        "    showMathMenu: true," +
        "    messageStyle: 'normal'," +
        "    tex2jax: { " +
        "        inlineMath: [ ['\\\\(','\\\\)'] ], " +
        "        displayMath: [ ['$$','$$'] ]," +
        "        processEscapes: true," +
        "        preview: 'TeX'," +
        "    }, " +
        "    'HTML-CSS': { " +
        "        availableFonts: ['STIX', 'TeX']," +
        "        preferredFont: 'STIX'," +
        "        styles: { '.MathJax_Display, .MathJax .mo, .MathJax .mi, .MathJax .mn': {color: 'inherit ! important'} }," +
        "        linebreaks: { automatic: "+ linebreak +", width: '90% container' }," +
        "    }, " +
        "}); " +
        "if ('default' !== 'default') {" +
            "MathJax.Hub.Register.StartupHook('HTML-CSS Jax Ready',function () {" +
                "var VARIANT = MathJax.OutputJax['HTML-CSS'].FONTDATA.VARIANT;" +
                "VARIANT['normal'].fonts.unshift('MathJax_default');" +
                "VARIANT['bold'].fonts.unshift('MathJax_default-bold');" +
                "VARIANT['italic'].fonts.unshift('MathJax_default-italic');" +
                "VARIANT['-tex-mathit'].fonts.unshift('MathJax_default-italic');" +
            "});" +
            "MathJax.Hub.Register.StartupHook('SVG Jax Ready',function () {" +
                "var VARIANT = MathJax.OutputJax.SVG.FONTDATA.VARIANT;" +
                "VARIANT['normal'].fonts.unshift('MathJax_default');" +
                "VARIANT['bold'].fonts.unshift('MathJax_default-bold');" +
                "VARIANT['italic'].fonts.unshift('MathJax_default-italic');" +
                "VARIANT['-tex-mathit'].fonts.unshift('MathJax_default-italic');" +
            "});" +
        "}";

    (document.body || document.getElementsByTagName('head')[0]).appendChild(configscript);
    (document.body || document.getElementsByTagName('head')[0]).appendChild(mathjaxscript);
}
&lt;/script&gt;</content><category term="Statistics"/></entry><entry><title>A quick summary of CVPR 2015</title><link href="https://www.nowozin.net/sebastian/blog/a-quick-summary-of-cvpr-2015.html" rel="alternate"/><published>2015-06-11T22:00:00+01:00</published><updated>2015-06-11T22:00:00+01:00</updated><author><name>Sebastian Nowozin</name></author><id>tag:www.nowozin.net,2015-06-11:/sebastian/blog/a-quick-summary-of-cvpr-2015.html</id><summary type="html">&lt;p&gt;&lt;a href="http://www.pamitc.org/cvpr15/"&gt;CVPR 2015&lt;/a&gt;, "Computer Vision and Pattern
Recognition" is the main conference of the computer vision community and just
finished.
I unfortunately was only able to stay for the three main conference days, but
here is my short subjective summary.&lt;/p&gt;
&lt;p&gt;For an overview of individual research papers, see &lt;a href="http://cs.stanford.edu/people/karpathy/cvpr2015papers/"&gt;this excellent summary …&lt;/a&gt;&lt;/p&gt;</summary><content type="html">&lt;p&gt;&lt;a href="http://www.pamitc.org/cvpr15/"&gt;CVPR 2015&lt;/a&gt;, "Computer Vision and Pattern
Recognition" is the main conference of the computer vision community and just
finished.
I unfortunately was only able to stay for the three main conference days, but
here is my short subjective summary.&lt;/p&gt;
&lt;p&gt;For an overview of individual research papers, see &lt;a href="http://cs.stanford.edu/people/karpathy/cvpr2015papers/"&gt;this excellent summary
page&lt;/a&gt; by &lt;a href="http://cs.stanford.edu/people/karpathy/"&gt;Andrej
Karpathy&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;From the papers I have seen at the conference my personal favorite is Barron
et al., "Fast Bilateral-Space Stereo for Synthetic Defocus",
&lt;a href="http://www.cv-foundation.org/openaccess/content_cvpr_2015/papers/Barron_Fast_Bilateral-Space_Stereo_2015_CVPR_paper.pdf"&gt;PDF here&lt;/a&gt;.
I liked it for a number of reasons.  First, this research is already
successfully productized in a high-profile product and the presentation of the
work was excellent.  Second, the flavour of this work is to take a data
structure (the permutohedral lattice) which has been used for one problem
successfully (bilateral filtering), and use it to solve a more difficult
problem (disparity from stereo) within the domain of the data structure.  This
general idea may be useful in other contexts.  To admit the truth, I never
liked pixels as a representation of image data, and many statistical models
are just awkward to specify on the pixel level; for this reason we as a
community often use higher representations such as superpixels or region
proposals.  This paper provides an alternative method on how a regular
representation that is more aligned with the semantic content of the image
could be used to solve problems in such a way that one can reconstruct a
solution on the pixel level.&lt;/p&gt;
&lt;h2&gt;Research Trends&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Deep Learning and Convolutional Neural Networks&lt;/strong&gt;.  Since the seminal ECCV
  2012 workshop presentation by &lt;a href="http://www.cs.toronto.edu/~kriz/"&gt;Alex
  Krizhevsky&lt;/a&gt; that announced the ImageNet
  results and was &lt;a href="http://books.nips.cc/papers/files/nips25/NIPS2012_0534.pdf"&gt;published as a NIPS paper the same
  year&lt;/a&gt; the
  computer vision community has rapidly adopted convolutional networks and
  some of the largest vision labs developed toolkits that democratized this
  technology, such as &lt;a href="http://caffe.berkeleyvision.org/"&gt;Caffe&lt;/a&gt;, and existing
  toolkits such as &lt;a href="http://torch.ch/"&gt;Torch&lt;/a&gt;, and
  &lt;a href="http://deeplearning.net/software/theano/"&gt;Theano&lt;/a&gt; are also used.
  In effect, I estimate that around 30 percent of all papers used
  convolutional networks or features derived from them in their work, often
  substantially increasing predictive performance on the given task.
  Significant research directions remain open to everyone, but it is fair to
  say that standard convnets are now a mature vision technology regularly used
  by large parts of the community.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Rich Linguistic Outputs&lt;/strong&gt;.  Automatic image captioning is now feasible.
  There is an &lt;a href="https://pdollar.wordpress.com/2015/01/21/image-captioning/"&gt;excellent
  summary&lt;/a&gt; of the
  may works at &lt;a href="https://pdollar.wordpress.com"&gt;Piotr Dollar's blog&lt;/a&gt; and also
  in another &lt;a href="http://blogs.technet.com/b/machinelearning/archive/2014/11/18/rapid-progress-in-automatic-image-captioning.aspx"&gt;summary by John
  Platt&lt;/a&gt;.
  Many of these works are enabled by the recent
  &lt;a href="http://mscoco.org/"&gt;Microsoft COCO dataset&lt;/a&gt; and by &lt;a href="http://karpathy.github.io/2015/05/21/rnn-effectiveness/"&gt;recurrent neural
  networks&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;Non-Research Trends and the IEEE Controversy&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Growth in attendance&lt;/strong&gt;.  Attendance was at more than 2,400 persons,
  continuing the rapid growth of the computer vision community.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;More code published&lt;/strong&gt;.  On almost every second poster there was a
  &lt;a href="http://github.com/"&gt;github&lt;/a&gt; URL and the licenses are generally very liberal
  (MIT, BSD, etc.) so as to permit wide distribution; this is great as it
  further accelerates the speed at which efforts can be redirected towards
  promising approaches.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;IEEE splits from CVPR&lt;/strong&gt;.  The conference has always been organized in part
  by &lt;a href="http://www.ieee.org/"&gt;IEEE&lt;/a&gt; in various capacities as an insurer,
  organizer, and publisher.  However, with traditional publishing models being
  obsoleted, and with examples of independent conferences and journals in the
  machine learning community (&lt;a href="http://nips.cc/"&gt;NIPS&lt;/a&gt;,
  &lt;a href="http://icml.cc/"&gt;ICML&lt;/a&gt;, and &lt;a href="http://jmlr.org/"&gt;JMLR&lt;/a&gt;), and considering that
  CVPR as one of the premier conferences in all of computer science, the power
  balance has shifted away from IEEE towards the computer vision community; as
  a result, over the last few years the ties with IEEE have been weakened and
  now seem to be lost.  To be fair, following CVPR 2011, IEEE has moved and
  negotiated a fairer deal, with CVPR papers made available
  &lt;a href="http://www.cv-foundation.org/openaccess/"&gt;open-access&lt;/a&gt; since
  CVPR 2013, and allowing co-sponsoring arrangements with the
  &lt;a href="http://www.cv-foundation.org/"&gt;Computer Vision Foundation&lt;/a&gt;.
  But now, after threats made by IEEE, it has been voted at the PAMI-TC
  meeting that future CVPR conferences (starting with CVPR 2016) that the
  computer vision foundation will take over the functions previously carried
  out by the IEEE.  More details will be announced shortly, I am sure.
  Whether this has any repercussions for the
  &lt;a href="http://www.computer.org/web/tpami"&gt;TPAMI journal&lt;/a&gt; is unclear at the current
  point, but before making threats and actions that would serve as a catalyst
  for community action, IEEE would be wise to consider what has happened to Springer's
  &lt;em&gt;Machine Learning&lt;/em&gt; journal in 2001 and the events that led to the founding
  of the &lt;a href="http://en.wikipedia.org/wiki/Journal_of_Machine_Learning_Research"&gt;&lt;em&gt;Journal of Machine Learning
  Research&lt;/em&gt;&lt;/a&gt;,
  a &lt;a href="http://blogs.law.harvard.edu/pamphlet/2012/03/06/an-efficient-journal/"&gt;very successful
  experiment&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;</content><category term="Computer Vision, Conferences"/></entry><entry><title>Demosaicing</title><link href="https://www.nowozin.net/sebastian/blog/demosaicing.html" rel="alternate"/><published>2015-05-29T23:00:00+01:00</published><updated>2015-05-29T23:00:00+01:00</updated><author><name>Sebastian Nowozin</name></author><id>tag:www.nowozin.net,2015-05-29:/sebastian/blog/demosaicing.html</id><summary type="html">&lt;p&gt;This article describes the basic problem of image demosaicing and a recent work
of mine providing a research dataset for demosaicing research.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://en.wikipedia.org/wiki/Demosaicing"&gt;Image demosaicing&lt;/a&gt; is a procedure
used in almost all digital cameras.
From your smartphone camera to the top-of-the-line digital SLR cameras, they
all use a demosaicing algorithm to …&lt;/p&gt;</summary><content type="html">&lt;p&gt;This article describes the basic problem of image demosaicing and a recent work
of mine providing a research dataset for demosaicing research.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://en.wikipedia.org/wiki/Demosaicing"&gt;Image demosaicing&lt;/a&gt; is a procedure
used in almost all digital cameras.
From your smartphone camera to the top-of-the-line digital SLR cameras, they
all use a demosaicing algorithm to convert the captured sensor information into
a color image.
So what is this algorithm doing and why is it needed?&lt;/p&gt;
&lt;h2&gt;Why do we need Demosaicing?&lt;/h2&gt;
&lt;p&gt;Modern imaging sensors are based on semiconductors which have a large number of
photo-sensitive sensor elements, called &lt;em&gt;sensels&lt;/em&gt;.
When a quantum of light hits a sensel it creates an electric charge.
The amount of the charge created depends on the energy of the photon which
depends on the wavelength of the incident light.
Unfortunately, in current imaging sensors, once the electric charge is created
it is no longer possible to deduce the color of the light.
(The exception is the &lt;a href="http://www.foveon.com/"&gt;Foveon sensor&lt;/a&gt; which uses a
layered silicon design in which photons of higher energy levels (green and
blue) penetrate into lower silicon layers than photons of lower energy levels
(red)).&lt;/p&gt;
&lt;p&gt;To produce color images current sensors therefore do not record all wavelengths
equally at each sensor element.
Instead, each element has it's own color filter.
A typical modern sensor uses three distinct filter types, each most sensitive
to a particular range of wavelengths.
The three types are abbreviated red (R), green (G), and blue (B), although in
reality they are remain sensitive to all wavelengths.
For a detailed plot of the wavelength sensitivities, &lt;a href="http://www.dxomark.com/About/In-depth-measurements/Measurements/Color-sensitivity"&gt;this
page&lt;/a&gt;
has a nice graph.&lt;/p&gt;
&lt;p&gt;Each sensor element therefore records only one measurement: the charge related
to a certain range of wavelengths.
It does not record the full color information.
To reproduce an image suitable for human consumption we require three
measurements, such as red/green/blue values.  (This is a simplification, and in
real systems the concept of a color space is used; a camera records in a
camera-specific color space which is then transformed into a perceptual color
space such as Adobe sRGB.)&lt;/p&gt;
&lt;p&gt;The most popular arrangement of color filters is the so called Bayer filter
and has a layout as shown below.&lt;/p&gt;
&lt;p&gt;&lt;img alt="Bayer RGGB color filter array" src="https://www.nowozin.net/sebastian/blog/images/demosaicing-bayer.png"&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Image demosaicing&lt;/em&gt; is the process of recovering the missing colors at each
sensor element.
For example, in the top left sensel of the above figure only the blue response
is measured and we need to recover the value of the green and red responses at
this spatial location.&lt;/p&gt;
&lt;p&gt;In principle, why should this even be possible?
Because images of the natural world are slowly changing across the sensor,
we can use color information from adjacent sensels (but different filter types)
to provide the missing information.&lt;/p&gt;
&lt;h2&gt;Challenges for Demosaicing Algorithms&lt;/h2&gt;
&lt;p&gt;The above description is correct in that all demosaicing algorithms use
correlations among spatially close sensels to restore the missing information.
However, there are around three dozen publically available demosaicing
algorithms and probably many more proprietary ones.
Beside differences in resource requirements and complexity, these algorithms
also differ widely in their demosaicing performance.&lt;/p&gt;
&lt;p&gt;Without considering implementation concerns for a moment, what makes a good
demosaicing algorithm?
A good demosaicing method has the following desirable properties:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Visually pleasing demosaiced output images;&lt;/li&gt;
&lt;li&gt;No visible high-frequency artifacts (&lt;em&gt;zippering&lt;/em&gt;), no visible color artifacts;&lt;/li&gt;
&lt;li&gt;Robustness to noise present in the input;&lt;/li&gt;
&lt;li&gt;Applicable to different color filter array layouts (not just &lt;a href="http://en.wikipedia.org/wiki/Bayer_filter"&gt;Bayer&lt;/a&gt;);&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;To achieve this, a demosaicing algorithm has to be highly adapted to the
statistics of natural images.
That is, it has to have an understanding of typical image components such as
textures, edges, smooth surfaces, etcetera.&lt;/p&gt;
&lt;h2&gt;Research Dataset&lt;/h2&gt;
&lt;p&gt;One approach to image demosaicing is to treat it is a statistical regression
problem.
By learning about natural image statistics from ground truth data, one should
be able -- given sufficient data -- to approach the optimal demosaicing
performance possible.&lt;/p&gt;
&lt;p&gt;The problem is, perhaps surprisingly, that there are no suitable datasets.
Current comparisons of demosaicing algorithms in the literature resort to two
approaches to provide results for their algorithms:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Use a small set of Kodak images that were scanned onto Photo-CD's (remember
those?) in the mid-1990'ies from analogue films.  To me it is unclear whether
this scanning involved demosaicing, and whether the properties of the analogue
films are an adequate proxy for digital imaging sensors.&lt;/li&gt;
&lt;li&gt;Download sRGB images from the Internet and remove color channels to obtain a
mosaiced image.  But all these images have been demosaiced already, so we
merely measure the closeness of one demosaicing algorithm to another one.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;This is appalling on the one hand, but it is certainly challenging to improve
on it, if only for the reason that currently no sensor can capture ground truth
easily.
There have been ideas to obtain ground truth using a Foveon sensor or by using
a global switchable color filter and multiple captures.
The first idea (using a Foveon camera) sounds feasible but the noise and
sensitivity characteristics of a Foveon sensor are quite different from popular
CFA-CMOS sensors.
The second idea sounds ideal but would only work in a static lab setup.&lt;/p&gt;
&lt;p&gt;We introduce the &lt;a href="http://research.microsoft.com/en-us/um/cambridge/projects/msrdemosaic/"&gt;Microsoft Research Demosaicing
Dataset&lt;/a&gt;,
our attempt at providing a suitable dataset.
Our dataset is described in detail in an &lt;a href="http://www.nowozin.net/sebastian/papers/khashabi2014demosaicing.pdf"&gt;IEEE TIP
paper&lt;/a&gt;.
The dataset contains 500 images captured by ourselves containing both indoor
and outdoor imagery.  Here are some example images.&lt;/p&gt;
&lt;p&gt;&lt;img alt="MSR Demosaicing dataset example images" src="https://www.nowozin.net/sebastian/blog/images/msr-demosaicing-images.jpg"&gt;&lt;/p&gt;
&lt;p&gt;How did we overcome the problem of creating suitable ground truth images?
The basic idea is as follows: it is difficult to capture ground truth for
demosaicing for a full image sensor, but if we group multiple sensels into one
virtual sensel then we can interpret this group as possessing all necessary
color information.
That is, we simultaneously reduce the image resolution and perform demosaicing.
There are multiple proposals in the paper how to do this technically in a
sound manner, but to see it visually, here is an example of downsampling using
3-by-3 sensel blocks on a Bayer filter.&lt;/p&gt;
&lt;p&gt;&lt;img alt="Bayer RGGB 3-by-3 downsampling" src="https://www.nowozin.net/sebastian/blog/images/demosaicing-oddblock.png"&gt;&lt;/p&gt;
&lt;p&gt;As you can see, within each 3-by-3 sensel block we may have an unequal number
of measurements of each color, but the spatial distribution of sensels of
different types is uniform in the sense that their center of gravity is the
center of the 3-by-3 block.
This is not the case in general, for example when averaging 4-by-4 blocks of
Bayer measurements, then the red channels will have a higher density in the
upper left corner of each block.&lt;/p&gt;
&lt;h2&gt;Algorithm Comparison&lt;/h2&gt;
&lt;p&gt;So how do common algorithms (and our novel algorithm) fare on our benchmark
data set?
Performance is typically measured as a function of the mean-squared-error of
the predicted image intensities.  The most common measurement is the &lt;a href="http://en.wikipedia.org/wiki/Peak_signal-to-noise_ratio"&gt;peak
signal to noise
ratio&lt;/a&gt; measured in
decibels (dB), where higher is better.
We also report another performance measure based on a perceptual similarity
metric, the structural similarity index (SSIM) which measures mean and
variance statistics in image blocks, and again a higher score means a better
demosaiced image.&lt;/p&gt;
&lt;p&gt;The top algorithms achieve the following performance.  I also include bilinear
interpolation as a baseline method.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th style="text-align: left;"&gt;Method&lt;/th&gt;
&lt;th style="text-align: center;"&gt;PSNR (dB)&lt;/th&gt;
&lt;th style="text-align: center;"&gt;SSIM&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td style="text-align: left;"&gt;Bilinear interpolation&lt;/td&gt;
&lt;td style="text-align: center;"&gt;30.86&lt;/td&gt;
&lt;td style="text-align: center;"&gt;0.882&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td style="text-align: left;"&gt;Non-Local means&lt;/td&gt;
&lt;td style="text-align: center;"&gt;38.42&lt;/td&gt;
&lt;td style="text-align: center;"&gt;0.978&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td style="text-align: left;"&gt;Contour stencils&lt;/td&gt;
&lt;td style="text-align: center;"&gt;&lt;strong&gt;39.41&lt;/strong&gt;&lt;/td&gt;
&lt;td style="text-align: center;"&gt;&lt;strong&gt;0.980&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td style="text-align: left;"&gt;RTF (our method)&lt;/td&gt;
&lt;td style="text-align: center;"&gt;39.39&lt;/td&gt;
&lt;td style="text-align: center;"&gt;&lt;strong&gt;0.980&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;Hence we achieve a result comparable to the state of the art.
The experiments become interesting when we perform simultaneous denoising and
demosaicing.
Performing both operations simultaneously is desirable in a real imaging
pipeline because both they happen at the same stage in the processing.
For the task of simultaneous denoising and demosaicing the results tell a
different story.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th style="text-align: left;"&gt;Method&lt;/th&gt;
&lt;th style="text-align: center;"&gt;PSNR (dB)&lt;/th&gt;
&lt;th style="text-align: center;"&gt;SSIM&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td style="text-align: left;"&gt;Bilinear interpolation&lt;/td&gt;
&lt;td style="text-align: center;"&gt;30.40&lt;/td&gt;
&lt;td style="text-align: center;"&gt;0.859&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td style="text-align: left;"&gt;Non-Local means&lt;/td&gt;
&lt;td style="text-align: center;"&gt;36.46&lt;/td&gt;
&lt;td style="text-align: center;"&gt;0.949&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td style="text-align: left;"&gt;Contour stencils&lt;/td&gt;
&lt;td style="text-align: center;"&gt;37.17&lt;/td&gt;
&lt;td style="text-align: center;"&gt;0.953&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td style="text-align: left;"&gt;RTF (our method)&lt;/td&gt;
&lt;td style="text-align: center;"&gt;&lt;strong&gt;37.78&lt;/strong&gt;&lt;/td&gt;
&lt;td style="text-align: center;"&gt;&lt;strong&gt;0.961&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;In the paper we compare more than a dozen methods.
The proposed method achieves an improved demosaicing performance of over 0.5dB
in realistic conditions which is visually significant.
Our method is based on the non-parametric &lt;a href="http://www.nowozin.net/sebastian/papers/jancsary2012rtf.pdf"&gt;regression tree field model
(RTF)&lt;/a&gt;
which we have published earlier; essentially this is a Gaussian conditional
random field (CRF) with very rich potential functions defined by regression
trees.  Due to its high capacity it can learn a lot about image statistics
relevant to demosaicing.&lt;/p&gt;
&lt;p&gt;The next best method is the &lt;a href="http://www.ipol.im/pub/art/2012/g-dwcs/"&gt;contour stencils method of
Getreuer&lt;/a&gt;.
This method performs smoothing and completion of values along a graph defined
on the sensor positions.  While the method works well it is manually defined
for the Bayer pattern and may not be easily generalized to arbitrary color
filter arrays.&lt;/p&gt;
&lt;h2&gt;Outlook&lt;/h2&gt;
&lt;p&gt;Demosaicing for the Bayer layout is largely solved, but for novel color filter
array layouts there currently is no all-around best method.  While our
machine learning approach is feasible and leads to high quality demosaicing
results, the current loss functions used (such as peak signal to noise ratio
(PSNR) and structural similarity (SSIM)) are not sufficiently aligned with
human perception to accurately measure image quality, in particular for
zippering artifacts along edge structures.
Whatever demosaicing method is adopted, it is beneficial to simultaneously
perform demosaicing and denoising, because either task becomes more difficult
if performed in isolation.&lt;/p&gt;</content><category term="Image Processing, Digital Cameras"/></entry><entry><title>Becoming a Bayesian, Part 3</title><link href="https://www.nowozin.net/sebastian/blog/becoming-a-bayesian-part-3.html" rel="alternate"/><published>2015-05-15T21:00:00+01:00</published><updated>2015-05-15T21:00:00+01:00</updated><author><name>Sebastian Nowozin</name></author><id>tag:www.nowozin.net,2015-05-15:/sebastian/blog/becoming-a-bayesian-part-3.html</id><summary type="html">&lt;p&gt;This post continues the previous post, &lt;a href="https://www.nowozin.net/sebastian/blog/becoming-a-bayesian-part-1.html"&gt;part 1&lt;/a&gt; and
&lt;a href="https://www.nowozin.net/sebastian/blog/becoming-a-bayesian-part-2.html"&gt;part 2&lt;/a&gt;,
outlining my criticism towards a ''naive'' subjective Bayesian viewpoint:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;a href="https://www.nowozin.net/sebastian/blog/becoming-a-bayesian-part-1.html"&gt;The consequences of model misspecification&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.nowozin.net/sebastian/blog/becoming-a-bayesian-part-2.html"&gt;The ''model first computation last'' approach&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Denial of methods of classical statistics, in this post.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;Denial of the Value of Classical Statistics&lt;/h2&gt;
&lt;p&gt;Suppose for the …&lt;/p&gt;</summary><content type="html">&lt;p&gt;This post continues the previous post, &lt;a href="https://www.nowozin.net/sebastian/blog/becoming-a-bayesian-part-1.html"&gt;part 1&lt;/a&gt; and
&lt;a href="https://www.nowozin.net/sebastian/blog/becoming-a-bayesian-part-2.html"&gt;part 2&lt;/a&gt;,
outlining my criticism towards a ''naive'' subjective Bayesian viewpoint:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;a href="https://www.nowozin.net/sebastian/blog/becoming-a-bayesian-part-1.html"&gt;The consequences of model misspecification&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.nowozin.net/sebastian/blog/becoming-a-bayesian-part-2.html"&gt;The ''model first computation last'' approach&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Denial of methods of classical statistics, in this post.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;Denial of the Value of Classical Statistics&lt;/h2&gt;
&lt;p&gt;Suppose for the sake of a simple example that our task is to estimate the
unknown mean &lt;span class="math"&gt;\(\mu\)&lt;/span&gt; of an unknown probability distribution &lt;span class="math"&gt;\(P\)&lt;/span&gt; with bounded
support over the real line.
To this end we receive a sequence of &lt;span class="math"&gt;\(n\)&lt;/span&gt; iid samples
&lt;span class="math"&gt;\(X_1\)&lt;/span&gt;, &lt;span class="math"&gt;\(X_2\)&lt;/span&gt;, &lt;span class="math"&gt;\(\dots\)&lt;/span&gt;, &lt;span class="math"&gt;\(X_n\)&lt;/span&gt;.&lt;/p&gt;
&lt;p&gt;Now suppose that &lt;em&gt;after&lt;/em&gt; receiving these &lt;span class="math"&gt;\(n\)&lt;/span&gt; samples I do not use the obvious
sample mean estimator but I take only the first sample &lt;span class="math"&gt;\(X_1\)&lt;/span&gt; and estimate
&lt;span class="math"&gt;\(\hat{\mu} = X_1\)&lt;/span&gt;.
Is this a good estimator?
Intuition tells us that it is not, because it ignores part of the useful input
data, namely &lt;span class="math"&gt;\(X_i\)&lt;/span&gt; for any &lt;span class="math"&gt;\(i &amp;gt; 1\)&lt;/span&gt;, but how can we formally analyze this?&lt;/p&gt;
&lt;p&gt;From a subjective Bayesian viewpoint the &lt;a href="http://projecteuclid.org/download/pdf_1/euclid.lnms/1215466214"&gt;likelihood
principle&lt;/a&gt;
does not permit us to ignore evidence which is already available.
If we posit a model &lt;span class="math"&gt;\(P(X_i|\theta)\)&lt;/span&gt; and a prior &lt;span class="math"&gt;\(P(\theta)\)&lt;/span&gt; we have to work
with the posterior
    &lt;/p&gt;
&lt;div class="math"&gt;$$P(\theta | X_1,\dots,X_n) \propto
        \prod_{i=1,\dots,n} P(X_i|\theta) P(\theta).$$&lt;/div&gt;
&lt;p&gt;
Therefore our estimator &lt;span class="math"&gt;\(\hat{\mu}=X_1\)&lt;/span&gt; cannot correspond to a Bayesian
posterior mean of any non-trivial model for all parameters.
This is of course a very strict viewpoint and one may object that we
&lt;em&gt;can&lt;/em&gt; talk about properties of the sequence of posteriors &lt;span class="math"&gt;\(P(\theta | X_1)\)&lt;/span&gt;,
&lt;span class="math"&gt;\(P(\theta | X_1, X_2)\)&lt;/span&gt;, etc.
But even in this generous view, &lt;em&gt;after&lt;/em&gt; observing all samples we are not
permitted to ignore part of them.  (If you are still not convinced, consider
the estimator defined by &lt;span class="math"&gt;\(\hat{\mu} = X_2\)&lt;/span&gt; if &lt;span class="math"&gt;\(X_1 &amp;gt; 0\)&lt;/span&gt;, and &lt;span class="math"&gt;\(\hat{\mu} = X_3\)&lt;/span&gt;
otherwise.)
So Bayesian statistics does not offer us a method to analyze our proposed
estimator.&lt;/p&gt;
&lt;p&gt;A classical statistician &lt;em&gt;can&lt;/em&gt; analyze pretty much arbitrary procedures,
including ones of the silly type &lt;span class="math"&gt;\(\hat{\mu}\)&lt;/span&gt; that we proposed.
The analysis may be technically difficult or apply only in the asymptotic
regime but does not rule out any estimator apriori.
Typical results may take the form of a derivation of the variance or bias of
the estimator.
In our case we have an
&lt;a href="http://en.wikipedia.org/wiki/Bias_of_an_estimator"&gt;&lt;em&gt;unbiased&lt;/em&gt;&lt;/a&gt;
estimate of the mean, &lt;span class="math"&gt;\(\mathbb{E}[\hat{\mu}]-\mu = 0\)&lt;/span&gt;.
As for the variance, because we only take the first sample, even as &lt;span class="math"&gt;\(n \to
\infty\)&lt;/span&gt; the variance &lt;span class="math"&gt;\(\mathbb{V}[\hat{\mu}]\)&lt;/span&gt; remains constant, so the
estimator is
&lt;a href="http://en.wikipedia.org/wiki/Consistent_estimator"&gt;&lt;em&gt;inconsistent&lt;/em&gt;&lt;/a&gt;, a clear
indication that our &lt;span class="math"&gt;\(\hat{\mu}\)&lt;/span&gt; is a bad estimator.&lt;/p&gt;
&lt;p&gt;Another typical result is in the form of a &lt;a href="http://en.wikipedia.org/wiki/Confidence_interval"&gt;confidence
interval&lt;/a&gt; of a parameter of
interest.
One can argue that confidence intervals are &lt;a href="http://en.wikipedia.org/wiki/Credible_interval#Confidence_interval"&gt;not exactly answering the
question of
interest&lt;/a&gt;
(that is, whether the parameter really is in the given interval), but if they
are of interest, one can sometimes &lt;a href="http://onlinelibrary.wiley.com/doi/10.1111/rssb.12080/abstract"&gt;obtain them also from a Bayesian
analysis&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;There exist cases where existing statistical procedures can be reinterpreted
from a Bayesian viewpoint.  This is achieved by proposing a model and prior
such that inferences under this model and prior exactly or approximately match
the answers of the existing procedure or at least have satisfying frequentist
properties.
Two cases of this are the following:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://utstat.toronto.edu/pub/reid/research/vaneeden.pdf"&gt;Matching priors&lt;/a&gt;,
where in some cases it is possible to establish an exact equivalence for
simple parametric models without latent variables.
One recent example for even a non-parametric model is the &lt;a href="http://arxiv.org/abs/1401.0303"&gt;Good-Turing estimator
for the missing mass&lt;/a&gt;, where an asymptotic
equivalence between the classic &lt;a href="http://en.wikipedia.org/wiki/Good%E2%80%93Turing_frequency_estimation"&gt;Good-Turing
estimator&lt;/a&gt;
and a Bayesian non-parametric model is established.&lt;/li&gt;
&lt;li&gt;&lt;a href="http://projecteuclid.org/euclid.aos/1236693154"&gt;Reference priors&lt;/a&gt;, a
generalization of the Jeffrey prior, in which the prior is constructed to be
least informative.  Here least informative is in the sense that when you
sample from the prior and consider the resulting posterior using the sample,
the divergence to the original prior should be large in expectation; that is,
samples from the prior should be able to change your beliefs to the maximum
possible extend.  When it is possible to derive reference priors, these
typically have excellent frequentist robustness properties, and are useful
default prior choices.
Unfortunately, in models with multiple parameters there is no unique reference
prior, and generally the set of &lt;a href="http://www.stats.org.uk/priors/noninformative/YangBerger1998.pdf"&gt;known reference
priors&lt;/a&gt;
seems to be quite small.
This problematic case-by-case state is nicely summarized in this recent work
on &lt;a href="http://projecteuclid.org/euclid.ba/1422556416"&gt;overall objective priors&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Should we care at all about these classic notions of qualities of an
estimators?
I have seen &lt;em&gt;Bayesians&lt;/em&gt; dismiss properties such as &lt;em&gt;unbiasedness&lt;/em&gt;
and &lt;em&gt;consistency&lt;/em&gt; as unimportant, but I cannot understand this stance.
For example, an unbiased estimator operating on iid sampled data immediately
implies a scalable parallel estimator applicable to the big data setting,
simply by separately estimating the quantity of interest, then taking the
average of estimates.  This is a practical and useful consequence of the
unbiasedness property.  Similarly, &lt;em&gt;consistency&lt;/em&gt; is at least a guarantee that
when more data is available the qualities of your inferences are improving,
and this should be of interest to anyone whose goal it is to build systems
which can learn.  (There do exist some results on Bayesian posterior
consistency, for a summary see Chapter 20 of
&lt;a href="http://www.stat.purdue.edu/~dasgupta/"&gt;DasGupta's&lt;/a&gt;
&lt;a href="http://www.springer.com/mathematics/probability/book/978-0-387-75970-8"&gt;book&lt;/a&gt;.)&lt;/p&gt;
&lt;p&gt;Let me summarize.
Bayesian estimators are often superior to alternatives.
But the set of procedures yielding Bayesian estimates is strictly smaller than
the set of all statistical procedures.
We need methods to analyze the larger set, in particular to characterize the
subset of useful estimators, where &lt;em&gt;useful&lt;/em&gt; is application dependent.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Acknowledgements&lt;/em&gt;.  I thank &lt;a href="http://www.jancsary.net/"&gt;Jeremy Jancsary&lt;/a&gt;,
&lt;a href="http://files.is.tue.mpg.de/pgehler/"&gt;Peter Gehler&lt;/a&gt;,
&lt;a href="http://pub.ist.ac.at/~chl/"&gt;Christoph Lampert&lt;/a&gt;, and
&lt;a href="http://www.ong-home.my/"&gt;Cheng Soon-Ong&lt;/a&gt; for feedback.&lt;/p&gt;
&lt;script type="text/javascript"&gt;if (!document.getElementById('mathjaxscript_pelican_#%@#$@#')) {
    var align = "center",
        indent = "0em",
        linebreak = "false";

    if (false) {
        align = (screen.width &lt; 768) ? "left" : align;
        indent = (screen.width &lt; 768) ? "0em" : indent;
        linebreak = (screen.width &lt; 768) ? 'true' : linebreak;
    }

    var mathjaxscript = document.createElement('script');
    mathjaxscript.id = 'mathjaxscript_pelican_#%@#$@#';
    mathjaxscript.type = 'text/javascript';
    mathjaxscript.src = 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.3/latest.js?config=TeX-AMS-MML_HTMLorMML';

    var configscript = document.createElement('script');
    configscript.type = 'text/x-mathjax-config';
    configscript[(window.opera ? "innerHTML" : "text")] =
        "MathJax.Hub.Config({" +
        "    config: ['MMLorHTML.js']," +
        "    TeX: { extensions: ['AMSmath.js','AMSsymbols.js','noErrors.js','noUndefined.js'], equationNumbers: { autoNumber: 'none' } }," +
        "    jax: ['input/TeX','input/MathML','output/HTML-CSS']," +
        "    extensions: ['tex2jax.js','mml2jax.js','MathMenu.js','MathZoom.js']," +
        "    displayAlign: '"+ align +"'," +
        "    displayIndent: '"+ indent +"'," +
        "    showMathMenu: true," +
        "    messageStyle: 'normal'," +
        "    tex2jax: { " +
        "        inlineMath: [ ['\\\\(','\\\\)'] ], " +
        "        displayMath: [ ['$$','$$'] ]," +
        "        processEscapes: true," +
        "        preview: 'TeX'," +
        "    }, " +
        "    'HTML-CSS': { " +
        "        availableFonts: ['STIX', 'TeX']," +
        "        preferredFont: 'STIX'," +
        "        styles: { '.MathJax_Display, .MathJax .mo, .MathJax .mi, .MathJax .mn': {color: 'inherit ! important'} }," +
        "        linebreaks: { automatic: "+ linebreak +", width: '90% container' }," +
        "    }, " +
        "}); " +
        "if ('default' !== 'default') {" +
            "MathJax.Hub.Register.StartupHook('HTML-CSS Jax Ready',function () {" +
                "var VARIANT = MathJax.OutputJax['HTML-CSS'].FONTDATA.VARIANT;" +
                "VARIANT['normal'].fonts.unshift('MathJax_default');" +
                "VARIANT['bold'].fonts.unshift('MathJax_default-bold');" +
                "VARIANT['italic'].fonts.unshift('MathJax_default-italic');" +
                "VARIANT['-tex-mathit'].fonts.unshift('MathJax_default-italic');" +
            "});" +
            "MathJax.Hub.Register.StartupHook('SVG Jax Ready',function () {" +
                "var VARIANT = MathJax.OutputJax.SVG.FONTDATA.VARIANT;" +
                "VARIANT['normal'].fonts.unshift('MathJax_default');" +
                "VARIANT['bold'].fonts.unshift('MathJax_default-bold');" +
                "VARIANT['italic'].fonts.unshift('MathJax_default-italic');" +
                "VARIANT['-tex-mathit'].fonts.unshift('MathJax_default-italic');" +
            "});" +
        "}";

    (document.body || document.getElementsByTagName('head')[0]).appendChild(configscript);
    (document.body || document.getElementsByTagName('head')[0]).appendChild(mathjaxscript);
}
&lt;/script&gt;</content><category term="Machine Learning"/></entry><entry><title>Becoming a Bayesian, Part 2</title><link href="https://www.nowozin.net/sebastian/blog/becoming-a-bayesian-part-2.html" rel="alternate"/><published>2015-05-02T18:30:00+01:00</published><updated>2015-05-02T18:30:00+01:00</updated><author><name>Sebastian Nowozin</name></author><id>tag:www.nowozin.net,2015-05-02:/sebastian/blog/becoming-a-bayesian-part-2.html</id><summary type="html">&lt;p&gt;This post continues the previous post, &lt;a href="https://www.nowozin.net/sebastian/blog/becoming-a-bayesian-part-1.html"&gt;part 1&lt;/a&gt;,
outlining my criticism towards a ''naive'' subjective Bayesian viewpoint:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;a href="https://www.nowozin.net/sebastian/blog/becoming-a-bayesian-part-1.html"&gt;The consequences of model misspecification&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;The ''model first computation last'' approach, in this post.&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.nowozin.net/sebastian/blog/becoming-a-bayesian-part-3.html"&gt;Denial of methods of classical statistics&lt;/a&gt;.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;The ''Model First Computation Last'' approach&lt;/h2&gt;
&lt;p&gt;Without a model (not necessarily probabilistic) we …&lt;/p&gt;</summary><content type="html">&lt;p&gt;This post continues the previous post, &lt;a href="https://www.nowozin.net/sebastian/blog/becoming-a-bayesian-part-1.html"&gt;part 1&lt;/a&gt;,
outlining my criticism towards a ''naive'' subjective Bayesian viewpoint:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;a href="https://www.nowozin.net/sebastian/blog/becoming-a-bayesian-part-1.html"&gt;The consequences of model misspecification&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;The ''model first computation last'' approach, in this post.&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.nowozin.net/sebastian/blog/becoming-a-bayesian-part-3.html"&gt;Denial of methods of classical statistics&lt;/a&gt;.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;The ''Model First Computation Last'' approach&lt;/h2&gt;
&lt;p&gt;Without a model (not necessarily probabilistic) we cannot learn anything.
This is true for science, but it is also true for any machine learning system.
The model may be very general and make only a few general assumptions (e.g.
''the physical laws remain constant over time and space''),
or it may be highly specific (e.g. ''&lt;span class="math"&gt;\(X \sim \mathcal{N}(\mu,1)\)&lt;/span&gt;''),
but we need a model in order to relate observations to quantities of interest.&lt;/p&gt;
&lt;p&gt;But in contrast to science, when we build machine learning systems we are also
engineers.  We build models not in isolation or on a piece of whiteboard, but
instead we build them to run on our current technology.&lt;/p&gt;
&lt;p&gt;Many &lt;em&gt;Bayesians&lt;/em&gt; adhere to a strict separation of model and inference
procedure; that is, the model is independent of any inference procedure.
They argue convincingly that the goal of inference is to approximate the
posterior under the assumed model, and that for each model there exist a large
variety of possible approximate inference methods that can be applied, such as
Markov chain Monte Carlo (MCMC), importance sampling, mean field, belief
propagation, etc.
By selecting a suitable inference procedure, different accuracy and runtime
trade-offs can be realized.
In this viewpoint, the &lt;em&gt;model comes first and computation comes last&lt;/em&gt;, once the
model is in place.&lt;/p&gt;
&lt;p&gt;In practice this beautiful story does not play out very often.
What is more common is that instead of spending time building and refining a
model, time is spent on tuning the parameters of inference procedures, such
as:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;em&gt;MCMC&lt;/em&gt;: Markov kernel, diagnostics, burn-in, possible extensions (annealing,
  parallel tempering ladder, HMC parameters, etc.);&lt;/li&gt;
&lt;li&gt;Importance sampling: selecting the proposal distribution, effective sample
  size, possible extensions (e.g. multiple importance sampling);&lt;/li&gt;
&lt;li&gt;Mean field and belief propagation: message initialization, schedule, damping
  factor, convergence criterion.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;In fact, it seems to me, that many works describing novel models ultimately
also describe inference procedures that are required to make their models
work.
I say this not to diminish the tremendeous progress we as a community have
made in probabilistic inference; it is just an observation that the separation
of model and inference is not plug-and-play in practice.
(Other pragmatic reasons for deviating from the subjective Bayesian viewpoint
are provided in a &lt;a href="http://projecteuclid.org/euclid.ba/1340371036"&gt;paper by
Goldstein&lt;/a&gt;.)&lt;/p&gt;
&lt;p&gt;Suppose we have a probabilistic model and we are provided an
approximate inference procedure for it.
Let us draw a big box around these two components and call this the
&lt;em&gt;effective model&lt;/em&gt;, that is, the system that takes observations and produces
some probabilistic output.
How similar is this effective model to the model on our whiteboard?
I know of only very few results, for example &lt;a href="http://papers.nips.cc/paper/4649-the-bethe-partition-function-of-log-supermodular-graphical-models"&gt;Ruozzi's analysis of the Bethe
approximation&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Another practial example along these lines was given to me by Andrew Wilson is
to compare an analytically tractable model such as a Gaussian process against
a richer but intractable model such as a Gaussian process with Student-T
noise.  The latter model is certainly more capable formally but requires
approximate inference.
In this case, the approximate inference implicitly changes the model and it is
not clear at all whether it is it worth to give up analytic tractability.&lt;/p&gt;
&lt;h3&gt;Resource-Constrained Reasoning&lt;/h3&gt;
&lt;p&gt;It seems that when compared to machine learning, the field of artificial
intelligence is somewhat ahead; in 1987 &lt;a href="http://research.microsoft.com/en-us/um/people/horvitz/"&gt;Eric
Horvitz&lt;/a&gt; had a nice
paper at UAI on &lt;a href="http://arxiv.org/abs/1304.2759"&gt;reasoning and decision making under limited
resources&lt;/a&gt;.  When read liberally the problem
of adhering to the orthodox (normative) view he described in 1987 seems to
mirror the current issues faced by large scale probabilistic models used in
machine learning, namely that exact analysis in any but the simplest models is
intractable and resource constraints are not made explicit in the model or the
inference procedures.&lt;/p&gt;
&lt;p&gt;But some recent work is giving me new hopes that we will treat computation as
a first class citizen when building our models, here is some of that work from
the computer vision and natural language processing community:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://stat.fsu.edu/~abarbu/"&gt;Adrian Barbu's&lt;/a&gt; &lt;a href="http://stat.fsu.edu/~abarbu/papers/denoise_tip.pdf"&gt;active random
fields&lt;/a&gt; from 2009, where
he explicitly considers the effects of using suboptimal inference procedure in
graphical models.&lt;/li&gt;
&lt;li&gt;Stoyanov, Ropson, and Eisner's work on &lt;a href="http://www.cs.jhu.edu/~jason/papers/stoyanov+al.aistats11.pdf"&gt;predicting with approximate
inference
procedures&lt;/a&gt; at
AISTATS 2011; although this is an empirical risk minimization approach.&lt;/li&gt;
&lt;li&gt;&lt;a href="http://users.cecs.anu.edu.au/~jdomke/"&gt;Justin Domke's&lt;/a&gt; work on &lt;a href="http://users.cecs.anu.edu.au/~jdomke/papers/2013pami.pdf"&gt;unrolling
approximate inference
procedures&lt;/a&gt; and
training the resulting models end-to-end using backpropagation.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Cheng Soon Ong pointed me to &lt;a href="https://www.aaai.org/Papers/Workshops/2002/WS-02-15/WS02-15-002.pdf"&gt;work on anytime probabilistic
inference&lt;/a&gt;,
which I am not familiar with, but the goal of having inference algorithms
which adapt to the available resources is certainly desirable.  The &lt;a href="http://en.wikipedia.org/wiki/Anytime_algorithm"&gt;anytime
setting&lt;/a&gt; is practically
relevant in many applications, particular in the real-time systems.&lt;/p&gt;
&lt;p&gt;All these works share the characteristic that they take a probabilistic model
and approximate inference procedure and construct a new "effective
model" by entangling the model and inference.
By doing so the resulting model is tractable by construction and retains to a
large extent the specification of the original intractable model.
However, the separation between model and inference procedure is lost.&lt;/p&gt;
&lt;p&gt;This is the first step towards a &lt;em&gt;computation first approach&lt;/em&gt;, and I believe
we will see more machine learning works which recognize available
computational primitives and resources as equally important to the model
specification itself.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Acknowledgements&lt;/em&gt;.  I thank &lt;a href="http://www.jancsary.net/"&gt;Jeremy Jancsary&lt;/a&gt;,
&lt;a href="http://files.is.tue.mpg.de/pgehler/"&gt;Peter Gehler&lt;/a&gt;,
&lt;a href="http://pub.ist.ac.at/~chl/"&gt;Christoph Lampert&lt;/a&gt;,
&lt;a href="http://www.cs.cmu.edu/~andrewgw/"&gt;Andrew Wilson&lt;/a&gt;, and
&lt;a href="http://www.ong-home.my/"&gt;Cheng Soon-Ong&lt;/a&gt; for feedback.&lt;/p&gt;
&lt;script type="text/javascript"&gt;if (!document.getElementById('mathjaxscript_pelican_#%@#$@#')) {
    var align = "center",
        indent = "0em",
        linebreak = "false";

    if (false) {
        align = (screen.width &lt; 768) ? "left" : align;
        indent = (screen.width &lt; 768) ? "0em" : indent;
        linebreak = (screen.width &lt; 768) ? 'true' : linebreak;
    }

    var mathjaxscript = document.createElement('script');
    mathjaxscript.id = 'mathjaxscript_pelican_#%@#$@#';
    mathjaxscript.type = 'text/javascript';
    mathjaxscript.src = 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.3/latest.js?config=TeX-AMS-MML_HTMLorMML';

    var configscript = document.createElement('script');
    configscript.type = 'text/x-mathjax-config';
    configscript[(window.opera ? "innerHTML" : "text")] =
        "MathJax.Hub.Config({" +
        "    config: ['MMLorHTML.js']," +
        "    TeX: { extensions: ['AMSmath.js','AMSsymbols.js','noErrors.js','noUndefined.js'], equationNumbers: { autoNumber: 'none' } }," +
        "    jax: ['input/TeX','input/MathML','output/HTML-CSS']," +
        "    extensions: ['tex2jax.js','mml2jax.js','MathMenu.js','MathZoom.js']," +
        "    displayAlign: '"+ align +"'," +
        "    displayIndent: '"+ indent +"'," +
        "    showMathMenu: true," +
        "    messageStyle: 'normal'," +
        "    tex2jax: { " +
        "        inlineMath: [ ['\\\\(','\\\\)'] ], " +
        "        displayMath: [ ['$$','$$'] ]," +
        "        processEscapes: true," +
        "        preview: 'TeX'," +
        "    }, " +
        "    'HTML-CSS': { " +
        "        availableFonts: ['STIX', 'TeX']," +
        "        preferredFont: 'STIX'," +
        "        styles: { '.MathJax_Display, .MathJax .mo, .MathJax .mi, .MathJax .mn': {color: 'inherit ! important'} }," +
        "        linebreaks: { automatic: "+ linebreak +", width: '90% container' }," +
        "    }, " +
        "}); " +
        "if ('default' !== 'default') {" +
            "MathJax.Hub.Register.StartupHook('HTML-CSS Jax Ready',function () {" +
                "var VARIANT = MathJax.OutputJax['HTML-CSS'].FONTDATA.VARIANT;" +
                "VARIANT['normal'].fonts.unshift('MathJax_default');" +
                "VARIANT['bold'].fonts.unshift('MathJax_default-bold');" +
                "VARIANT['italic'].fonts.unshift('MathJax_default-italic');" +
                "VARIANT['-tex-mathit'].fonts.unshift('MathJax_default-italic');" +
            "});" +
            "MathJax.Hub.Register.StartupHook('SVG Jax Ready',function () {" +
                "var VARIANT = MathJax.OutputJax.SVG.FONTDATA.VARIANT;" +
                "VARIANT['normal'].fonts.unshift('MathJax_default');" +
                "VARIANT['bold'].fonts.unshift('MathJax_default-bold');" +
                "VARIANT['italic'].fonts.unshift('MathJax_default-italic');" +
                "VARIANT['-tex-mathit'].fonts.unshift('MathJax_default-italic');" +
            "});" +
        "}";

    (document.body || document.getElementsByTagName('head')[0]).appendChild(configscript);
    (document.body || document.getElementsByTagName('head')[0]).appendChild(mathjaxscript);
}
&lt;/script&gt;</content><category term="Machine Learning"/></entry><entry><title>Becoming a Bayesian, Part 1</title><link href="https://www.nowozin.net/sebastian/blog/becoming-a-bayesian-part-1.html" rel="alternate"/><published>2015-04-19T17:30:00+01:00</published><updated>2015-04-19T17:30:00+01:00</updated><author><name>Sebastian Nowozin</name></author><id>tag:www.nowozin.net,2015-04-19:/sebastian/blog/becoming-a-bayesian-part-1.html</id><summary type="html">&lt;p&gt;I have used probabilistic models for a number of years now and over this time
I have used different paradigms to build my models, to estimate them from
data, and to perform inference and predictions.&lt;/p&gt;
&lt;p&gt;Overall I have slowly become a Bayesian; however, it has been a rough journey.
When …&lt;/p&gt;</summary><content type="html">&lt;p&gt;I have used probabilistic models for a number of years now and over this time
I have used different paradigms to build my models, to estimate them from
data, and to perform inference and predictions.&lt;/p&gt;
&lt;p&gt;Overall I have slowly become a Bayesian; however, it has been a rough journey.
When I say that "I became a Bayesian" I mean that my default view on problems
now is to think about a probabilistic model that relates observables to
quantities of interest and of suitable prior distributions for any unknowns
that are present in this model.
When it comes to solving the practical problem using a
computer program however, I am ready to depart from the model on my whiteboard
whenever the advantages to do so are large enough, for example in simplicity,
runtime speed, tractability, etc.
Some recent work to that end:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Our work on &lt;a href="http://arxiv.org/abs/1402.0859"&gt;informed sampling for generative computer vision
models&lt;/a&gt; with
&lt;a href="http://ps.is.tue.mpg.de/person/jampani"&gt;Varun&lt;/a&gt;,
&lt;a href="http://ps.is.tue.mpg.de/person/loper"&gt;Matthew&lt;/a&gt; and
&lt;a href="http://files.is.tue.mpg.de/pgehler/"&gt;Peter&lt;/a&gt;, where we argue for a generative
and Bayesian approach to computer vision problems;&lt;/li&gt;
&lt;li&gt;Our &lt;a href="http://arxiv.org/abs/1402.3580"&gt;Bayesian NMR work&lt;/a&gt; (and
&lt;a href="http://www.nowozin.net/sebastian/papers/wu2014porousmedia.pdf"&gt;here&lt;/a&gt;) with
&lt;a href="http://www.cs.cmu.edu/~andrewgw/"&gt;Andrew Wilson&lt;/a&gt; and collaborators from the
Cambridge university chemical department we have taken a full Bayesian
viewpoint, with great success over conventional NMR Fourier analysis;&lt;/li&gt;
&lt;li&gt;Our work on using &lt;a href="http://www.nowozin.net/sebastian/papers/bratieres2014scalablegpstruct.pdf"&gt;GPs for structured
prediction&lt;/a&gt;
with &lt;a href="http://mlg.eng.cam.ac.uk/sebastien/"&gt;Sebastien&lt;/a&gt;,
&lt;a href="http://www.sussex.ac.uk/Users/nq28/"&gt;Novi&lt;/a&gt;, and
&lt;a href="http://mlg.eng.cam.ac.uk/zoubin/"&gt;Zoubin&lt;/a&gt;, which was motivated by the
struggle to scale up a conceptually satisfying model.&lt;/li&gt;
&lt;li&gt;My work on &lt;a href="http://www.nowozin.net/sebastian/papers/nowozin2014intersectionoverunion.pdf"&gt;maximum expected utility in some structured prediction
models&lt;/a&gt;
at CVPR 2014, which was motivated by applying basic decision theory, but ended
up trying to cope with resulting intractabilities.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;However, I have remained skeptical of the naive and unconditional adoption of
the &lt;em&gt;subjective Bayesian viewpoint&lt;/em&gt;.
In particular, I object to the viewpoint that every model and every system
ought to be Bayesian, or to the view that at the very least, if a statistical
system is useful that it should have an approximate Bayesian interpretation.
In this post and the following two posts I will try to explain my skepticism.&lt;/p&gt;
&lt;p&gt;There is a risk of barking up the wrong tree by attacking a caricature of a
Bayesian here, which is not my intention.  In fact, to be frank, every one of
the researchers I have interacted with in the past few years holds a nuanced
view of their principles and methods and more often than not is aware of their
principles' limitations and willing to adjust if circumstances require it.&lt;/p&gt;
&lt;p&gt;Let me summarize the subjective Bayesian viewpoint.
In my experience this view of the world is arguably the most prevalent among
Bayesians in the machine learning community, for example at NIPS and at
machine learning summer schools.&lt;/p&gt;
&lt;h3&gt;The Subjective Bayesian Viewpoint&lt;/h3&gt;
&lt;p&gt;The subjective Bayesian viewpoint on any system under study is as
follows:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Specify a probabilistic model relating what is known to what is unknown;&lt;/li&gt;
&lt;li&gt;Specify a proper prior probability distribution over unknowns based on any
information that is available to you;&lt;/li&gt;
&lt;li&gt;Obtain the posterior distribution over unknowns given the known data
(using &lt;a href="http://en.wikipedia.org/wiki/Bayes%27_theorem"&gt;Bayes
rule&lt;/a&gt;);&lt;/li&gt;
&lt;li&gt;Draw conclusions based on the posterior distribution; for example, solve a
decision problem or select a model among the alternative models.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;This approach is used exclusively for any statistical problem that may
arise.
This approach is strongly advocated, for example by
&lt;a href="http://www.jstor.org/discover/10.2307/2681060"&gt;Lindley&lt;/a&gt; and
in a &lt;a href="http://projecteuclid.org/euclid.ba/1340371036"&gt;paper by Michael
Goldstein&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Alternative Bayesian views deviate from this recipe.  For example, they may
allow for &lt;em&gt;improper&lt;/em&gt; prior distributions or instead aim to select
uninformative prior distributions, or even select the prior as a function of
the inferential question at hand.&lt;/p&gt;
&lt;h1&gt;Criticism&lt;/h1&gt;
&lt;p&gt;My main criticism towards a ''naive'' subjective Bayesian viewpoint are
related to the following three points:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;The consequences of model misspecification.&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.nowozin.net/sebastian/blog/becoming-a-bayesian-part-2.html"&gt;The ''model first computation last'' approach&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.nowozin.net/sebastian/blog/becoming-a-bayesian-part-3.html"&gt;Denial of methods of classical statistics&lt;/a&gt;.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;The Consequences of Model Misspecification&lt;/h2&gt;
&lt;p&gt;To model some system in the world we often use probabilistic models of the
form
    &lt;/p&gt;
&lt;div class="math"&gt;$$p(x;\theta),\qquad \theta \in \Theta,$$&lt;/div&gt;
&lt;p&gt;
where &lt;span class="math"&gt;\(x \in \mathcal{X}\)&lt;/span&gt; is a random variable of interest and &lt;span class="math"&gt;\(\Theta\)&lt;/span&gt; is the
set of possible parameters &lt;span class="math"&gt;\(\theta\)&lt;/span&gt;.  We are interested in &lt;span class="math"&gt;\(p(x)\)&lt;/span&gt; and thus
would like to find a suitable parameter given some observed data &lt;span class="math"&gt;\(x_1, x_2,
\dots, x_n \in \mathcal{X}\)&lt;/span&gt;.  Because we can never be entirely certain about
our parameters we may represent our current beliefs through a posterior
distribution &lt;span class="math"&gt;\(p(\theta|x_1,\dots,x_n)\)&lt;/span&gt;.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Misspecification&lt;/em&gt; is the case when no parameter in &lt;span class="math"&gt;\(\Theta\)&lt;/span&gt; leads to a
distribution &lt;span class="math"&gt;\(p(x;\theta)\)&lt;/span&gt; that behaves like the true distribution.
This is not exceptional, infact most models of real world systems are
misspecified.
It also is not a property of any inferential approach but rather a fundamental
limitation of building expressive models given our limited knowledge.  If we
could observe all relevant quantities and know their deterministic relationships we
would not need a probabilistic model.
Hence the need for a probabilistic model arises because we cannot observe
everything and we do not know all the dependencies that exist in the real
world.  (Alas, as Andrew Wilson pointed out to me, the previous two sentences
expose my deterministic world view.)
So what can be said about this common case of misspecified models?&lt;/p&gt;
&lt;p&gt;Let us talk about calibration of probabilities, and what happens in case your
model is wrong.
Informally, you are &lt;em&gt;well-calibrated&lt;/em&gt; if you neither overestimate nor
underestimate the probability of certain events.
Crucially, this does not imply a degree of certainty, only that your
uncertain statements (forecasted probabilities of events) are on average
correct.&lt;/p&gt;
&lt;p&gt;For any probabilistic model, being well-calibrated is a desirable goal.
There are &lt;a href="http://en.wikipedia.org/wiki/Scoring_rule"&gt;various methods&lt;/a&gt; to
assess calibration and to check the forecasts of your model.
In 1982 &lt;a href="http://www.statslab.cam.ac.uk/~apd/"&gt;Dawid&lt;/a&gt;, in a
&lt;a href="http://www.jstor.org/stable/2287720"&gt;seminal paper&lt;/a&gt;,
established a general theorem whose consequence (in Section 4.3 of that paper)
is to guarantee that a Bayesian using a parametric model will eventually be
well-calibrated.&lt;/p&gt;
&lt;p&gt;This is reassuring, except there is one catch:
it does not apply in the case when the model is misspecified.
Unfortunately, in most practical applications of probabilistic modelling,
misspecification is the rule rather than the exception (''All models are
wrong'').
We could hope for a ''graceful degradation'', in that we are still at least
approximately calibrated.  But this is not the case.&lt;/p&gt;
&lt;h3&gt;Calibration and Misspecification&lt;/h3&gt;
&lt;p&gt;In the misspecified case, there are &lt;a href="http://delong.typepad.com/sdj/2013/01/cosma-shalizi-vs-the-fen-dwelling-bayesians.html"&gt;simple
examples&lt;/a&gt;
due to &lt;a href="http://delong.typepad.com/sdj/"&gt;Brad Delong&lt;/a&gt; and &lt;a href="http://www.stat.cmu.edu/~cshalizi/"&gt;Cosma
Shalizi&lt;/a&gt;
where beliefs in a parametric model do not converge and
become less-calibrated over time.
In their example two contradicting things happen at the same time:
the beliefs become very confident, yet a single new observation revises the
belief to the other extreme, again confident.&lt;/p&gt;
&lt;h3&gt;Improving the model?&lt;/h3&gt;
&lt;p&gt;One can object that in these examples, and more generally, one should revise
the model to more accurately reflect the system under study.
But then, in order not to end up in an infinite loop of trying to improve
a model, how to determine when to stop?
Actually, how to even determine the accuracy of the model?
&lt;a href="http://en.wikipedia.org/wiki/Marginal_likelihood"&gt;Model evidence&lt;/a&gt; cannot be
used to this end, as it is conditioned on the set of possible models being
used.  (In fact, in Delong's example the evidence would assure us that
everything is fine.)
The answers to how model's can be criticised and improved are not simple, and
quite likely not Bayesian.&lt;/p&gt;
&lt;p&gt;Andrew Gelman and Cosma Shalizi discuss this issue and others in a &lt;a href="http://www.stat.columbia.edu/~gelman/research/published/philosophy_chapter.pdf"&gt;position
paper&lt;/a&gt;,
and I find myself agreeing with their assessment that there is no answer to
wrong model assumptions within the (strictly) subjective Bayesian viewpoint:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;"We fear that a philosophy of Bayesian statistics as subjective, inductive
inference can encourage a complacency about picking or averaging over existing
models rather than trying to falsify and go further.
Likelihood and Bayesian inference are powerful, and with great power comes
great responsibility.  Complex models can and should be checked and
falsified."&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3&gt;Non-parametric Models to the Rescue?&lt;/h3&gt;
&lt;p&gt;Another objection is that this is all well-known and hence we should use
non-parametric models which endow us with prior support over essentially all
reasonable alternatives.&lt;/p&gt;
&lt;p&gt;Unfortunately, while the resulting models are richer and are practically
useful in real applications, we now may have other problems: even when there
is prior support for the true model simple properties like &lt;em&gt;consistency&lt;/em&gt;
(which were guaranteed to hold in the parametric case) &lt;a href="http://projecteuclid.org/euclid.aos/1176349830"&gt;can no longer be taken
for granted&lt;/a&gt;.  The current
literature and basic results on this topic are nicely summarized in
Section 20.12 of &lt;a href="http://www.stat.purdue.edu/~dasgupta/"&gt;DasGupta's&lt;/a&gt;
&lt;a href="http://www.springer.com/mathematics/probability/book/978-0-387-75970-8"&gt;book&lt;/a&gt;.&lt;/p&gt;
&lt;h3&gt;Conclusion&lt;/h3&gt;
&lt;p&gt;Misspecification is not a Bayesian problem, and applies equally to other
estimation approaches, for example in the case of maximum likelihood
estimation see the &lt;a href="https://books.google.com/books?isbn=0521574463"&gt;book by
White&lt;/a&gt;.
However, a subjective Bayesian has no Bayesian means to test for the presence
of misspecification and that makes it hard to deal with the consequences.&lt;/p&gt;
&lt;p&gt;There are some ideas for applying Bayesian inference in a
misspecification-aware manner, for example the &lt;a href="http://homepages.cwi.nl/~pdg/ftp/alt12longer.pdf"&gt;&lt;em&gt;Safe
Bayesian&lt;/em&gt;&lt;/a&gt; approach, and an
interesting analysis of approximate Bayesian inference using the Bootstrap in
a relatively unknown &lt;a href="http://projecteuclid.org/euclid.bj/1126126768"&gt;paper of
Fushiki&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Are these alternatives practical and do they somehow overcome the
misspecification problem?  To be frank, I am not aware of any satisfactory
solution and common practice seems to be a careful model criticism using tools
such as predictive model checking and graphical inspection.  But these require
first acknowledging the problem.&lt;/p&gt;
&lt;p&gt;When the model is wrong ideally it would be reassuring to have,&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;a reliable diagnostic and quantification on how wrong it is (say, an
  estimate &lt;span class="math"&gt;\(D(q\|p^*)\)&lt;/span&gt; where &lt;span class="math"&gt;\(q\)&lt;/span&gt; is the true distribution), and&lt;/li&gt;
&lt;li&gt;a test for whether the type of model error present will matter for making
  certain predictions (say, an error bound on the deviation of certain
  expectations, &lt;span class="math"&gt;\(\mathbb{E}_q[f(x)] - \mathbb{E}_{p^*}[f(x)]\)&lt;/span&gt; for a given
  function &lt;span class="math"&gt;\(f\)&lt;/span&gt;).&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;To me it appears the (pure) subjective Bayesian paradigm cannot provide the
above.&lt;/p&gt;
&lt;h3&gt;Addendum&lt;/h3&gt;
&lt;p&gt;Andrew Wilson pointed out to me that in most cases of statistical problems we
cannot know the &lt;em&gt;true distribution&lt;/em&gt;, even in principle.  I agree, and indeed
if we pursue such elusive ideal then this may divert our attention away from
the practical issue of building a model good enough for the task at hand.
I entirely agree with taking such pragmatic stance and this follows Francis
Bacon's ideal of assessing the worth of a model (scientific theory in his
case) not by an abstract ideal of truthfulness, but instead by its utility.&lt;/p&gt;
&lt;p&gt;In machine learning and most industrial applications building the model is
&lt;em&gt;easy&lt;/em&gt; because we merely focus on predictive performance which can be
reliably assessed using holdout data.
For scientific discovery however, things are more subtle in that our goal is
in establishing the truth of certain statements with sufficient confidence;
but this truth is only a conditional truth, conditioned on assumptions we have
to make.&lt;/p&gt;
&lt;p&gt;A Bayesian makes all assumptions explicit and then proceeds by formally
treating them as truth, correctly inferring the consequences.
A classical/frequentist approach also makes assumptions by positing a model,
but then may be able to make statements that hold uniformly over all
possibilities encoded in the model.
Therefore, in my mind the Bayesian is an optimist, believing entirely in their
assumptions, whereas the classical approach is more pessimistic, believing
in their model but then providing worst-case results over all possibilities.
Misspecification affects both approaches.&lt;/p&gt;
&lt;p&gt;If you want to continue reading, &lt;a href="https://www.nowozin.net/sebastian/blog/becoming-a-bayesian-part-2.html"&gt;the second part of this
post&lt;/a&gt; is now available.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Acknowledgements&lt;/em&gt;.  I thank &lt;a href="http://www.jancsary.net/"&gt;Jeremy Jancsary&lt;/a&gt;,
&lt;a href="http://files.is.tue.mpg.de/pgehler/"&gt;Peter Gehler&lt;/a&gt;,
&lt;a href="http://pub.ist.ac.at/~chl/"&gt;Christoph Lampert&lt;/a&gt;, and
&lt;a href="http://www.cs.cmu.edu/~andrewgw/"&gt;Andrew Wilson&lt;/a&gt; for feedback.&lt;/p&gt;
&lt;script type="text/javascript"&gt;if (!document.getElementById('mathjaxscript_pelican_#%@#$@#')) {
    var align = "center",
        indent = "0em",
        linebreak = "false";

    if (false) {
        align = (screen.width &lt; 768) ? "left" : align;
        indent = (screen.width &lt; 768) ? "0em" : indent;
        linebreak = (screen.width &lt; 768) ? 'true' : linebreak;
    }

    var mathjaxscript = document.createElement('script');
    mathjaxscript.id = 'mathjaxscript_pelican_#%@#$@#';
    mathjaxscript.type = 'text/javascript';
    mathjaxscript.src = 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.3/latest.js?config=TeX-AMS-MML_HTMLorMML';

    var configscript = document.createElement('script');
    configscript.type = 'text/x-mathjax-config';
    configscript[(window.opera ? "innerHTML" : "text")] =
        "MathJax.Hub.Config({" +
        "    config: ['MMLorHTML.js']," +
        "    TeX: { extensions: ['AMSmath.js','AMSsymbols.js','noErrors.js','noUndefined.js'], equationNumbers: { autoNumber: 'none' } }," +
        "    jax: ['input/TeX','input/MathML','output/HTML-CSS']," +
        "    extensions: ['tex2jax.js','mml2jax.js','MathMenu.js','MathZoom.js']," +
        "    displayAlign: '"+ align +"'," +
        "    displayIndent: '"+ indent +"'," +
        "    showMathMenu: true," +
        "    messageStyle: 'normal'," +
        "    tex2jax: { " +
        "        inlineMath: [ ['\\\\(','\\\\)'] ], " +
        "        displayMath: [ ['$$','$$'] ]," +
        "        processEscapes: true," +
        "        preview: 'TeX'," +
        "    }, " +
        "    'HTML-CSS': { " +
        "        availableFonts: ['STIX', 'TeX']," +
        "        preferredFont: 'STIX'," +
        "        styles: { '.MathJax_Display, .MathJax .mo, .MathJax .mi, .MathJax .mn': {color: 'inherit ! important'} }," +
        "        linebreaks: { automatic: "+ linebreak +", width: '90% container' }," +
        "    }, " +
        "}); " +
        "if ('default' !== 'default') {" +
            "MathJax.Hub.Register.StartupHook('HTML-CSS Jax Ready',function () {" +
                "var VARIANT = MathJax.OutputJax['HTML-CSS'].FONTDATA.VARIANT;" +
                "VARIANT['normal'].fonts.unshift('MathJax_default');" +
                "VARIANT['bold'].fonts.unshift('MathJax_default-bold');" +
                "VARIANT['italic'].fonts.unshift('MathJax_default-italic');" +
                "VARIANT['-tex-mathit'].fonts.unshift('MathJax_default-italic');" +
            "});" +
            "MathJax.Hub.Register.StartupHook('SVG Jax Ready',function () {" +
                "var VARIANT = MathJax.OutputJax.SVG.FONTDATA.VARIANT;" +
                "VARIANT['normal'].fonts.unshift('MathJax_default');" +
                "VARIANT['bold'].fonts.unshift('MathJax_default-bold');" +
                "VARIANT['italic'].fonts.unshift('MathJax_default-italic');" +
                "VARIANT['-tex-mathit'].fonts.unshift('MathJax_default-italic');" +
            "});" +
        "}";

    (document.body || document.getElementsByTagName('head')[0]).appendChild(configscript);
    (document.body || document.getElementsByTagName('head')[0]).appendChild(mathjaxscript);
}
&lt;/script&gt;</content><category term="Machine Learning"/></entry><entry><title>Extended Formulations</title><link href="https://www.nowozin.net/sebastian/blog/extended-formulations.html" rel="alternate"/><published>2015-04-05T16:30:00+01:00</published><updated>2015-04-05T16:30:00+01:00</updated><author><name>Sebastian Nowozin</name></author><id>tag:www.nowozin.net,2015-04-05:/sebastian/blog/extended-formulations.html</id><summary type="html">&lt;p&gt;An amazing fact in high dimensions is this:
&lt;em&gt;Projecting a simple convex set described by a small number of inequalities
can create complicated convex set with an exponential number of inequalities.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;It is amazing because it contradicts our everyday human experience.
We are most familiar with projections of objects in …&lt;/p&gt;</summary><content type="html">&lt;p&gt;An amazing fact in high dimensions is this:
&lt;em&gt;Projecting a simple convex set described by a small number of inequalities
can create complicated convex set with an exponential number of inequalities.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;It is amazing because it contradicts our everyday human experience.
We are most familiar with projections of objects in three dimensions down to
two dimensions, namely when objects cast shadows, like this:&lt;/p&gt;
&lt;p&gt;&lt;img alt="Object with shadow, by Cloud Nines
Designs" src="https://www.nowozin.net/sebastian/blog/images/cloudninesdesigns-object.jpg"&gt;
(Image courtesy to &lt;a href="http://cloudninesdesigns.deviantart.com/art/Abstract-Vector-Object-117257819"&gt;Cloud Nines
Designs&lt;/a&gt;.)&lt;/p&gt;
&lt;p&gt;In three dimensions any polyhedral object, when projected onto a plane,
becomes &lt;em&gt;simpler&lt;/em&gt;, i.e. the number of facets stays the same or becomes
smaller.  Think of a three dimensional cube that casts a shadow.  The cube has
six facets but &lt;a href="http://www.etudes.ru/en/etudes/teni/"&gt;its shadow has four or
six&lt;/a&gt;, depending on the position of the
light and plane.
&lt;em&gt;[Edit and correction, July 2015: Thanks to reader Paul (comment below), I
have been made aware that it is not true that the number of facets cannot
increase when projecting form three dimensions onto the plane.
A great example is provided by &lt;a href="http://www.pokutta.com/Homepage/Bio.html"&gt;Sebastian
Pokutta&lt;/a&gt;, where a convex 3D
polytope with six facets projects onto the 2D plane as an octagon with eight
facets.  Thanks Paul!]&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Now, how I can I convince you that a convex set can become more complex when
projected?  Here is an impressive example.&lt;/p&gt;
&lt;h2&gt;Ben-Tal/Nemirovski Polyhedron&lt;/h2&gt;
&lt;p&gt;The following example is from
&lt;a href="http://pubsonline.informs.org/doi/abs/10.1287/moor.26.2.193.10561"&gt;(Ben-Tal, Nemirovski,
2001)&lt;/a&gt;,
(&lt;a href="http://www2.isye.gatech.edu/~nemirovs/ApprLor_fin.pdf"&gt;PDF&lt;/a&gt;).
In this paper the authors are motivated by approximating certain second order
cones using extended polyhedral formulations, in order to be able to perform
&lt;a href="http://en.wikipedia.org/wiki/Robust_optimization"&gt;robust optimization&lt;/a&gt; using
linear programming.
As a special case of their results I select the problem of approximating a
unit disk in the 2D plane.  (The following is a specialization of equation (8)
in the paper.)&lt;/p&gt;
&lt;p&gt;First, let us fix some notation.  Let
&lt;span class="math"&gt;\(x=(x_1,x_2,\dots,x_n,\alpha_1,\dots,\alpha_m) \in \mathbb{R}^{n+m}\)&lt;/span&gt; be a
vector, where &lt;span class="math"&gt;\(x_1\)&lt;/span&gt; to &lt;span class="math"&gt;\(x_n\)&lt;/span&gt; represent the &lt;em&gt;basic dimensions&lt;/em&gt; and &lt;span class="math"&gt;\(\alpha_1\)&lt;/span&gt; to
&lt;span class="math"&gt;\(\alpha_m\)&lt;/span&gt; represent the &lt;em&gt;extended dimensions&lt;/em&gt;.  For any set &lt;span class="math"&gt;\(\mathcal{E}
\subseteq \mathbb{R}^{n+m}\)&lt;/span&gt; we define the &lt;em&gt;projection&lt;/em&gt; as
&lt;/p&gt;
&lt;div class="math"&gt;$$\textrm{proj}_x(\mathcal{E}) = \{ (x_1,\dots,x_n) \:|\:
    \exists (\alpha_1,\dots,\alpha_m):
        (x_1,\dots,x_n,\alpha_1,\dots,\alpha_m) \in \mathcal{E} \}.$$&lt;/div&gt;
&lt;p&gt;
This corresponds to the familiar notion of a projection.&lt;/p&gt;
&lt;p&gt;For the 2D unit disk the following is an extended polyhedral formulation,
parametrized by an integer accuracy parameter &lt;span class="math"&gt;\(k \geq 2\)&lt;/span&gt;.  The formulation
has the basic dimensions &lt;span class="math"&gt;\(x_1\)&lt;/span&gt; and &lt;span class="math"&gt;\(x_2\)&lt;/span&gt;, and the extended dimensions
&lt;span class="math"&gt;\(\mathbf{\alpha}=(\xi_j,\eta_j)_{j=0,\dots,k}\)&lt;/span&gt;.
Defining the constants &lt;span class="math"&gt;\(c_j = \cos(\pi / 2^{j})\)&lt;/span&gt;, &lt;span class="math"&gt;\(s_j = \sin(\pi / 2^j)\)&lt;/span&gt;,
and &lt;span class="math"&gt;\(t_j = \tan(\pi / 2^j)\)&lt;/span&gt; the polyhedral set &lt;span class="math"&gt;\(\mathcal{E}_k\)&lt;/span&gt; is given by the
following intersection of linear inequality and equality constraints.
&lt;/p&gt;
&lt;div class="math"&gt;\begin{eqnarray}
\xi_0 - x_1 &amp;amp; \geq &amp;amp; 0,\nonumber\\
\xi_0 + x_1 &amp;amp; \geq &amp;amp; 0,\nonumber\\
\eta_0 - x_2 &amp;amp; \geq &amp;amp; 0,\nonumber\\
\eta_0 + x_2 &amp;amp; \geq &amp;amp; 0,\nonumber\\
\xi_j - c_{j+1} \xi_{j-1} - s_{j+1} \eta_{j-1} &amp;amp; = &amp;amp; 0,
    \qquad\textrm{for $j=1,\dots,k$,}\nonumber\\
\eta_j + s_{j+1} \xi_{j-1} - c_{j+1} \eta_{j-1} &amp;amp; \geq &amp;amp; 0,
    \qquad\textrm{for $j=1,\dots,k$,}\nonumber\\
\eta_j - s_{j+1} \xi_{j-1} + c_{j+1} \eta_{j-1} &amp;amp; \geq &amp;amp; 0,
    \qquad\textrm{for $j=1,\dots,k$,}\nonumber\\
\xi_k &amp;amp; \leq &amp;amp; 1,\nonumber\\
\eta_k - t_{k+1} \xi_k &amp;amp; \leq &amp;amp; 0.\nonumber
\end{eqnarray}&lt;/div&gt;
&lt;p&gt;Note that the set &lt;span class="math"&gt;\(\mathcal{E}_k\)&lt;/span&gt; can be described by &lt;span class="math"&gt;\(6+3k\)&lt;/span&gt; sparse linear
constraints.  The intersection of these convex constraint sets is of course
again a convex set.  Thus, the description of the set takes &lt;span class="math"&gt;\(O(k)\)&lt;/span&gt; space,
where &lt;span class="math"&gt;\(k\)&lt;/span&gt; is the approximation parameter.&lt;/p&gt;
&lt;p&gt;If we write &lt;span class="math"&gt;\(\mathcal{D}_k := \textrm{proj}_{x_1,x_2} \mathcal{E}_k\)&lt;/span&gt; for the
projection onto the first two dimensions, the following figure illustrates
just how remarkably accurate the formulation is as we increase &lt;span class="math"&gt;\(k\)&lt;/span&gt;.&lt;/p&gt;
&lt;p&gt;&lt;img alt="Ben-Tal/Nemirovski polyhedral approximation to the unit
disk" src="https://www.nowozin.net/sebastian/blog/images/bental-nemirovski.svg"&gt;&lt;/p&gt;
&lt;p&gt;How accurate is it?  Ben-Tal and Nemirovski say that a set &lt;span class="math"&gt;\(\mathcal{D}\)&lt;/span&gt; is an
&lt;span class="math"&gt;\(\epsilon\)&lt;/span&gt;-approximation to a set &lt;span class="math"&gt;\(\mathcal{L}\)&lt;/span&gt; if &lt;span class="math"&gt;\(\mathcal{L} \subseteq
\mathcal{D}\)&lt;/span&gt; and if for all &lt;span class="math"&gt;\(x \in \mathcal{D}\)&lt;/span&gt; it holds that
&lt;span class="math"&gt;\((\frac{1}{1+\epsilon} x) \in \mathcal{L}\)&lt;/span&gt;.
They then show that the above formulation is an &lt;span class="math"&gt;\(\epsilon_k\)&lt;/span&gt;-approximation,
where
&lt;/p&gt;
&lt;div class="math"&gt;$$\epsilon_k = \frac{1}{\cos(\pi / 2^{k+1})} - 1 = O(\frac{1}{4^k}).$$&lt;/div&gt;
&lt;p&gt;
That is, despite having a compact description in &lt;span class="math"&gt;\(O(k)\)&lt;/span&gt; space the accuracy
improves exponentially.
In the basic dimensions the set &lt;span class="math"&gt;\(\mathcal{D}_k\)&lt;/span&gt; has exponentially many facets
and cannot be described compactly through a polynomial sized collection of
linear inequalities.
(The paper further generalizes the above results to the family of
&lt;span class="math"&gt;\(d\)&lt;/span&gt;-dimensional Lorentz cones.)&lt;/p&gt;
&lt;h2&gt;Is there a Recurring Pattern?&lt;/h2&gt;
&lt;p&gt;The abstract idea behind obtaining complicated structures in one space by
means of something &lt;em&gt;like an extended formulation&lt;/em&gt; can be found in other
domains; for example, in probabilistic &lt;a href="http://en.wikipedia.org/wiki/Graphical_model"&gt;graphical
models&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Suppose we would like to specify a potentially complicated probability
distribution &lt;span class="math"&gt;\(P(X)\)&lt;/span&gt;.
Akin to an extended formulation we may proceed as follows.  We define an
extended set of random variables &lt;span class="math"&gt;\(\alpha\)&lt;/span&gt; and a distribution &lt;span class="math"&gt;\(P(\alpha)\)&lt;/span&gt;.
We then couple both spaces by means of a conditional specification,
&lt;span class="math"&gt;\(P(X|\alpha) P(\alpha)\)&lt;/span&gt;.
We then &lt;em&gt;project&lt;/em&gt;, that is, marginalize out, the extended dimensions &lt;span class="math"&gt;\(\alpha\)&lt;/span&gt;
to obtain
&lt;/p&gt;
&lt;div class="math"&gt;$$P(X) = \int P(X|\alpha) P(\alpha) \,\textrm{d}\alpha.$$&lt;/div&gt;
&lt;p&gt;
In practice this construction is often used in the form of a
&lt;a href="http://en.wikipedia.org/wiki/Bayesian_network"&gt;hierarchical graphical model&lt;/a&gt;,
for example when using a &lt;a href="http://sumsar.net/blog/2013/12/t-as-a-mixture-of-normals/"&gt;Normal mixture to define a student T
distribution&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;The increase in flexibility of the resulting marginal distribution can be as
impressive as for the above polyhedral sets: for example, if &lt;span class="math"&gt;\(P(X|\alpha)\)&lt;/span&gt; is
a Normal distribution and &lt;span class="math"&gt;\(P(\alpha)\)&lt;/span&gt; is a distribution over Normal
parameters, then the infinite Normal mixture can essentially represent any
absolutely continuous distribution.&lt;/p&gt;
&lt;p&gt;Another observation, which may be just a coincidence, but maybe there is more
to it: the extended formulation construction in both cases suggests a
practical implementation.  In the polyhedral set this was through linear
programming in the extended space, for the graphical model it would be
ancestral sampling or MCMC inference.&lt;/p&gt;
&lt;p&gt;This leaves me with the following questions:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Are there more examples of similar constructions (extension, coupling,
  projection)?&lt;/li&gt;
&lt;li&gt;What is the shared mathematical structure behind this similarity (e.g.
  permitting a projection operation that leads to complexity in the basic
  dimensions that no longer admits a compact description in this space)?&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Feedback very much welcome :-)&lt;/p&gt;
&lt;h2&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;I first learned of extended formulations from &lt;a href="http://www.springer.com/business+%26+management/production/book/978-0-387-29959-4"&gt;this book of Pochet and
Wolsey&lt;/a&gt;,
who pioneered the technique for practical scheduling optimization problems.
(Yes, I had enough time for tinkering during my PhD to take such creative diversions.)
A recent summary of extended formulations for &lt;em&gt;combinatorial optimization&lt;/em&gt;
problems is &lt;a href="http://integer.tepper.cmu.edu/webpub/ExtendedFormulation.pdf"&gt;Conforti, Cornuejols, Zambelli,
2012&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Many so called &lt;em&gt;higher-order interactions&lt;/em&gt; in computer vision random field
models are representable as extended formulations, a point I elaborated on in
a &lt;a href="http://users.cecs.anu.edu.au/~julianm/cvpr2011/slides/nowozin.pdf"&gt;talk&lt;/a&gt; I
gave at the &lt;a href="http://cseweb.ucsd.edu/~jmcauley/cvpr2011.html"&gt;Inference in Graphical Models with Structured Potentials
workshop&lt;/a&gt; at the CVPR 2011
conference.  Another relevant work is &lt;a href="http://link.springer.com/article/10.1007/s10107-003-0397-3"&gt;Miller and Wolsey,
2003&lt;/a&gt;.&lt;/p&gt;
&lt;script type="text/javascript"&gt;if (!document.getElementById('mathjaxscript_pelican_#%@#$@#')) {
    var align = "center",
        indent = "0em",
        linebreak = "false";

    if (false) {
        align = (screen.width &lt; 768) ? "left" : align;
        indent = (screen.width &lt; 768) ? "0em" : indent;
        linebreak = (screen.width &lt; 768) ? 'true' : linebreak;
    }

    var mathjaxscript = document.createElement('script');
    mathjaxscript.id = 'mathjaxscript_pelican_#%@#$@#';
    mathjaxscript.type = 'text/javascript';
    mathjaxscript.src = 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.3/latest.js?config=TeX-AMS-MML_HTMLorMML';

    var configscript = document.createElement('script');
    configscript.type = 'text/x-mathjax-config';
    configscript[(window.opera ? "innerHTML" : "text")] =
        "MathJax.Hub.Config({" +
        "    config: ['MMLorHTML.js']," +
        "    TeX: { extensions: ['AMSmath.js','AMSsymbols.js','noErrors.js','noUndefined.js'], equationNumbers: { autoNumber: 'none' } }," +
        "    jax: ['input/TeX','input/MathML','output/HTML-CSS']," +
        "    extensions: ['tex2jax.js','mml2jax.js','MathMenu.js','MathZoom.js']," +
        "    displayAlign: '"+ align +"'," +
        "    displayIndent: '"+ indent +"'," +
        "    showMathMenu: true," +
        "    messageStyle: 'normal'," +
        "    tex2jax: { " +
        "        inlineMath: [ ['\\\\(','\\\\)'] ], " +
        "        displayMath: [ ['$$','$$'] ]," +
        "        processEscapes: true," +
        "        preview: 'TeX'," +
        "    }, " +
        "    'HTML-CSS': { " +
        "        availableFonts: ['STIX', 'TeX']," +
        "        preferredFont: 'STIX'," +
        "        styles: { '.MathJax_Display, .MathJax .mo, .MathJax .mi, .MathJax .mn': {color: 'inherit ! important'} }," +
        "        linebreaks: { automatic: "+ linebreak +", width: '90% container' }," +
        "    }, " +
        "}); " +
        "if ('default' !== 'default') {" +
            "MathJax.Hub.Register.StartupHook('HTML-CSS Jax Ready',function () {" +
                "var VARIANT = MathJax.OutputJax['HTML-CSS'].FONTDATA.VARIANT;" +
                "VARIANT['normal'].fonts.unshift('MathJax_default');" +
                "VARIANT['bold'].fonts.unshift('MathJax_default-bold');" +
                "VARIANT['italic'].fonts.unshift('MathJax_default-italic');" +
                "VARIANT['-tex-mathit'].fonts.unshift('MathJax_default-italic');" +
            "});" +
            "MathJax.Hub.Register.StartupHook('SVG Jax Ready',function () {" +
                "var VARIANT = MathJax.OutputJax.SVG.FONTDATA.VARIANT;" +
                "VARIANT['normal'].fonts.unshift('MathJax_default');" +
                "VARIANT['bold'].fonts.unshift('MathJax_default-bold');" +
                "VARIANT['italic'].fonts.unshift('MathJax_default-italic');" +
                "VARIANT['-tex-mathit'].fonts.unshift('MathJax_default-italic');" +
            "});" +
        "}";

    (document.body || document.getElementsByTagName('head')[0]).appendChild(configscript);
    (document.body || document.getElementsByTagName('head')[0]).appendChild(mathjaxscript);
}
&lt;/script&gt;</content><category term="Optimization"/></entry><entry><title>How to report uncertainty</title><link href="https://www.nowozin.net/sebastian/blog/how-to-report-uncertainty.html" rel="alternate"/><published>2015-03-19T22:30:00+00:00</published><updated>2015-03-19T22:30:00+00:00</updated><author><name>Sebastian Nowozin</name></author><id>tag:www.nowozin.net,2015-03-19:/sebastian/blog/how-to-report-uncertainty.html</id><summary type="html">&lt;p&gt;&lt;a href="http://en.wikipedia.org/wiki/Error_bar"&gt;Error bars&lt;/a&gt; and the
&lt;a href="http://en.wikipedia.org/wiki/Plus-minus_sign"&gt;&lt;span class="math"&gt;\(\pm\)&lt;/span&gt;-notation&lt;/a&gt;
are used to quantitatively convey uncertainty in experimental results.
For example, you would often read statements like &lt;span class="math"&gt;\(140.7 \textrm{Hz} \pm 2.8
\textrm{ Hz SEM}\)&lt;/span&gt; in a paper to report both an experimental average and its
uncertainty.&lt;/p&gt;
&lt;p&gt;Unfortunately, in many fields (such …&lt;/p&gt;</summary><content type="html">&lt;p&gt;&lt;a href="http://en.wikipedia.org/wiki/Error_bar"&gt;Error bars&lt;/a&gt; and the
&lt;a href="http://en.wikipedia.org/wiki/Plus-minus_sign"&gt;&lt;span class="math"&gt;\(\pm\)&lt;/span&gt;-notation&lt;/a&gt;
are used to quantitatively convey uncertainty in experimental results.
For example, you would often read statements like &lt;span class="math"&gt;\(140.7 \textrm{Hz} \pm 2.8
\textrm{ Hz SEM}\)&lt;/span&gt; in a paper to report both an experimental average and its
uncertainty.&lt;/p&gt;
&lt;p&gt;Unfortunately, in many fields (such as computer vision, and, to a lesser
extent, machine learning) researchers often do not report uncertainty or if
they do, &lt;a href="http://archpedi.jamanetwork.com/article.aspx?articleid=510667"&gt;they may do it
wrong&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Of course, dear reader, I am sure &lt;em&gt;you&lt;/em&gt; always do report it properly, so the
following remarks may only serve as a reminder to your common practice.&lt;/p&gt;
&lt;p&gt;First, when reporting a quantitative measurement of uncertainty, it is
important to establish the goal of doing so.  The two popular goals are as
follows.&lt;/p&gt;
&lt;h2&gt;1. Convey Variability&lt;/h2&gt;
&lt;p&gt;Here the focus is on the variability itself.
For example, take a look at this table of &lt;a href="http://www.nature.com/ijo/journal/v27/n7/fig_tab/0802297t1.html"&gt;food intake of
US teenagers&lt;/a&gt;.
The variability among the participants of the study is reported through the
&lt;a href="http://en.wikipedia.org/wiki/Standard_deviation"&gt;standard deviation&lt;/a&gt;, the
square root of the variance.&lt;/p&gt;
&lt;p&gt;The reason why the standard deviation (SD) is prefered over the variance is
that the SD is on the same scale as the original values.  That is, if the
original measurements were in &lt;span class="math"&gt;\(\textrm{Hz}\)&lt;/span&gt; the standard deviation is also in
the unit of &lt;span class="math"&gt;\(\textrm{Hz}\)&lt;/span&gt;, whereas the variance is the square.&lt;/p&gt;
&lt;p&gt;One easy question you can ask yourself when thinking about the results you
would like to report in an experiment is this:
Do you expect the error bars to shrink with more available data?
If your goal is to convey variability they would &lt;em&gt;not&lt;/em&gt; shrink but remain of a
certain size, no matter how many samples are available.&lt;/p&gt;
&lt;p&gt;The correct wording to report this type of uncertainty is something similar to&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;"We report the mean and one unit standard deviation."&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2&gt;2. Convey Uncertainty about an Unknown Parameter&lt;/h2&gt;
&lt;p&gt;Here the focus is on your remaining uncertainty about a fixed quantity which
does not vary.
For example, take a look at &lt;a href="http://loristalter.com/wp-content/uploads/CDC_1960_2002.pdf"&gt;Table 1
in Ogden et al.,
2004&lt;/a&gt; where the
average weight of US children is reported.
Together with the mean weight in pounds the authors report the &lt;a href="http://en.wikipedia.org/wiki/Standard_error"&gt;standard error
of the mean&lt;/a&gt;.  (Sometimes this is
just called standard error.)&lt;/p&gt;
&lt;p&gt;Here the uncertainty represents a measurement of uncertainty about the average
weight.  It is related to the standard deviation &lt;span class="math"&gt;\(\sigma\)&lt;/span&gt; by means of&lt;/p&gt;
&lt;div class="math"&gt;$$\textrm{SEM} = \frac{\sigma}{\sqrt{n}},$$&lt;/div&gt;
&lt;p&gt;where &lt;span class="math"&gt;\(n\)&lt;/span&gt; is the sample size of the experiment.  For example, in Table 1 of
the above paper the authors report that between 1963 and 1965 for boys of age
6 years living in the USA the average weight was &lt;span class="math"&gt;\(\hat{\mu}=48.4\)&lt;/span&gt; pounds with
&lt;span class="math"&gt;\(\textrm{SEM}=0.3\)&lt;/span&gt; standard error of the mean and a sample size of &lt;span class="math"&gt;\(n=575\)&lt;/span&gt;.
Using the above formula this immediately gives&lt;/p&gt;
&lt;div class="math"&gt;$$\sigma \approx \sqrt{n} \textrm{SEM} = \sqrt{575} \cdot 0.3 \approx 7.19.$$&lt;/div&gt;
&lt;p&gt;What is the use of the standard error?
Because of the &lt;a href="http://en.wikipedia.org/wiki/Central_limit_theorem"&gt;central limit
theorem&lt;/a&gt; for independent
samples the standard error provides approximate confidence intervals for the
unknown true mean of the population, as&lt;/p&gt;
&lt;div class="math"&gt;$$[\hat{\mu} - 1.96 \textrm{SEM}, \hat{\mu} + 1.96 \textrm{SEM}].$$&lt;/div&gt;
&lt;p&gt;Using the above numbers we then know that with 95% confidence over the
sampling variation the true average weight &lt;span class="math"&gt;\(\mu \in [47.8,49.0]\)&lt;/span&gt;.
(Note that for a &lt;em&gt;single experiment&lt;/em&gt; this does not mean we
&lt;a href="http://en.wikipedia.org/wiki/Coverage_probability"&gt;cover&lt;/a&gt; the true
value with a certain probability, because either we cover it or we do not
cover it.  The 95% probability is the probability associated to a
(hypothetical) repetition of the experiment.)&lt;/p&gt;
&lt;p&gt;The correct wording to report this type of uncertainty is&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;"We report the average of &lt;span class="math"&gt;\(n=123\)&lt;/span&gt; samples and the standard error of the
mean."&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2&gt;How many digits to report?&lt;/h2&gt;
&lt;p&gt;When writing out numbers a natural question that arises is how many
significant digits to report.
&lt;a href="http://arxiv.org/abs/1301.1034"&gt;Richard Clymo has some advice&lt;/a&gt; on how many
digits to report.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Most bioscientists need to report mean values, yet many have little idea of
how many digits are significant, and at what point further digits are mere
random junk. Thus a recent report that the mean of 17 values was 3.863 with
a standard error of the mean (SEM) of 2.162 revealed only that none of the
seven authors understood the limitations of their work.
The simple rule derived here by experiment for restricting a mean value to
its significant digits (sig-digs) is this: the last sig-dig in the mean
value is at the same decimal decade as the first sig-dig (the first
non-zero) in the SEM.
...
For the example above the reported values should be a mean of 4 with SEM
2.2. Routine application of these simple rules will often show that a result
is not as compelling as one had hoped.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Let's compare with the numbers from before: the average height was reported as
48.4 and the SEM as 0.3.
The last significant digit in the mean is the four after the decimal point,
and this is the same decimal decade as the first significant digit of the SEM.
So the study did it right.&lt;/p&gt;
&lt;p&gt;Clymo develops the following simple-to-follow rules for reporting the sample
average and SEM:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;em&gt;Rule 1&lt;/em&gt; (for determining the significant digits in the reported mean):
the &lt;em&gt;last&lt;/em&gt; significant digit in the mean is in the same decade as the &lt;em&gt;first&lt;/em&gt;
non-zero digit in the SEM.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;em&gt;Rule 2&lt;/em&gt; (for determining significant digits in the reported SEM):
depending on the sample size &lt;span class="math"&gt;\(n\)&lt;/span&gt;, as per the following table:&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th style="text-align: left;"&gt;Sample size &lt;span class="math"&gt;\(n\)&lt;/span&gt;&lt;/th&gt;
&lt;th style="text-align: center;"&gt;Significant digits to report&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td style="text-align: left;"&gt;&lt;span class="math"&gt;\(2 \leq n \leq 6\)&lt;/span&gt;&lt;/td&gt;
&lt;td style="text-align: center;"&gt;1&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td style="text-align: left;"&gt;&lt;span class="math"&gt;\(7 \leq n \leq 100\)&lt;/span&gt;&lt;/td&gt;
&lt;td style="text-align: center;"&gt;2&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td style="text-align: left;"&gt;&lt;span class="math"&gt;\(101 \leq n \leq 10,000\)&lt;/span&gt;&lt;/td&gt;
&lt;td style="text-align: center;"&gt;3&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td style="text-align: left;"&gt;&lt;span class="math"&gt;\(10,001 \leq n \leq 10^6\)&lt;/span&gt;&lt;/td&gt;
&lt;td style="text-align: center;"&gt;4&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td style="text-align: left;"&gt;&lt;span class="math"&gt;\(n &amp;gt; 10^6\)&lt;/span&gt;&lt;/td&gt;
&lt;td style="text-align: center;"&gt;5&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;h2&gt;Quiz&lt;/h2&gt;
&lt;p&gt;Ok, that is enough information.  Let's practice.&lt;/p&gt;
&lt;h3&gt;Question 1&lt;/h3&gt;
&lt;p&gt;You sample the height of male students in a German school class (grade 6)
in centimeters: 148, 148, 137, 152, 140, 149, 152, 152, 159, 155.  Report your
estimate of the population height (here the population is all German male
students in grade 6).&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Answer&lt;/em&gt;: &lt;span class="math"&gt;\(149\textrm{cm} \pm 2.1\textrm{cm}\)&lt;/span&gt; SEM.
Explanation: we are interested in the population mean and hence would like to
convey the remaining uncertainty of our estimate.
The sample mean is &lt;span class="math"&gt;\(\hat{\mu} \approx 149.24467\textrm{cm}\)&lt;/span&gt;, the standard
deviation is &lt;span class="math"&gt;\(6.579429\textrm{cm}\)&lt;/span&gt;, and the sample size is &lt;span class="math"&gt;\(n=10\)&lt;/span&gt;.  This gives
a &lt;span class="math"&gt;\(\textrm{SEM} = 6.579429/\sqrt{10} \approx 2.080598\)&lt;/span&gt;.  Applying the above
rules: Rule 1 tells us that the first significant digit is in the &lt;span class="math"&gt;\(10^0\)&lt;/span&gt;
decade, so we report &lt;span class="math"&gt;\(149\textrm{cm}\)&lt;/span&gt; as mean.  Rule 2 tells us that for a
sample size of &lt;span class="math"&gt;\(n=10\)&lt;/span&gt; we should report two digits in the SEM, which needs to be
properly rounded to &lt;span class="math"&gt;\(2.1\textrm{cm}\)&lt;/span&gt;.&lt;/p&gt;
&lt;h3&gt;Question 2&lt;/h3&gt;
&lt;p&gt;You run a company and regularly send bills to customers for payment.
You measure the time in days between sending the bill and receiving the
payment: 10, 7, 10, 7, 12, 10, 8, 4, 15, 3, 9, 4.  Report the average and
variability.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Answer&lt;/em&gt;: &lt;span class="math"&gt;\(8 \pm 3.5\)&lt;/span&gt; SD.
Explanation: we are interested in the average time and the variability, so a
standard deviation is appropriate.  Rule 1 from Clymo still applies and we
truncate the sample mean of &lt;span class="math"&gt;\(8.25\)&lt;/span&gt; after the first digit.  Rule 2 does not
apply (this is the standard deviation, not the SEM), but because we have
truncated the mean it makes no sense to be more accurate than the mean except
for one additional digit.&lt;/p&gt;
&lt;script type="text/javascript"&gt;if (!document.getElementById('mathjaxscript_pelican_#%@#$@#')) {
    var align = "center",
        indent = "0em",
        linebreak = "false";

    if (false) {
        align = (screen.width &lt; 768) ? "left" : align;
        indent = (screen.width &lt; 768) ? "0em" : indent;
        linebreak = (screen.width &lt; 768) ? 'true' : linebreak;
    }

    var mathjaxscript = document.createElement('script');
    mathjaxscript.id = 'mathjaxscript_pelican_#%@#$@#';
    mathjaxscript.type = 'text/javascript';
    mathjaxscript.src = 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.3/latest.js?config=TeX-AMS-MML_HTMLorMML';

    var configscript = document.createElement('script');
    configscript.type = 'text/x-mathjax-config';
    configscript[(window.opera ? "innerHTML" : "text")] =
        "MathJax.Hub.Config({" +
        "    config: ['MMLorHTML.js']," +
        "    TeX: { extensions: ['AMSmath.js','AMSsymbols.js','noErrors.js','noUndefined.js'], equationNumbers: { autoNumber: 'none' } }," +
        "    jax: ['input/TeX','input/MathML','output/HTML-CSS']," +
        "    extensions: ['tex2jax.js','mml2jax.js','MathMenu.js','MathZoom.js']," +
        "    displayAlign: '"+ align +"'," +
        "    displayIndent: '"+ indent +"'," +
        "    showMathMenu: true," +
        "    messageStyle: 'normal'," +
        "    tex2jax: { " +
        "        inlineMath: [ ['\\\\(','\\\\)'] ], " +
        "        displayMath: [ ['$$','$$'] ]," +
        "        processEscapes: true," +
        "        preview: 'TeX'," +
        "    }, " +
        "    'HTML-CSS': { " +
        "        availableFonts: ['STIX', 'TeX']," +
        "        preferredFont: 'STIX'," +
        "        styles: { '.MathJax_Display, .MathJax .mo, .MathJax .mi, .MathJax .mn': {color: 'inherit ! important'} }," +
        "        linebreaks: { automatic: "+ linebreak +", width: '90% container' }," +
        "    }, " +
        "}); " +
        "if ('default' !== 'default') {" +
            "MathJax.Hub.Register.StartupHook('HTML-CSS Jax Ready',function () {" +
                "var VARIANT = MathJax.OutputJax['HTML-CSS'].FONTDATA.VARIANT;" +
                "VARIANT['normal'].fonts.unshift('MathJax_default');" +
                "VARIANT['bold'].fonts.unshift('MathJax_default-bold');" +
                "VARIANT['italic'].fonts.unshift('MathJax_default-italic');" +
                "VARIANT['-tex-mathit'].fonts.unshift('MathJax_default-italic');" +
            "});" +
            "MathJax.Hub.Register.StartupHook('SVG Jax Ready',function () {" +
                "var VARIANT = MathJax.OutputJax.SVG.FONTDATA.VARIANT;" +
                "VARIANT['normal'].fonts.unshift('MathJax_default');" +
                "VARIANT['bold'].fonts.unshift('MathJax_default-bold');" +
                "VARIANT['italic'].fonts.unshift('MathJax_default-italic');" +
                "VARIANT['-tex-mathit'].fonts.unshift('MathJax_default-italic');" +
            "});" +
        "}";

    (document.body || document.getElementsByTagName('head')[0]).appendChild(configscript);
    (document.body || document.getElementsByTagName('head')[0]).appendChild(mathjaxscript);
}
&lt;/script&gt;</content><category term="Machine Learning"/></entry><entry><title>Estimating Discrete Entropy, Part 3</title><link href="https://www.nowozin.net/sebastian/blog/estimating-discrete-entropy-part-3.html" rel="alternate"/><published>2015-03-07T16:00:00+00:00</published><updated>2015-03-07T16:00:00+00:00</updated><author><name>Sebastian Nowozin</name></author><id>tag:www.nowozin.net,2015-03-07:/sebastian/blog/estimating-discrete-entropy-part-3.html</id><summary type="html">&lt;p&gt;In the last two parts (&lt;a href="https://www.nowozin.net/sebastian/blog/estimating-discrete-entropy-part-1.html"&gt;part one&lt;/a&gt;,
&lt;a href="https://www.nowozin.net/sebastian/blog/estimating-discrete-entropy-part-2.html"&gt;part two&lt;/a&gt;) we looked at the problem of
entropy estimation and several popular estimators.&lt;/p&gt;
&lt;p&gt;In this final article we will take a look at two Bayesian approaches to the
problem.&lt;/p&gt;
&lt;h2&gt;Bayesian Estimator due to Wolpert and Wolf&lt;/h2&gt;
&lt;p&gt;The first Bayesian approach to entropy …&lt;/p&gt;</summary><content type="html">&lt;p&gt;In the last two parts (&lt;a href="https://www.nowozin.net/sebastian/blog/estimating-discrete-entropy-part-1.html"&gt;part one&lt;/a&gt;,
&lt;a href="https://www.nowozin.net/sebastian/blog/estimating-discrete-entropy-part-2.html"&gt;part two&lt;/a&gt;) we looked at the problem of
entropy estimation and several popular estimators.&lt;/p&gt;
&lt;p&gt;In this final article we will take a look at two Bayesian approaches to the
problem.&lt;/p&gt;
&lt;h2&gt;Bayesian Estimator due to Wolpert and Wolf&lt;/h2&gt;
&lt;p&gt;The first Bayesian approach to entropy estimation was proposed by David
Wolpert and David Wolf in 1995 in their paper "Estimating functions of
probability distributions from a finite set of samples", published in Physical
Review E, Vol. 52, No. 6, 1995,
&lt;a href="http://journals.aps.org/pre/abstract/10.1103/PhysRevE.52.6841"&gt;publisher link&lt;/a&gt;, and
a longer &lt;a href="http://www.santafe.edu/media/workingpapers/93-07-046.pdf"&gt;tech report from
1993&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;The idea is simple and elegant Bayesian reasoning: specify a model relating
the known observations to the unknown quantity, then compute the posterior
distribution over the entropy given the observations.&lt;/p&gt;
&lt;p&gt;The model is the following &lt;a href="http://en.wikipedia.org/wiki/Dirichlet-multinomial_distribution"&gt;Dirichlet-Multinomial
model&lt;/a&gt;,
assuming a given non-negative vector &lt;span class="math"&gt;\(\mathbb{\alpha} \in \mathbb{R}^K_+\)&lt;/span&gt;,&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;span class="math"&gt;\(\mathbb{p} \sim \textrm{Dirichlet}(\mathbb{\alpha})\)&lt;/span&gt;,&lt;/li&gt;
&lt;li&gt;&lt;span class="math"&gt;\(x_i \sim \textrm{Categorical}(\mathbb{p})\)&lt;/span&gt;, &lt;span class="math"&gt;\(i=1,\dots,n\)&lt;/span&gt;, iid.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;If we define, for each bin &lt;span class="math"&gt;\(k \in \{1,2,\dots,K\}\)&lt;/span&gt; the count&lt;/p&gt;
&lt;div class="math"&gt;$$n_k = \sum_{i=1}^n 1_{\{x_i = k\}},$$&lt;/div&gt;
&lt;p&gt;so that &lt;span class="math"&gt;\((n_1,n_2,\dots,n_K)\)&lt;/span&gt; is a histogram over &lt;span class="math"&gt;\(K\)&lt;/span&gt; outcomes, which is
distributed according to a multinomial distribution.
Then, due to &lt;a href="http://en.wikipedia.org/wiki/Conjugate_prior"&gt;&lt;em&gt;conjugacy&lt;/em&gt;&lt;/a&gt;, the
posterior over the unknown distribution &lt;span class="math"&gt;\(\mathbb{p}\)&lt;/span&gt; is again a Dirichlet
distribution and given as&lt;/p&gt;
&lt;div class="math"&gt;$$P(\mathbb{p} | x_1,\dots,x_n) = \textrm{Dirichlet}(\alpha_1 + n_1, \dots,
    \alpha_K + n_K).$$&lt;/div&gt;
&lt;p&gt;We can now attempt to compute the squared-error optimal point estimate of the
entropy under this posterior.  One of the main contributions of Wolpert and
Wolf is to provide a family of results that enable moment computations of the
Shannon entropy under the Dirichlet distribution.&lt;/p&gt;
&lt;p&gt;In particular, with &lt;span class="math"&gt;\(n = \sum_{k=1}^K n_k\)&lt;/span&gt; and &lt;span class="math"&gt;\(\alpha = \sum_{k=1}^K
\alpha_k\)&lt;/span&gt;, they provide the posterior mean of the entropy as&lt;/p&gt;
&lt;div class="math"&gt;$$\hat{H}_{\textrm{Bayes}} = \mathbb{E}[H(\mathbb{p}) | n_1,\dots,n_K] =
    \psi(n + \alpha + 1)
    - \sum_{k=1}^K \frac{n_k+\alpha_k}{n+\alpha} \psi(n_k + \alpha_k + 1),$$&lt;/div&gt;
&lt;p&gt;where &lt;span class="math"&gt;\(\psi\)&lt;/span&gt; is the &lt;a href="http://en.wikipedia.org/wiki/Digamma_function"&gt;digamma
function&lt;/a&gt;.
This expression is efficient to compute, and similarly the second moment and
hence the variance of &lt;span class="math"&gt;\(H(p)\)&lt;/span&gt; under the posterior can be computed efficiently.&lt;/p&gt;
&lt;p&gt;The only open question is how to select the prior vector of &lt;span class="math"&gt;\(\mathbb{\alpha}\)&lt;/span&gt;.
In absence of further information about the distribution we can assume
symmetry.
Then there are four common options,&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;span class="math"&gt;\(\alpha_k = 1\)&lt;/span&gt;, due to Bayes in 1763 and Laplace in 1812.&lt;/li&gt;
&lt;li&gt;&lt;span class="math"&gt;\(\alpha_k = 1/K\)&lt;/span&gt;, due to
&lt;a href="http://www.actuaries.org.uk/system/files/documents/pdf/0285-0334.pdf"&gt;Perks in 1947&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;&lt;span class="math"&gt;\(\alpha_k = 1/2\)&lt;/span&gt;, due to Jeffreys in 1946 and 1961.&lt;/li&gt;
&lt;li&gt;&lt;span class="math"&gt;\(\alpha_k = 0\)&lt;/span&gt;, due to Haldane in 1948.  This yields an &lt;a href="http://en.wikipedia.org/wiki/Prior_probability#Improper_priors"&gt;improper
prior&lt;/a&gt;.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;It may not be clear which choice is the best, but I found an interesting
discussion in a paper by &lt;a href="http://www.aaai.org/ocs/index.php/IJCAI/IJCAI11/paper/viewFile/3292/3802"&gt;de Campos and
Benavoli&lt;/a&gt;.
Further down in this article we will be better equiped to assess the above
choices.&lt;/p&gt;
&lt;p&gt;Independent of the choice of the prior parameter Wolpert and Wolf are very
optimistic about their model and highlight the advantages that come from the
Bayesian approach:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;"One of the strength of Bayesian analysis is its power for dealing with such
small-data cases.  In particular, not only are Bayesian estimators in many
respects more 'reasonable' than non-Bayesian estimators for small data, they
also naturally provide error bars to govern one's use of their results.
...
In addition, the Bayesian formalism automatically tells you when it is unsure
of its estimate, through its error bars."&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Also, on the empirical performance they comment,&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;"... for all N the Bayes estimator has a smaller mean-squared error than the
frequency-counts estimator."&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;And indeed, also asymptotically the prior has support for every possible
distribution, so consistency of the estimated entropy is guaranteed as
&lt;span class="math"&gt;\(n\to\infty\)&lt;/span&gt;.&lt;/p&gt;
&lt;p&gt;All good then?&lt;/p&gt;
&lt;p&gt;Here is the comparison of the squared error and bias of various Bayes
estimators with different choices of prior &lt;span class="math"&gt;\(\alpha\)&lt;/span&gt;.  The plot shows, like in
the previous article, the performance when evaluated on data generated from a
&lt;em&gt;different&lt;/em&gt; Dirichlet prior.  Each value on the x-axis is a different
generating distribution, but the prior of the estimator remains fixed.&lt;/p&gt;
&lt;p&gt;&lt;img alt="RMSE and bias experiments for different alpha
hyperparameters" src="https://www.nowozin.net/sebastian/blog/images/entropy-estimation-3-exp.svg"&gt;&lt;/p&gt;
&lt;p&gt;While all of the Bayes estimators perform better than the plugin estimator,
overall they all fare quite badly:
there is a low error and bias only at the matching &lt;span class="math"&gt;\(\alpha\)&lt;/span&gt; value, but they
deteriorate quickly at different values of &lt;span class="math"&gt;\(\alpha\)&lt;/span&gt;.&lt;/p&gt;
&lt;p&gt;How can this be the case?&lt;/p&gt;
&lt;h2&gt;Nemenman-Shafee-Bialek&lt;/h2&gt;
&lt;p&gt;In 2002 &lt;a href="http://arxiv.org/abs/physics/0108025"&gt;Nemenman, Shafee, and Bialek&lt;/a&gt;
recognized that the innocent looking Dirichlet-Multinomial model implies a
very concentrated prior belief over the entropy of the distribution:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;"Thus a seemingly innocent choice of the prior ... leads to a disaster:
fixing &lt;span class="math"&gt;\(\alpha\)&lt;/span&gt; specifies the entropy almost uniquely. Furthermore, the
situation persists even after we observe some data: until the distribution
is well sampled, our estimate of the entropy is dominated by the prior!"&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3&gt;The Implied Beliefs over the Entropy&lt;/h3&gt;
&lt;p&gt;The following experiment visualizes this: each of the following histograms
shows the &lt;em&gt;implied prior&lt;/em&gt; over &lt;span class="math"&gt;\(H(\mathbb{p})\)&lt;/span&gt;.
To create each histogram, I fixed &lt;span class="math"&gt;\(K\)&lt;/span&gt; and &lt;span class="math"&gt;\(\alpha\)&lt;/span&gt; and take 1,000,000 samples
of distributions &lt;span class="math"&gt;\(\mathbb{p}\)&lt;/span&gt;, then record its entropy.
In each histogram plot the x-axis covers exactly the full range over
possible entropies.&lt;/p&gt;
&lt;p&gt;&lt;img alt="Induced prior on the entropy, K=2" src="https://www.nowozin.net/sebastian/blog/images/entropy-estimation-3-prior-K2.svg"&gt;&lt;/p&gt;
&lt;p&gt;For the case &lt;span class="math"&gt;\(K=2\)&lt;/span&gt; everything looks fine: the implied prior spreads well over
the entire range of possible entropies.
But look what happens for &lt;span class="math"&gt;\(K=10\)&lt;/span&gt; and &lt;span class="math"&gt;\(K=100\)&lt;/span&gt;:&lt;/p&gt;
&lt;p&gt;&lt;img alt="Induced prior on the entropy, K=10" src="https://www.nowozin.net/sebastian/blog/images/entropy-estimation-3-prior-K10.svg"&gt;
&lt;img alt="Induced prior on the entropy, K=100" src="https://www.nowozin.net/sebastian/blog/images/entropy-estimation-3-prior-K100.svg"&gt;&lt;/p&gt;
&lt;p&gt;Here, the implied prior clearly concentrates sharply.  (The least possible
concentration of the entropy can be achieved using Perks choice of &lt;span class="math"&gt;\(\alpha =
1/K\)&lt;/span&gt;.)
In fact, there is no choice of &lt;span class="math"&gt;\(\alpha\)&lt;/span&gt; for which the prior belief over the
very quantity to be estimated does not concentrate as &lt;span class="math"&gt;\(K \to \infty\)&lt;/span&gt;.
If we have no reason to believe that the entropy really is in the range where
the prior dictates it should be, then this is a bad prior.&lt;/p&gt;
&lt;p&gt;How did Nemenman, Shafee, and Bialek solve this problem?&lt;/p&gt;
&lt;h2&gt;NSB estimator&lt;/h2&gt;
&lt;p&gt;They construct a mixture-of-Dirichlet prior by defining a hyperprior on
&lt;span class="math"&gt;\(\alpha\)&lt;/span&gt; itself.  The hyperprior &lt;span class="math"&gt;\(P(\alpha)\)&lt;/span&gt; is chosen such that&lt;/p&gt;
&lt;div class="math"&gt;$$P(\alpha) \propto \frac{\textrm{d} \mathbb{E}[H|\alpha]}{\textrm{d} \alpha}.$$&lt;/div&gt;
&lt;p&gt;Let us take a look at how this can be derived.
Nemenman and collaborators first show that under the Dirichlet-Multinomial
model the expected entropy is a strictly monotonic continuous function in
&lt;span class="math"&gt;\(\alpha\)&lt;/span&gt;, and therefore it is invertible.
Let us define the shorthand &lt;span class="math"&gt;\(g^{-1}(\alpha) := \mathbb{E}[H|\alpha]\)&lt;/span&gt; as the function
that takes &lt;span class="math"&gt;\(\alpha\)&lt;/span&gt; to the expected entropy.
Now, by the &lt;a href="http://en.wikipedia.org/wiki/Random_variable#Functions_of_random_variables"&gt;transformation formula for random
vairables&lt;/a&gt;,
we have the induced density&lt;/p&gt;
&lt;div class="math"&gt;$$P_{\alpha}(\alpha) = P_H(g^{-1}(\alpha))
    \cdot \left|\frac{\textrm{d} g^{-1}(\alpha)}{\textrm{d} \alpha}\right|.$$&lt;/div&gt;
&lt;p&gt;If we assume that &lt;span class="math"&gt;\(P(H|\alpha)\)&lt;/span&gt; is highly concentrated (at least for large &lt;span class="math"&gt;\(K\)&lt;/span&gt;
in the above plots, this holds), then
&lt;span class="math"&gt;\(P_H(g^{-1}(\alpha)) \approx P(H|\alpha)\)&lt;/span&gt;, and we want this density to be
constant.  Hence, we have&lt;/p&gt;
&lt;div class="math"&gt;$$P_{\alpha}(\alpha) \propto
    \left|\frac{\textrm{d} g^{-1}(\alpha)}{\textrm{d} \alpha}\right|.$$&lt;/div&gt;
&lt;p&gt;Because the right hand side is positive, with &lt;span class="math"&gt;\(g^{-1}(\alpha) =
\mathbb{E}[H|\alpha]\)&lt;/span&gt; this yields exactly the original expression above.
This expression has an analytic solution which, properly normalized is&lt;/p&gt;
&lt;div class="math"&gt;$$P(\alpha) = \frac{1}{\log K} \left(K \psi_1(K \alpha + 1)
    - \psi_1(\alpha+1)\right),$$&lt;/div&gt;
&lt;p&gt;where &lt;span class="math"&gt;\(\psi_1\)&lt;/span&gt; is the &lt;a href="http://en.wikipedia.org/wiki/Trigamma_function"&gt;trigamma
function&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;img alt="NSB Dirichlet-mixture prior for entropy estimation, K=2,10, and
100" src="https://www.nowozin.net/sebastian/blog/images/entropy-estimation-3-nsb.svg"&gt;&lt;/p&gt;
&lt;p&gt;Let us look at the &lt;em&gt;implied prior&lt;/em&gt; of the entropy when using the NSB prior.
They are much more uniform now:&lt;/p&gt;
&lt;p&gt;&lt;img alt="Implied entropy beliefs when using the NSB Dirichlet-mixture prior, K=2,10, and
100" src="https://www.nowozin.net/sebastian/blog/images/entropy-estimation-3-nsb-entropy-hist.svg"&gt;&lt;/p&gt;
&lt;p&gt;This uniformity results in the NSB estimator having excellent robustness
properties and small bias.  It is probably the best general purpose discrete
entropy estimator available.
One drawback however is the increased computational cost: in order to compute
the estimator we need to solve a 1D integral numerically over &lt;span class="math"&gt;\(\alpha\)&lt;/span&gt;.
Each pointwise evaluation of the integrand function corresponds to computing
&lt;span class="math"&gt;\(\hat{H}_{\textrm{Bayes}}\)&lt;/span&gt; for a fixed value of &lt;span class="math"&gt;\(\alpha\)&lt;/span&gt;.
High accuracy requires several hundred such evaluations, and this may be
prohibitively expensive in some applications (for example, decision tree
induction). &lt;/p&gt;
&lt;h3&gt;Addendum: Undersampled Regime&lt;/h3&gt;
&lt;p&gt;After a comment from Ilya Nemenman on the previous version of this article, I
also did an experiment in the undersampled regime (&lt;span class="math"&gt;\(N &amp;lt; K\)&lt;/span&gt;), where we observe
fewer outcomes than there are bins.  I am glad I did perform this experiment!&lt;/p&gt;
&lt;p&gt;I select &lt;span class="math"&gt;\(N=100\)&lt;/span&gt; and &lt;span class="math"&gt;\(K=2000\)&lt;/span&gt;, with &lt;span class="math"&gt;\(500\)&lt;/span&gt; replicates and compare the same
methods as in the second part of the article.  The results are as follows.&lt;/p&gt;
&lt;p&gt;&lt;img alt="RMSE and bias experiments for undersampled
regime" src="https://www.nowozin.net/sebastian/blog/images/entropy-estimation-3-undersampled-exp.svg"&gt;&lt;/p&gt;
&lt;p&gt;Almost all estimators perform very poorly in this setting, with the naive
Miller correction even being off the chart.
Only the NSB and the Hausser-Strimmer estimator can be considered usable in
this severely undersampled regime, with clear preference towards the NSB
estimator.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.physics.emory.edu/home/people/faculty/nemenman-ilya.html"&gt;Ilya
Nemenman&lt;/a&gt;,
the inventor of the NSB estimator, was kind enough to share his feedback on
these experiments with me and to allow me to post them here:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;I am glad to hear that NSB estimator did well on this test. It's also not
surprising that HS estimator did rather well too -- in some sense, it's a
frequentist version of NSB. Both NSB and HS perform shrinking towards the
uniform distribution (infinite pseudocounts or "alpha" in your notation),
and then they lift the shrinkage as &lt;span class="math"&gt;\(N\)&lt;/span&gt; grows. However, HS shrinks much
stronger than NSB does. As a result, HS performs very well for large entropy
(large alpha) distributions, and worse for lower entropies. It's probably
possible to set up a frequentist shrinkage estimator that would shrink
towards entropy being half of the maximum value, or shrink towards the
maximum value, but less strongly than HS — I think that such an estimator
would do better over the whole range of alpha. In practice, the strong
shrinkage imposed by HS becomes problematic when the alphabet size is very
large, say &lt;span class="math"&gt;\(2^{150}\)&lt;/span&gt;, which is what one gets when one takes a 30ms long
spike train and discretizes it at 0.2 ms resolution (yes spike = 1, no spike
=0). We had numbers like this in our 2008 PLoS Comp Bio paper. With entropy
of &lt;span class="math"&gt;\(\approx 15\)&lt;/span&gt; bits, alphabet size of &lt;span class="math"&gt;\(2^{150}\)&lt;/span&gt;, and 100-1000 samples, NSB
may work (more on this below), and HS will shrink towards 150 bits, and will
likely overestimate. One way to see this problem is to realize that, in your
comparison plots, once you use &lt;span class="math"&gt;\(\alpha &amp;gt; 1\)&lt;/span&gt;, the entropy
is nearly the maximum possible entropy. This is why HS works well there, but
fails for &lt;span class="math"&gt;\(\alpha \ll 1\)&lt;/span&gt;, where the entropy is substantially smaller than the
maximum. If you were to replot the data putting the true entropy of the
analyzed probability distribution (rather than alpha) on the horizontal
axis, this will be visible, I think.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;He continues,&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;A key point for both NSB and HS is that both may work in the regime of
&lt;span class="math"&gt;\(N \sim \sqrt{K}\)&lt;/span&gt; (better yet, &lt;span class="math"&gt;\(\sim \sqrt{2^{H/2}}\)&lt;/span&gt;). On the contrary,
most other estimators you analyzed work well only up to &lt;span class="math"&gt;\(N \sim 2^H\)&lt;/span&gt; (unless
I am missing something important). This is because NSB and HS require not
good sampling of the underlying distribution, but coincidences in the data
only. They estimate entropy, effectively, by inverting the usual birthday
paradox, and using the frequency of coincidences to measure the diversity of
data. One can illustrate this by pushing &lt;span class="math"&gt;\(K\)&lt;/span&gt; to even larger values in your
last plot, 10000 or even more, if you limit yourself to smaller alpha.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;These comments are very insightful and show that my earlier discussion and
results were, in a way, limited to the simple case where we have a reasonable
number of samples per bin.  The case Ilya considers in his work is the
severely undersampled regime.&lt;/p&gt;
&lt;p&gt;One difficulty in producing the plot he suggests that plots the entropy of the
distribution along the x-axis is that it would require an additional binning
operation along that axis, so I have not produced this plot yet.&lt;/p&gt;
&lt;h3&gt;Reference Prior, Anyone?&lt;/h3&gt;
&lt;p&gt;I wonder whether the NSB prior is a simplification of a full &lt;a href="http://projecteuclid.org/euclid.aos/1236693154"&gt;reference
prior&lt;/a&gt;
treatment.  This is not exactly the standard setting of reference priors
because we are interested in a function (the entropy) of our random variables,
so there is an additional indirection.  But I believe it could work as
follows: find in the space of all priors on &lt;span class="math"&gt;\(\alpha\)&lt;/span&gt; the prior that maximizes
the KL divergence between implied entropy prior and entropy posterior.&lt;/p&gt;
&lt;p&gt;Using the numerical method suggested in the paper above, I obtained a
numerical reference prior (with one additional ABC approximation for the
likelihood) for &lt;span class="math"&gt;\(K=2\)&lt;/span&gt; and this closely matches the NSB prior.&lt;/p&gt;
&lt;p&gt;&lt;img alt="Numerically obtained reference prior for K=2" src="https://www.nowozin.net/sebastian/blog/images/entropy-estimation-3-refprior.svg"&gt;&lt;/p&gt;
&lt;p&gt;(Interestingly, I recently discovered this work
on &lt;a href="http://projecteuclid.org/euclid.ba/1422556416"&gt;overall objective priors&lt;/a&gt;
in which their &lt;em&gt;hierarchical reference prior&lt;/em&gt; approach for the
Dirichlet-Multinomial model yields an analytic proper prior which is very
similar to the NSB and numerical reference priors.)&lt;/p&gt;
&lt;h3&gt;Further Reading&lt;/h3&gt;
&lt;p&gt;As you hopefully have noticed, the problem of discrete entropy estimation is
quite rich and still actively being worked on.
Current work focuses on the case where the distribution is countably infinite.
For example, the probability distribution of English words in popular usage is
an example: there are infinitely many possible words, but a total lexical
order implies a countable discrete distribution.&lt;/p&gt;
&lt;p&gt;A great up-to-date overview of discrete entropy estimation, including a
summary of the current work on the countable infinite case is given in this
&lt;a href="https://memming.wordpress.com/2014/02/09/a-guide-to-discrete-entropy-estimators/"&gt;article&lt;/a&gt;
by &lt;a href="http://www.memming.com/"&gt;Memming Park&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;To a general introduction to the difficulties of the entropy estimation
problem, this
&lt;a href="http://stat.columbia.edu/~liam/research/pubs/info_est-nc.pdf"&gt;2003 paper&lt;/a&gt; by
&lt;a href="http://www.stat.columbia.edu/~liam/"&gt;Liam Paninski&lt;/a&gt; is still the best entry
point.
Another &lt;a href="http://arxiv.org/abs/cond-mat/0403192"&gt;very nice overview on entropy
estimation&lt;/a&gt; is due to Thomas Sch&amp;uuml;rmann
in 2004.
To me the best introduction to the family of Bayesian estimators is &lt;a href="http://arxiv.org/abs/1302.0328"&gt;(Archer,
Park, Pillow, 2013)&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;If you wonder why I care about entropy estimation, then, &lt;a href="http://www.nowozin.net/sebastian/papers/nowozin2012infogain.pdf"&gt;my ICML 2012
paper&lt;/a&gt; was
the application that originally led me to consider the problem.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Acknowledgements&lt;/em&gt;.  I thank &lt;a href="http://www.memming.com/"&gt;Il Memming Park&lt;/a&gt;,
&lt;a href="http://ei.is.tuebingen.mpg.de/person/jpeters"&gt;Jonas Peters&lt;/a&gt;, and
&lt;a href="http://www.physics.emory.edu/home/people/faculty/nemenman-ilya.html"&gt;Ilya Nemenman&lt;/a&gt;
for reading a draft version of the article and providing very helpful feedback.&lt;/p&gt;
&lt;script type="text/javascript"&gt;if (!document.getElementById('mathjaxscript_pelican_#%@#$@#')) {
    var align = "center",
        indent = "0em",
        linebreak = "false";

    if (false) {
        align = (screen.width &lt; 768) ? "left" : align;
        indent = (screen.width &lt; 768) ? "0em" : indent;
        linebreak = (screen.width &lt; 768) ? 'true' : linebreak;
    }

    var mathjaxscript = document.createElement('script');
    mathjaxscript.id = 'mathjaxscript_pelican_#%@#$@#';
    mathjaxscript.type = 'text/javascript';
    mathjaxscript.src = 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.3/latest.js?config=TeX-AMS-MML_HTMLorMML';

    var configscript = document.createElement('script');
    configscript.type = 'text/x-mathjax-config';
    configscript[(window.opera ? "innerHTML" : "text")] =
        "MathJax.Hub.Config({" +
        "    config: ['MMLorHTML.js']," +
        "    TeX: { extensions: ['AMSmath.js','AMSsymbols.js','noErrors.js','noUndefined.js'], equationNumbers: { autoNumber: 'none' } }," +
        "    jax: ['input/TeX','input/MathML','output/HTML-CSS']," +
        "    extensions: ['tex2jax.js','mml2jax.js','MathMenu.js','MathZoom.js']," +
        "    displayAlign: '"+ align +"'," +
        "    displayIndent: '"+ indent +"'," +
        "    showMathMenu: true," +
        "    messageStyle: 'normal'," +
        "    tex2jax: { " +
        "        inlineMath: [ ['\\\\(','\\\\)'] ], " +
        "        displayMath: [ ['$$','$$'] ]," +
        "        processEscapes: true," +
        "        preview: 'TeX'," +
        "    }, " +
        "    'HTML-CSS': { " +
        "        availableFonts: ['STIX', 'TeX']," +
        "        preferredFont: 'STIX'," +
        "        styles: { '.MathJax_Display, .MathJax .mo, .MathJax .mi, .MathJax .mn': {color: 'inherit ! important'} }," +
        "        linebreaks: { automatic: "+ linebreak +", width: '90% container' }," +
        "    }, " +
        "}); " +
        "if ('default' !== 'default') {" +
            "MathJax.Hub.Register.StartupHook('HTML-CSS Jax Ready',function () {" +
                "var VARIANT = MathJax.OutputJax['HTML-CSS'].FONTDATA.VARIANT;" +
                "VARIANT['normal'].fonts.unshift('MathJax_default');" +
                "VARIANT['bold'].fonts.unshift('MathJax_default-bold');" +
                "VARIANT['italic'].fonts.unshift('MathJax_default-italic');" +
                "VARIANT['-tex-mathit'].fonts.unshift('MathJax_default-italic');" +
            "});" +
            "MathJax.Hub.Register.StartupHook('SVG Jax Ready',function () {" +
                "var VARIANT = MathJax.OutputJax.SVG.FONTDATA.VARIANT;" +
                "VARIANT['normal'].fonts.unshift('MathJax_default');" +
                "VARIANT['bold'].fonts.unshift('MathJax_default-bold');" +
                "VARIANT['italic'].fonts.unshift('MathJax_default-italic');" +
                "VARIANT['-tex-mathit'].fonts.unshift('MathJax_default-italic');" +
            "});" +
        "}";

    (document.body || document.getElementsByTagName('head')[0]).appendChild(configscript);
    (document.body || document.getElementsByTagName('head')[0]).appendChild(mathjaxscript);
}
&lt;/script&gt;</content><category term="Statistics"/></entry><entry><title>Machine Learning in Cambridge 2015</title><link href="https://www.nowozin.net/sebastian/blog/machine-learning-in-cambridge-2015.html" rel="alternate"/><published>2015-02-26T20:00:00+00:00</published><updated>2015-02-26T20:00:00+00:00</updated><author><name>Sebastian Nowozin</name></author><id>tag:www.nowozin.net,2015-02-26:/sebastian/blog/machine-learning-in-cambridge-2015.html</id><summary type="html">&lt;p&gt;This year we (&lt;a href="http://mlg.eng.cam.ac.uk/zoubin/"&gt;Zoubin&lt;/a&gt;, together with
&lt;a href="http://lopezpaz.org/"&gt;David&lt;/a&gt; and myself) are again organizing a workshop
event for the local Cambridge (UK) machine learning community.
The schedule is available at the workshop homepage,
&lt;a href="http://research.microsoft.com/en-us/um/cambridge/events/CamML2015/"&gt;Machine Learning in Cambridge
2015&lt;/a&gt;, and
we also plan to make all talks available as video recordings after the …&lt;/p&gt;</summary><content type="html">&lt;p&gt;This year we (&lt;a href="http://mlg.eng.cam.ac.uk/zoubin/"&gt;Zoubin&lt;/a&gt;, together with
&lt;a href="http://lopezpaz.org/"&gt;David&lt;/a&gt; and myself) are again organizing a workshop
event for the local Cambridge (UK) machine learning community.
The schedule is available at the workshop homepage,
&lt;a href="http://research.microsoft.com/en-us/um/cambridge/events/CamML2015/"&gt;Machine Learning in Cambridge
2015&lt;/a&gt;, and
we also plan to make all talks available as video recordings after the event.&lt;/p&gt;
&lt;p&gt;See you at the event!&lt;/p&gt;</content><category term="Machine Learning"/></entry><entry><title>Estimating Discrete Entropy, Part 2</title><link href="https://www.nowozin.net/sebastian/blog/estimating-discrete-entropy-part-2.html" rel="alternate"/><published>2015-02-21T19:00:00+00:00</published><updated>2015-02-21T19:00:00+00:00</updated><author><name>Sebastian Nowozin</name></author><id>tag:www.nowozin.net,2015-02-21:/sebastian/blog/estimating-discrete-entropy-part-2.html</id><summary type="html">&lt;p&gt;In the &lt;a href="https://www.nowozin.net/sebastian/blog/estimating-discrete-entropy-part-1.html"&gt;last part&lt;/a&gt; we have looked at the
basic problem of discrete entropy estimation.
In this article we will see a number of proposals of improved estimators.&lt;/p&gt;
&lt;h3&gt;Miller Correction&lt;/h3&gt;
&lt;p&gt;In 1955 George Miller proposed a simple correction to the naive plugin
estimator &lt;span class="math"&gt;\(\hat{H}_N\)&lt;/span&gt; by adding the constant …&lt;/p&gt;</summary><content type="html">&lt;p&gt;In the &lt;a href="https://www.nowozin.net/sebastian/blog/estimating-discrete-entropy-part-1.html"&gt;last part&lt;/a&gt; we have looked at the
basic problem of discrete entropy estimation.
In this article we will see a number of proposals of improved estimators.&lt;/p&gt;
&lt;h3&gt;Miller Correction&lt;/h3&gt;
&lt;p&gt;In 1955 George Miller proposed a simple correction to the naive plugin
estimator &lt;span class="math"&gt;\(\hat{H}_N\)&lt;/span&gt; by adding the constant offset in the bias expression as
follows.&lt;/p&gt;
&lt;div class="math"&gt;$$\hat{H}_M = \hat{H}_N + \frac{K-1}{2n}.$$&lt;/div&gt;
&lt;p&gt;This is an improvement over the plugin estimator but the added offset does not
depend on the distribution but only on the sample size.  We can do better.&lt;/p&gt;
&lt;p&gt;(A variant of the Miller estimator for the infinite alphabet case is the so
called Miller-Madow estimator in which the quantity &lt;span class="math"&gt;\(K\)&lt;/span&gt; is estimated from the
data as well.)&lt;/p&gt;
&lt;h3&gt;Jackknife Estimator&lt;/h3&gt;
&lt;p&gt;A classic method for bias correction is the
&lt;a href="http://en.wikipedia.org/wiki/Jackknife_resampling"&gt;jackknife&lt;/a&gt; &lt;a href="http://en.wikipedia.org/wiki/Resampling_(statistics)"&gt;resampling
method&lt;/a&gt; due to
&lt;a href="http://www.jstor.org/discover/10.2307/2332914"&gt;(Quenouille, 1947)&lt;/a&gt;, although
the somewhat catchy name is due to &lt;a href="http://en.wikipedia.org/wiki/John_Tukey"&gt;John
Tukey&lt;/a&gt;.
(The literature on the jackknife methodology is quite classic now.  A very
readable modern summary of the jackknife methodology can be found in
&lt;a href="http://www.stat.purdue.edu/~dasgupta/"&gt;DasGupta's&lt;/a&gt;
&lt;a href="http://www.springer.com/mathematics/probability/book/978-0-387-75970-8"&gt;book&lt;/a&gt;.
An older but still readable introduction is &lt;a href="http://biomet.oxfordjournals.org/content/61/1/1.short"&gt;(Miller,
1974)&lt;/a&gt;,
&lt;a href="http://www.csee.wvu.edu/~xinl/library/papers/math/statistics/jackknife.pdf"&gt;PDF&lt;/a&gt;.)&lt;/p&gt;
&lt;p&gt;In a nutshell, jackknife resampling methods are used to estimate bias and
variance of estimators.  They are typically simple to implement,
and often computationally cheaper than the bootstrap.
For the bias reduction application, they often manage to reduce bias
considerably, often knocking the bias down to &lt;span class="math"&gt;\(O(n^{-2})\)&lt;/span&gt;.&lt;/p&gt;
&lt;p&gt;The use of jackknife bias estimation to improve entropy estimation was
suggested by &lt;a href="http://www.jstor.org/discover/10.2307/1936227"&gt;(Zahl, 1977)&lt;/a&gt;.
The jackknife bias-corrected estimator of the plugin estimator is given as
follows.&lt;/p&gt;
&lt;div class="math"&gt;\begin{equation}
    \hat{H}_{J} = n \hat{H}_N - (n-1) \hat{H}^{(\cdot)}_N.
    \label{H:jackknife}
\end{equation}&lt;/div&gt;
&lt;p&gt;The quantity &lt;span class="math"&gt;\(\hat{H}^{(\cdot)}_N\)&lt;/span&gt; is the average of &lt;span class="math"&gt;\(n\)&lt;/span&gt; estimates
obtained by leaving out a single observation.  Thus, writing
&lt;span class="math"&gt;\(\mathbb{h}=(h_1,\dots,h_K)\)&lt;/span&gt; for the histogram of bin counts on the full
sample, and &lt;span class="math"&gt;\(\mathbb{h}_{\setminus i}\)&lt;/span&gt; for the histogram with the count in
&lt;span class="math"&gt;\(X_i=k\)&lt;/span&gt; reduced by one, we have&lt;/p&gt;
&lt;div class="math"&gt;$$\hat{H}^{\setminus i}_N := \hat{H}_N(\mathbb{h}_{\setminus i}),$$&lt;/div&gt;
&lt;p&gt;and the mean of these quantities,&lt;/p&gt;
&lt;div class="math"&gt;$$\hat{H}^{(\cdot)}_N :=
    \frac{1}{n} \sum_{i=1}^n \hat{H}^{\setminus i}_N.$$&lt;/div&gt;
&lt;p&gt;Interestingly, normally it would be expensive to compute &lt;span class="math"&gt;\(n\)&lt;/span&gt; leave-one-out
estimates.  Here however, two tricks are possible: First, because the
histogram is a sufficient statistic, we need to compute only &lt;span class="math"&gt;\(K\)&lt;/span&gt; holdout
estimates instead of &lt;span class="math"&gt;\(n\)&lt;/span&gt;.  Second, one can interleave computation in such a
way that computing each holdout estimate is &lt;span class="math"&gt;\(O(1)\)&lt;/span&gt;, reducing the overall
computation of &lt;span class="math"&gt;\((\ref{H:jackknife})\)&lt;/span&gt; to &lt;span class="math"&gt;\(O(K)\)&lt;/span&gt; runtime and no additional
memory over the plugin estimate.  In essence, the computational complexity is
comparable to that of the inexpensive plugin estimate, making the jackknife
estimator computationally cheap.&lt;/p&gt;
&lt;h3&gt;Grassberger Estimator&lt;/h3&gt;
&lt;p&gt;Another proposal for an improved estimator is due to
&lt;a href="http://www.ucalgary.ca/complexity/people/faculty/peter"&gt;Peter Grassberger&lt;/a&gt;.
In &lt;a href="http://arxiv.org/abs/physics/0307138"&gt;(Grassberger, 2003)&lt;/a&gt;
he derives two estimators based on an argument using analytic continuation
which I have to admit is somewhat beyond my grasp.
The better of the two estimators is the following:&lt;/p&gt;
&lt;div class="math"&gt;$$\hat{H}_G = \log n - \frac{1}{n} \sum_{k=1}^K h_k G(h_k),$$&lt;/div&gt;
&lt;p&gt;where the logarithm of the original naive estimator &lt;span class="math"&gt;\(\hat{H}_N\)&lt;/span&gt; have been
replaced by a scalar function &lt;span class="math"&gt;\(G\)&lt;/span&gt;, defined as&lt;/p&gt;
&lt;div class="math"&gt;$$G(h) = \psi(h) + \frac{1}{2} (-1)^{h}
    \left(\psi(\frac{h+1}{2}) - \psi(\frac{h}{2})\right).$$&lt;/div&gt;
&lt;p&gt;The function &lt;span class="math"&gt;\(\psi\)&lt;/span&gt; is the &lt;a href="http://en.wikipedia.org/wiki/Digamma_function"&gt;digamma
function&lt;/a&gt;.
(The function &lt;span class="math"&gt;\(G(h)\)&lt;/span&gt; is the solution of &lt;span class="math"&gt;\(G(h)=\psi(h)+(-1)^h \int^1_0
\frac{x^{h-1}}{x+1} \textrm{d}x\)&lt;/span&gt; given as equation &lt;span class="math"&gt;\((30)\)&lt;/span&gt; in &lt;a href="http://arxiv.org/pdf/physics/0307138v2.pdf"&gt;the
paper&lt;/a&gt;.)
Computationally this estimator is almost as efficient as the original plugin
estimator, because for integer arguments the digamma function can be
accurately approximated by an &lt;a href="http://en.wikipedia.org/wiki/Digamma_function#Computation_and_approximation"&gt;efficient series
expansion&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;When compared to the plugin estimator (in &lt;a href="https://www.nowozin.net/sebastian/blog/estimating-discrete-entropy-part-1.html"&gt;histogram count
form&lt;/a&gt;), we can see an upwards
correction of this estimator but also an interesting difference between even
and odd histogram counts.&lt;/p&gt;
&lt;p&gt;&lt;img alt="xlogx compared to xGx" src="https://www.nowozin.net/sebastian/blog/images/entropy-estimation-2-gb.svg"&gt;&lt;/p&gt;
&lt;p&gt;Unfortunately, the original derivation in Grassberger's paper is quite
involved and beyond my full understanding.
However, for practical purposes, among the computationally efficient
estimators, the 2003 Grassberger estimator is probably the most useful and
robust estimator.&lt;/p&gt;
&lt;h2&gt;Experiment&lt;/h2&gt;
&lt;p&gt;The following plots show a simple evaluation of some popular discrete entropy
estimators.  We assume a categorical distribution with &lt;span class="math"&gt;\(K=64\)&lt;/span&gt; outcomes with
the probability vector &lt;span class="math"&gt;\(\mathbb{p}\)&lt;/span&gt; sampled from a symmetric Dirichlet
distribution with hyperparameter &lt;span class="math"&gt;\(\alpha \in [0.25,5.0]\)&lt;/span&gt;.
We obtain &lt;span class="math"&gt;\(n=100\)&lt;/span&gt; samples from the distribution and estimate the entropy based
on this sample.  For each &lt;span class="math"&gt;\(\alpha\)&lt;/span&gt; we repeat this procedure 5,000 times to
estimate the root mean squared error (RMSE) and bias.&lt;/p&gt;
&lt;p&gt;We plot all the estimators discussed above, but also plot four additional
estimators:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://arxiv.org/abs/0811.3579"&gt;Hausser-Strimmer estimator&lt;/a&gt;, based on
a shrinkage estimate,&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.martinvinck.com/page2/assets/PRE_entropy00_subm_rev_00.pdf"&gt;Polynomial estimator&lt;/a&gt;
due to Vinck et al.; this is equivalent to &lt;a href="http://math2.uncc.edu/~zzhang/papers/ZhangNUCO2012.pdf"&gt;Zhiyi Zhang's
estimator&lt;/a&gt;,
but numerically simpler and more stable to evaluate.  (I only mention this
here because I have not found this mentioned elsewhere.)&lt;/li&gt;
&lt;li&gt;Two Bayesian estimators (Bayes and NSB), to be discussed in the next post.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;img alt="RMSE and bias experiments for seven different discrete entropy
estimators" src="https://www.nowozin.net/sebastian/blog/images/entropy-estimation-2-exp.svg"&gt;&lt;/p&gt;
&lt;p&gt;These experiments are not fully representative because the Dirichlet prior
makes assumptions which may not be satisfied in your application; in
particular, this experiment considers the well-sampled case (&lt;span class="math"&gt;\(N &amp;gt; K\)&lt;/span&gt;), and
simple bias correction methods work well in this regime (this was pointed out
to me by Ilya and Jonas); however, some clear trends are visible:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The Plugin estimator fares badly on both RMSE and bias;&lt;/li&gt;
&lt;li&gt;The Miller estimator fares less badly, suggesting RMSE is affected mainly by
bias, however, significant errors remain for small values of &lt;span class="math"&gt;\(\alpha\)&lt;/span&gt;;&lt;/li&gt;
&lt;li&gt;The Bayes estimator fares almost as bad as the plugin estimator, except for
&lt;span class="math"&gt;\(\alpha=1/2\)&lt;/span&gt;.  More on this point in the next post;&lt;/li&gt;
&lt;li&gt;The Jackknife, Grassberger 2003, and NSB estimators provide excellent
performance throughout the whole range of &lt;span class="math"&gt;\(\alpha\)&lt;/span&gt; values.&lt;/li&gt;
&lt;li&gt;The performance of the Polynomial and Hausser estimates are mediocre.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;In the next part we will be looking at Bayesian estimators.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Acknowledgements&lt;/em&gt;.  I thank &lt;a href="http://www.memming.com/"&gt;Il Memming Park&lt;/a&gt;,
&lt;a href="http://ei.is.tuebingen.mpg.de/person/jpeters"&gt;Jonas Peters&lt;/a&gt;, and
&lt;a href="http://www.physics.emory.edu/home/people/faculty/nemenman-ilya.html"&gt;Ilya Nemenman&lt;/a&gt;
for reading a draft version of the article and providing very helpful feedback.&lt;/p&gt;
&lt;script type="text/javascript"&gt;if (!document.getElementById('mathjaxscript_pelican_#%@#$@#')) {
    var align = "center",
        indent = "0em",
        linebreak = "false";

    if (false) {
        align = (screen.width &lt; 768) ? "left" : align;
        indent = (screen.width &lt; 768) ? "0em" : indent;
        linebreak = (screen.width &lt; 768) ? 'true' : linebreak;
    }

    var mathjaxscript = document.createElement('script');
    mathjaxscript.id = 'mathjaxscript_pelican_#%@#$@#';
    mathjaxscript.type = 'text/javascript';
    mathjaxscript.src = 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.3/latest.js?config=TeX-AMS-MML_HTMLorMML';

    var configscript = document.createElement('script');
    configscript.type = 'text/x-mathjax-config';
    configscript[(window.opera ? "innerHTML" : "text")] =
        "MathJax.Hub.Config({" +
        "    config: ['MMLorHTML.js']," +
        "    TeX: { extensions: ['AMSmath.js','AMSsymbols.js','noErrors.js','noUndefined.js'], equationNumbers: { autoNumber: 'none' } }," +
        "    jax: ['input/TeX','input/MathML','output/HTML-CSS']," +
        "    extensions: ['tex2jax.js','mml2jax.js','MathMenu.js','MathZoom.js']," +
        "    displayAlign: '"+ align +"'," +
        "    displayIndent: '"+ indent +"'," +
        "    showMathMenu: true," +
        "    messageStyle: 'normal'," +
        "    tex2jax: { " +
        "        inlineMath: [ ['\\\\(','\\\\)'] ], " +
        "        displayMath: [ ['$$','$$'] ]," +
        "        processEscapes: true," +
        "        preview: 'TeX'," +
        "    }, " +
        "    'HTML-CSS': { " +
        "        availableFonts: ['STIX', 'TeX']," +
        "        preferredFont: 'STIX'," +
        "        styles: { '.MathJax_Display, .MathJax .mo, .MathJax .mi, .MathJax .mn': {color: 'inherit ! important'} }," +
        "        linebreaks: { automatic: "+ linebreak +", width: '90% container' }," +
        "    }, " +
        "}); " +
        "if ('default' !== 'default') {" +
            "MathJax.Hub.Register.StartupHook('HTML-CSS Jax Ready',function () {" +
                "var VARIANT = MathJax.OutputJax['HTML-CSS'].FONTDATA.VARIANT;" +
                "VARIANT['normal'].fonts.unshift('MathJax_default');" +
                "VARIANT['bold'].fonts.unshift('MathJax_default-bold');" +
                "VARIANT['italic'].fonts.unshift('MathJax_default-italic');" +
                "VARIANT['-tex-mathit'].fonts.unshift('MathJax_default-italic');" +
            "});" +
            "MathJax.Hub.Register.StartupHook('SVG Jax Ready',function () {" +
                "var VARIANT = MathJax.OutputJax.SVG.FONTDATA.VARIANT;" +
                "VARIANT['normal'].fonts.unshift('MathJax_default');" +
                "VARIANT['bold'].fonts.unshift('MathJax_default-bold');" +
                "VARIANT['italic'].fonts.unshift('MathJax_default-italic');" +
                "VARIANT['-tex-mathit'].fonts.unshift('MathJax_default-italic');" +
            "});" +
        "}";

    (document.body || document.getElementsByTagName('head')[0]).appendChild(configscript);
    (document.body || document.getElementsByTagName('head')[0]).appendChild(mathjaxscript);
}
&lt;/script&gt;</content><category term="Statistics"/></entry><entry><title>Estimating Discrete Entropy, Part 1</title><link href="https://www.nowozin.net/sebastian/blog/estimating-discrete-entropy-part-1.html" rel="alternate"/><published>2015-02-07T14:00:00+00:00</published><updated>2015-02-07T14:00:00+00:00</updated><author><name>Sebastian Nowozin</name></author><id>tag:www.nowozin.net,2015-02-07:/sebastian/blog/estimating-discrete-entropy-part-1.html</id><summary type="html">&lt;p&gt;Estimation of the
&lt;a href="http://en.wikipedia.org/wiki/Entropy_%28information_theory%29"&gt;entropy&lt;/a&gt; of a
random variable is an important problem that has many applications.
If you can estimate entropy accurately, you can also estimate &lt;a href="http://en.wikipedia.org/wiki/Mutual_information"&gt;mutual
information&lt;/a&gt;, which allows
you to find dependent random variables in large data sets.
There are &lt;a href="http://en.wikipedia.org/wiki/Mutual_information#Applications_of_mutual_information"&gt;numerous
applications&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;The setting of discrete entropy estimation …&lt;/p&gt;</summary><content type="html">&lt;p&gt;Estimation of the
&lt;a href="http://en.wikipedia.org/wiki/Entropy_%28information_theory%29"&gt;entropy&lt;/a&gt; of a
random variable is an important problem that has many applications.
If you can estimate entropy accurately, you can also estimate &lt;a href="http://en.wikipedia.org/wiki/Mutual_information"&gt;mutual
information&lt;/a&gt;, which allows
you to find dependent random variables in large data sets.
There are &lt;a href="http://en.wikipedia.org/wiki/Mutual_information#Applications_of_mutual_information"&gt;numerous
applications&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;The setting of discrete entropy estimation with a finite number of outcomes is
as follows.
There is an unknown categorical distribution over &lt;span class="math"&gt;\(K \geq 2\)&lt;/span&gt; different
outcomes, defined by means of a probability vector
&lt;span class="math"&gt;\(\mathbb{p} = (p_1,p_2,\dots,p_K)\)&lt;/span&gt;, such that &lt;span class="math"&gt;\(p_k \geq 0\)&lt;/span&gt; and
&lt;span class="math"&gt;\(\sum_k p_k = 1\)&lt;/span&gt;.
We are interested in the quantity&lt;/p&gt;
&lt;div class="math"&gt;\begin{equation}
H(\mathbb{p}) = -\sum_{k=1}^K p_k \log p_k,\label{eqn:Hdiscrete}
\end{equation}&lt;/div&gt;
&lt;p&gt;where &lt;span class="math"&gt;\(0 \log 0 = 0\)&lt;/span&gt; by convention.&lt;/p&gt;
&lt;p&gt;Because the probability vector is unknown to us we cannot directly use
&lt;span class="math"&gt;\((\ref{eqn:Hdiscrete})\)&lt;/span&gt;.
Instead we assume that we observe &lt;span class="math"&gt;\(n\)&lt;/span&gt; samples &lt;span class="math"&gt;\(X_i\)&lt;/span&gt;, &lt;span class="math"&gt;\(i=1,\dots,n\)&lt;/span&gt;, from the
categorical distribution in order to estimate &lt;span class="math"&gt;\(H(\mathbb{p})\)&lt;/span&gt;.&lt;/p&gt;
&lt;h3&gt;Naive Plugin Estimator of the Discrete Entropy&lt;/h3&gt;
&lt;p&gt;The naive plugin estimator uses the frequency estimates of the categorical
probabilities in the expression for the true entropy, that is,&lt;/p&gt;
&lt;div class="math"&gt;\begin{equation}
\hat{H}_N = - \sum_{k=1}^K \hat{p}_k \log \hat{p}_k,\label{Hplugin1}
\end{equation}&lt;/div&gt;
&lt;p&gt;where &lt;span class="math"&gt;\(\hat{p}_k = h_k / n\)&lt;/span&gt; are the maximum likelihood estimates of each
probability &lt;span class="math"&gt;\(p_k\)&lt;/span&gt;, and &lt;span class="math"&gt;\(h_k = \sum_{i=1}^n 1_{\{X_i = k\}}\)&lt;/span&gt; is simply the
histogram over outcomes.
The form &lt;span class="math"&gt;\((\ref{Hplugin1})\)&lt;/span&gt; is equivalent to the simpler form&lt;/p&gt;
&lt;div class="math"&gt;$$\hat{H}_N = \log n - \frac{1}{n} \sum_{k=1}^K h_k \log h_k.$$&lt;/div&gt;
&lt;h3&gt;Problems of the Naive Plugin Estimator&lt;/h3&gt;
&lt;p&gt;It has long been known, due to &lt;a href="http://epubs.siam.org/doi/abs/10.1137/1104033"&gt;(Basharin,
1959)&lt;/a&gt; and &lt;a href="http://www.dtic.mil/cgi-bin/GetTRDoc?AD=ADA020217"&gt;(Harris,
1975)&lt;/a&gt; that the estimator
&lt;span class="math"&gt;\((\ref{Hplugin1})\)&lt;/span&gt; underestimates the true entropy &lt;span class="math"&gt;\((\ref{eqn:Hdiscrete})\)&lt;/span&gt;.
In fact, we have for any distribution specified by &lt;span class="math"&gt;\(\mathbb{p}\)&lt;/span&gt; that&lt;/p&gt;
&lt;div class="math"&gt;$$H(\mathbb{p}) - \mathbb{E}[\hat{H}_N] =
    \frac{K-1}{2n}
    - \frac{1}{12 n^2} \left(1-\sum_k^{K} \frac{1}{p_k}\right)
    + O(n^{-3}) \geq 0,$$&lt;/div&gt;
&lt;p&gt;so that most often the true entropy is at least as large as what &lt;span class="math"&gt;\(\hat{H}_N\)&lt;/span&gt;
claims it is.
Why is this the case?  There is a simple explanation illustrated by
the following figure and description.&lt;/p&gt;
&lt;p&gt;&lt;img alt="xlogx bias explanation" src="https://www.nowozin.net/sebastian/blog/images/entropy-estimation-1-bias.svg"&gt;&lt;/p&gt;
&lt;p&gt;Let us only consider a single bin &lt;span class="math"&gt;\(k\)&lt;/span&gt; with true probability &lt;span class="math"&gt;\(p_k\)&lt;/span&gt;.
If we would know &lt;span class="math"&gt;\(p_k\)&lt;/span&gt; exactly, the contribution this bin makes to the true
entropy of the distribution is &lt;span class="math"&gt;\(-p_k \log p_k\)&lt;/span&gt;.
We do not know &lt;span class="math"&gt;\(p_k\)&lt;/span&gt; and instead estimate it using its frequency estimate
&lt;span class="math"&gt;\(\hat{p}_k = h_k / n\)&lt;/span&gt;.  The marginal distribution of &lt;span class="math"&gt;\(\hat{p}_k\)&lt;/span&gt; is a
&lt;a href="http://en.wikipedia.org/wiki/Binomial_distribution"&gt;Binomial distribution&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;I have shown an empirical histogram of 50,000 samples from a
&lt;span class="math"&gt;\(\textrm{Binomial}(1000,p_k)\)&lt;/span&gt; distribution in red, where &lt;span class="math"&gt;\(p_k=0.27\)&lt;/span&gt; in this
case.  As you can see, there is significant sampling variance about the true
&lt;span class="math"&gt;\(p_k\)&lt;/span&gt;, despite having seen 1,000 samples.  It is however exactly centered at
&lt;span class="math"&gt;\(p_k\)&lt;/span&gt; because &lt;span class="math"&gt;\(\hat{p}_k\)&lt;/span&gt; is an &lt;em&gt;unbiased&lt;/em&gt; estimate of &lt;span class="math"&gt;\(p_k\)&lt;/span&gt;, that is we have
&lt;span class="math"&gt;\(\mathbb{E} \hat{p}_k = p_k\)&lt;/span&gt;.  It also is &lt;a href="http://en.wikipedia.org/wiki/Binomial_distribution#Normal_approximation"&gt;approximately
normally
distributed&lt;/a&gt;,
as can be clearly seen in the Gaussian shape of the red histogram.&lt;/p&gt;
&lt;p&gt;When we now evaluate the function &lt;span class="math"&gt;\(f(x) = -x \log x\)&lt;/span&gt; we evaluate it at the
slightly wrong place &lt;span class="math"&gt;\(\hat{p}_k\)&lt;/span&gt; instead of the true place &lt;span class="math"&gt;\(p_k\)&lt;/span&gt;.
Because &lt;span class="math"&gt;\(f\)&lt;/span&gt; is concave in this case, the famous &lt;a href="http://en.wikipedia.org/wiki/Jensen%27s_inequality"&gt;Jensen's
inequality&lt;/a&gt; tells us that&lt;/p&gt;
&lt;div class="math"&gt;$$H = \sum_k f(p_k) = \sum_k f(\mathbb{E} \hat{p}_k) \geq \sum_k \mathbb{E}
f(\hat{p}_k) = \mathbb{E} \sum_k f(\hat{p}_k) = \mathbb{E} H_N,$$&lt;/div&gt;
&lt;p&gt;so that for each &lt;span class="math"&gt;\(p_k\)&lt;/span&gt; the contribution to the entropy is underestimated on
average.  (This does not imply that each particular finite sample estimate is
below the true entropy however.)&lt;/p&gt;
&lt;p&gt;In the next part we will take a look at some improved estimators of the
discrete entropy.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Acknowledgements&lt;/em&gt;.  I thank &lt;a href="http://www.memming.com/"&gt;Il Memming Park&lt;/a&gt; and
&lt;a href="http://ei.is.tuebingen.mpg.de/person/jpeters"&gt;Jonas Peters&lt;/a&gt;
for reading a draft version of the article and providing feedback.&lt;/p&gt;
&lt;script type="text/javascript"&gt;if (!document.getElementById('mathjaxscript_pelican_#%@#$@#')) {
    var align = "center",
        indent = "0em",
        linebreak = "false";

    if (false) {
        align = (screen.width &lt; 768) ? "left" : align;
        indent = (screen.width &lt; 768) ? "0em" : indent;
        linebreak = (screen.width &lt; 768) ? 'true' : linebreak;
    }

    var mathjaxscript = document.createElement('script');
    mathjaxscript.id = 'mathjaxscript_pelican_#%@#$@#';
    mathjaxscript.type = 'text/javascript';
    mathjaxscript.src = 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.3/latest.js?config=TeX-AMS-MML_HTMLorMML';

    var configscript = document.createElement('script');
    configscript.type = 'text/x-mathjax-config';
    configscript[(window.opera ? "innerHTML" : "text")] =
        "MathJax.Hub.Config({" +
        "    config: ['MMLorHTML.js']," +
        "    TeX: { extensions: ['AMSmath.js','AMSsymbols.js','noErrors.js','noUndefined.js'], equationNumbers: { autoNumber: 'none' } }," +
        "    jax: ['input/TeX','input/MathML','output/HTML-CSS']," +
        "    extensions: ['tex2jax.js','mml2jax.js','MathMenu.js','MathZoom.js']," +
        "    displayAlign: '"+ align +"'," +
        "    displayIndent: '"+ indent +"'," +
        "    showMathMenu: true," +
        "    messageStyle: 'normal'," +
        "    tex2jax: { " +
        "        inlineMath: [ ['\\\\(','\\\\)'] ], " +
        "        displayMath: [ ['$$','$$'] ]," +
        "        processEscapes: true," +
        "        preview: 'TeX'," +
        "    }, " +
        "    'HTML-CSS': { " +
        "        availableFonts: ['STIX', 'TeX']," +
        "        preferredFont: 'STIX'," +
        "        styles: { '.MathJax_Display, .MathJax .mo, .MathJax .mi, .MathJax .mn': {color: 'inherit ! important'} }," +
        "        linebreaks: { automatic: "+ linebreak +", width: '90% container' }," +
        "    }, " +
        "}); " +
        "if ('default' !== 'default') {" +
            "MathJax.Hub.Register.StartupHook('HTML-CSS Jax Ready',function () {" +
                "var VARIANT = MathJax.OutputJax['HTML-CSS'].FONTDATA.VARIANT;" +
                "VARIANT['normal'].fonts.unshift('MathJax_default');" +
                "VARIANT['bold'].fonts.unshift('MathJax_default-bold');" +
                "VARIANT['italic'].fonts.unshift('MathJax_default-italic');" +
                "VARIANT['-tex-mathit'].fonts.unshift('MathJax_default-italic');" +
            "});" +
            "MathJax.Hub.Register.StartupHook('SVG Jax Ready',function () {" +
                "var VARIANT = MathJax.OutputJax.SVG.FONTDATA.VARIANT;" +
                "VARIANT['normal'].fonts.unshift('MathJax_default');" +
                "VARIANT['bold'].fonts.unshift('MathJax_default-bold');" +
                "VARIANT['italic'].fonts.unshift('MathJax_default-italic');" +
                "VARIANT['-tex-mathit'].fonts.unshift('MathJax_default-italic');" +
            "});" +
        "}";

    (document.body || document.getElementsByTagName('head')[0]).appendChild(configscript);
    (document.body || document.getElementsByTagName('head')[0]).appendChild(mathjaxscript);
}
&lt;/script&gt;</content><category term="Statistics"/></entry><entry><title>Advanced Structured Prediction</title><link href="https://www.nowozin.net/sebastian/blog/advanced-structured-prediction.html" rel="alternate"/><published>2015-01-29T22:30:00+00:00</published><updated>2015-01-29T22:30:00+00:00</updated><author><name>Sebastian Nowozin</name></author><id>tag:www.nowozin.net,2015-01-29:/sebastian/blog/advanced-structured-prediction.html</id><summary type="html">&lt;p&gt;In December 2014, just in time for NIPS, &lt;a href="http://mitpress.mit.edu/"&gt;MIT Press&lt;/a&gt;
released an edited volume on structured prediction models and their
applications in natural language processing, computer vision, and
computational biology.&lt;/p&gt;
&lt;p&gt;&lt;img alt="Advanced Structured Prediction cover image" src="https://www.nowozin.net/sebastian/blog/images/asp-cover.jpg"&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://mitpress.mit.edu/books/advanced-structured-prediction"&gt;Advanced Structured Prediction&lt;/a&gt;,
Editors Sebastian Nowozin, Peter V. Gehler, Jeremy Jancsary,
Christoph H. Lampert,
(&lt;a href="http://mitpress.mit.edu/"&gt;MIT Press&lt;/a&gt;,
&lt;a href="http://www.amazon.com/Advanced-Structured-Prediction-Information-Processing/dp/0262028379"&gt;Amazon&lt;/a&gt;)&lt;/p&gt;
&lt;p&gt;The volume offers …&lt;/p&gt;</summary><content type="html">&lt;p&gt;In December 2014, just in time for NIPS, &lt;a href="http://mitpress.mit.edu/"&gt;MIT Press&lt;/a&gt;
released an edited volume on structured prediction models and their
applications in natural language processing, computer vision, and
computational biology.&lt;/p&gt;
&lt;p&gt;&lt;img alt="Advanced Structured Prediction cover image" src="https://www.nowozin.net/sebastian/blog/images/asp-cover.jpg"&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://mitpress.mit.edu/books/advanced-structured-prediction"&gt;Advanced Structured Prediction&lt;/a&gt;,
Editors Sebastian Nowozin, Peter V. Gehler, Jeremy Jancsary,
Christoph H. Lampert,
(&lt;a href="http://mitpress.mit.edu/"&gt;MIT Press&lt;/a&gt;,
&lt;a href="http://www.amazon.com/Advanced-Structured-Prediction-Information-Processing/dp/0262028379"&gt;Amazon&lt;/a&gt;)&lt;/p&gt;
&lt;p&gt;The volume offers an overview of the recent research on structured prediction
in order to make the work accessible to a broader research community. The
chapters, by leading researchers in the field, cover a range of topics,
including research trends, the linear programming relaxation approach,
innovations in probabilistic modeling, recent theoretical progress, and
resource-aware learning.&lt;/p&gt;
&lt;h3&gt;Contributors&lt;/h3&gt;
&lt;p&gt;&lt;a href="https://www1.ethz.ch/bsse/cbg/people/behrj"&gt;Jonas Behr&lt;/a&gt;,
&lt;a href="http://yutianchen.com/"&gt;Yutian Chen&lt;/a&gt;,
&lt;a href="http://www.cs.cmu.edu/~ftorre/"&gt;Fernando De La Torre&lt;/a&gt;,
&lt;a href="http://users.cecs.anu.edu.au/~jdomke/"&gt;Justin Domke&lt;/a&gt;,
&lt;a href="http://files.is.tue.mpg.de/pgehler/"&gt;Peter V. Gehler&lt;/a&gt;,
&lt;a href="http://labs.yahoo.com/author/agelfand/"&gt;Andrew E. Gelfand&lt;/a&gt;,
&lt;a href="http://graal.ift.ulaval.ca/"&gt;S&amp;eacute;bastien Gigu&amp;egrave;re&lt;/a&gt;,
&lt;a href="http://www.cs.huji.ac.il/~gamir/"&gt;Amir Globerson&lt;/a&gt;,
&lt;a href="http://hci.iwr.uni-heidelberg.de/Staff/fhamprec/"&gt;Fred A. Hamprecht&lt;/a&gt;,
&lt;a href="http://www3.cs.stonybrook.edu/~minhhoai/"&gt;Minh Hoai&lt;/a&gt;,
&lt;a href="http://people.csail.mit.edu/tommi/"&gt;Tommi Jaakkola&lt;/a&gt;,
&lt;a href="http://www.jancsary.net/"&gt;Jeremy Jancsary&lt;/a&gt;,
&lt;a href="http://u.cs.biu.ac.il/~jkeshet/"&gt;Joseph Keshet&lt;/a&gt;,
&lt;a href="http://www2.informatik.hu-berlin.de/~kloftmar/"&gt;Marius Kloft&lt;/a&gt;,
&lt;a href="http://pub.ist.ac.at/~vnk/"&gt;Vladimir Kolmogorov&lt;/a&gt;,
&lt;a href="http://pub.ist.ac.at/~chl/"&gt;Christoph H. Lampert&lt;/a&gt;,
&lt;a href="http://www2.ift.ulaval.ca/~laviolette/"&gt;Fran&amp;ccedil;ois Laviolette&lt;/a&gt;,
&lt;a href="http://www.xinghua-lou.org/"&gt;Xinghua Lou&lt;/a&gt;,
&lt;a href="http://www2.ift.ulaval.ca/~mmarchand/"&gt;Mario Marchand&lt;/a&gt;,
&lt;a href="http://www.cs.cmu.edu/~afm/Home.html"&gt;Andr&amp;eacute; F. T. Martins&lt;/a&gt;,
&lt;a href="http://ttic.uchicago.edu/~meshi/"&gt;Ofer Meshi&lt;/a&gt;,
&lt;a href="http://www.nowozin.net/"&gt;Sebastian Nowozin&lt;/a&gt;,
&lt;a href="http://ttic.uchicago.edu/~gpapan/"&gt;George Papandreou&lt;/a&gt;,
&lt;a href="http://cmp.felk.cvut.cz/~prusapa1/"&gt;Daniel Prusa&lt;/a&gt;,
&lt;a href="http://cbio.mskcc.org/directory/gunnar-ratsch/index.html"&gt;Gunnar R&amp;auml;tsch&lt;/a&gt;,
&lt;a href="http://graal.ift.ulaval.ca/"&gt;Am&amp;eacute;lie Rolland&lt;/a&gt;,
&lt;a href="http://hci.iwr.uni-heidelberg.de/Staff/bsavchyn/"&gt;Bogdan Savchynskyy&lt;/a&gt;,
&lt;a href="http://ipa.iwr.uni-heidelberg.de/dokuwiki/doku.php?id=schmidt"&gt;Stefan Schmidt&lt;/a&gt;,
&lt;a href="http://user.phil-fak.uni-duesseldorf.de/~tosch/"&gt;Thomas Schoenemann&lt;/a&gt;,
&lt;a href="http://homepages.inf.ed.ac.uk/gschweik/"&gt;Gabriele Schweikert&lt;/a&gt;,
&lt;a href="http://www.bentaskar.com/"&gt;Ben Taskar&lt;/a&gt;,
&lt;a href="http://web.engr.oregonstate.edu/~sinisa/"&gt;Sinisa Todorovic&lt;/a&gt;,
&lt;a href="http://www.mlplatform.nl/researchgroups/machine-learning-group-university-of-amsterdam/"&gt;Max Welling&lt;/a&gt;,
&lt;a href="http://scholar.google.com/citations?user=wMV9MiMAAAAJ&amp;amp;hl=en"&gt;David Weiss&lt;/a&gt;,
&lt;a href="http://cmp.felk.cvut.cz/~werner/"&gt;Thomas Werner&lt;/a&gt;,
&lt;a href="http://www.stat.ucla.edu/~yuille/"&gt;Alan Yuille&lt;/a&gt;,
&lt;a href="http://www.cs.ox.ac.uk/Stanislav.Zivny/homepage/"&gt;Stanislav Zivny&lt;/a&gt;.&lt;/p&gt;</content><category term="Machine Learning, Structured Prediction"/></entry><entry><title>Streaming Mean and Variance Computation</title><link href="https://www.nowozin.net/sebastian/blog/streaming-mean-and-variance-computation.html" rel="alternate"/><published>2015-01-25T21:30:00+00:00</published><updated>2015-01-25T21:30:00+00:00</updated><author><name>Sebastian Nowozin</name></author><id>tag:www.nowozin.net,2015-01-25:/sebastian/blog/streaming-mean-and-variance-computation.html</id><summary type="html">&lt;p&gt;Given a sequence of observed data we would often like to estimate simple
quantities like the mean and variance.&lt;/p&gt;
&lt;p&gt;Sometimes the data is available in a &lt;em&gt;streaming&lt;/em&gt; setting, that is, we are
given one sample at a time.  For example, this is the case when&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;the number of samples is …&lt;/li&gt;&lt;/ul&gt;</summary><content type="html">&lt;p&gt;Given a sequence of observed data we would often like to estimate simple
quantities like the mean and variance.&lt;/p&gt;
&lt;p&gt;Sometimes the data is available in a &lt;em&gt;streaming&lt;/em&gt; setting, that is, we are
given one sample at a time.  For example, this is the case when&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;the number of samples is apriori unknown,&lt;/li&gt;
&lt;li&gt;we have to perform some stopping test after each sample,&lt;/li&gt;
&lt;li&gt;the number of samples is very large and we cannot store all samples.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;More formally, given weighted observations &lt;span class="math"&gt;\(X_1\)&lt;/span&gt;, &lt;span class="math"&gt;\(X_2\)&lt;/span&gt;, &lt;span class="math"&gt;\(\dots\)&lt;/span&gt;, with &lt;span class="math"&gt;\(X_i
\in \mathbb{R}\)&lt;/span&gt;, and &lt;span class="math"&gt;\(w_1\)&lt;/span&gt;, &lt;span class="math"&gt;\(w_2\)&lt;/span&gt;, &lt;span class="math"&gt;\(\dots\)&lt;/span&gt;, with &lt;span class="math"&gt;\(w_i \geq 0\)&lt;/span&gt; we would like to
calculate simple statistics like the weighted mean or weighted variance of the
sample without having to store all samples, and by processing them one-by-one.&lt;/p&gt;
&lt;p&gt;In this situation we can compute the mean and variance of a sample (and, more
generally, any higher-order moments) using a &lt;a href="http://en.wikipedia.org/wiki/Streaming_algorithm"&gt;streaming
algorithm&lt;/a&gt;.
Many possibilities exist but because of the incremental computation particular
attention needs to be paid to numerical stability.
If we were to ignore numerical accuracy we could use a simple derivation to
show that the following updates for &lt;span class="math"&gt;\(i=1,2,\dots\)&lt;/span&gt; are correct, when
initializing &lt;span class="math"&gt;\(S^{(0)} = T^{(0)} = U^{(0)} = 0\)&lt;/span&gt;:&lt;/p&gt;
&lt;div class="math"&gt;$$S^{(i+1)} = S^{(i)} + w_i$$&lt;/div&gt;
&lt;div class="math"&gt;$$T^{(i+1)} = T^{(i)} + w_i X_i$$&lt;/div&gt;
&lt;div class="math"&gt;$$U^{(i+1)} = U^{(i)} + w_i X_i^2$$&lt;/div&gt;
&lt;p&gt;Then &lt;span class="math"&gt;\(\hat{\mu} = T^{(n)} / S^{(n)}\)&lt;/span&gt; is the weighted sample mean, and
&lt;span class="math"&gt;\(\hat{\mathbb{V}} = \frac{n}{(n-1) S^{(n)}} (U^{(n)} - S^{(n)} \hat{\mu}^2)\)&lt;/span&gt;
is an unbiased estimate of the weighted variance.&lt;/p&gt;
&lt;p&gt;The problem with this naive derivation arises when &lt;span class="math"&gt;\(n\)&lt;/span&gt; is very large.  Then
the in all three updates the summation may sum quantities of very different
magnitude, leading to &lt;a href="http://www.validlab.com/goldberg/paper.pdf"&gt;large round-off
errors&lt;/a&gt;.
By the way, this can even arise when one is computing the simple sum of many
numbers, and a classic solution in that case is &lt;a href="http://en.wikipedia.org/wiki/Kahan_summation_algorithm"&gt;Kahan
summation&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;A clever solution to this problem for streaming mean and variance computation
was proposed by West in 1979.
In his algorithm the summed quantities are controlled to be on average of
comparable size.  (It is not the only alternative, for a detailed numerical
study of possible options, see the paper linked below.)&lt;/p&gt;
&lt;p&gt;The West algorithm supports mean and variance computation for
positively weighted samples &lt;span class="math"&gt;\((w_i, X_i)\)&lt;/span&gt; with &lt;span class="math"&gt;\(w_i \geq 0\)&lt;/span&gt;, &lt;span class="math"&gt;\(X_i \in
\mathbb{R}\)&lt;/span&gt; and the original paper is&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;D.H.D. West, &lt;a href="http://people.xiph.org/~tterribe/tmp/homs/West79-_Updating_Mean_and_Variance_Estimates-_An_Improved_Method.pdf"&gt;"Updating Mean and Variance Estimates: An Improved
Method"&lt;/a&gt;
(&lt;a href="http://dl.acm.org/citation.cfm?id=359153"&gt;publisher link&lt;/a&gt;),
Comm. of the ACM, Vol. 22, Issue 9, 532--535, 1979.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;It outputs&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;The weighted unbiased mean estimate, &lt;span class="math"&gt;\(\hat{\mu} = (\sum_i w_i X_i) / (\sum_i w_i)\)&lt;/span&gt;,&lt;/li&gt;
&lt;li&gt;The weighted unbiased variance estimate, &lt;span class="math"&gt;\(\hat{\mathbb{V}} = \left(\sum_i w_i (X_i - \mu)^2\right) / (\frac{n-1}{n} \sum_i w_i)\)&lt;/span&gt;.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Here is an implementation for the &lt;a href="http://julialang.org/"&gt;Julia programming
language&lt;/a&gt;.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="n"&gt;type&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;MeanVarianceAccumulator&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;sumw&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="kt"&gt;Float64&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;wmean&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="kt"&gt;Float64&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="kt"&gt;Float64&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="kt"&gt;Int&lt;/span&gt;

&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="k"&gt;function&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;MeanVarianceAccumulator&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="n"&gt;new&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;0.0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mf"&gt;0.0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mf"&gt;0.0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="k"&gt;end&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;span class="k"&gt;function&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;observe!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;mvar&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="kt"&gt;MeanVarianceAccumulator&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;weight&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nd"&gt;@assert&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;weight&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;&amp;gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mf"&gt;0.0&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;q&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;mvar&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;wmean&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;temp_sumw&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;mvar&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sumw&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;weight&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;q&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;weight&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;temp_sumw&lt;/span&gt;

&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;mvar&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;wmean&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;+=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;mvar&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;+=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;q&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;mvar&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sumw&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;mvar&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sumw&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;temp_sumw&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;mvar&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;+=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;

&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nb"&gt;nothing&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;span class="n"&gt;count&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;mvar&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="kt"&gt;MeanVarianceAccumulator&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;mvar&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;
&lt;span class="n"&gt;mean&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;mvar&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="kt"&gt;MeanVarianceAccumulator&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;mvar&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;wmean&lt;/span&gt;
&lt;span class="n"&gt;var&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;mvar&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="kt"&gt;MeanVarianceAccumulator&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;mvar&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;mvar&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;mvar&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sumw&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;mvar&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;span class="n"&gt;std&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;mvar&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="kt"&gt;MeanVarianceAccumulator&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;sqrt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;var&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;mvar&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;You would call it as follows (tested with Julia version 0.3.5):&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="n"&gt;X&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mf"&gt;5.0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mf"&gt;1.5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mf"&gt;3.33&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="n"&gt;w&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mf"&gt;0.5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mf"&gt;1.0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mf"&gt;0.1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;length&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;X&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;mu_exact&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;w&lt;/span&gt;&lt;span class="o"&gt;.*&lt;/span&gt;&lt;span class="n"&gt;X&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;w&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;V_exact&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;w&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;.*&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="n"&gt;X&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;.-&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;mu_exact&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;.^&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(((&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;w&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;

&lt;span class="n"&gt;mvar&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;MeanVarianceAccumulator&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;observe!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;mvar&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;X&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;w&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;span class="n"&gt;mean&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;mvar&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;mu_exact&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;var&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;mvar&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;V_exact&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;This gives the correct output (running mean, mean, running variance, variance):&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;0.8331250000000003&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mf"&gt;0.8331249999999999&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mf"&gt;13.826563476562498&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mf"&gt;13.8265634765625&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Alternative algorithms and variants for higher-order moments can be found on
the excellent &lt;a href="http://en.wikipedia.org/wiki/Algorithms_for_calculating_variance"&gt;Wikipedia page on the
topic&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Addendum&lt;/strong&gt;: (October 2015) A recent paper by &lt;a href="http://arxiv.org/abs/1510.04923"&gt;(Meng,
2015)&lt;/a&gt; contains a variant of the above
algorithm for the unweighted case to compute the first four central moments
in a numerically stable manner.  Meng provides a simple implementation
requiring only 24 floating point operations per observation.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Acknowledgements&lt;/em&gt;.  I thank Amit Adam for reading a draft and providing
comments that improved clarity.&lt;/p&gt;
&lt;script type="text/javascript"&gt;if (!document.getElementById('mathjaxscript_pelican_#%@#$@#')) {
    var align = "center",
        indent = "0em",
        linebreak = "false";

    if (false) {
        align = (screen.width &lt; 768) ? "left" : align;
        indent = (screen.width &lt; 768) ? "0em" : indent;
        linebreak = (screen.width &lt; 768) ? 'true' : linebreak;
    }

    var mathjaxscript = document.createElement('script');
    mathjaxscript.id = 'mathjaxscript_pelican_#%@#$@#';
    mathjaxscript.type = 'text/javascript';
    mathjaxscript.src = 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.3/latest.js?config=TeX-AMS-MML_HTMLorMML';

    var configscript = document.createElement('script');
    configscript.type = 'text/x-mathjax-config';
    configscript[(window.opera ? "innerHTML" : "text")] =
        "MathJax.Hub.Config({" +
        "    config: ['MMLorHTML.js']," +
        "    TeX: { extensions: ['AMSmath.js','AMSsymbols.js','noErrors.js','noUndefined.js'], equationNumbers: { autoNumber: 'none' } }," +
        "    jax: ['input/TeX','input/MathML','output/HTML-CSS']," +
        "    extensions: ['tex2jax.js','mml2jax.js','MathMenu.js','MathZoom.js']," +
        "    displayAlign: '"+ align +"'," +
        "    displayIndent: '"+ indent +"'," +
        "    showMathMenu: true," +
        "    messageStyle: 'normal'," +
        "    tex2jax: { " +
        "        inlineMath: [ ['\\\\(','\\\\)'] ], " +
        "        displayMath: [ ['$$','$$'] ]," +
        "        processEscapes: true," +
        "        preview: 'TeX'," +
        "    }, " +
        "    'HTML-CSS': { " +
        "        availableFonts: ['STIX', 'TeX']," +
        "        preferredFont: 'STIX'," +
        "        styles: { '.MathJax_Display, .MathJax .mo, .MathJax .mi, .MathJax .mn': {color: 'inherit ! important'} }," +
        "        linebreaks: { automatic: "+ linebreak +", width: '90% container' }," +
        "    }, " +
        "}); " +
        "if ('default' !== 'default') {" +
            "MathJax.Hub.Register.StartupHook('HTML-CSS Jax Ready',function () {" +
                "var VARIANT = MathJax.OutputJax['HTML-CSS'].FONTDATA.VARIANT;" +
                "VARIANT['normal'].fonts.unshift('MathJax_default');" +
                "VARIANT['bold'].fonts.unshift('MathJax_default-bold');" +
                "VARIANT['italic'].fonts.unshift('MathJax_default-italic');" +
                "VARIANT['-tex-mathit'].fonts.unshift('MathJax_default-italic');" +
            "});" +
            "MathJax.Hub.Register.StartupHook('SVG Jax Ready',function () {" +
                "var VARIANT = MathJax.OutputJax.SVG.FONTDATA.VARIANT;" +
                "VARIANT['normal'].fonts.unshift('MathJax_default');" +
                "VARIANT['bold'].fonts.unshift('MathJax_default-bold');" +
                "VARIANT['italic'].fonts.unshift('MathJax_default-italic');" +
                "VARIANT['-tex-mathit'].fonts.unshift('MathJax_default-italic');" +
            "});" +
        "}";

    (document.body || document.getElementsByTagName('head')[0]).appendChild(configscript);
    (document.body || document.getElementsByTagName('head')[0]).appendChild(mathjaxscript);
}
&lt;/script&gt;</content><category term="Algorithms"/></entry><entry><title>The Beginning</title><link href="https://www.nowozin.net/sebastian/blog/the-beginning.html" rel="alternate"/><published>2015-01-25T21:00:00+00:00</published><updated>2015-01-25T21:00:00+00:00</updated><author><name>Sebastian Nowozin</name></author><id>tag:www.nowozin.net,2015-01-25:/sebastian/blog/the-beginning.html</id><summary type="html">&lt;p&gt;This is the start of my blog.
This will be a quite technical blog and therefore address a more specialized
audience.&lt;/p&gt;
&lt;p&gt;The articles will cover topics in the area of machine learning, statistics,
maybe some computer vision, let's see.
I plan to publish one article every two weeks, but let …&lt;/p&gt;</summary><content type="html">&lt;p&gt;This is the start of my blog.
This will be a quite technical blog and therefore address a more specialized
audience.&lt;/p&gt;
&lt;p&gt;The articles will cover topics in the area of machine learning, statistics,
maybe some computer vision, let's see.
I plan to publish one article every two weeks, but let us see how that goes.&lt;/p&gt;</content><category term="Personal"/></entry></feed>