<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom"><title>Yibo Yang - notes</title><link href="https://yiboyang.com/" rel="alternate"/><link href="https://yiboyang.com/feeds/notes.atom.xml" rel="self"/><id>https://yiboyang.com/</id><updated>2022-03-02T12:35:00-08:00</updated><entry><title>Estimating the rate-distortion function of real-world data, part 2</title><link href="https://yiboyang.com/posts/estimating-the-rate-distortion-function-of-real-world-data-part-2/" rel="alternate"/><published>2022-03-02T12:35:00-08:00</published><updated>2022-03-02T12:35:00-08:00</updated><author><name>Yibo Yang</name></author><id>tag:yiboyang.com,2022-03-02:/posts/estimating-the-rate-distortion-function-of-real-world-data-part-2/</id><summary type="html">&lt;p&gt;Your (beta-)VAE might be secretly estimating the rate-distortion function of your data.&lt;/p&gt;</summary><content type="html">&lt;p&gt;As we saw in &lt;a href="https://yiboyang.com/posts/estimating-the-rate-distortion-function-of-real-world-data-part-1/"&gt;part 1 of this post&lt;/a&gt;,
given a data (source) distribution &lt;span class="math"&gt;\(P_X\)&lt;/span&gt;
and a distortion function &lt;span class="math"&gt;\(\rho\)&lt;/span&gt;, the rate-distortion (R-D) function of 
the data &lt;strong&gt;quantifies&lt;/strong&gt; its &lt;strong&gt;compressibility&lt;/strong&gt;. It gives us an idea about
the best possible compression performance we can expect, and can help us design
better compression algorithms and data communication systems in general.&lt;/p&gt;
&lt;p&gt;In this part 2 of the post, I'll introduce a simple method to estimate
the R-D function, i.e., to train a family of &lt;span class="math"&gt;\(\beta\)&lt;/span&gt;-VAE-like models.
This method is much more scalable and
widely-applicable than the classic &lt;a href="https://en.wikipedia.org/wiki/Blahut%E2%80%93Arimoto_algorithm"&gt;Blahut-Arimoto algorithm&lt;/a&gt;,
and works in an online fashion as it is based on stochastic gradient descent
(SGD). Perhaps not coincidentally, a subset of these &lt;span class="math"&gt;\(\beta\)&lt;/span&gt;-VAEs are also
the basis of many learned lossy compression models today. 
You can find more details in &lt;a href="https://arxiv.org/abs/2111.12166"&gt;the ICLR2022 paper&lt;/a&gt;,
and a quick demo for how this all works in &lt;a href="https://github.com/mandt-lab/RD-sandwich/blob/master/demo.ipynb"&gt;this ipython notebook&lt;/a&gt;.&lt;/p&gt;
&lt;h3&gt;Estimating the R-D function.&lt;/h3&gt;
&lt;p&gt;Recall the definintion of the rate-distortion function from last time:&lt;/p&gt;
&lt;div class="math"&gt;$$\begin{aligned}
R(D) := \inf_{Q_{Y|X}: \ \mathbb{E} [\rho(X, Y) ]\leq D} I(X; Y).\end{aligned}$$&lt;/div&gt;
&lt;p&gt;To be able to carry out the integrals, we need knowledge of &lt;span class="math"&gt;\(P_X\)&lt;/span&gt;, i.e., the
probability that the distribution assigns to any event.
For a Bernoulli or Gaussian source, the R-D function can be worked out mathematically.
Unfortunately, outside of these special cases, the R-D function
has no analytical form, and we have little knowledge of the R-D function
of most data sources.&lt;/p&gt;
&lt;p&gt;If the source and reproduction alphabets are finite (thus necessarily
discrete), and if we know the source probability mass function &lt;span class="math"&gt;\(P_X\)&lt;/span&gt;,
then the Blahut-Arimoto (BA) algorithm can numerically compute the R-D
function by solving the mathematical optimization problem defining it.
However, there are two major difficulties with establishing the R-D
function of real-world sources, which make the BA algorithm
inapplicable:&lt;/p&gt;
&lt;p&gt;1. the source distribution (e.g., the distribution of natural images)
is almost always unknown; &lt;sup id="fnref:1"&gt;&lt;a class="footnote-ref" href="#fn:1"&gt;1&lt;/a&gt;&lt;/sup&gt;&lt;/p&gt;
&lt;p&gt;2. the data and the lossy reproductions may be continuously valued,
e.g., in scientific applications.&lt;/p&gt;
&lt;p&gt;The availability of massive amounts of data prompts us to consider
&lt;em&gt;estimating&lt;/em&gt; the R-D function from data samples. Indeed, &lt;a href="https://arxiv.org/pdf/cs/0702018.pdf"&gt;Harrison &amp;amp;
Kontoyiannis (2008)&lt;/a&gt; proved that
that in many general settings, the R-D estimator from replacing the true
data distribution by an empirical distribution of samples will asymptotically recover
the true R-D function. Thus, one might try running the BA algorithm on
an empirical distribution of data samples, after discretizing the source
and reproduction alphabets if they are continuous. However, besides the
inaccuracy from discretization, this approach also quickly runs into
computational difficulties. In higher dimensions, an exceedingly large
number of samples is required to faithfully represent the source
distribution. This in turn creates a blowup in the number of discretized
states in the source and reproduction alphabets. As the BA algorithm
operates on tabular representations of the various quantities over all the
possible discrete states (e.g., the source PMF &lt;span class="math"&gt;\(p(x_i)\)&lt;/span&gt;, and the matrix of pairwise distortion values
&lt;span class="math"&gt;\(\rho(x_i, y_j)\)&lt;/span&gt;, where &lt;span class="math"&gt;\(x_i\)&lt;/span&gt; and &lt;span class="math"&gt;\(y_j\)&lt;/span&gt; range over all values of source and reproduction alphabets), the memory requirement of BA alone can quickly
become infeasible in just a handful of dimensions.&lt;/p&gt;
&lt;h3&gt;Alternative approach based on an R-D-VAE.&lt;/h3&gt;
&lt;p&gt;Now I'll introduce an alternative to the BA algorithm, which works with
general alphabets, and can be viewed as an SGD version of the BA
algorithm. Besides being much more scalable, this method can also free
us from working with a fixed (possibly discretized) empirical data
distribution: if a stream of i.i.d. samples from the source is
available, we will be able to continually improve our estimate of the
R-D function in an online fashion, overcoming the finite-sample bias of
the BA algorithm.&lt;/p&gt;
&lt;p&gt;The basic idea is straightforward, and may appear unrelated at first
sight: fitting a VAE to the data source. For now, let's use a common
Gaussian likelihood model in the VAE, so that
&lt;span class="math"&gt;\(p(x|z) \sim \mathcal{N}(x|\mu(z), \sigma^2(z))\)&lt;/span&gt;, with the mean and
variance parameters computed by a decoder neural network. Denoting the
prior and posterior densities by &lt;span class="math"&gt;\(q(z)\)&lt;/span&gt; and &lt;span class="math"&gt;\(q(z|x)\)&lt;/span&gt;, the standard
maximum likelihood training objective is the aggregate ELBO (evidence
lower bound):&lt;/p&gt;
&lt;div class="math"&gt;$$\mathbb{E}_{x \sim P_X}[- KL(q(z|x) \|q(z))] + \mathbb{E}_{x \sim P_X, z \sim q(z|x)}[ \log p(x|z)]$$&lt;/div&gt;
&lt;p&gt;As I wrote in &lt;a href="https://yiboyang.com/posts/the-ill-defined-problem-of-maximum-likelihood-estimation/"&gt;a previous note&lt;/a&gt;,
fitting such a density may be problematic
if the true data distribution does not have full support over its
ambient space. For instance, the true distribution of MNIST images has
no probability mass outside of a collection of integer-valued points in
&lt;span class="math"&gt;\(\mathbb{R}^{784}\)&lt;/span&gt;. In this case, the maximum likelihood training
objective is ill-defined (indeed, it seems silly to fit a density model
to discrete data), and may reach arbitrarily high values.&lt;/p&gt;
&lt;p&gt;One way to avoid this nonsensical scenario is to restrict, or regularize
the density model in some way, so that the training objective has a
finite maximum. For the Gaussian VAE, it is common to fix the variance
of the likelihood model to a constant, like &lt;span class="math"&gt;\(\sigma^2 I\)&lt;/span&gt;, and only learn
its mean. The authors of &lt;a href="https://openreview.net/pdf?id=r1xaVLUYuE"&gt;this
paper&lt;/a&gt; did just that: they fit
a series of Gaussian VAE models to MNIST digits, keeping &lt;span class="math"&gt;\(\sigma^2\)&lt;/span&gt;
fixed for each model, and varying it across models; they observe that
models with smaller &lt;span class="math"&gt;\(\sigma^2\)&lt;/span&gt; achieve better/higher aggregate ELBO and
exhibit less posterior collapse.&lt;/p&gt;
&lt;p&gt;How should we interpret the aggregate ELBO in this model, which could be
unbounded had we not fixed &lt;span class="math"&gt;\(\sigma^2\)&lt;/span&gt;? And how should we set &lt;span class="math"&gt;\(\sigma^2\)&lt;/span&gt;?
Similar questions can framed in terms of &lt;span class="math"&gt;\(\beta\)&lt;/span&gt;-VAEs; indeed, since the
log-likelihood has the form
&lt;span class="math"&gt;\(\log p(x|z) = \frac{1}{2\sigma^2} \|x - \mu(z) \|^2 + const\)&lt;/span&gt;, the VAE
with a fixed variance is essentially equivalent to a &lt;span class="math"&gt;\(\beta\)&lt;/span&gt;-VAE with a
unit variance in the likelihood model, with &lt;span class="math"&gt;\(2\sigma^2\)&lt;/span&gt; playing the same
role as &lt;span class="math"&gt;\(\beta\)&lt;/span&gt;.&lt;/p&gt;
&lt;p&gt;The answer: &lt;strong&gt;this &lt;span class="math"&gt;\(\beta\)&lt;/span&gt;-VAE is optimizing an upper bound on the
R-D function of the data distribution, under a suitable distortion
metric.&lt;/strong&gt; The key is to look at the aggregate ELBO objective just the
right way, and identify a correspondence between the likelihood model
and the distortion function. A Gaussian &lt;span class="math"&gt;\(\beta\)&lt;/span&gt;-VAE, for example, gives
us an estimate of the compressibility of the data samples under a
squared error distortion. A &lt;span class="math"&gt;\(\beta\)&lt;/span&gt;-VAE with a Laplace likelihood model
then corresponds to an &lt;span class="math"&gt;\(L_1\)&lt;/span&gt; distortion, &lt;span class="math"&gt;\(\rho(x,y) = \|x  - y \|_1\)&lt;/span&gt;.&lt;/p&gt;
&lt;p&gt;The general statement is something like this (see Theorem A.3 in the
paper for details): Let &lt;span class="math"&gt;\(q(z), q(z|x)\)&lt;/span&gt; be arbitrary choices of prior and
posterior distributions in a VAE. Suppose the likelihood density
&lt;span class="math"&gt;\(p(x|z)\)&lt;/span&gt; has the form of an exponentiated distortion,&lt;/p&gt;
&lt;div class="math"&gt;$$p(x|z) = \frac{1}{const} \exp\{\rho(x, \omega(z))\},$$&lt;/div&gt;
&lt;p&gt; where &lt;span class="math"&gt;\(\omega\)&lt;/span&gt;
is an arbitrary decoder function, and the normalizing constant
&lt;span class="math"&gt;\(const = \int \exp\{\rho(x, \omega(z))\} d x\)&lt;/span&gt; does not depend on &lt;span class="math"&gt;\(z\)&lt;/span&gt; and
is allowed to be infinite. Then, the point &lt;span class="math"&gt;\((\mathcal{D}, \mathcal{R})\)&lt;/span&gt;
formed by the two terms of the negative ELBO,
&lt;/p&gt;
&lt;div class="math"&gt;$$\mathcal{D} := \mathbb{E}_{x \sim P_X, z \sim q(z|x)}[ \rho(x, \omega(z))] ,$$&lt;/div&gt;
&lt;p&gt;
and &lt;/p&gt;
&lt;div class="math"&gt;$$\mathcal{R} := \mathbb{E}_{x \sim P_X}[ KL(q(z|x) \|q(z))],$$&lt;/div&gt;
&lt;p&gt; lies on an
upper bound of the rate-distortion function of the source under
distortion function &lt;span class="math"&gt;\(\rho\)&lt;/span&gt;. Moreover, by optimizing the objective
&lt;span class="math"&gt;\(\mathcal{R} + \lambda \mathcal{D}\)&lt;/span&gt; (or, equivalently in the &lt;span class="math"&gt;\(\beta\)&lt;/span&gt;-VAE
formulation, &lt;span class="math"&gt;\(\beta \mathcal{R} +  \mathcal{D}\)&lt;/span&gt;) over all possible
choices of the prior, posterior, and decoder, the resulting point
&lt;span class="math"&gt;\((\mathcal{D}, \mathcal{R})\)&lt;/span&gt; will lie exactly on the source R-D
function. All of this pertains to a fixed &lt;span class="math"&gt;\(\lambda\)&lt;/span&gt; value; the optimal
&lt;span class="math"&gt;\((\mathcal{D}, \mathcal{R})\)&lt;/span&gt; pairs resulting from different settings of
&lt;span class="math"&gt;\(\lambda\)&lt;/span&gt; then trace out the full &lt;span class="math"&gt;\(R(D)\)&lt;/span&gt; curve.&lt;/p&gt;
&lt;p&gt;I refer to a &lt;span class="math"&gt;\(\beta\)&lt;/span&gt;-VAE-like model satisfying the above condition on
the likelihood-model an &lt;em&gt;R-D (rate-distortion) VAE&lt;/em&gt;. The rate and
distortion terms purposefully mirror the quantities in the definition of
the R-D function, and it's not hard to prove the above result by noting
that &lt;span class="math"&gt;\(\mathcal{R}\)&lt;/span&gt; is an upper bound on the mutual information
&lt;span class="math"&gt;\(I(X; Z)\)&lt;/span&gt;, which in turn is an upper bound on &lt;span class="math"&gt;\(I(X; Y), Y:= \omega(Z)\)&lt;/span&gt;
by data processing inequality. The above result essentially allows us to
train an R-D-VAE on a NELBO-like objective to optimize an upper bound on
the source R-D function. The lossless counterpart of this result is that
when the data is discrete, we can train a standard VAE with a discrete
likelihood by optimizing the standard negative ELBO, which upper bounds
the entropy of the source (this is explained towards the end of &lt;a href="https://yiboyang.com/posts/all-the-ways-to-carve-up-the-elbo/"&gt;my note on ELBO decompositions&lt;/a&gt;).&lt;/p&gt;
&lt;p&gt;Thus, we can think of an R-D-VAE as a theoretical data compressor.
Compared to the lossless case, where a single algorithm, bits-back
coding, has made it possible (and in many cases practical) to do
lossless compression with generic VAEs and achieve compression rates
close to the negative ELBO, the lossy case appears more challenging, and
research is still ongoing to develop practical compression algorithms
that realize the theoretical performance of R-D-VAEs, often with
restrictions on the "prior" and "posterior" distributions to make things
practical. 
You can learn more about these topics in Section 3.4
("Compression without quantization") of my &lt;a href="https://arxiv.org/pdf/2202.06533"&gt;intro article to neural
data compression with Stephan Mandt and Lucas
Theis&lt;/a&gt;.&lt;/p&gt;
&lt;h3&gt;The need for a lower bound.&lt;/h3&gt;
&lt;p&gt;Although training an R-D-VAE is straightforward with deep learning libraries like
Tensorflow or PyTorch, at the end of the day this only gives us an upper bound
on the R-D function.  We know that in theory, this upper bound becomes arbitrarily tight as we increase
the expressive power of the R-D-VAEs, but deeper and bigger neural networks may
also mean more local minima in the SGD optimization landscape, and not necessarily
tighter bounds in practice.&lt;/p&gt;
&lt;p&gt;To verify the tightness of an upper bound (and ultimately, to decide if an algorithm's
R-D performance is close to theoretically optimal), we also need to estimate a
&lt;strong&gt;lower bound&lt;/strong&gt; on the R-D function.
This the second half of the "sandwich bounds" proposed in the paper. I won't go into the
details as they are a bit involved, but the basic idea is similar -- optimizing over functions parameterized by neural
networks with SGD. 
It's really amazing how well SGD scales to large-scale datasets in the R-D-VAE
upper bound method (afterall, it's just training a VAE), and by comparison, how
much more challenging it appears to solve a large-scale optimization problem
when SGD cannot be directly applied. Indeed, the bulk of my technical work on the lower
bound went into reformulating the problem to make it suitable for
stochastic optimization.&lt;/p&gt;
&lt;div class="footnote"&gt;
&lt;hr&gt;
&lt;ol&gt;
&lt;li id="fn:1"&gt;
&lt;p&gt;In some cases where we are in full control of the data generation process, we
might be able to assert knowledge of the true data distribution, e.g., the toss
of a fair coin is, for all intents and purposes, Bernoulli(0.5); but these
cases tend to be rare or toyish.&amp;#160;&lt;a class="footnote-backref" href="#fnref:1" title="Jump back to footnote 1 in the text"&gt;&amp;#8617;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&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://cdn.jsdelivr.net/npm/mathjax@2.7.9/MathJax.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="notes"/><category term="information theory"/><category term="rate-distortion theory"/><category term="data compression"/><category term="machine learning"/><category term="generative modeling"/></entry><entry><title>Estimating the rate-distortion function of real-world data, part 1</title><link href="https://yiboyang.com/posts/estimating-the-rate-distortion-function-of-real-world-data-part-1/" rel="alternate"/><published>2022-03-02T12:34:00-08:00</published><updated>2022-03-02T12:34:00-08:00</updated><author><name>Yibo Yang</name></author><id>tag:yiboyang.com,2022-03-02:/posts/estimating-the-rate-distortion-function-of-real-world-data-part-1/</id><summary type="html">&lt;p&gt;What is the rate-distortion function, and why we may care about it.&lt;/p&gt;</summary><content type="html">&lt;p&gt;This is part 1 of an informal introduction to some of the ideas I have been
working on in the past year or so, which have been published as a
&lt;a href="https://openreview.net/pdf?id=0CqQp8_6GH8"&gt;workshop paper at ICLR 2021&lt;/a&gt;
and &lt;a href="https://arxiv.org/abs/2111.12166"&gt;conference paper at ICLR 2022&lt;/a&gt;.
The high-level idea is to use neural networks and
machine learning to estimate a basic quantity in information theory --
the &lt;em&gt;rate-distortion function&lt;/em&gt;, for real-world data such as images.&lt;/p&gt;
&lt;p&gt;To start with, let's get some jargon out of the way, and set the stage
for lossy compression. In information theory, the &lt;em&gt;source&lt;/em&gt; is simply the
random variable that we'd like to compress or transmit. The
corresponding concept in machine learning and statistics is the &lt;em&gt;data&lt;/em&gt;
random variable, whose unknown distribution &lt;span class="math"&gt;\(P_X\)&lt;/span&gt; we'd like to model or
infer. For our purpose they are really the same thing, and I'll talk
about the (data) source and distribution interchangeably. Let's also
only consider a memoryless source, so that the data samples are i.i.d.
--- the standard setting for statistical estimation &lt;sup id="fnref:1"&gt;&lt;a class="footnote-ref" href="#fn:1"&gt;1&lt;/a&gt;&lt;/sup&gt;. As a concrete
example, the data samples may correspond to the photos stored on your
smartphone. A lossy compression algorithm can be viewed as a blackbox
that takes a data sample as input, encodes it into a binary
representation, based on which a reconstruction (or, &lt;em&gt;reproduction&lt;/em&gt;) is
decoded and returned. The set of values that the data (or, reproduction)
can take is called the source (or, reproduction) &lt;em&gt;alphabet&lt;/em&gt;, and can be
thought of as the "domain" or "co-domain" of the compression blackbox;
e.g., this might be &lt;span class="math"&gt;\(\{0, 1, ..., 255\}^{H \times W \times 3}\)&lt;/span&gt; for
digital images.&lt;/p&gt;
&lt;h3&gt;Rate v.s. distortion.&lt;/h3&gt;
&lt;p&gt;If you've ever used a lossy data compression algorithm, say JPEG, you're
likely already familiar with the so-called rate-distortion tradeoff.
"Rate" is simply the average size of compressed files, and "distortion"
is the loss of quality from the lossy compression process, on average.
As you compress more aggressively (e.g., by dialing down the quality
parameter in JPEG), you end up with smaller file sizes, but also have to
live with increased distortion. It turns out there exist
information-theoretic "laws" that govern this rate-distortion tradeoff.
To quantiy the idea of distortion, let's also suppose we are given a
&lt;em&gt;distortion&lt;/em&gt; function &lt;span class="math"&gt;\(\rho\)&lt;/span&gt;, which receives a data sample &lt;span class="math"&gt;\(x\)&lt;/span&gt; and its
lossy reconstruction &lt;span class="math"&gt;\(y\)&lt;/span&gt;, and returns a non-negative number &lt;span class="math"&gt;\(\rho(x,y)\)&lt;/span&gt;
representing the amount of distortion/deviation in &lt;span class="math"&gt;\(y\)&lt;/span&gt; relative to &lt;span class="math"&gt;\(x\)&lt;/span&gt;;
e.g., this can be a squared error, &lt;span class="math"&gt;\(\rho(x,y) = \| x- y\|^2\)&lt;/span&gt;.&lt;/p&gt;
&lt;p&gt;Keep in mind throughout the discussion, we always have a fixed, target
data distribution in mind. It doesn't really make sense to talk about
the compression performance of an algorithm without referencing a data
distribution, as a compression algorithm that does well on one data
distribution may do worse on another, and it's simply impossible to
compress all possible data equally well.&lt;/p&gt;
&lt;p&gt;We now have a way to quantitatively evaluate the performance of a lossy
compression algorithm on a data distribution: collect a large number of
random samples from the distribution, compress and decompress each of
them, and compute the rate and distortion averaged over the samples. The
resulting pair of numbers, (distortion, rate), then corresponds to a
point on the two-dimensional plane, which may look like this:&lt;/p&gt;
&lt;p&gt;&lt;img src="https://yiboyang.com/images/R-D-tradeoff-conceptual.svg" alt="Conceptual illustration of the rate-distortion tradeoff." width="800"/&gt;&lt;/p&gt;
&lt;p&gt;In this picture, the green point &lt;span class="math"&gt;\((D_1, R_1)\)&lt;/span&gt; corresponds to an algorithm with relatively high rate
but low distortion, while the orange point &lt;span class="math"&gt;\((D_2, R_2)\)&lt;/span&gt; trades off higher distortion
for a lower rate. The two points might also be of the same algorithm, but operating at
two different settings.
I also plotted the source rate-distortion function -- to be
introduced below -- in the blue curve. &lt;/p&gt;
&lt;h3&gt;The rate-distortion function.&lt;/h3&gt;
&lt;p&gt;Next, let's talk about the rate-distortion (R-D) function, denoted
&lt;span class="math"&gt;\(R(D)\)&lt;/span&gt;. Intuitively, the R-D function captures the fundamental "lossy
compressibility" of a data source. Thus, the R-D function is to lossy
function what &lt;em&gt;entropy&lt;/em&gt; is to lossless compression, and it generalizes the
latter concept to lossy compression. Formally, &lt;span class="math"&gt;\(R(D)\)&lt;/span&gt; is a real-valued
function of a single parameter &lt;span class="math"&gt;\(D\)&lt;/span&gt;, the distortion tolerance,
and is given by the mathematical definition,&lt;/p&gt;
&lt;div class="math"&gt;$$\begin{aligned}
R(D) := \inf_{Q_{Y|X}: \ \mathbb{E} [\rho(X, Y) ]\leq D} I(X; Y).\end{aligned}$$&lt;/div&gt;
&lt;p&gt;
In words, we consider all conditional distributions &lt;span class="math"&gt;\(Q_{Y|X}\)&lt;/span&gt; whose
expected distortion is within the given threshold &lt;span class="math"&gt;\(D\)&lt;/span&gt;, and minimize the
mutual information between the source &lt;span class="math"&gt;\(X\)&lt;/span&gt; and its reproduction &lt;span class="math"&gt;\(Y\)&lt;/span&gt; (as
induced by &lt;span class="math"&gt;\(P_X Q_{Y|X}\)&lt;/span&gt;). This minimum value is then &lt;span class="math"&gt;\(R(D)\)&lt;/span&gt;. Note that
the R-D function is entirely determined by the data distribution &lt;span class="math"&gt;\(P_X\)&lt;/span&gt;
and distortion metric &lt;span class="math"&gt;\(\rho\)&lt;/span&gt;.&lt;/p&gt;
&lt;p&gt;So far, &lt;span class="math"&gt;\(R(D)\)&lt;/span&gt; is nothing but a purely theoretical construction.
However, it amazingly turns out to have a practical significance -- for each given
distortion threshold &lt;span class="math"&gt;\(D\)&lt;/span&gt;, the number &lt;span class="math"&gt;\(R(D)\)&lt;/span&gt; is the &lt;em&gt;minimum achievable&lt;/em&gt;
rate (as measured in nats per sample) with which any lossy compression
algorithm can compress the data to an averaged distortion not exceeding
&lt;span class="math"&gt;\(D\)&lt;/span&gt;. The "minimum" part asserts that no compression algorithm can
perform better than the R-D function of the source, while the
"achievable" part says that conversely, the performance &lt;span class="math"&gt;\((D, R(D))\)&lt;/span&gt; is
also realizable by a (potentially expensive) compression algorithm.
In my example illustration, this means the rate-distortion performance (or more precisely,
distortion-rate performance) of all compression algorithms
must lie above the blue curve; thus the red point is logically unattainable.
Moreover, the orange point can be considered more optimal than the green point,
in the sense that it lies closer to the source R-D curve.
These results, known as lossy source coding theorems, were
proven by Shannon in his two landmark papers from the 1950s and 60s, and
formed the basis of the branch of information theory known as
rate-distortion theory.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Why do we care about the rate-distortion function?&lt;/strong&gt; Because knowledge of
it can help researchers and engineers build more effective data
communication systems. Here are two example applications:&lt;/p&gt;
&lt;p&gt;1. Assessing the optimality of lossy compression algorithms: If the
(distortion, rate) performance of a compression algorithm lies high
above the source &lt;span class="math"&gt;\(R(D)\)&lt;/span&gt; curve, then further performance improvement may
be expected; otherwise, its R-D performance is already close to
theoretically optimal, and we may decide to focus our attention on other
aspects of the algorithm.  Data compression is big business, and one day,
sooner or later, compression algorithms may run into their information-theoretic
limit, as determined by the ultimate compressibility of the data. It would be helpful to
know when we are getting close to this limit, before deciding to devote more
time and resources to improving the compression performance of an algorithm further.&lt;/p&gt;
&lt;p&gt;2. Assessing the minimum channel capacity required to transmit the
compressed source. Consider a common data communication system that first
subjects the data to compression, i.e., source coding, and then
transmits the bits through an information channel with channel coding.
For example, this could be a sensor repeatedly generating data and
sending it to a user over a wifi network. And suppose the user can only
tolerate an average distortion of at most &lt;span class="math"&gt;\(D\)&lt;/span&gt; in the received data,
under some notion of distortion. Then, it turns out that reliable
real-time communication in this setup is possible only if the channel
capacity is at least &lt;span class="math"&gt;\(R(D)\)&lt;/span&gt;, as given by the R-D function of the data
source. If the channel capacity is less than &lt;span class="math"&gt;\(R(D)\)&lt;/span&gt;, then this
communication goal is simply infeasible (one workaround is to buffer the
bitstream to be sent over the channel, but this introduces latency).
This is a consequence of Shannon's source-channel separation theorem.&lt;/p&gt;
&lt;p&gt;In &lt;a href="https://yiboyang.com/posts/estimating-the-rate-distortion-function-of-real-world-data-part-2/"&gt;part 2 of this post&lt;/a&gt;,
I'll introduce a simple and scalable way to estimate the rate-distortion function from data.&lt;/p&gt;
&lt;div class="footnote"&gt;
&lt;hr&gt;
&lt;ol&gt;
&lt;li id="fn:1"&gt;
&lt;p&gt;One way to extend the setup to a non i.i.d. (e.g., a higher order Markovian)
source is by defining an R-D function on blocks of &lt;span class="math"&gt;\(k\)&lt;/span&gt; data samples,
resulting in something called the &lt;span class="math"&gt;\(k\)&lt;/span&gt;-th order R-D function.&amp;#160;&lt;a class="footnote-backref" href="#fnref:1" title="Jump back to footnote 1 in the text"&gt;&amp;#8617;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&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://cdn.jsdelivr.net/npm/mathjax@2.7.9/MathJax.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="notes"/><category term="information theory"/><category term="rate-distortion theory"/><category term="data compression"/><category term="machine learning"/><category term="generative modeling"/><category term="statistics"/></entry><entry><title>The Ill-defined Problem of Maximum Likelihood Estimation</title><link href="https://yiboyang.com/posts/the-ill-defined-problem-of-maximum-likelihood-estimation/" rel="alternate"/><published>2021-10-28T21:01:00-07:00</published><updated>2021-10-28T21:01:00-07:00</updated><author><name>Yibo Yang</name></author><id>tag:yiboyang.com,2021-10-28:/posts/the-ill-defined-problem-of-maximum-likelihood-estimation/</id><summary type="html">&lt;p&gt;Why we use maximum likelihood for density estimation, when it breaks down (especially on real-world data), and what can be done about it.&lt;/p&gt;</summary><content type="html">&lt;!--- ![Illusting a simple data distribution in R^2 that does not have a density.]({static}/images/singular_measure_demo_blogpost.svg) ---&gt;
&lt;p&gt;&lt;img src="https://yiboyang.com/images/singular_measure_demo_blogpost.svg" alt="Illusting a simple data distribution in R^2 that does not have a density." width="400"/&gt;&lt;/p&gt;
&lt;p&gt;When I first read the &lt;a href="https://arxiv.org/abs/1701.07875"&gt;WGAN paper&lt;/a&gt; a while ago, I only had a vague understanding of what's meant by ``the data distribution may not have a density'', and why this spells trouble for density estimation (and hence motivates likelihood-free learning).
I hope to clarify these and related issues in an accessible note &lt;a href="https://yiboyang.com/files/ill_defined_mle.pdf"&gt;&lt;strong&gt;here&lt;/strong&gt;&lt;/a&gt;.&lt;/p&gt;</content><category term="notes"/><category term="machine learning"/><category term="generative modeling"/><category term="statistics"/></entry><entry><title>All the Ways to Carve Up the ELBO</title><link href="https://yiboyang.com/posts/all-the-ways-to-carve-up-the-elbo/" rel="alternate"/><published>2020-03-10T11:24:00-07:00</published><updated>2020-03-10T11:24:00-07:00</updated><author><name>Yibo Yang</name></author><id>tag:yiboyang.com,2020-03-10:/posts/all-the-ways-to-carve-up-the-elbo/</id><summary type="html">&lt;p&gt;My list of fancy decompositions of the aggregate ELBO, focusing on the role of the aggregate KL regularizer, its relation to the aggregate posterior, and the mutual information between the data and the latent variable.&lt;/p&gt;</summary><content type="html">&lt;p&gt;Despite the title, this is my by-no-means exhaustive collection of known
ways to decompose the ELBO, focusing on the role
of the aggregate KL regularizer, its relation to the aggregate
posterior, and the mutual information between the data and the latent
variable.&lt;/p&gt;
&lt;h3&gt;Setup&lt;/h3&gt;
&lt;p&gt;We assume the data distribution has a density, &lt;span class="math"&gt;\(p^*(x)\)&lt;/span&gt;, and we would
like to estimate it by that of a latent variable model
&lt;span class="math"&gt;\(p(x) := \int p(x|z) p(z) dz\)&lt;/span&gt;, via maximum likelihood. Everything works
the same in the discrete setting by replacing the word "density" with
"PMF", and integrals with sums. In reality, the data distribution may
not have a probability density, as is likely the case for real-world
data such as natural images; then maximum likelihood density estimation
runs into severe trouble, as I explain &lt;a href="https://yiboyang.com/files/ill_defined_mle.pdf"&gt;&lt;strong&gt;here&lt;/strong&gt;&lt;/a&gt;. However, let's just
stick with the standard textbook setting, and suppose the data
distribution really &lt;em&gt;does&lt;/em&gt; have a density &lt;span class="math"&gt;\(p^*(x)\)&lt;/span&gt; &lt;sup id="fnref:1"&gt;&lt;a class="footnote-ref" href="#fn:1"&gt;1&lt;/a&gt;&lt;/sup&gt;.&lt;/p&gt;
&lt;p&gt;The &lt;em&gt;ELBO&lt;/em&gt; (evidence lower bound) is a tractable lower bound on the
model log density &lt;span class="math"&gt;\(p(x)\)&lt;/span&gt;:
&lt;/p&gt;
&lt;div class="math"&gt;$$ELBO(x) := \mathbb{E}_{q(z|x)}[ \log p(x,z) - \log q(z|x) ] = \log p(x) - KL(q(z|x)\|p(z|x)) \leq \log p(x)$$&lt;/div&gt;
&lt;p&gt;
where &lt;span class="math"&gt;\(q(z|x)\)&lt;/span&gt; is any distribution &lt;sup id="fnref:2"&gt;&lt;a class="footnote-ref" href="#fn:2"&gt;2&lt;/a&gt;&lt;/sup&gt; over the latent space, and
&lt;span class="math"&gt;\(p(z|x) \propto p(z,x)\)&lt;/span&gt; is the Bayesian posterior of &lt;span class="math"&gt;\(z\)&lt;/span&gt; given &lt;span class="math"&gt;\(x\)&lt;/span&gt; under
our latent variable model. Note that all the distributions without the
* superscript (i.e., everything except the true data density &lt;span class="math"&gt;\(p^*(x)\)&lt;/span&gt;)
are ones we can potentially control and parameterize.&lt;/p&gt;
&lt;p&gt;For maximum-likelihood training, ideally we would like to maximize the
population log-likelihood &lt;span class="math"&gt;\(\mathbb{E}_{p^*(x)}[ \log p(x)]\)&lt;/span&gt;, or its
sample approximation based on a training set. Since &lt;span class="math"&gt;\(\log p(x)\)&lt;/span&gt; is
intractable, we replace it with the ELBO, resulting in the &lt;em&gt;aggregate
ELBO&lt;/em&gt; objective,
&lt;/p&gt;
&lt;div class="math"&gt;$$\mathbb{E}_{p^*(x)} [\mathbb{E}_{q(z|x)}[ \log p(x,z) - \log q(z|x) ] ],$$&lt;/div&gt;
&lt;p&gt;
which can be decomposed into an aggregate conditional log-likelihood,
minus an &lt;em&gt;aggregate ELBO regularizer&lt;/em&gt;:
&lt;/p&gt;
&lt;div class="math"&gt;$$\mathbb{E}_{p^*(x)} [\mathbb{E}_{q(z|x)}[ \log p(x|z)] - \mathbb{E}_{p^*(x)} [KL(q(z|x)\| p(z)) ].$$&lt;/div&gt;
&lt;p&gt;Of particular interest to me is the aggregate ELBO regularizer. Many of
the decompositions of the aggregate ELBO are simply based on rewriting
the aggregate regularizer term. Moreover, the aggregate ELBO regularizer
also arises outside the context of latent variable modeling and density
estimation, and has a nice connection to information theory.&lt;/p&gt;
&lt;h3&gt;Decomposing the Aggregate ELBO Regularizer&lt;/h3&gt;
&lt;p&gt;Besides the standard interpretation of the aggregate ELBO regularizer as
penalizing the complexity of the approximate posterior &lt;span class="math"&gt;\(q(z|x)\)&lt;/span&gt; by
pulling it closer to the prior &lt;span class="math"&gt;\(p(z)\)&lt;/span&gt;, here are some other ways to
decompose and interpret it:&lt;/p&gt;
&lt;p&gt;1. &lt;strong&gt;As the cross entropy between the aggregate posterior and prior,
plus the negative average entropy of approximate posteriors&lt;/strong&gt;:
&lt;/p&gt;
&lt;div class="math"&gt;$$\mathbb{E}_{p^*(x)} [KL(q(z|x)\| p(z)) ] = CE(q(z)\| p(z)) + \mathbb{E}_{p^*(x)} [ - \mathbb{H}[q(z|x)]].$$&lt;/div&gt;
&lt;p&gt;
The aggregate posterior is defined as
&lt;span class="math"&gt;\(q(z) = \mathbb{E}_{p^*(x)}[ q(z|x) ]\)&lt;/span&gt;, and the cross-entropy
&lt;span class="math"&gt;\(CE(q(z)\| p(z)) = \mathbb{E}_{q(z)} [-\log p(z)]\)&lt;/span&gt;. This form is easily
obtained by writing out
&lt;span class="math"&gt;\(KL(q(z|x)\| p(z)) = \mathbb{E}_{q(z|x)}[- \log p(z) + \log q(z|x) ]\)&lt;/span&gt;
and simplifying on the LHS.&lt;/p&gt;
&lt;p&gt;This form reveals that the optimal prior, in the sense of minimizing the
aggregate KL regularizer (and hence the aggregate ELBO), should be equal
to the aggregate posterior, i.e., &lt;span class="math"&gt;\(p(z) = q(z)\)&lt;/span&gt;, which is when the
cross-entropy term is minimized. See the &lt;a href="http://approximateinference.org/accepted/HoffmanJohnson2016.pdf"&gt;ELBO surgery
paper&lt;/a&gt;
and the &lt;a href="https://arxiv.org/abs/1705.07120"&gt;VampPrior paper&lt;/a&gt;, which
popularized this decomposition.&lt;/p&gt;
&lt;p&gt;2. &lt;strong&gt;As the KL divergence between the aggregate posterior and prior,
plus the mutual information of &lt;span class="math"&gt;\((x, z) \sim p^*(x) q(z|x)\)&lt;/span&gt;&lt;/strong&gt;:
&lt;/p&gt;
&lt;div class="math"&gt;$$\mathbb{E}_{p^*(x)} [KL(q(z|x)\| p(z)) ] = KL(q(z)||p(z)) + I_{p^*(x) q(z|x)}[X; Z],$$&lt;/div&gt;
&lt;p&gt;
where the mutual information is equal to
&lt;/p&gt;
&lt;div class="math"&gt;$$I_{p^*(x) q(z|x)}[X; Z] := \int \int p^*(x) q(z|x) \log \frac{q(z|x)} {q(z)}  dz dx.$$&lt;/div&gt;
&lt;p&gt;This form can be derived from the first decomposition ("cross-entropy
plus negative posterior entropy"), by adding and subtracting
&lt;span class="math"&gt;\(\mathbb{E}_{q(z)}[\log q(z)] = \mathbb{E}_{p^*(x)q(z|x)}[\log q(z)]\)&lt;/span&gt;
from the two terms. As in the first decomposition, the prior &lt;span class="math"&gt;\(p(z)\)&lt;/span&gt; only
appears in one term -- its divergence to the aggregate posterior, which
immediately reveals that the optimal &lt;span class="math"&gt;\(p(z) = q(z)\)&lt;/span&gt;. This decomposition
also nicely reveals the minimum value of the ELBO regularizer (when
&lt;span class="math"&gt;\(p(z) = q(z)\)&lt;/span&gt;) as the mutual information.&lt;/p&gt;
&lt;p&gt;Looked at another way, given any joint distribution &lt;span class="math"&gt;\(p^*(x) q(z|x)\)&lt;/span&gt;, the
aggregate ELBO regularizer is a variational upper bound on its mutual
information, with &lt;span class="math"&gt;\(p(z)\)&lt;/span&gt; being any arbitrary variational distribution,
&lt;/p&gt;
&lt;div class="math"&gt;$$I_{p^*(x) q(z|x)}[X; Z] = \min_{p(z)} \mathbb{E}_{p^*(x)} [KL(q(z|x)\| p(z)) ].$$&lt;/div&gt;
&lt;p&gt;
This is quite a useful upper bound on mutual information, a quantity
that often appears in machine learning but is typically challenging to
compute; see &lt;a href="http://proceedings.mlr.press/v97/poole19a.html"&gt;Poole et. al
2019&lt;/a&gt;. This upper bound
also plays a key role in the Blahut-Arimoto algorithm, a
well-established algorithm from information theory for computing
rate-distortion functions and channel capacity (see Section 19.8 of the
&lt;a href="https://onlinelibrary.wiley.com/doi/book/10.1002/047174882X"&gt;Elements of Information Theory
textbook&lt;/a&gt;).&lt;/p&gt;
&lt;p&gt;3. &lt;strong&gt;As the KL divergence between joint distributions &lt;span class="math"&gt;\(p^*(x) q(z|x)\)&lt;/span&gt;
and &lt;span class="math"&gt;\(p^*(x) p(z)\)&lt;/span&gt;&lt;/strong&gt;:
&lt;/p&gt;
&lt;div class="math"&gt;$$\mathbb{E}_{p^*(x)} [KL(q(z|x)\| p(z)) ] = \mathbb{E}_{p^*(x) q(z|x)} [ \log \frac{q(z|x)}{p(z)} + \log \frac{p^*(x)}{p^*(x)} ] = KL(p^*(x) q(z|x) \| p^*(x) p(z)).$$&lt;/div&gt;
&lt;p&gt;This is an intuitive restatement of effect of the aggregate ELBO
regularizer in pulling the approximate posteriors towards the prior, in
an "aggregate" sense. This form in terms of a KL divergence between two
distributions defined on the product space
&lt;span class="math"&gt;\(\mathcal{X} \times \mathcal{Z}\)&lt;/span&gt; has some technical advantages,
especially in the convergence proof of the Blahut-Arimoto algorithm.&lt;/p&gt;
&lt;p&gt;4 &lt;strong&gt;(bonus content)&lt;/strong&gt;. This a decomposition of the whole aggregate ELBO,
rather than just the aggregate ELBO regularizer term, but I'm including
it given its popularity in the literature:
&lt;/p&gt;
&lt;div class="math"&gt;$$\mathbb{E}_{p^*(x)} [\mathbb{E}_{q(z|x)}[ \log p(x,z) - \log q(z|x) ] ]
= - KL(q(z|x)p^*(x) \| p(x,z)) - \mathbb{H}[p^*]$$&lt;/div&gt;
&lt;p&gt; which is very much
analogous to how the (true) maximum likelihood objective decomposes into
the &lt;strong&gt;negative KL between the data and the model distributions, minus
the data entropy&lt;/strong&gt;:
&lt;/p&gt;
&lt;div class="math"&gt;$$\mathbb{E}_{p^*(x)} [ \log p(x) ] = - KL(p^*(x) \| p(x)) - \mathbb{H}[p^*]$$&lt;/div&gt;
&lt;p&gt;To obtain this decomposition, first integrate the following equality w.r.t. &lt;span class="math"&gt;\(p^*(x)\)&lt;/span&gt;
&lt;/p&gt;
&lt;div class="math"&gt;$$ELBO(x) = \log p(x) - KL(q(z|x)\|p(z|x))$$&lt;/div&gt;
&lt;p&gt;
to get
&lt;/p&gt;
&lt;div class="math"&gt;$$\mathbb{E}_{p^*(x)} [\mathbb{E}_{q(z|x)}[ \log p(x,z) - \log q(z|x) ] ]
= \mathbb{E}_{p^*(x)}[\log p(x)] - \mathbb{E}_{p^*(x)} [KL(q(z|x)\|p(z|x))].$$&lt;/div&gt;
&lt;p&gt;
As a sidenote: this tells us maximizing the aggregate ELBO objective (LHS) is equivalent
to maximizing the marginal log-likelihood &lt;span class="math"&gt;\(\mathbb{E}_{p^*(x)}[\log p(x)]\)&lt;/span&gt;, modulo
a gap equal to an aggregate mismatch between the variational and true posterior &lt;span class="math"&gt;\(\mathbb{E}_{p^*(x)} [ KL(q(z|x)\|p(z|x)) ]\)&lt;/span&gt;.
Next, replace the marginal log-likelihood (negative cross-entropy) term with
&lt;/p&gt;
&lt;div class="math"&gt;$$\mathbb{E}_{p^*(x)} [ \log p(x) ] = - KL(p^*(x) \| p(x)) - \mathbb{H}[p^*],$$&lt;/div&gt;
&lt;p&gt;
and finally, replace the marginal KL divergence using the chain rule of KL divergence,
&lt;/p&gt;
&lt;div class="math"&gt;$$KL(p^*(x) \| p(x)) = KL(q(z|x)p^*(x) \| p(x,z)) - \mathbb{E}_{p^*(x)} [ KL(q(z|x)\|p(z|x)) ],$$&lt;/div&gt;
&lt;p&gt;
we'll see that the &lt;span class="math"&gt;\(\mathbb{E}_{p^*(x)} [ KL(q(z|x)\|p(z|x)) ]\)&lt;/span&gt; terms cancel and the desired
result follows.&lt;/p&gt;
&lt;p&gt;This form is discussed at length in, e.g., &lt;a href="https://arxiv.org/pdf/1804.02086.pdf"&gt;Structured Disentangled
Representations&lt;/a&gt; (note that in
their definition, &lt;span class="math"&gt;\(p^*(x)\)&lt;/span&gt; is the empirical distribution defined by
training samples, rather the true data distribution).&lt;/p&gt;
&lt;div class="footnote"&gt;
&lt;hr&gt;
&lt;ol&gt;
&lt;li id="fn:1"&gt;
&lt;p&gt;It's possible to relax this assumption if we consider a more general notion
of ``density'' than the standard Lebesgue density on &lt;span class="math"&gt;\(\mathbb{R}^n\)&lt;/span&gt;.
i.e., if we know in advance the "manifold" on which the
data is concentrated, then the data distribution has a density function (Radon–Nikodym derivative)
w.r.t. the reference measure of that manifold, which we can still model/learn
with a latent variable model.&amp;#160;&lt;a class="footnote-backref" href="#fnref:1" title="Jump back to footnote 1 in the text"&gt;&amp;#8617;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li id="fn:2"&gt;
&lt;p&gt;Throughout this note I use the words "distribution" and "density"
interchangeably.&amp;#160;&lt;a class="footnote-backref" href="#fnref:2" title="Jump back to footnote 2 in the text"&gt;&amp;#8617;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&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://cdn.jsdelivr.net/npm/mathjax@2.7.9/MathJax.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="notes"/><category term="machine learning"/><category term="information theory"/></entry><entry><title>Equivalent Definitions of the (Best) Lipschitz Constant</title><link href="https://yiboyang.com/posts/equivalent-definitions-of-the-best-lipschitz-constant/" rel="alternate"/><published>2018-12-14T09:20:00-08:00</published><updated>2018-12-14T09:20:00-08:00</updated><author><name>Yibo Yang</name></author><id>tag:yiboyang.com,2018-12-14:/posts/equivalent-definitions-of-the-best-lipschitz-constant/</id><summary type="html">&lt;p&gt;A quick note on the equivalent (dual?) definitions of the Lipschitz constant.&lt;/p&gt;</summary><content type="html">&lt;p&gt;The &lt;a href="https://en.wikipedia.org/wiki/Lipschitz_continuity"&gt;standard, Wikipedia definition of a Lipschitz continuous function&lt;/a&gt; is the following:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Given two metric spaces &lt;span class="math"&gt;\((X, d_X)\)&lt;/span&gt; and &lt;span class="math"&gt;\((Y, d_Y)\)&lt;/span&gt;, where &lt;span class="math"&gt;\(d_X\)&lt;/span&gt; denotes the metric on the set &lt;span class="math"&gt;\(X\)&lt;/span&gt; and &lt;span class="math"&gt;\(d_Y\)&lt;/span&gt; is the metric on set &lt;span class="math"&gt;\(Y\)&lt;/span&gt;, a function &lt;span class="math"&gt;\(f : X → Y\)&lt;/span&gt; is called Lipschitz continuous if there exists a real constant &lt;span class="math"&gt;\(K ≥ 0\)&lt;/span&gt; such that, for all &lt;span class="math"&gt;\(x_1\)&lt;/span&gt; and &lt;span class="math"&gt;\(x_2\)&lt;/span&gt; in &lt;span class="math"&gt;\(X\)&lt;/span&gt;,
&lt;div class="math"&gt;$$
d_Y(f(x_1), f(x_2)) \leq K d_X(x_1, x_2)
$$&lt;/div&gt;
Any such &lt;span class="math"&gt;\(K\)&lt;/span&gt; is referred to as a Lipschitz constant for the function &lt;span class="math"&gt;\(f\)&lt;/span&gt;. The smallest constant &lt;span class="math"&gt;\(K^*\)&lt;/span&gt; is sometimes called the (best) Lipschitz constant...&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;From the above definition, it's not immediately clear to me that &lt;span class="math"&gt;\(K^*\)&lt;/span&gt; exists (it's possible that given any Lipschitz constant &lt;span class="math"&gt;\(K\)&lt;/span&gt;, we can always find another Lipschitz constant &lt;span class="math"&gt;\(K_2\)&lt;/span&gt; with &lt;span class="math"&gt;\(K_2 &amp;lt; K\)&lt;/span&gt;). 
The definition of &lt;span class="math"&gt;\(K^*\)&lt;/span&gt; in my textbook attemps to avoid this potential problem:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Given a Lipschitz continuous function &lt;span class="math"&gt;\(f: X \to Y\)&lt;/span&gt;, define the set of all Lipschitz constants by
&lt;div class="math"&gt;$$
C = \{K &amp;gt; 0| \forall x_1, x_2 \in X, d_Y(f(x_1), f(x_2)) \leq K d_X(x_1, x_2) \},
$$&lt;/div&gt;
and define the (best) Lipschitz constant by:
&lt;div class="math"&gt;$$
K^* = \inf C
$$&lt;/div&gt;
&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;but stops short of showing that &lt;span class="math"&gt;\(K^* \in C\)&lt;/span&gt;, i.e., &lt;span class="math"&gt;\(K^*\)&lt;/span&gt; is actually &lt;em&gt;a&lt;/em&gt; Lipschitz constant.&lt;/p&gt;
&lt;p&gt;Here's a nice way to see this is indeed the case. Consider the following supremum
&lt;/p&gt;
&lt;div class="math"&gt;$$
S := \sup \{ \frac{d_Y(f(x_1), f(x_2))}{d_X(x_1,x_2)} | x_1, x_2 \in X, x_1 \neq x_2 \}
$$&lt;/div&gt;
&lt;p&gt;
We know that &lt;span class="math"&gt;\(S &amp;gt;0\)&lt;/span&gt;, and &lt;span class="math"&gt;\(S\)&lt;/span&gt; is finite because &lt;span class="math"&gt;\(f\)&lt;/span&gt; is Lipschitz continuous.
Moreover,
&lt;/p&gt;
&lt;div class="math"&gt;$$
\forall x_1 \neq x_2 \in X, d_Y(f(x_1), f(x_2)) \leq S d_X(x_1, x_2)
$$&lt;/div&gt;
&lt;p&gt;
from the definition of &lt;span class="math"&gt;\(S\)&lt;/span&gt;, and the above inequality also holds when &lt;span class="math"&gt;\(x_1 = x_2\)&lt;/span&gt;, so &lt;span class="math"&gt;\(S \in C\)&lt;/span&gt; is a Lipschitz constant.
It's also easy to verify from first principles that we in fact have
&lt;/p&gt;
&lt;div class="math"&gt;$$
S = \inf C = \inf \{K &amp;gt; 0| \forall x_1, x_2 \in X, d_Y(f(x_1), f(x_2)) \leq K d_X(x_1, x_2) \}
$$&lt;/div&gt;
&lt;p&gt;
therefore
&lt;/p&gt;
&lt;div class="math"&gt;$$
K^* = S = \min C
$$&lt;/div&gt;
&lt;p&gt;
We see that
&lt;/p&gt;
&lt;div class="math"&gt;$$
\sup \{ \frac{d_Y(f(x_1), f(x_2))}{d_X(x_1,x_2)} | x_1, x_2 \in X, x_1 \neq x_2 \}
$$&lt;/div&gt;
&lt;p&gt;
gives an equivalent (and in some sense, dual) definition of the (best) Lipschitz constant.&lt;/p&gt;
&lt;p&gt;It's sometimes easier to work with this more direct definition of the Lipschitz constant.
For example, let &lt;span class="math"&gt;\(f, g: X \to Y\)&lt;/span&gt; be Lipschitz with the (best) Lipschitz constants &lt;span class="math"&gt;\(K_1, K_2\)&lt;/span&gt;, where
&lt;span class="math"&gt;\((X, d_X)\)&lt;/span&gt; is a metric space as usual, and &lt;span class="math"&gt;\((Y, \| \cdot \|)\)&lt;/span&gt; is a normed space.
Then it's easy to see that &lt;span class="math"&gt;\(f+g\)&lt;/span&gt; is also Lipschitz continuous, and if &lt;span class="math"&gt;\(K\)&lt;/span&gt; is the (best) Lipschitz
constant of &lt;span class="math"&gt;\(f+g\)&lt;/span&gt;, we can characterize it in terms of &lt;span class="math"&gt;\(K_1\)&lt;/span&gt; and &lt;span class="math"&gt;\(K_2\)&lt;/span&gt;:&lt;/p&gt;
&lt;div class="math"&gt;\begin{align*}
K &amp;amp;:= \sup_{x_1 \neq x_2} \frac{ \|f(x_1)+g(x_1) - f(x_2)-g(x_2) \| }{d_X(x_1,x_2)} \\
&amp;amp;\leq \sup_{x_1 \neq x_2} \frac{ \|f(x_1)-f(x_2)\|}{d_X(x_1,x_2)} + \frac{ \|g(x_1)-g(x_2)\| }{d_X(x_1,x_2)} \\
&amp;amp; \leq \sup_{x_1 \neq x_2} \frac{ \|f(x_1)-f(x_2)\|}{d_X(x_1,x_2)} + \sup_{x_1 \neq x_2}  \frac{ \|g(x_1)-g(x_2)\| }{d_X(x_1,x_2)} \\
&amp;amp;= K_1 + K_2
\end{align*}&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://cdn.jsdelivr.net/npm/mathjax@2.7.9/MathJax.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="notes"/><category term="real analysis"/></entry><entry><title>Variational Autoencoder</title><link href="https://yiboyang.com/posts/variational-autoencoder/" rel="alternate"/><published>2018-05-25T00:48:00-07:00</published><updated>2018-05-25T00:48:00-07:00</updated><author><name>Yibo Yang</name></author><id>tag:yiboyang.com,2018-05-25:/posts/variational-autoencoder/</id><summary type="html">&lt;p&gt;Training a VAE on MNIST from scratch using Keras.&lt;/p&gt;</summary><content type="html">&lt;p&gt;&lt;a href="https://nbviewer.jupyter.org/github/yiboyang/PRMLPY/blob/master/Variational_Autoencoder.ipynb"&gt;See my notebook here&lt;/a&gt;, based on section 3 of the &lt;a href="https://arxiv.org/pdf/1312.6114.pdf"&gt;VAE paper&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;It's worth comparing VAE with &lt;a href="https://yiboyang.com/posts/restricted-boltzmann-machine-and-contrastive-divergence/"&gt;RBM&lt;/a&gt; (and MRFs in general).  VAE as a directed graphical model doesn't have to deal with intractable partition function, which RBM approximates with MCMC in Contrastive Divergence. Instead, the conditional inference &lt;span class="math"&gt;\(p_\theta(z|x)\)&lt;/span&gt; required for learning VAE is intractable (which is tractable and efficient for RBM and other undirected models, because of their specially designed graphical structures), and the &lt;a href="https://yiboyang.com/posts/projections-of-probability-distributions-and-the-reparameterization-trick/"&gt;Reparameterization Trick&lt;/a&gt; is used to find an approximate I-projection &lt;span class="math"&gt;\(q_\phi(z|x)\)&lt;/span&gt;. 
Conceptually VAE is no different from probabilistic PCA (and other similar factor analysis models), except that neural networks are used to approximate the parameters in distributions like &lt;span class="math"&gt;\(q_\phi(z|x)\)&lt;/span&gt; and &lt;span class="math"&gt;\(p_\theta(x|z)\)&lt;/span&gt; (instead of simple linear-Gaussian models), and the variational posteriors for the different data samples &lt;span class="math"&gt;\(x^{(n)}\)&lt;/span&gt; share parameters, like &lt;span class="math"&gt;\(q(z^{(n)} | x^{(n)})=q_\phi(z|x^{(n)})\)&lt;/span&gt; (which is typically not the case in mean-field variational inference).&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://cdn.jsdelivr.net/npm/mathjax@2.7.9/MathJax.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="notes"/><category term="machine learning"/><category term="PGM"/><category term="generative modeling"/><category term="jupyter notebook"/><category term="python"/></entry><entry><title>Projections of Probability Distributions and the Reparameterization Trick</title><link href="https://yiboyang.com/posts/projections-of-probability-distributions-and-the-reparameterization-trick/" rel="alternate"/><published>2017-08-21T11:34:00-07:00</published><updated>2017-08-21T11:34:00-07:00</updated><author><name>Yibo Yang</name></author><id>tag:yiboyang.com,2017-08-21:/posts/projections-of-probability-distributions-and-the-reparameterization-trick/</id><summary type="html">&lt;p&gt;A brief review of M-projection, I-projection, REINFORCE, and the Reparameterization Trick.&lt;/p&gt;</summary><content type="html">&lt;p&gt;&lt;a href="http://nbviewer.jupyter.org/github/yiboyang/PRMLPY/blob/master/Probability_Distribution_Projections_and_the_Reparameterization_Trick.ipynb"&gt;See my notebook here&lt;/a&gt;.&lt;/p&gt;</content><category term="notes"/><category term="machine learning"/><category term="PGM"/><category term="jupyter notebook"/><category term="python"/></entry><entry><title>Restricted Boltzmann Machine and Contrastive Divergence</title><link href="https://yiboyang.com/posts/restricted-boltzmann-machine-and-contrastive-divergence/" rel="alternate"/><published>2017-07-21T17:48:00-07:00</published><updated>2017-07-21T17:48:00-07:00</updated><author><name>Yibo Yang</name></author><id>tag:yiboyang.com,2017-07-21:/posts/restricted-boltzmann-machine-and-contrastive-divergence/</id><summary type="html">&lt;p&gt;RBM training with CD from scratch on MNIST data.&lt;/p&gt;</summary><content type="html">&lt;p&gt;Previously I wrote about &lt;a href="https://yiboyang.com/posts/gibbs-sampling-in-pairwise-markov-networks/"&gt;Gibbs sampling in pairwise Markov Random Fields&lt;/a&gt;, where we generally have to update one variable at a time to obtain a full Gibbs sample. The Restricted Boltzmann Machine is a special MRF with additional independence assumptions that allow for efficient conditional inference and block Gibbs sampling; this makes maximum-likelihood learning tractable, using sampling-based methods like Contrastive Divergence.
&lt;a href="https://nbviewer.jupyter.org/github/yiboyang/PRMLPY/blob/master/Restricted_Boltzmann_Machine.ipynb"&gt;I demonstrate this in a Python notebook&lt;/a&gt;.&lt;/p&gt;</content><category term="notes"/><category term="machine learning"/><category term="PGM"/><category term="generative modeling"/><category term="jupyter notebook"/><category term="python"/></entry><entry><title>Linear Regression as Conditional Random Field</title><link href="https://yiboyang.com/posts/linear-regression-as-conditional-random-field/" rel="alternate"/><published>2017-02-07T18:47:00-08:00</published><updated>2017-02-07T18:47:00-08:00</updated><author><name>Yibo Yang</name></author><id>tag:yiboyang.com,2017-02-07:/posts/linear-regression-as-conditional-random-field/</id><summary type="html">&lt;p&gt;Classical linear regression simply uses a linear Gaussian model (CRF).&lt;/p&gt;</summary><content type="html">&lt;p&gt;Generally we can represent a CRF as a log-linear model:
&lt;/p&gt;
&lt;div class="math"&gt;\begin{equation} p_\theta(y|x) = \exp \{ \langle \theta, \phi(y,x) \rangle - A(\theta, x)   \} \label{eq:crf_exp_fam} \end{equation}&lt;/div&gt;
&lt;p&gt;
which can be obtained by conditioning a joint Markov network over &lt;span class="math"&gt;\((Y,X)\)&lt;/span&gt; on the observation &lt;span class="math"&gt;\(X=x\)&lt;/span&gt;. For simplicity we only consider a scalar r.v. &lt;span class="math"&gt;\(Y\)&lt;/span&gt;. For each fixed &lt;span class="math"&gt;\(x \in \mathbb{R}^d\)&lt;/span&gt;, the CRF has &lt;span class="math"&gt;\(\phi(\cdot, x)\)&lt;/span&gt; as the sufficient statistics function, and &lt;span class="math"&gt;\(A(\theta, x)\)&lt;/span&gt; the log partition function. As before, the derivative of &lt;span class="math"&gt;\(A\)&lt;/span&gt; yields the expected sufficient statistics, here taken w.r.t the conditional distribution &lt;span class="math"&gt;\(p_\theta(y|x)\)&lt;/span&gt;:
&lt;/p&gt;
&lt;div class="math"&gt;\begin{align*}
\frac{\partial A(\theta, x)}{\partial \theta_i}:= \frac{\partial} {\partial \theta_i} \log \int \exp \{ \langle \theta, \phi(y,x) \rangle \} dx =  \mathbb{E}[\phi_i(Y,x)|x]
\end{align*}&lt;/div&gt;
&lt;p&gt;In the case of linear regression, we assume that conditioned on &lt;span class="math"&gt;\(X=x\)&lt;/span&gt;, the target variable &lt;span class="math"&gt;\(Y\)&lt;/span&gt; is generated in the following way:
&lt;/p&gt;
&lt;div class="math"&gt;$$Y = f(x,\beta) + \epsilon$$&lt;/div&gt;
&lt;p&gt;
where &lt;span class="math"&gt;\(f(x,\beta)\)&lt;/span&gt; is a deterministic function parameterized by &lt;span class="math"&gt;\(\beta\)&lt;/span&gt;, and &lt;span class="math"&gt;\(\epsilon\)&lt;/span&gt; is random noise distributed as &lt;span class="math"&gt;\(\mathcal{N}(0, \sigma^2)\)&lt;/span&gt;. For simplicity, we consider a function &lt;span class="math"&gt;\(f\)&lt;/span&gt; that is linear in &lt;span class="math"&gt;\(\beta\)&lt;/span&gt; and &lt;span class="math"&gt;\(x\)&lt;/span&gt;, and append a dummy variable &lt;span class="math"&gt;\(x_0=1\)&lt;/span&gt; to the vector &lt;span class="math"&gt;\(x\)&lt;/span&gt;, so that &lt;span class="math"&gt;\(f(x,\beta) = \beta_0 + \beta_1 x_1 + ... + \beta_d x_d  = \beta^T x\)&lt;/span&gt;.&lt;/p&gt;
&lt;p&gt;Equivalently, &lt;span class="math"&gt;\(Y \sim \mathcal{N}(f(x,\beta), \sigma ^2)\)&lt;/span&gt;, and we can write
&lt;/p&gt;
&lt;div class="math"&gt;$$p(y|x) = \frac{1}{ \sqrt{2 \pi \sigma^2}} \exp \{ - \frac{(\beta_0 + \beta^T x - y)^2}{2\sigma^2} \}  $$&lt;/div&gt;
&lt;p&gt; To put it in the standard log-linear form, we consider the log conditional likelihood:
&lt;/p&gt;
&lt;div class="math"&gt;\begin{align*}
\log p(y|x) &amp;amp;= -\frac{1}{2} \log(2\pi \sigma^2) - \frac{1}{2\sigma^2}(\beta_0 + \beta^T x - y)^2 \\
&amp;amp; = \frac{\beta^T x}{\sigma^2}y -\frac{1}{2\sigma^2}y^2 - \frac{(\beta^Tx)^2}{2\sigma^2} -\frac{1}{2} \log(2\pi \sigma^2) \\
&amp;amp; = \sum_{i=0}^d \frac{\beta_i}{\sigma^2} x_i y + \frac{-1}{2\sigma^2} y^2 - \frac{(\beta^Tx)^2}{2\sigma^2} -\frac{1}{2} \log(2\pi \sigma^2)\\
&amp;amp; = \begin{bmatrix}
\frac{\beta_0}{\sigma^2} &amp;amp; \frac{\beta_1}{\sigma^2} \cdots \frac{\beta_d}{\sigma^2} &amp;amp; \frac{-1}{2\sigma^2}
\end{bmatrix}
\begin{bmatrix}
y\\
x_1y\\
\vdots\\
x_dy\\
y^2
\end{bmatrix} - A(\beta, \sigma, x)
\end{align*}&lt;/div&gt;
&lt;p&gt;
from which we recognize the vector of canonical parameters &lt;span class="math"&gt;\(\theta = (\frac{\beta_0}{\sigma^2}, \frac{\beta_1}{\sigma^2}, ... , \frac{\beta_d}{\sigma^2}, \frac{-1}{2\sigma^2})\)&lt;/span&gt; and sufficient statistics &lt;span class="math"&gt;\(\phi(y,x)=(y, x_1y,...,x_dy,y^2)\)&lt;/span&gt;.&lt;/p&gt;
&lt;p&gt;Suppose we have a data set &lt;span class="math"&gt;\(\mathcal{D}\)&lt;/span&gt; of i.i.d. observations &lt;span class="math"&gt;\((x^{(1)}, y^{(1)}), ..., (x^{(N)}, y^{(N)})\)&lt;/span&gt;; from (&lt;span class="math"&gt;\(\ref{eq:crf_exp_fam}\)&lt;/span&gt;) we obtain the data log likelihood under the CRF:
&lt;/p&gt;
&lt;div class="math"&gt;$$ l_{\mathbf{y}|\mathbf{x}} (\theta; \mathcal{D}) := \log p_\theta(y^{(1)},...,y^{(N)}|x^{(1)},...,x^{(N)}) = \sum_{n=1}^N \langle \theta, \phi(y^{(n)},x^{(n)} \rangle - A(\theta, x^{(n)}) $$&lt;/div&gt;
&lt;p&gt;
Note each data case defines a Markov network with its own sufficient statistics function and partition function.&lt;/p&gt;
&lt;p&gt;We find MLE for the parameters by differentiating the log likelihood function, making use of the cumulant-generating property of &lt;span class="math"&gt;\(A\)&lt;/span&gt;:
&lt;/p&gt;
&lt;div class="math"&gt;$$ \frac{\partial l_{\mathbf{y}|\mathbf{x}} (\theta; \mathcal{D})  }{\partial \theta_i} = \sum_{n=1}^N \phi_i(y^{(n)},x^{(n)}) - \mathbb{E}[\phi_i(Y,x^{(n)})|x^{(n)}] $$&lt;/div&gt;
&lt;p&gt;Note the above deals directly with canonical parameters &lt;span class="math"&gt;\(\theta\)&lt;/span&gt; in the log-linear model (whereas conventionally linear regression performs MLE w.r.t. the parameters &lt;span class="math"&gt;\(\beta\)&lt;/span&gt; and &lt;span class="math"&gt;\(\sigma^2\)&lt;/span&gt;). To apply it to our conditional Gaussian distribution, we define the subvector &lt;span class="math"&gt;\(\theta_\beta:= (\frac{\beta_0}{\sigma^2}, \frac{\beta_1}{\sigma^2}, ... , \frac{\beta_d}{\sigma^2})\)&lt;/span&gt; of canonical parameters, which is associated with the subvector &lt;span class="math"&gt;\(\phi_\beta(y,x) := (x_0y, x_1y,...,x_dy) = y x \in \mathbb{R}^d\)&lt;/span&gt; of sufficient statistics. Then
&lt;/p&gt;
&lt;div class="math"&gt;\begin{align*}
\frac{\partial l_{\mathbf{y}|\mathbf{x}} (\theta; \mathcal{D}) }{\partial \theta_\beta} 
&amp;amp;= \sum_{n=1}^N \phi_\beta (y^{(n)}, x^{(n)}) -  \mathbb{E}[\phi_\beta(Y, x^{(n)})|x^{(n)}] \\
&amp;amp;= \sum_{n=1}^N y^{(n)} x^{(n)} -  \mathbb{E}[Y x^{(n)}|x^{(n)}] \\
&amp;amp;= \sum_{n=1}^N y^{(n)} x^{(n)} - \mathbb{E}[ Y|x^{(n)}] x^{(n)}\\
&amp;amp;= \sum_{n=1}^N y^{(n)} x^{(n)} - (\beta^T x^{(n)}) x^{(n)}\\
&amp;amp;= \sum_{n=1}^N (y^{(n)} - (\beta^T x^{(n)})) x^{(n)} 
\end{align*}&lt;/div&gt;
&lt;p&gt;
where we made use of the linearity of expectations, and the fact that the mean parameter &lt;span class="math"&gt;\(\mathbb{E}[Y|x]\)&lt;/span&gt; of our Gaussian distribution is by design &lt;span class="math"&gt;\(\beta^T x\)&lt;/span&gt;. Setting the gradient to zero recovers the normal equations, yielding the MLE solution &lt;span class="math"&gt;\(\beta_{ML}\)&lt;/span&gt;.
The gradient encourages the model prediction (given by conditional expectation &lt;span class="math"&gt;\(\mathbb{E}[Y|x^{(n)}])\)&lt;/span&gt; to match the observed data &lt;span class="math"&gt;\(y^{(n)}\)&lt;/span&gt;. This form of gradient holds more generally for GLM, and indeed much of the derivation above goes unchanged, except for the specific form of mean parameters.&lt;/p&gt;
&lt;p&gt;Similarly, define &lt;span class="math"&gt;\(\theta_{\sigma}:= \frac{-1}{2\sigma^2}\)&lt;/span&gt; and &lt;span class="math"&gt;\(\phi_\sigma(y,x) = y^2\)&lt;/span&gt;. Taking derivative w.r.t &lt;span class="math"&gt;\(\theta_{\sigma}\)&lt;/span&gt;:
&lt;/p&gt;
&lt;div class="math"&gt;\begin{align*}
\frac{\partial l_{\mathbf{y}|\mathbf{x}} (\theta; \mathcal{D}) }{\partial \theta_\sigma} 
&amp;amp;= \sum_{n=1}^N \phi_\beta (y^{(n)}, x^{(n)}) -  \mathbb{E}[\phi_\sigma(Y, x^{(n)})|x^{(n)}]\\
&amp;amp;= \sum_{n=1}^N (y^{(n)})^2 - \mathbb{E}[Y^2|x^{(n)}]\\
&amp;amp;= \sum_{n=1}^N (y^{(n)})^2 - (\sigma^2 + (\beta^T x^{(n)})^2)
\end{align*}&lt;/div&gt;
&lt;p&gt;
where we made use of the formula for the second moment of the Gaussian. Again, setting the derivative to zero results in a moment matching condition for &lt;span class="math"&gt;\(\sigma\)&lt;/span&gt;, from which we can solve for the MLE (after plugging in &lt;span class="math"&gt;\(\beta_{ML}\)&lt;/span&gt;). After some algebra it can be verified that &lt;span class="math"&gt;\(\sigma^2_{ML}\)&lt;/span&gt; is indeed the average residual sum of squares. The optimal ``conventional'' parameters &lt;span class="math"&gt;\((\beta_{ML}, \sigma^2_{ML})\)&lt;/span&gt; implicitly define the optimal canonical parameters &lt;span class="math"&gt;\(\theta_{ML}\)&lt;/span&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://cdn.jsdelivr.net/npm/mathjax@2.7.9/MathJax.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="notes"/><category term="linear algebra"/><category term="statistics"/></entry><entry><title>Gibbs Sampling in Pairwise Markov Networks</title><link href="https://yiboyang.com/posts/gibbs-sampling-in-pairwise-markov-networks/" rel="alternate"/><published>2017-02-01T19:02:00-08:00</published><updated>2017-02-01T19:02:00-08:00</updated><author><name>Yibo Yang</name></author><id>tag:yiboyang.com,2017-02-01:/posts/gibbs-sampling-in-pairwise-markov-networks/</id><summary type="html">&lt;p&gt;Discrete pairwise Markov networks are pretty straightforward to work with analytically.
Let's use the canonical overcomplete representation, where the sufficient statistics functions are indicator functions ...&lt;/p&gt;</summary><content type="html">&lt;p&gt;Discrete pairwise Markov networks are pretty straightforward to work with analytically.
Let's use the canonical overcomplete representation, where the sufficient statistics functions are indicator functions for events &lt;span class="math"&gt;\(\{X_s = j\}\)&lt;/span&gt; and &lt;span class="math"&gt;\(\{X_s = j,X_t = k \}\)&lt;/span&gt;, and define an exponential family of the form
&lt;/p&gt;
&lt;div class="math"&gt;\begin{align}
p_\theta(x) = \exp \{ \sum_{s\in V} \theta_s(x_s) + \sum_{(s,t)\in E} \theta_{st}(x_s,x_t) - A(\theta) \}
\end{align}&lt;/div&gt;
&lt;p&gt;
where we have introduced the convenient shorthand notation
&lt;/p&gt;
&lt;div class="math"&gt;\begin{align}
\theta_s(x_s) &amp;amp;:=  \sum_j \theta_{s;j} \mathbb{I}_{s;j}(x_s)\\
\theta_{st}(x_s,x_t) &amp;amp;:=  \sum_{(j,k)} \theta_{st;jk} \mathbb{I}_{st;jk}(x_s, x_t)
\end{align}&lt;/div&gt;
&lt;p&gt;
i.e. when &lt;span class="math"&gt;\(x_s = j\)&lt;/span&gt;, &lt;span class="math"&gt;\(\theta_s(x_s=j)\)&lt;/span&gt; selects the number &lt;span class="math"&gt;\(\theta_{s;j}\)&lt;/span&gt;; similarly &lt;span class="math"&gt;\(\theta_{st}(x_s=j,x_t=k)\)&lt;/span&gt; selects the number &lt;span class="math"&gt;\(\theta_{st;jk}\)&lt;/span&gt;, so &lt;span class="math"&gt;\(\theta_s\)&lt;/span&gt; is a vector of size &lt;span class="math"&gt;\(|\chi_s|\)&lt;/span&gt;, and &lt;span class="math"&gt;\(\theta_{st}\)&lt;/span&gt; is a matrix of size &lt;span class="math"&gt;\(|\chi_s| \times |\chi_t|\)&lt;/span&gt;--in fact, they are potential tables for the factors over &lt;span class="math"&gt;\(X_s\)&lt;/span&gt; and &lt;span class="math"&gt;\((X_s, X_t)\)&lt;/span&gt;. To see this, rewrite our exponential representation as a standard Gibbs distribution:
&lt;/p&gt;
&lt;div class="math"&gt;\begin{align}
p_\theta(x) = \frac{1}{Z} \prod_{s\in V} \exp \{  \theta_s(x_s) \}  \prod_{(s,t)\in E}  \exp \{ \theta_{st}(x_s,x_t) \}
\end{align}&lt;/div&gt;
&lt;p&gt;If we define singleton potential &lt;span class="math"&gt;\(\psi_s(x_s) := \exp \{  \theta_s(x_s) \}\)&lt;/span&gt;, and pair-wise potential &lt;span class="math"&gt;\(\psi_{st}(x_s,x_t) :=\exp \{ \theta_{st}(x_s,x_t) \}\)&lt;/span&gt;, then we see that our canonical parameters are precisely the &lt;span class="math"&gt;\(\log\)&lt;/span&gt; potential values: &lt;span class="math"&gt;\(\theta_{s;j} = \theta_s(x_s=j) = \log  \psi_s(x_s=j)\)&lt;/span&gt;, and &lt;span class="math"&gt;\(\theta_{st;jk} = \theta_{st}(x_s=j,x_t=k) = \log \psi_{st}(x_s=j,x_t=k)\)&lt;/span&gt;.&lt;/p&gt;
&lt;p&gt;Let's consider making conditional inference in the model, which we need for Gibbs sampling. More precisely, we're interested in the marginal distribution of one node, call it &lt;span class="math"&gt;\(s\)&lt;/span&gt;, conditioned on the instantiation to all the rest of the nodes.
(ypically this distribution is called the full conditional distribution). By Bayes rule,
&lt;/p&gt;
&lt;div class="math"&gt;\begin{align}
p(x_s | x_{V \setminus s}) &amp;amp;= \frac{p(x_s, x_{V \setminus s})}{p(x_{V \setminus s})}\\
&amp;amp;= \frac{p(x)}{\sum_{x_s'} p(x_s', x_{V \setminus s})}\\
&amp;amp;= \frac{ \exp\{\theta_s(x_s) + \sum_{n \in V: n \neq s}\theta_n(x_n) + \sum_{n\in N(s)} \theta_{ns}(x_n, x_s) + \sum_{ (m,n) \in E: m\neq s, n\neq s} \theta_{mn}(x_m, x_n) - A(\theta)  \} }{ \sum_{x_s'} \exp\{\theta_s(x_s') + \sum_{n \in V: n \neq s}\theta_n (x_n) + \sum_{n\in N(s)} \theta_{ns}(x_n, x_s') + \sum_{ (m,n) \in E: m\neq s, n\neq s} \theta_{mn}(x_m, x_n) - A(\theta)}\\
&amp;amp;= \frac{ \exp\{\theta_s(x_s) + \sum_{n\in N(s)} \theta_{ns}(x_n, x_s) \} }{ \sum_{x_s'} \exp\{\theta_s x_s' + \sum_{n\in N(s)} \theta_{ns}(x_n, x_s') \} }
\end{align}&lt;/div&gt;
&lt;p&gt;
where &lt;span class="math"&gt;\(N(s)\)&lt;/span&gt; means &lt;span class="math"&gt;\(\{n \in V, (n, s) \in E \}\)&lt;/span&gt;, i.e. the neighbor nodes of &lt;span class="math"&gt;\(s\)&lt;/span&gt;. Not surprisingly the conditional distribution is a softmax function, as we're working with exponential family distributions.&lt;/p&gt;
&lt;p&gt;Equivalently, we can write the above as a Gibbs distribution:
&lt;/p&gt;
&lt;div class="math"&gt;$$ p(x_s | x_{V \setminus s}) \propto \psi(x_s) \prod_{n\in N(s)} \psi(x_n, x_s) $$&lt;/div&gt;
&lt;p&gt;
Generally, in an arbitrary Gibbs distribution &lt;span class="math"&gt;\(p\)&lt;/span&gt;, the full conditional distribution for some variable &lt;span class="math"&gt;\(s\)&lt;/span&gt;, &lt;span class="math"&gt;\(p(x_s|x_{V \setminus s})\)&lt;/span&gt;,
involves precisely the factors over the Markov blanket of &lt;span class="math"&gt;\(s\)&lt;/span&gt;. The proof of this isn't too different from what we showed above for the
pairwise case (i.e. expanding the factorized form of &lt;span class="math"&gt;\(p\)&lt;/span&gt; in the numerator and denominator of &lt;span class="math"&gt;\(p(x_s|x_{V \setminus s})\)&lt;/span&gt;, then canceling out common factors).&lt;/p&gt;
&lt;p&gt;In the specific example of an Ising model, we restrict the range of all the node values to &lt;span class="math"&gt;\(\chi = \{0, 1\}\)&lt;/span&gt; &lt;sup&gt;&lt;a href="#myfootnote1"&gt;1&lt;/a&gt;&lt;/sup&gt;, 
and let the sufficient statistics to simply be the node values and their pairwise products, i.e., &lt;span class="math"&gt;\(x_s\)&lt;/span&gt; for &lt;span class="math"&gt;\(s \in V\)&lt;/span&gt;, and &lt;span class="math"&gt;\(x_s x_t\)&lt;/span&gt; for &lt;span class="math"&gt;\(s, t \in E\)&lt;/span&gt;.
The full conditional distribution then becomes
&lt;/p&gt;
&lt;div class="math"&gt;$$p(x_s | x_{V \setminus s}) =  \frac{ \exp\{\theta_s x_s + \sum_{n\in N(s)} \theta_{ns}x_n x_s \} }{ \sum_{x_s'} \exp\{\theta_s x_s' + \sum_{n\in N(s)} \theta_{ns}x_n x_s' \} }$$&lt;/div&gt;
&lt;p&gt;
In particular, we have
&lt;/p&gt;
&lt;div class="math"&gt;\begin{align}
p(x_s=1| x_{V \setminus s}) &amp;amp; = \frac{\exp\{\theta_s + \sum_{t\in N(s)} \theta_{ts}x_t \}}{\exp\{\theta_s + \sum_{t\in N(s)} \theta_{ts}x_t \}+1} \\
&amp;amp;= \{ 1 + \exp\{- (\theta_s + \sum_{t\in N(s)} \theta_{ts}x_t) \} \}^{-1} = \text{logistic sigmoid }(\theta_s + \sum_{t\in N(s)} \theta_{ts}x_t)
\end{align}&lt;/div&gt;
&lt;p&gt;
which suggests this type of distribution can well be viewed as a stochastic recurrent neural network (with sigmoid activations)!&lt;/p&gt;
&lt;p&gt;&lt;a name="myfootnote1"&gt;1&lt;/a&gt;: Traditionally the variables in an Ising model take values in &lt;span class="math"&gt;\(\{-1, 1\}\)&lt;/span&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://cdn.jsdelivr.net/npm/mathjax@2.7.9/MathJax.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="notes"/><category term="PGM"/><category term="probability"/><category term="statistics"/></entry><entry><title>Kernel =&gt; RKHS + Feature Map</title><link href="https://yiboyang.com/posts/kernel-rkhs-feature-map/" rel="alternate"/><published>2016-12-15T17:09:00-08:00</published><updated>2016-12-15T17:09:00-08:00</updated><author><name>Yibo Yang</name></author><id>tag:yiboyang.com,2016-12-15:/posts/kernel-rkhs-feature-map/</id><summary type="html">&lt;p&gt;Given a kernel function, find the Reproducing Kernel Hilbert Space and the feature map it defines.&lt;/p&gt;</summary><content type="html">&lt;p&gt;Let the input vector space be &lt;span class="math"&gt;\(\mathcal{X} = \mathbb{R}^2\)&lt;/span&gt;, and define kernel &lt;span class="math"&gt;\(k: \mathcal{X} \times \mathcal{X} \to \mathbb{R}, k(x,y)=\|x-y\|_2^2 = (x_1-y_1)^2+(x_2-y_2)^2\)&lt;/span&gt;. Let's find the space of functions &lt;span class="math"&gt;\(\mathcal{H}\)&lt;/span&gt; on &lt;span class="math"&gt;\(\mathcal{X}\)&lt;/span&gt;, for which &lt;span class="math"&gt;\(k\)&lt;/span&gt; is the reproducing kernel. The corresponding feature map is then &lt;span class="math"&gt;\(\phi: \mathcal{X}\to \mathcal{H}, \phi(x) = k(\cdot, x) = \|\cdot - x\|_2^2\)&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;To construct a unique RKHS given kernel, I copied and pasted the standard procedure (i.e. &lt;a href="https://en.wikipedia.org/wiki/Reproducing_kernel_Hilbert_space#Moore.E2.80.93Aronszajn_theorem"&gt;Moore-Aronszajn theorem&lt;/a&gt;) here:
For all &lt;span class="math"&gt;\(x\in \mathcal{X}\)&lt;/span&gt;, define the function &lt;/p&gt;
&lt;div class="math"&gt;$$k_x = k(\cdot, x)$$&lt;/div&gt;
&lt;p&gt;
Let &lt;span class="math"&gt;\(\mathcal{H}_0\)&lt;/span&gt; be the linear span of &lt;span class="math"&gt;\(k_x\)&lt;/span&gt;, i.e. &lt;span class="math"&gt;\(\mathcal{H}_0\)&lt;/span&gt; consists of functions of the form &lt;/p&gt;
&lt;div class="math"&gt;$$\forall i, x_i \in \mathcal{X}, f(\cdot) = \sum_i a_i k_{x_i}(\cdot)$$&lt;/div&gt;
&lt;p&gt;
Define an inner product on &lt;span class="math"&gt;\(\mathcal{H}_0\)&lt;/span&gt; by &lt;/p&gt;
&lt;div class="math"&gt;$$\langle f, g \rangle = \langle \sum_i^m a_i k_{x_i}, \sum_j^n b_j k_{x_j}\rangle = \sum_i^m \sum_j^n a_i b_j k(x_i, x_j)  \tag{*} \label{eq:inner}$$&lt;/div&gt;
&lt;p&gt;Let &lt;span class="math"&gt;\(\mathcal{H}\)&lt;/span&gt; be the completion of &lt;span class="math"&gt;\(\mathcal{H}_0\)&lt;/span&gt; with respect to this inner product. Then &lt;span class="math"&gt;\(\mathcal{H}\)&lt;/span&gt; consists of functions of the form
&lt;/p&gt;
&lt;div class="math"&gt;$$f(\cdot) = \sum_i^\infty a_i k_{x_i}(\cdot)$$&lt;/div&gt;
&lt;p&gt;Ok that's all very cool, but what does an element in &lt;span class="math"&gt;\(\mathcal{H}\)&lt;/span&gt; actually look like for our kernel &lt;span class="math"&gt;\(k(x,y)=\|x-y\|_2^2 = (x_1-y_1)^2+(x_2-y_2)^2\)&lt;/span&gt;? Consider a concrete &lt;span class="math"&gt;\(\tilde y = (a,b) \in \mathcal{X}\)&lt;/span&gt;, say &lt;span class="math"&gt;\((a,b)=(3,4)\)&lt;/span&gt;, then its representer &lt;span class="math"&gt;\(k_{\tilde y} = k_{(a,b)} \in \mathcal{H}\)&lt;/span&gt; is the function such that &lt;span class="math"&gt;\(k_{(a,b)} (x) = x_1^2 + x_2^2 - 2ax_1 - 2bx_2 + a^2 + b^2\)&lt;/span&gt;. An element in &lt;span class="math"&gt;\(\mathcal{H_0}\)&lt;/span&gt; then takes the form of a linear combination of functions &lt;span class="math"&gt;\(k_{(a,b)}\)&lt;/span&gt;, as we vary &lt;span class="math"&gt;\((a,b) \in \mathcal{X}\)&lt;/span&gt;. An element &lt;span class="math"&gt;\(f\)&lt;/span&gt; in &lt;span class="math"&gt;\(\mathcal{H}\)&lt;/span&gt; is some linear combination of infinitely many such &lt;span class="math"&gt;\(k_{(a,b)}\)&lt;/span&gt;, and it'll look something like &lt;span class="math"&gt;\(f(x) = ax_1^2 + ax_2^2 + bx_1 + cx_2 + d\)&lt;/span&gt;, where &lt;span class="math"&gt;\(a,b,c,d\in\mathbb{R}\)&lt;/span&gt; have some funky convergent property.&lt;/p&gt;
&lt;p&gt;For our earlier example &lt;span class="math"&gt;\(k_{\tilde y} = k_{(3,4)}\)&lt;/span&gt;, you may be tempted to write
&lt;/p&gt;
&lt;div class="math"&gt;$$k_{\tilde y} (x) = \langle k_{\tilde y}, k_x \rangle_{\mathcal{H}} =
\begin{bmatrix}
1 &amp;amp; 1 &amp;amp; -6 &amp;amp; -8 &amp;amp; 25
\end{bmatrix}
\begin{bmatrix}
x_1^2 \\ x_2^2 \\ x_1 \\ x_2 \\ 1
\end{bmatrix}$$&lt;/div&gt;
&lt;p&gt;
then identify &lt;span class="math"&gt;\(k_{\tilde y}\)&lt;/span&gt; with the vector &lt;span class="math"&gt;\((1,1,-6,-8,25)\)&lt;/span&gt; and conclude that the feature map defined by &lt;span class="math"&gt;\(k\)&lt;/span&gt; is &lt;span class="math"&gt;\(\phi: \mathbb{R}^2 \to \mathbb{R}^5, \phi(x) = k_x = (x_1^2, x_2^2, x_1, x_2, 1)\)&lt;/span&gt;. This is incorrect, as our RKHS &lt;span class="math"&gt;\(\mathcal{H} \neq \mathbb{R}^5\)&lt;/span&gt;, and &lt;/p&gt;
&lt;div class="math"&gt;$$
\begin{bmatrix}
1 &amp;amp; 1 &amp;amp; -6 &amp;amp; -8 &amp;amp; 25
\end{bmatrix}
\begin{bmatrix}
x_1^2 \\ x_2^2 \\ x_1 \\ x_2 \\ 1
\end{bmatrix}
$$&lt;/div&gt;
&lt;p&gt;
is not the inner product \eqref{eq:inner} on &lt;span class="math"&gt;\({\mathcal{H}}\)&lt;/span&gt; (although it is the inner product on &lt;span class="math"&gt;\(\mathbb{R}^5\)&lt;/span&gt;).
If you are not convinced, take the inner product (on &lt;span class="math"&gt;\(\mathbb{R}^5\)&lt;/span&gt;) between &lt;span class="math"&gt;\((x_1^2, x_2^2, x_1, x_2, 1)\)&lt;/span&gt; and &lt;span class="math"&gt;\((y_1^2, y_2^2, y_1, y_2, 1)\)&lt;/span&gt;; this is certainly not equal to &lt;span class="math"&gt;\(k(x,y)\)&lt;/span&gt;.&lt;/p&gt;
&lt;p&gt;To write kernel evaluation as inner product in the feature space &lt;span class="math"&gt;\(\mathcal{H}\)&lt;/span&gt; defined by the kernel, we have to follow the definition \eqref{eq:inner}:
&lt;/p&gt;
&lt;div class="math"&gt;$$k(x, y) = \langle k_{x}, k_{y} \rangle_{\mathcal{H}}$$&lt;/div&gt;
&lt;p&gt;Good resources on RKHS:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href="https://www.youtube.com/watch?v=jgi8hbOmUmk"&gt;intro to Hilbert space video&lt;/a&gt;; optionally &lt;a href="https://www.youtube.com/watch?v=PTm1H40g-UI"&gt;application in Fourier analysis&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Arthur Gretton's tutorials &lt;a href="http://www.gatsby.ucl.ac.uk/~gretton/coursefiles/lecture4_introToRKHS.pdf"&gt;here&lt;/a&gt; and &lt;a href="http://www.gatsby.ucl.ac.uk/~gretton/coursefiles/RKHS_Notes1.pdf"&gt;here (great theoretical details)&lt;/a&gt;&lt;/p&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://cdn.jsdelivr.net/npm/mathjax@2.7.9/MathJax.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="notes"/><category term="RKHS"/><category term="machine learning"/></entry><entry><title>Separating Hyerplane Example</title><link href="https://yiboyang.com/posts/separating-hyerplane-example/" rel="alternate"/><published>2016-11-30T16:30:00-08:00</published><updated>2016-11-30T16:30:00-08:00</updated><author><name>Yibo Yang</name></author><id>tag:yiboyang.com,2016-11-30:/posts/separating-hyerplane-example/</id><summary type="html">&lt;p&gt;What it takes to separate an affine and a convex set.&lt;/p&gt;</summary><content type="html">&lt;p&gt;p.49. Example 2.19: Separation of an affine and a convex set:
Suppose &lt;span class="math"&gt;\(C\)&lt;/span&gt; is convex and &lt;span class="math"&gt;\(D\)&lt;/span&gt; is affine, i.e., &lt;span class="math"&gt;\(D = \{F u + g | u ∈ \mathbb{R}^m\}\)&lt;/span&gt;, where &lt;span class="math"&gt;\(F ∈ \mathbb{R}^{n×m}\)&lt;/span&gt;. Suppose C and D are disjoint, so by the separating hyperplane theorem there are &lt;span class="math"&gt;\(a \neq 0\)&lt;/span&gt; and &lt;span class="math"&gt;\(b\)&lt;/span&gt; such that &lt;span class="math"&gt;\(a^\top x ≤ b\)&lt;/span&gt; for all &lt;span class="math"&gt;\(x ∈ C\)&lt;/span&gt; and &lt;span class="math"&gt;\(a^\top x ≥ b\)&lt;/span&gt; for all &lt;span class="math"&gt;\(x ∈ D\)&lt;/span&gt;.
Now &lt;span class="math"&gt;\(a^\top x ≥ b\)&lt;/span&gt; for all x ∈ D means &lt;span class="math"&gt;\(a^\top F u ≥ b − aT g\)&lt;/span&gt; for all &lt;span class="math"&gt;\(u ∈ \mathbb{R}^m\)&lt;/span&gt;. But a linear function is bounded below on &lt;span class="math"&gt;\(\mathbb{R}^m\)&lt;/span&gt; only when it is zero, so we conclude &lt;span class="math"&gt;\(a^\top F = 0\)&lt;/span&gt; (and hence, &lt;span class="math"&gt;\(b ≤ a^\top g\)&lt;/span&gt;).&lt;/p&gt;
&lt;p&gt;A geometric way to look at this is to think of &lt;span class="math"&gt;\(D\)&lt;/span&gt; as the range of the linear map &lt;span class="math"&gt;\(F\)&lt;/span&gt; plus an offset vector &lt;span class="math"&gt;\(g\)&lt;/span&gt;, or the column space of a matrix &lt;span class="math"&gt;\(F\)&lt;/span&gt; plus &lt;span class="math"&gt;\(g\)&lt;/span&gt;. The only way to draw a hyperplane in space that doesn't intersect &lt;span class="math"&gt;\(D\)&lt;/span&gt; is for it to be parallel to &lt;span class="math"&gt;\(D\)&lt;/span&gt;, i.e. the normal vector &lt;span class="math"&gt;\(a\)&lt;/span&gt; needs to be perpendicular to the column space of &lt;span class="math"&gt;\(F\)&lt;/span&gt;, which requires &lt;span class="math"&gt;\(a\)&lt;/span&gt; to be in the left-null space of &lt;span class="math"&gt;\(F\)&lt;/span&gt;, so &lt;span class="math"&gt;\(a^\top F = 0\)&lt;/span&gt;. This and the requirement that &lt;span class="math"&gt;\(a^\top F u ≥ b − a^\top g\)&lt;/span&gt; give a constraint on the legal choices of &lt;span class="math"&gt;\(b\)&lt;/span&gt;, i.e. &lt;span class="math"&gt;\(b ≤ a^\top g\)&lt;/span&gt;. Then we also have &lt;span class="math"&gt;\(a^\top x \leq b \leq a^\top g\)&lt;/span&gt; for all &lt;span class="math"&gt;\(x \in C\)&lt;/span&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://cdn.jsdelivr.net/npm/mathjax@2.7.9/MathJax.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="notes"/><category term="convex optimization"/></entry><entry><title>Relative Interior</title><link href="https://yiboyang.com/posts/relative-interior/" rel="alternate"/><published>2016-10-14T22:59:00-07:00</published><updated>2016-10-14T22:59:00-07:00</updated><author><name>Yibo Yang</name></author><id>tag:yiboyang.com,2016-10-14:/posts/relative-interior/</id><summary type="html">&lt;p&gt;A relative notion of set interior.&lt;/p&gt;</summary><content type="html">&lt;p&gt;&lt;em&gt;This is a series of notes on convex optimization, covering technical details/backgrounds as I study it for the first time. The classic text &lt;a href="http://stanford.edu/~boyd/cvxbook/"&gt;Convex Optimization&lt;/a&gt;, will be heavily referenced.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;The mathematical definition &lt;span class="math"&gt;\(\textbf{relint }C = \{x \in C | B(x, r) ∩ \textbf{aff } C ⊆ C \text{ for some }r &amp;gt; 0\}\)&lt;/span&gt;, stated in English, is the set of points that are the centers of norm balls with some positive radius such that these balls' intersections with &lt;span class="math"&gt;\(\textbf{aff }C\)&lt;/span&gt; are always contained in &lt;span class="math"&gt;\(C\)&lt;/span&gt;. We then define the relative boundary of a set &lt;span class="math"&gt;\(C\)&lt;/span&gt; as &lt;span class="math"&gt;\(\textbf{cl } C \setminus \textbf{relint } C\)&lt;/span&gt;, where &lt;span class="math"&gt;\(\textbf{cl } C\)&lt;/span&gt; is the closure of &lt;span class="math"&gt;\(C\)&lt;/span&gt;. The notion of closure is in many ways dual to the notion of interior--the closure of &lt;span class="math"&gt;\(C\)&lt;/span&gt; is the smallest closed set containing &lt;span class="math"&gt;\(C\)&lt;/span&gt;, whereas the interior of &lt;span class="math"&gt;\(C\)&lt;/span&gt; is the biggest open set within &lt;span class="math"&gt;\(C\)&lt;/span&gt;. The boundary of &lt;span class="math"&gt;\(C\)&lt;/span&gt; is the set of points in &lt;span class="math"&gt;\(\textbf{cl }C\)&lt;/span&gt; not belonging to the interior of &lt;span class="math"&gt;\(C\)&lt;/span&gt;.&lt;/p&gt;
&lt;p&gt;A point is in the &lt;span class="math"&gt;\(\textit{interior}\)&lt;/span&gt; of a set if you can draw a small open ball around it which is itself contained in the set. The concept of the ''interior'' of a set can also be defined relative to the ''ambient space'' around it (more precisely, its affine hull)--that's the idea behind the relative interior. This is most useful when the &lt;em&gt;interior&lt;/em&gt; of a set is empty, but its &lt;em&gt;relative interior&lt;/em&gt; captures the points we want to work with. For example, the unit circle in &lt;span class="math"&gt;\(\mathbb{R}^2\)&lt;/span&gt;, &lt;span class="math"&gt;\(A=\{x ∈ \mathbb{R}^2 | x_1^2 + x_2^2 = 1\}\)&lt;/span&gt;, has the unit open disk &lt;span class="math"&gt;\(B=\{x ∈ \mathbb{R}^2 | x_1^2 + x_2^2 &amp;lt; 1\}\)&lt;/span&gt; as its interior; but the unit circle sitting on x-y plane in &lt;span class="math"&gt;\(\mathbb{R}^3\)&lt;/span&gt;, i.e.,&lt;span class="math"&gt;\(E=\{x ∈ \mathbb{R}^3 | x_1^2 + x_2^2 = 1, x_3=0\}\)&lt;/span&gt;, has empty interior, by definition. The open disk &lt;span class="math"&gt;\(D=\{x ∈ \mathbb{R}^3 | x_1^2 + x_2^2 &amp;lt; 1, x_3=0\}\)&lt;/span&gt; is not the interior of &lt;span class="math"&gt;\(E\)&lt;/span&gt;, since any norm ball with center located in &lt;span class="math"&gt;\(D\)&lt;/span&gt; will necessarily capture some points of &lt;span class="math"&gt;\(\mathbb{R}^3\)&lt;/span&gt; above and below &lt;span class="math"&gt;\(D\)&lt;/span&gt; that are not in &lt;span class="math"&gt;\(E\)&lt;/span&gt;. But &lt;span class="math"&gt;\(D\)&lt;/span&gt; is kind of an interior (and a far more interesting one than the empty interior)--we declare it the relative interior of &lt;span class="math"&gt;\(E\)&lt;/span&gt;, relative to &lt;span class="math"&gt;\(\textbf{aff }E = \{x ∈ \mathbb{R}^3|x_3=0\}\)&lt;/span&gt;; then we're back to the &lt;span class="math"&gt;\(\mathbb{R}^2\)&lt;/span&gt; case of &lt;span class="math"&gt;\(B\)&lt;/span&gt; being the interior of &lt;span class="math"&gt;\(A\)&lt;/span&gt;.&lt;/p&gt;
&lt;p&gt;Also see book example 2.2, p.23 of a relative boundary.&lt;/p&gt;
&lt;p&gt;Other resources:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://en.wikipedia.org/wiki/Relative_interior"&gt;https://en.wikipedia.org/wiki/Relative_interior&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.quora.com/What-is-the-difference-between-the-interior-and-the-relative-interior-of-a-set"&gt;https://www.quora.com/What-is-the-difference-between-the-interior-and-the-relative-interior-of-a-set&lt;/a&gt;&lt;br&gt;
&lt;a href="http://math.stackexchange.com/questions/1144750/whats-the-difference-between-interior-and-relative-interior"&gt;http://math.stackexchange.com/questions/1144750/whats-the-difference-between-interior-and-relative-interior&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://cdn.jsdelivr.net/npm/mathjax@2.7.9/MathJax.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="notes"/><category term="convex optimization"/></entry><entry><title>Geometric Interpretations of First-Order Taylor Approximation</title><link href="https://yiboyang.com/posts/geometric-interpretations-of-first-order-taylor-approximation/" rel="alternate"/><published>2016-09-05T11:09:00-07:00</published><updated>2016-09-05T11:09:00-07:00</updated><author><name>Yibo Yang</name></author><id>tag:yiboyang.com,2016-09-05:/posts/geometric-interpretations-of-first-order-taylor-approximation/</id><summary type="html">&lt;p&gt;Geometric views from the output space, input space, and graph space.&lt;/p&gt;</summary><content type="html">&lt;p&gt;For a scalar valued function &lt;span class="math"&gt;\(f: \mathbb{R}^n \to \mathbb{R}\)&lt;/span&gt;,  the first order Taylor expansion near some point &lt;span class="math"&gt;\(x_0\)&lt;/span&gt; gives the best approximating affine function &lt;span class="math"&gt;\(p_1: \mathbb{R}^n \to \mathbb{R}\)&lt;/span&gt;
&lt;/p&gt;
&lt;div class="math"&gt;$$p_1(x) = f(x_0) + \nabla f(x_0) (x-x_0) $$&lt;/div&gt;
&lt;p&gt;
Note that the gradient of &lt;span class="math"&gt;\(p_1\)&lt;/span&gt; at any point &lt;span class="math"&gt;\(x\)&lt;/span&gt; is the same (since it's an affine map): &lt;span class="math"&gt;\(\nabla p_1(x) = \nabla f(x_0)\)&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;We can give &lt;span class="math"&gt;\(p_1\)&lt;/span&gt; three geometric interpretations:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;In the &lt;strong&gt;output space&lt;/strong&gt; &lt;span class="math"&gt;\(\mathbb{R}\)&lt;/span&gt;, for points &lt;span class="math"&gt;\(x\)&lt;/span&gt; near &lt;span class="math"&gt;\(x_0\)&lt;/span&gt;, the values of &lt;span class="math"&gt;\(f\)&lt;/span&gt; lie on a &lt;span class="math"&gt;\(1\)&lt;/span&gt; dimensional affine subspace that is the image of &lt;span class="math"&gt;\(p_1(x)\)&lt;/span&gt;.
This geometric interpretation becomes more interesting for a vector valued function &lt;span class="math"&gt;\(\mathbf{f}: \mathbb{R}^n \to \mathbb{R}^m\)&lt;/span&gt;:
the values of &lt;span class="math"&gt;\(\mathbf{f}\)&lt;/span&gt; lie roughly on an affine subspace of &lt;span class="math"&gt;\(\mathbb{R}^m\)&lt;/span&gt;, which is the column space of the &lt;span class="math"&gt;\(m \times n\)&lt;/span&gt; Jacobian matrix shifted by &lt;span class="math"&gt;\(\mathbf{f}(x_0)\)&lt;/span&gt;.&lt;/p&gt;
&lt;p&gt;This first interpretation comes straight from the definition of differentiability, which is all about locally approximating an arbitrary function by an affine map.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;In the &lt;strong&gt;input space&lt;/strong&gt; &lt;span class="math"&gt;\(\mathbb{R}^n\)&lt;/span&gt;, if we pick a point &lt;span class="math"&gt;\(x_0 \in \textbf{dom }f\)&lt;/span&gt;, the level set/surface of &lt;span class="math"&gt;\(p_1\)&lt;/span&gt; at &lt;span class="math"&gt;\(f(x_0)\)&lt;/span&gt;,
&lt;span class="math"&gt;\(P = \{ x \in \mathbb{R}^n | p_1(x) = f(x_0)\}\)&lt;/span&gt;, is a hyperplane with the normal vector &lt;span class="math"&gt;\(\nabla f(x_0)\)&lt;/span&gt; passing through the point &lt;span class="math"&gt;\(x_0\)&lt;/span&gt;.
That is, &lt;span class="math"&gt;\(P\)&lt;/span&gt; is the set of points in &lt;span class="math"&gt;\(\mathbb{R}^n\)&lt;/span&gt; that satisfy:
&lt;div class="math"&gt;$$ \nabla f(x_0) (x-x_0) =0 $$&lt;/div&gt;
Consider the level set of &lt;span class="math"&gt;\(f\)&lt;/span&gt; at &lt;span class="math"&gt;\(f(x_0)\)&lt;/span&gt;, &lt;span class="math"&gt;\(S = \{ x \in \mathbb{R}^n | f(x) = f(x_0)\}\)&lt;/span&gt;. In &lt;span class="math"&gt;\(\mathbb{R}^2\)&lt;/span&gt;, &lt;span class="math"&gt;\(S\)&lt;/span&gt; is a contour line of &lt;span class="math"&gt;\(f\)&lt;/span&gt;, and &lt;span class="math"&gt;\(P\)&lt;/span&gt; is just a straight line, both passing through &lt;span class="math"&gt;\(x_0\)&lt;/span&gt;. Important facts:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span class="math"&gt;\(\nabla f(x_0)\)&lt;/span&gt; is the direction of steepest ascent of &lt;span class="math"&gt;\(f\)&lt;/span&gt; at the point &lt;span class="math"&gt;\(x_0 \in S\)&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span class="math"&gt;\(\nabla f(x_0)\)&lt;/span&gt; is perpendicular to &lt;span class="math"&gt;\(S\)&lt;/span&gt; at the point &lt;span class="math"&gt;\(x_0\)&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span class="math"&gt;\(P\)&lt;/span&gt; is tangent to &lt;span class="math"&gt;\(S\)&lt;/span&gt; at the point &lt;span class="math"&gt;\(x_0\)&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;img alt="contour map of a function with annotations" src="https://yiboyang.com/images/contour-grad.png"&gt;&lt;/p&gt;
&lt;p&gt;This second geometric view is used most often in the context of gradient based optimization.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;In the &lt;strong&gt;graph space&lt;/strong&gt; &lt;span class="math"&gt;\(\mathbb{R}^{n+1}\)&lt;/span&gt;, the graph of &lt;span class="math"&gt;\(p_1\)&lt;/span&gt; is a hyperplane tangent to the graph of &lt;span class="math"&gt;\(f\)&lt;/span&gt; at the point &lt;span class="math"&gt;\((x_0, f(x_0))\)&lt;/span&gt;.
Recall we define the graph of &lt;span class="math"&gt;\(f\)&lt;/span&gt; to be the set &lt;span class="math"&gt;\(\{ (x, t) | f(x) = t \}\)&lt;/span&gt;, call it &lt;span class="math"&gt;\(G_f\)&lt;/span&gt;.
To find a hyperplane in &lt;span class="math"&gt;\(\mathbb{R}^{n+1}\)&lt;/span&gt; that is tangent to &lt;span class="math"&gt;\(G_f\)&lt;/span&gt; at the point &lt;span class="math"&gt;\((x_0, f(x_0)) \in G_f\)&lt;/span&gt;, we introduce a helper function 
&lt;span class="math"&gt;\(F: \mathbb{R}^{n+1} \to \mathbb{R}\)&lt;/span&gt;, s.t. &lt;span class="math"&gt;\(\forall x \in \textbf{dom } f, \forall t \in \mathbb{R}, F(x,t) := f(x) - t\)&lt;/span&gt; (think of it as
reporting the difference in temperature between the point &lt;span class="math"&gt;\(x\)&lt;/span&gt; measured by &lt;span class="math"&gt;\(f(x)\)&lt;/span&gt; and some pre-specified value &lt;span class="math"&gt;\(t\)&lt;/span&gt;).
Then the level set/surface of &lt;span class="math"&gt;\(F\)&lt;/span&gt; at &lt;span class="math"&gt;\(0\)&lt;/span&gt; is precisely &lt;span class="math"&gt;\(G_f\)&lt;/span&gt;, and based on the second geometric view, we can find the normal vector to
&lt;span class="math"&gt;\(G_f\)&lt;/span&gt; at &lt;span class="math"&gt;\((x_0, f(x_0))\)&lt;/span&gt; by evaluating the gradient of &lt;span class="math"&gt;\(F\)&lt;/span&gt; at &lt;span class="math"&gt;\((x_0, f(x_0))\)&lt;/span&gt; (which is just another point in its input space):
&lt;div class="math"&gt;$$\nabla F(x_0, f(x_0)) = [ \nabla f(x_0) \quad \frac{\partial F}{\partial t} ] = [ \nabla f(x_0) \quad -1 ] $$&lt;/div&gt;
The hyperplane we're looking for is therefore the set of points &lt;span class="math"&gt;\((x,t) \in \mathbb{R}^{n+1}\)&lt;/span&gt; that satisfy:
&lt;div class="math"&gt;$$ \nabla F(x_0, f(x_0)) (\begin{bmatrix}
           x \\
           t
         \end{bmatrix}
         -
         \begin{bmatrix}
           x_0 \\
           f(x_0)
         \end{bmatrix}) = 0
         $$&lt;/div&gt;
or simply,
&lt;div class="math"&gt;$$f(x_0) + \nabla f(x_0) (x-x_0) = t$$&lt;/div&gt;
This is precisely the graph of &lt;span class="math"&gt;\(p_1\)&lt;/span&gt;, i.e. the set &lt;span class="math"&gt;\(G_p = \{ (x, t) | p_1(x) = t \}\)&lt;/span&gt;.
So we see that the &lt;span class="math"&gt;\(G_p\)&lt;/span&gt; is tangent to &lt;span class="math"&gt;\(G_f\)&lt;/span&gt; at the point &lt;span class="math"&gt;\((x_0, f(x_0))\)&lt;/span&gt;, and the vector &lt;span class="math"&gt;\([ \nabla f(x_0) \quad -1 ]\)&lt;/span&gt; is perpendicular to &lt;span class="math"&gt;\(G_f\)&lt;/span&gt; at &lt;span class="math"&gt;\((x_0, f(x_0))\)&lt;/span&gt;.
Since &lt;span class="math"&gt;\(S\)&lt;/span&gt; is just a slice of &lt;span class="math"&gt;\(G_f\)&lt;/span&gt; at the height &lt;span class="math"&gt;\(f(x_0)\)&lt;/span&gt;, similarly &lt;span class="math"&gt;\(P\)&lt;/span&gt; a slice of &lt;span class="math"&gt;\(G_p\)&lt;/span&gt; at the same height, the earlier assertion makes
geometric sense: &lt;span class="math"&gt;\(P\)&lt;/span&gt; must be tangent to &lt;span class="math"&gt;\(S\)&lt;/span&gt; at the point &lt;span class="math"&gt;\(x_0\)&lt;/span&gt;, because the graphs containing them (&lt;span class="math"&gt;\(G_f\)&lt;/span&gt; and &lt;span class="math"&gt;\(G_p\)&lt;/span&gt;) are tangent at &lt;span class="math"&gt;\((x_0, f(x_0)\)&lt;/span&gt;.&lt;/p&gt;
&lt;p&gt;This view is most helpful for working with epigraphs of functions.&lt;/p&gt;
&lt;p&gt;For an application, let's consider the geometry of epigraphs for convex functions, based on the last view from graph space.
Recall the epigraph of a function &lt;span class="math"&gt;\(f: \mathbb{R}^n \to \mathbb{R}\)&lt;/span&gt; is a subset of &lt;span class="math"&gt;\(\mathbb{R}^{n+1}\)&lt;/span&gt;, &lt;span class="math"&gt;\(\textbf{epi }f := \{ (x, t)| x \in \textbf{dom }f, f(x) \leq t  \}\)&lt;/span&gt;. By the first order condition of convexity, for convex &lt;span class="math"&gt;\(f\)&lt;/span&gt; we have 
&lt;div class="math"&gt;$$\forall x, y \in \textbf{dom }f, f(y) \geq f(x) + \nabla f(x)^\top (y-x) $$&lt;/div&gt;
which says that the first-order Taylor approximation of &lt;span class="math"&gt;\(f\)&lt;/span&gt; at any point &lt;span class="math"&gt;\(x\)&lt;/span&gt; is always  a global underestimator of the function.
This inequality implies:
&lt;div class="math"&gt;$$ \forall (y,t) \in \textbf{epi }f, \quad t \geq f(y) \geq f(x) + \nabla f(x)^\top (y-x)   $$&lt;/div&gt;
or
&lt;div class="math"&gt;$$ (y,t) \in \textbf{epi }f \implies [\nabla f(x) \quad -1] (\begin{bmatrix}
           y \\
           t
         \end{bmatrix}
         -
         \begin{bmatrix}
           x \\
           f(x)
         \end{bmatrix}) \leq 0 $$&lt;/div&gt;
for all choices of &lt;span class="math"&gt;\(x\)&lt;/span&gt;. Geometrically, this says that the hyperplane defined by the normal vector &lt;span class="math"&gt;\((∇f(x), −1)\)&lt;/span&gt; &lt;em&gt;supports&lt;/em&gt; &lt;span class="math"&gt;\(\textbf{epi }f\)&lt;/span&gt; at the boundary point &lt;span class="math"&gt;\((x, f(x))\)&lt;/span&gt;.&lt;/p&gt;
&lt;p&gt;&lt;img alt="epigraph of a function" src="https://yiboyang.com/images/cvx-epigraph.png"&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;References: &lt;a href="https://www.pearsonhighered.com/program/Colley-Vector-Calculus-4th-Edition/PGM126263.html"&gt;Vector Calculus&lt;/a&gt; p. 165 - p. 168 (esp. example 8 on p. 167) and &lt;a href="http://stanford.edu/~boyd/cvxbook/"&gt;Convex Optimization&lt;/a&gt; p. 76.&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://cdn.jsdelivr.net/npm/mathjax@2.7.9/MathJax.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="notes"/><category term="calculus"/><category term="linear algebra"/><category term="convex optimization"/></entry><entry><title>Polar Decomposition Example</title><link href="https://yiboyang.com/posts/polar-decomposition-example/" rel="alternate"/><published>2016-04-01T00:21:00-07:00</published><updated>2016-04-01T00:21:00-07:00</updated><author><name>Yibo Yang</name></author><id>tag:yiboyang.com,2016-04-01:/posts/polar-decomposition-example/</id><summary type="html">&lt;p&gt;A small numeric example illustrating polar decomposition.&lt;/p&gt;</summary><content type="html">&lt;p&gt;&lt;em&gt;This is a series of notes taken during my review of linear algebra, using Axler's excellent textbook &lt;a href="http://linear.axler.net"&gt;Linear Algera Done Right&lt;/a&gt;, which will be heavily referenced.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Every complex number can be written as a nonnegative real number &lt;span class="math"&gt;\(r\)&lt;/span&gt; times a number &lt;span class="math"&gt;\(e^{i \theta}\)&lt;/span&gt; on the unit circle:
&lt;/p&gt;
&lt;div class="math"&gt;$$ z = (\frac{z}{\bar{z}}) |z| =  (\frac{z}{\bar{z}}) \sqrt{\bar{z}z} = e^{i \theta} r $$&lt;/div&gt;
&lt;p&gt;
Similarly, every operator &lt;span class="math"&gt;\(T\)&lt;/span&gt; can be written as an isometry &lt;span class="math"&gt;\(S\)&lt;/span&gt; times a positive semidefinite (positive definite when &lt;span class="math"&gt;\(T\)&lt;/span&gt; is invertible) operator:
&lt;/p&gt;
&lt;div class="math"&gt;$$ T = S \sqrt{T^*T} $$&lt;/div&gt;
&lt;p&gt;
This theorem has a nice physical manifestation: in continuum mechanics, any deformation can be separated into a pure rotation effect and pure compression effect (as an imprecise analogy, a Rasengan should to hurled at the opponent with the maximum rotation and velocity in order to deliver the greatest damage).&lt;/p&gt;
&lt;p&gt;Example, exercise 7.D.7: Define &lt;span class="math"&gt;\(T \in \mathcal{L}(\mathbb{F}^3)\)&lt;/span&gt; by
&lt;span class="math"&gt;\(T(z_1, z_2, z_3) = (z_3,2z_1,3z_2)\)&lt;/span&gt;. Find (explicitly) an isometry &lt;span class="math"&gt;\(S \in \mathcal{L}(\mathbb{F}^3)\)&lt;/span&gt; such that &lt;span class="math"&gt;\(T = S \sqrt{T^*T}\)&lt;/span&gt;.&lt;/p&gt;
&lt;p&gt;Solution: with respect to the standard basis,
&lt;/p&gt;
&lt;div class="math"&gt;$$ \mathcal{M}(T) =
\begin{bmatrix}
0 &amp;amp; 0 &amp;amp; 1\\
2 &amp;amp; 0 &amp;amp; 0 \\
0 &amp;amp; 3 &amp;amp; 0
\end{bmatrix},
\mathcal{M}(T^*) =
\begin{bmatrix}
0 &amp;amp; 2 &amp;amp; 0\\
0 &amp;amp; 0 &amp;amp; 3 \\
1 &amp;amp; 0 &amp;amp; 0
\end{bmatrix},
\mathcal{M}(T^*T) =
\begin{bmatrix}
4 &amp;amp; 0 &amp;amp; 0\\
0 &amp;amp; 9 &amp;amp; 0 \\
0 &amp;amp; 0 &amp;amp; 1
\end{bmatrix},
\mathcal{M}(\sqrt{T^*T}) =
\begin{bmatrix}
2 &amp;amp; 0 &amp;amp; 0\\
0 &amp;amp; 3 &amp;amp; 0 \\
0 &amp;amp; 0 &amp;amp; 1
\end{bmatrix}
$$&lt;/div&gt;
&lt;p&gt;
By inspection, &lt;span class="math"&gt;\(\mathcal{M}(\sqrt{T^*T})\)&lt;/span&gt; differs from &lt;span class="math"&gt;\(\mathcal{M}(T)\)&lt;/span&gt; only in the order of the entries,
so if we define &lt;span class="math"&gt;\(S\)&lt;/span&gt; by &lt;span class="math"&gt;\(S(z_1,z_2,z_3) = (z_3,z_1,z_2)\)&lt;/span&gt;, then &lt;span class="math"&gt;\(S\)&lt;/span&gt; is certainly an isometry, and we arrive at the beautiful decomposition:
&lt;/p&gt;
&lt;div class="math"&gt;$$\mathcal{M}(S) \mathcal{M}(\sqrt{T^*T})= \mathcal{M}(T) =
\begin{bmatrix}
0 &amp;amp; 0 &amp;amp; 1\\
2 &amp;amp; 0 &amp;amp; 0 \\
0 &amp;amp; 3 &amp;amp; 0
\end{bmatrix}=
\begin{bmatrix}
0 &amp;amp; 0 &amp;amp; 1\\
1 &amp;amp; 0 &amp;amp; 0 \\
0 &amp;amp; 1 &amp;amp; 0
\end{bmatrix}
\begin{bmatrix}
2 &amp;amp; 0 &amp;amp; 0\\
0 &amp;amp; 3 &amp;amp; 0 \\
0 &amp;amp; 0 &amp;amp; 1
\end{bmatrix}
$$&lt;/div&gt;
&lt;p&gt;We have decomposed the matrix description of &lt;span class="math"&gt;\(T\)&lt;/span&gt; into a pure rotation matrix &lt;span class="math"&gt;\(\mathcal{M}(S)\)&lt;/span&gt; and a (positive) "stretching" matrix
&lt;span class="math"&gt;\(\mathcal{M}(\sqrt{T^*T})\)&lt;/span&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://cdn.jsdelivr.net/npm/mathjax@2.7.9/MathJax.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="notes"/><category term="linear algebra"/></entry><entry><title>Eigendecomposition as Change of Basis</title><link href="https://yiboyang.com/posts/eigendecomposition-as-change-of-basis/" rel="alternate"/><published>2016-03-28T15:22:00-07:00</published><updated>2016-03-28T15:22:00-07:00</updated><author><name>Yibo Yang</name></author><id>tag:yiboyang.com,2016-03-28:/posts/eigendecomposition-as-change-of-basis/</id><summary type="html">&lt;p&gt;An operator has a particularly simple matrix description in its eigenbasis.&lt;/p&gt;</summary><content type="html">&lt;p&gt;&lt;em&gt;This is a series of notes taken during my review of linear algebra, using Axler's excellent textbook &lt;a href="http://linear.axler.net"&gt;Linear Algera Done Right&lt;/a&gt;, which will be heavily referenced.&lt;/em&gt;
&lt;/p&gt;
&lt;div class="math"&gt;$$
\newcommand{\X}{$X$}
\newcommand{\Y}{$Y$}
\newcommand{\la}{\langle}
\newcommand{\ra}{\rangle}
\newcommand{\bv}{\mathbf{v}}
\newcommand{\bu}{\mathbf{u}}
\newcommand{\bw}{\mathbf{w}}
\newcommand{\be}{\mathbf{e}}
\newcommand{\bs}{\mathbf{s}}
\newcommand{\bff}{\mathbf{f}}
$$&lt;/div&gt;
&lt;p&gt;As before, we work with a finite-dimensional vector space &lt;span class="math"&gt;\(V\)&lt;/span&gt;, and reuse some of the notations from an earlier post on
&lt;a href="https://yiboyang.com/posts/change-of-basis/"&gt;change of basis&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Recall that an operator &lt;span class="math"&gt;\(T \in \mathcal{L}(V)\)&lt;/span&gt; is diagonalizable if and only if there exists a basis &lt;span class="math"&gt;\(\be = (e_1,...,e_n)\)&lt;/span&gt; consisting entirely of eigenvectors of &lt;span class="math"&gt;\(T\)&lt;/span&gt;.
That is, &lt;span class="math"&gt;\(T\)&lt;/span&gt; has a diagonal matrix
&lt;/p&gt;
&lt;div class="math"&gt;$$[T]_\be =
\begin{bmatrix}
\lambda_1 &amp;amp; &amp;amp;\\
&amp;amp; \ddots &amp;amp;\\
&amp;amp; &amp;amp; \lambda_n
\end{bmatrix}
$$&lt;/div&gt;
&lt;p&gt;
with respect to basis &lt;span class="math"&gt;\(\be = e_1,...,e_n\)&lt;/span&gt; if and only if &lt;span class="math"&gt;\(Te_j=\lambda_j e_j\)&lt;/span&gt; for each &lt;span class="math"&gt;\(j\)&lt;/span&gt;.
Equivalently, the existence of such a basis &lt;span class="math"&gt;\(\be = e_1,...,e_n\)&lt;/span&gt;, together with any arbitrary basis &lt;span class="math"&gt;\(\bff\)&lt;/span&gt; of &lt;span class="math"&gt;\(V\)&lt;/span&gt; (which always exists), allows the matrix
of the identity operator &lt;span class="math"&gt;\(I\)&lt;/span&gt; with respect to these two bases to ``diagonalize'' matrix &lt;span class="math"&gt;\([T]_{\bff}\)&lt;/span&gt;:
&lt;/p&gt;
&lt;div class="math"&gt;$$[T]_\be= [I]_\bff^\be [T]_\bff [I]_\be^\bff$$&lt;/div&gt;
&lt;p&gt;
In words: &lt;strong&gt;a linear operator has a particularly simple matrix description in its eigenbasis&lt;/strong&gt;. Most commonly, the arbitrary basis &lt;span class="math"&gt;\(\bff\)&lt;/span&gt; is chosen to be the
standard basis &lt;span class="math"&gt;\(\bs\)&lt;/span&gt; of &lt;span class="math"&gt;\(V\)&lt;/span&gt; (recall &lt;span class="math"&gt;\(\be\)&lt;/span&gt; is already used to denote the eigenbasis, i.e., the basis of its eigenvectors). Then let
&lt;span class="math"&gt;\(\Lambda = [T]_\be\)&lt;/span&gt;, &lt;span class="math"&gt;\(A=[T]_\bs\)&lt;/span&gt;, and &lt;span class="math"&gt;\(S=[I]_\be^\bs\)&lt;/span&gt; expresses the eigenbasis in terms of the standard basis; then we have the famous factorizations:
&lt;/p&gt;
&lt;div class="math"&gt;$$\Lambda = S^{-1} A S $$&lt;/div&gt;
&lt;div class="math"&gt;$$A = S \Lambda S^{-1} $$&lt;/div&gt;
&lt;p&gt;
In the special case of a normal operator, &lt;span class="math"&gt;\(Q=[I]_\be^\bs\)&lt;/span&gt; becomes orthonormal, then &lt;span class="math"&gt;\(Q^{-1}=Q^*\)&lt;/span&gt;, so the factorizations become even nicer:
&lt;/p&gt;
&lt;div class="math"&gt;$$\Lambda = Q^* A Q $$&lt;/div&gt;
&lt;div class="math"&gt;$$A = Q \Lambda Q^* $$&lt;/div&gt;
&lt;p&gt;Let's look at the decomposition &lt;span class="math"&gt;\([T]_\bff= [I]_\be^\bff [T]_\be  [I]_\bff^\be\)&lt;/span&gt; and see what it's really saying. As before, &lt;span class="math"&gt;\(\bff\)&lt;/span&gt; is an arbitrary basis of
&lt;span class="math"&gt;\(V\)&lt;/span&gt;, but let's choose it to be &lt;span class="math"&gt;\(\bs\)&lt;/span&gt; since &lt;span class="math"&gt;\(\bs\)&lt;/span&gt; is the default basis for matrices,  and let &lt;span class="math"&gt;\([x]_\bs\)&lt;/span&gt; be the coordinates of a vector &lt;span class="math"&gt;\(x\)&lt;/span&gt; in this basis
(which are trivially obtained: e.g. if &lt;span class="math"&gt;\(x=(1,2,3)\)&lt;/span&gt;, then &lt;span class="math"&gt;\([x]_\bs=[1 \quad 2 \quad 3]^\top\)&lt;/span&gt;). &lt;span class="math"&gt;\(T\)&lt;/span&gt; acts on &lt;span class="math"&gt;\(x\)&lt;/span&gt;, and we seek the resulting
vector &lt;span class="math"&gt;\(Tx\)&lt;/span&gt;--naturally corresponding to &lt;span class="math"&gt;\([Tx]_\bs\)&lt;/span&gt;, the coordinates of &lt;span class="math"&gt;\(Tx\)&lt;/span&gt; in
&lt;span class="math"&gt;\(\bs\)&lt;/span&gt;. The answer is in the matrix multiplication &lt;span class="math"&gt;\([T]_\bs [x]_\bs = [I]_\be^\bs [T]_\be
[I]_\bs^\be [x]_\bs\)&lt;/span&gt;, which decomposes into a series of three multiplications.
First, &lt;span class="math"&gt;\(S^{-1} =[I]_\bs^\be\)&lt;/span&gt; translates the
coordinates of &lt;span class="math"&gt;\(x\)&lt;/span&gt; from &lt;span class="math"&gt;\(\bs\)&lt;/span&gt; to &lt;span class="math"&gt;\(\be\)&lt;/span&gt;:
&lt;/p&gt;
&lt;div class="math"&gt;$$[I]_\bs^\be [x]_\bs = S^{-1}[x]_\bs = [x]_\be  =
\begin{bmatrix}
c_1 &amp;amp; ... &amp;amp; c_n
\end{bmatrix}^\top
$$&lt;/div&gt;
&lt;p&gt;
Next, &lt;span class="math"&gt;\(\Lambda = [T]_\be\)&lt;/span&gt; describes the stretching of individual eigenvectors, corresponding to the rescaling of coordinates by eigenvalues:
&lt;/p&gt;
&lt;div class="math"&gt;$$
[T]_\be [I]_\bs^\be [x]_\bs = [T]_\be [x]_\be = \Lambda \begin{bmatrix}
c_1 &amp;amp; ... &amp;amp; c_n
\end{bmatrix}^\top
=
\begin{bmatrix}
\lambda_1 c_1 &amp;amp; ... &amp;amp; \lambda_n c_n
\end{bmatrix}^\top
$$&lt;/div&gt;
&lt;p&gt;
Last step, &lt;span class="math"&gt;\(S=[I]_\be^\bs\)&lt;/span&gt; translates the resulting ``eigen-coordinates'' above back to the original basis &lt;span class="math"&gt;\(\bs\)&lt;/span&gt;:
&lt;/p&gt;
&lt;div class="math"&gt;$$ [Tx]_\bs = [T]_\bs [x]_\bs =  [I]_\be^\bs [T]_\be [I]_\bs^\be [x]_\bs =  [I]_\be^\bs [T]_\be [x]_\be = S
\begin{bmatrix}
\lambda_1 c_1 &amp;amp; ... &amp;amp; \lambda_n c_n
\end{bmatrix}^\top
= c_1 \lambda_1 [e_1]_\bs + ..., + c_n \lambda_n [e_n]_\bs
$$&lt;/div&gt;
&lt;p&gt;
Remember, column &lt;span class="math"&gt;\(j\)&lt;/span&gt; of &lt;span class="math"&gt;\(S= [I]_\be^\bs\)&lt;/span&gt; is, by definition &lt;span class="math"&gt;\([e_j]_\bs\)&lt;/span&gt;, the &lt;span class="math"&gt;\(j\)&lt;/span&gt;th eigenvector of &lt;span class="math"&gt;\(T\)&lt;/span&gt; expressed in the original basis &lt;span class="math"&gt;\(\bs\)&lt;/span&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://cdn.jsdelivr.net/npm/mathjax@2.7.9/MathJax.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="notes"/><category term="linear algebra"/></entry><entry><title>Change of Basis</title><link href="https://yiboyang.com/posts/change-of-basis/" rel="alternate"/><published>2016-03-27T18:47:00-07:00</published><updated>2016-03-27T18:47:00-07:00</updated><author><name>Yibo Yang</name></author><id>tag:yiboyang.com,2016-03-27:/posts/change-of-basis/</id><summary type="html">&lt;p&gt;How to encode a linear operator in a different matrix.&lt;/p&gt;</summary><content type="html">&lt;p&gt;&lt;em&gt;This is a series of notes taken during my review of linear algebra, using Axler's excellent textbook &lt;a href="http://linear.axler.net"&gt;Linear Algera Done Right&lt;/a&gt;, which will be heavily referenced.&lt;/em&gt;
This topic is actually banished to the end of Axler's book, with discussions about trace and determinants. But I like to introduce it early, as it's beneficial to view some of the operator decomposition (esp. eigen-decomposition) as simply a change of basis.
&lt;/p&gt;
&lt;div class="math"&gt;$$
\newcommand{\X}{$X$}
\newcommand{\Y}{$Y$}
\newcommand{\la}{\langle}
\newcommand{\ra}{\rangle}
\newcommand{\bv}{\mathbf{v}}
\newcommand{\bu}{\mathbf{u}}
\newcommand{\bw}{\mathbf{w}}
\newcommand{\be}{\mathbf{e}}
\newcommand{\bs}{\mathbf{s}}
\newcommand{\bff}{\mathbf{f}}
$$&lt;/div&gt;
&lt;p&gt;A bit of (sloppy) notations/conventions first:
in general we work with a linear map &lt;span class="math"&gt;\(T \in \mathcal{L}(V, W)\)&lt;/span&gt;, and finite dimensional vector spaces &lt;span class="math"&gt;\(V\)&lt;/span&gt; and &lt;span class="math"&gt;\(W\)&lt;/span&gt;. Assume the vector spaces have bases denoted by the corresponding lowercase bold letters, for example
&lt;span class="math"&gt;\(V\)&lt;/span&gt; has the basis &lt;span class="math"&gt;\(\bv = v_1,...,v_n\)&lt;/span&gt; (assuming &lt;span class="math"&gt;\(\operatorname{dim}(V)=n\)&lt;/span&gt;). The book uses the notation &lt;span class="math"&gt;\(\mathcal{M}(T, (v_1,...,v_n), (w_1,...,w_m) )\)&lt;/span&gt; to denote the matrix associated with &lt;span class="math"&gt;\(T\)&lt;/span&gt; with respect to input basis &lt;span class="math"&gt;\(\bv\)&lt;/span&gt; and output basis &lt;span class="math"&gt;\(\bw\)&lt;/span&gt;,
to emphasize the nature of &lt;span class="math"&gt;\(\mathcal{M}\)&lt;/span&gt; as a linear map (an isomorphism in fact) and its dependence on the bases, but we'll use the shorthand &lt;span class="math"&gt;\([T]_\bv^\bw\)&lt;/span&gt; to save space.&lt;/p&gt;
&lt;p&gt;In the case of an operator &lt;span class="math"&gt;\(T \in \mathcal{L}(V,V)\)&lt;/span&gt;, since we almost always use the same basis for the input and output spaces (which are both &lt;span class="math"&gt;\(V\)&lt;/span&gt;), we will use &lt;span class="math"&gt;\([T]_\bv\)&lt;/span&gt; as a shorthand for &lt;span class="math"&gt;\([T]_\bv^\bv\)&lt;/span&gt;. Additionally, we also use
&lt;/p&gt;
&lt;div class="math"&gt;$$[x]_\bv =
\begin{bmatrix}
c_1\\ \vdots \\ c_n
\end{bmatrix}
$$&lt;/div&gt;
&lt;p&gt;
to denote the n-by-1 (coordinate) matrix of vector &lt;span class="math"&gt;\(x\)&lt;/span&gt; with respect to basis &lt;span class="math"&gt;\(\bv\)&lt;/span&gt;, so that &lt;span class="math"&gt;\(x =c_1 v_1 + ... + c_n v_n\)&lt;/span&gt; (see definition 3.62). With this notation we can write (3.65) for linear operators as
&lt;/p&gt;
&lt;div class="math"&gt;$$\forall x \in V, [Tx]_\bv = [T]_\bv [x]_\bv $$&lt;/div&gt;
&lt;h4&gt;10.4 The matrix of the product of linear maps&lt;/h4&gt;
&lt;p&gt;This is a convenient restatement of (3.43) applied to two different bases of the same vector space (with &lt;span class="math"&gt;\(U\)&lt;/span&gt; and &lt;span class="math"&gt;\(W\)&lt;/span&gt; both equal to &lt;span class="math"&gt;\(V\)&lt;/span&gt;), and holds because of how we defined matrix multiplication.&lt;/p&gt;
&lt;p&gt;Theorem: suppose &lt;span class="math"&gt;\(\bv = v_1,...,v_n\)&lt;/span&gt;, &lt;span class="math"&gt;\(\bu=u_1,...,u_n\)&lt;/span&gt; and  &lt;span class="math"&gt;\(\bw=w_1,...,w_n\)&lt;/span&gt; are all bases of &lt;span class="math"&gt;\(V\)&lt;/span&gt;; suppose &lt;span class="math"&gt;\(S,T \in \mathcal{L}(V)\)&lt;/span&gt;. Then
&lt;/p&gt;
&lt;div class="math"&gt;$$[ST]_\bu^\bw = [S]_\bv^\bw [T]_\bu^\bv $$&lt;/div&gt;
&lt;h4&gt;10.5 Matrix of the identity with respect to two bases&lt;/h4&gt;
&lt;p&gt;The identity operator &lt;span class="math"&gt;\(I\)&lt;/span&gt; takes any vector in a vector space &lt;span class="math"&gt;\(V\)&lt;/span&gt; back to itself, that is &lt;span class="math"&gt;\(\forall x \in V, Ix=x\)&lt;/span&gt;.
With respect to any basis of &lt;span class="math"&gt;\(V\)&lt;/span&gt;, &lt;span class="math"&gt;\(I\)&lt;/span&gt;'s matrix always has ones on the diagonal and zeros elsewhere--it's the identity matrix.
Things get more interesting when we consider &lt;span class="math"&gt;\(I\)&lt;/span&gt; to be a "conventional" linear map, one defined over potentially different input space and output space, each with its own basis.&lt;/p&gt;
&lt;p&gt;Let &lt;span class="math"&gt;\(\bv = v_1,...,v_n\)&lt;/span&gt;, &lt;span class="math"&gt;\(\bu=u_1,...,u_n\)&lt;/span&gt; be two bases of &lt;span class="math"&gt;\(V\)&lt;/span&gt;.
Then the matrix &lt;span class="math"&gt;\([I]_\bu^\bv\)&lt;/span&gt; effectively translates the
coordinates of a vector &lt;span class="math"&gt;\(x\)&lt;/span&gt; in &lt;span class="math"&gt;\(\bu\)&lt;/span&gt; to those in &lt;span class="math"&gt;\(\bv\)&lt;/span&gt; (but &lt;span class="math"&gt;\(x\)&lt;/span&gt; stays the same), i.e.
&lt;/p&gt;
&lt;div class="math"&gt;$$ [x]_\bv = [I]_\bu^\bv [x]_\bu $$&lt;/div&gt;
&lt;p&gt;To see this, start with the definition of the identity:
&lt;/p&gt;
&lt;div class="math"&gt;$$Ix=x$$&lt;/div&gt;
&lt;p&gt;
To bring bases and matrices into the picture, consider the matrix representation of the above w.r.t &lt;span class="math"&gt;\(\bv\)&lt;/span&gt;:
&lt;/p&gt;
&lt;div class="math"&gt;$$[Ix]_\bv = [x]_\bv$$&lt;/div&gt;
&lt;p&gt;
Suppose &lt;span class="math"&gt;\(x=a_1 u_1 + ... + a_n u_n\)&lt;/span&gt;, then the LHS can be rewritten
&lt;/p&gt;
&lt;div class="math"&gt;$$[a_1 I u_1 + ... + a_n I u_n]_\bv = a_1[I u_1]_\bv + ... + a_n[I u_n]_\bv$$&lt;/div&gt;
&lt;p&gt;
where we used the linearity of the isomorphism &lt;span class="math"&gt;\(\mathcal{M}\)&lt;/span&gt; (recall our notation &lt;span class="math"&gt;\([\cdot]_\bv\)&lt;/span&gt; is equivalent to &lt;span class="math"&gt;\(\mathcal{M}(\cdot,\bv)\)&lt;/span&gt;).
Remember that by definition the kth column of the matrix &lt;span class="math"&gt;\([I]_\bu^\bv\)&lt;/span&gt; consists of the scalars needed to write &lt;span class="math"&gt;\(I u_k = u_k\)&lt;/span&gt; as a linear combination of &lt;span class="math"&gt;\(v_1,...,v_n\)&lt;/span&gt;--but this is precisely &lt;span class="math"&gt;\([I u_k]_\bv\)&lt;/span&gt;! So the above is a linear combination of columns of &lt;span class="math"&gt;\([I]_\bu^\bv\)&lt;/span&gt;, with
the coefficients &lt;span class="math"&gt;\(a_1,...,a_n\)&lt;/span&gt;, which is equal to the matrix multiplication &lt;span class="math"&gt;\([I]_\bu^\bv [x]_\bu\)&lt;/span&gt; (see (3.52)).&lt;/p&gt;
&lt;p&gt;Theorem 10.5 then says that &lt;span class="math"&gt;\([I]_\bu^\bv\)&lt;/span&gt; and &lt;span class="math"&gt;\([I]_\bv^\bu\)&lt;/span&gt; are matrix inverses of each other; the two associated ``translations" cancel out. But keep in mind the identity operator &lt;span class="math"&gt;\(I\)&lt;/span&gt; remains the same. See example 10.6.&lt;/p&gt;
&lt;h4&gt;10.7 Change of basis formula&lt;/h4&gt;
&lt;p&gt;Suppose &lt;span class="math"&gt;\(\bv = v_1,...,v_n\)&lt;/span&gt;, &lt;span class="math"&gt;\(\bu=u_1,...,u_n\)&lt;/span&gt; are bases of &lt;span class="math"&gt;\(V\)&lt;/span&gt;. Let &lt;span class="math"&gt;\(A=[I]_\bu^\bv\)&lt;/span&gt;. Then
&lt;/p&gt;
&lt;div class="math"&gt;$$[T]_\bu = [I]_\bv^\bu [T]_\bv^\bv [I]_\bu^\bv = A^{-1} [T]_\bv A $$&lt;/div&gt;
&lt;p&gt;
The matrix &lt;span class="math"&gt;\([I]_\bu^\bv\)&lt;/span&gt; is often called a ``change of basis transformation'' from &lt;span class="math"&gt;\(\bu\)&lt;/span&gt; to &lt;span class="math"&gt;\(\bv\)&lt;/span&gt;.&lt;/p&gt;
&lt;p&gt;We also call &lt;span class="math"&gt;\([T]_\bu\)&lt;/span&gt; and &lt;span class="math"&gt;\([T]_\bv\)&lt;/span&gt; &lt;span class="math"&gt;\(\textit{similar matrices}\)&lt;/span&gt;, and say they're related by a similarity transform. And since they describe the same operator &lt;span class="math"&gt;\(T\)&lt;/span&gt; (in two different bases), &lt;span class="math"&gt;\([T]_\bu\)&lt;/span&gt; and &lt;span class="math"&gt;\([T]_\bv\)&lt;/span&gt; have the same characteristics, including rank (thus invertibility) and characteristic polynomial (thus eigenvalues, trace, and determinant; but generally not the same eigenvectors). Basically, all the important &lt;span class="math"&gt;\(\textit{numbers}\)&lt;/span&gt; go with the operators; the exact &lt;span class="math"&gt;\(\textit{vectors}\)&lt;/span&gt; depend on the particular basis and matrix (indeed, the book first defines the trace and determinant of an &lt;span class="math"&gt;\(\textit{operator}\)&lt;/span&gt;, then defines them for its matrix in arbitrary basis, and show that they actually agree).&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://cdn.jsdelivr.net/npm/mathjax@2.7.9/MathJax.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="notes"/><category term="linear algebra"/></entry><entry><title>The Matrix of a Linear Map</title><link href="https://yiboyang.com/posts/the-matrix-of-a-linear-map/" rel="alternate"/><published>2016-01-19T11:18:00-08:00</published><updated>2016-01-19T11:18:00-08:00</updated><author><name>Yibo Yang</name></author><id>tag:yiboyang.com,2016-01-19:/posts/the-matrix-of-a-linear-map/</id><summary type="html">&lt;p&gt;Matrices are descriptions of linear maps.&lt;/p&gt;</summary><content type="html">&lt;p&gt;&lt;em&gt;This is a series of notes taken during my review of linear algebra, using Axler's excellent textbook &lt;a href="http://linear.axler.net"&gt;Linear Algera Done Right&lt;/a&gt;, which will be heavily referenced.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;This is based on book section (3.C).&lt;/p&gt;
&lt;p&gt;Suppose &lt;span class="math"&gt;\(T \in  \mathcal{L}(V, W)\)&lt;/span&gt; and &lt;span class="math"&gt;\(v_1,...,v_n\)&lt;/span&gt; is a basis of &lt;span class="math"&gt;\(V\)&lt;/span&gt; and &lt;span class="math"&gt;\(w_1,...,w_m\)&lt;/span&gt; is a basis of &lt;span class="math"&gt;\(W\)&lt;/span&gt;. The matrix of &lt;span class="math"&gt;\(T\)&lt;/span&gt; with respect to these bases is the &lt;span class="math"&gt;\(m\)&lt;/span&gt;-by-&lt;span class="math"&gt;\(n\)&lt;/span&gt; matrix &lt;span class="math"&gt;\(\mathcal{M}(T)\)&lt;/span&gt; whose entries &lt;span class="math"&gt;\(A_{j,k}\)&lt;/span&gt; are defined by &lt;/p&gt;
&lt;div class="math"&gt;$$T v_k = \sum_{j=1}^m A_{j,k} w_j = A_{1,k} w_1 + ... +A_{m,k} w_m$$&lt;/div&gt;
&lt;p&gt;
The &lt;span class="math"&gt;\(k\)&lt;/span&gt;th column of &lt;span class="math"&gt;\(\mathcal{M}(T)\)&lt;/span&gt; consists of the scalars needed to write &lt;span class="math"&gt;\(T v_k\)&lt;/span&gt; as a linear combination of &lt;span class="math"&gt;\(w_1,...,w_m\)&lt;/span&gt;.&lt;/p&gt;
&lt;p&gt;Example (3.33): Suppose &lt;span class="math"&gt;\(T \in \mathcal{L}(\mathbb{F}^2,\mathbb{F}^3)\)&lt;/span&gt; is defined by &lt;/p&gt;
&lt;div class="math"&gt;$$T(x, y) = (x +3y, 2x + 5y, 7x + 9y)$$&lt;/div&gt;
&lt;p&gt;
Find the matrix of &lt;span class="math"&gt;\(T\)&lt;/span&gt; with respect to the standard bases of &lt;span class="math"&gt;\(\mathbb{F}^2\)&lt;/span&gt; and &lt;span class="math"&gt;\(\mathbb{F}^3\)&lt;/span&gt;.&lt;/p&gt;
&lt;p&gt;Solution:
Because &lt;span class="math"&gt;\(T(1, 0)=(1,2,7)\)&lt;/span&gt; and &lt;span class="math"&gt;\(T(0,1)=(3,5,9)\)&lt;/span&gt;, the matrix of
&lt;span class="math"&gt;\(T\)&lt;/span&gt; with respect to the standard bases is then
&lt;/p&gt;
&lt;div class="math"&gt;$$
\begin{bmatrix}
1 &amp;amp; 3\\
2 &amp;amp; 5\\
7 &amp;amp; 9
\end{bmatrix}
$$&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;Follow-up question&lt;/strong&gt;: find the matrix of &lt;span class="math"&gt;\(T\)&lt;/span&gt; with respect to the basis &lt;span class="math"&gt;\((1,1), (-1,1)\)&lt;/span&gt; of &lt;span class="math"&gt;\(\mathbb{F}^2\)&lt;/span&gt; and &lt;span class="math"&gt;\((1,3,0),(0,-1,0),(0,0,2)\)&lt;/span&gt; of &lt;span class="math"&gt;\(\mathbb{F}^3\)&lt;/span&gt;.&lt;/p&gt;
&lt;p&gt;Solution: Because &lt;span class="math"&gt;\(T(1,1) = (4,7,16) = 4(1,3,0) + 5(0,-1,0) + 8(0,0,2)\)&lt;/span&gt;, and &lt;span class="math"&gt;\(T(-1,1) = (2,3,2) = 2(1,3,0) -3(0,-1,0) + (0,0,2)\)&lt;/span&gt;, the matrix with respect to these (non-standard) bases is
&lt;/p&gt;
&lt;div class="math"&gt;$$
\begin{bmatrix}
4 &amp;amp; 2\\
5 &amp;amp; -3\\
8 &amp;amp; 1
\end{bmatrix}
$$&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;Key point: the matrices can change with bases, but the underlying operator stays the same!&lt;/strong&gt; Later on we will see how trace and determinant are really properties of operators, not just their matrix representations.&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://cdn.jsdelivr.net/npm/mathjax@2.7.9/MathJax.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="notes"/><category term="linear algebra"/></entry><entry><title>Example of a Polynomial Basis</title><link href="https://yiboyang.com/posts/example-of-a-polynomial-basis/" rel="alternate"/><published>2015-12-21T19:29:00-08:00</published><updated>2015-12-21T19:29:00-08:00</updated><author><name>Yibo Yang</name></author><id>tag:yiboyang.com,2015-12-21:/posts/example-of-a-polynomial-basis/</id><summary type="html">&lt;p&gt;Example basis of a function space.&lt;/p&gt;</summary><content type="html">&lt;p&gt;&lt;em&gt;This is a series of notes taken during my review of linear algebra, using Axler's excellent textbook &lt;a href="http://linear.axler.net"&gt;Linear Algera Done Right&lt;/a&gt;, which will be heavily referenced.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;p. 46, Example 2.41: Show that &lt;span class="math"&gt;\(1, (x-5)^2, (x-5)^3\)&lt;/span&gt; is a basis of the subpsace of &lt;span class="math"&gt;\(V=\mathcal{P}_3(\mathbb{R})\)&lt;/span&gt; defined by &lt;/p&gt;
&lt;div class="math"&gt;$$U= \{p \in \mathcal{P}_3(\mathbb{R}): p^\prime (5) =0 \}$$&lt;/div&gt;
&lt;p&gt;Solution:&lt;/p&gt;
&lt;p&gt;Step 1.  Verify the list of given polynomials are in &lt;span class="math"&gt;\(U\)&lt;/span&gt;, and they're independent (because &lt;span class="math"&gt;\(a, b, c \in \mathbb{R}, \forall x, a+b(x-5)^2+c(x-5)^3 = 0 \implies a=b=c=0\)&lt;/span&gt;). By the latter we know &lt;span class="math"&gt;\(\operatorname{dim} U \ge 3\)&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Step 2.  Show that dim &lt;span class="math"&gt;\(U \leq 3\)&lt;/span&gt;. This is because &lt;span class="math"&gt;\(U\)&lt;/span&gt; is a proper subspace (subset) of &lt;span class="math"&gt;\(V=\mathcal{P}_3(\mathbb{R})\)&lt;/span&gt;, i.e. &lt;span class="math"&gt;\(\exists q\)&lt;/span&gt;, (simply take &lt;span class="math"&gt;\(q(x)=x\)&lt;/span&gt;), s.t. &lt;span class="math"&gt;\(q \in V\)&lt;/span&gt; but &lt;span class="math"&gt;\(q \notin U\)&lt;/span&gt;. Then by p. 45, 2.39, this independent list of vectors in &lt;span class="math"&gt;\(U\)&lt;/span&gt; with length &lt;span class="math"&gt;\(\operatorname{dim} U\)&lt;/span&gt; is a basis of &lt;span class="math"&gt;\(U\)&lt;/span&gt;.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Extension&lt;/strong&gt;: extend the above basis of &lt;span class="math"&gt;\(U\)&lt;/span&gt; (call it &lt;span class="math"&gt;\(B\)&lt;/span&gt;) to a basis of &lt;span class="math"&gt;\(V\)&lt;/span&gt;.&lt;/p&gt;
&lt;p&gt;Solution:&lt;/p&gt;
&lt;p&gt;Use p. 41, 2.32, the algorithm for extending a linearly independent list to a basis. Start with a basis of &lt;span class="math"&gt;\(V\)&lt;/span&gt;, &lt;span class="math"&gt;\(A = 1, x, x^2, x^3\)&lt;/span&gt;. Try to add each vector in &lt;span class="math"&gt;\(A\)&lt;/span&gt; to &lt;span class="math"&gt;\(B\)&lt;/span&gt; only if it's not in the span of the vectors already in &lt;span class="math"&gt;\(B\)&lt;/span&gt;. Clearly &lt;span class="math"&gt;\(1 \in \operatorname{span}(B)\)&lt;/span&gt;, no need to add it. Is &lt;span class="math"&gt;\(x \in \operatorname{span}(B)\)&lt;/span&gt;? i.e. is there &lt;span class="math"&gt;\(a,b,c,d\)&lt;/span&gt; not all identically zero, s.t. &lt;span class="math"&gt;\(\forall{x},  a\times 1 + b(x-5)^2 + c(x-5)^3 + dx = 0\)&lt;/span&gt; ? No, so we add &lt;span class="math"&gt;\(x\)&lt;/span&gt; to &lt;span class="math"&gt;\(B\)&lt;/span&gt;, &lt;span class="math"&gt;\(B\)&lt;/span&gt; now includes &lt;span class="math"&gt;\(1, (x-5)^2, (x-5)^3, x\)&lt;/span&gt;. We can stop here, as we already have a list of independent vectors of the right dimension. But just to verify that &lt;span class="math"&gt;\(x^2 \in \operatorname{span}(B)\)&lt;/span&gt;, we indeed can write &lt;span class="math"&gt;\(-25\times 1 + 1(x-5)^2 + 0(x-5)^3 + 10x  - 1x^2 =0\)&lt;/span&gt;, similarly for &lt;span class="math"&gt;\(x^3\)&lt;/span&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://cdn.jsdelivr.net/npm/mathjax@2.7.9/MathJax.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="notes"/><category term="linear algebra"/></entry></feed>