Expectation in LaTeX (\mathbb{E}[X])
- LaTeX command
\mathbb{E}[X]- Package
- Add to your preamble:
\usepackage{amssymb} - Mode
- Math mode only
Where it is used
Expected value of a random variable X, written with a blackboard-bold E.
Expectation is the mean of X weighted by its distribution, \mathbb{E}[X] = \sum_x x\,p(x) or \int x f(x)\,dx. Machine learning papers use it everywhere, often with a subscript naming the distribution: \mathbb{E}_{x \sim p}[\ell(x)]. Square brackets are conventional, and \left[ \right] or \bigl[ \bigr] help when the argument contains fractions. The blackboard E sets the operator apart from an energy E or an edge set E. Linearity, \mathbb{E}[aX + bY] = a\mathbb{E}[X] + b\mathbb{E}[Y], holds even without independence, which is why it is used so freely.
Also listed under: 機械学習・AI
Minimal compilable example
Paste this into an empty .tex file and compile it with pdfLaTeX, XeLaTeX or LuaLaTeX.
\documentclass{article}
\usepackage{amssymb}
\begin{document}
Expectation: $\mathbb{E}[X]$
\[ \mathbb{E}_{x \sim p}[f(x)] = \int f(x)\, p(x)\, dx \]
\end{document}Related symbols
- Expectation (E)
E[X] - Probability of A
P(A) - Variance
\text{Var}(X) - Probability
\mathbb{P} - Covariance
\text{Cov}(X,Y) - Sigma
\sigma
Frequently asked questions
- How do I write Expectation in LaTeX?
- Type \mathbb{E}[X] in math mode, for example $\mathbb{E}_{x \sim p}[f(x)] = \int f(x)\, p(x)\, dx$. Load amssymb first with \usepackage{amssymb}.
- Which package do I need for \mathbb{E}[X]?
- \mathbb{E}[X] needs amssymb: add \usepackage{amssymb} to your preamble before the document starts.
- Can I use \mathbb{E}[X] in text mode, or only in math mode?
- Only in math mode. Outside $...$ LaTeX stops with "Missing $ inserted", so write $\mathbb{E}[X]$ in running text.