Conditional Probability in LaTeX (p(y | x))
- LaTeX command
p(y | x)- Package
- No package needed: built into LaTeX
- Mode
- Text and math mode
Where it is used
Conditional probability of y given x, such as a classifier's predicted label distribution for an input.
Discriminative models learn p(y | x) directly, while generative models learn p(x | y) and p(y) and apply Bayes' rule, p(y|x) = p(x|y)p(y)/p(x). The bare vertical bar typed as | is an ordinary character and gets no space around it; \mid is a relation and yields p(y \mid x), which reads better and is what most style guides recommend. For a tall conditioning expression, \middle| between \left( and \right) scales the bar with the parentheses. Subscripts like p_\theta(y \mid x) indicate the model's parameters.
Minimal compilable example
Paste this into an empty .tex file and compile it with pdfLaTeX, XeLaTeX or LuaLaTeX.
\documentclass{article}
\begin{document}
Conditional Probability: $p(y | x)$
\[ p(y \mid x) = \frac{p(x \mid y)\, p(y)}{p(x)} \]
\end{document}Related symbols
- Sum Over Classes
\sum_{c=1}^{C} - Probability Distribution
p(x) - Product Over Samples
\prod_{i=1}^{N} - Log Likelihood
\log p(x | \theta) - L1 Norm
\| \theta \|_1 - Mutual Information
I(X; Y)
Frequently asked questions
- How do I write Conditional Probability in LaTeX?
- Type p(y | x) in math mode, for example $p(y \mid x) = \frac{p(x \mid y)\, p(y)}{p(x)}$. It works in plain LaTeX without loading any package.
- Which package do I need for p(y | x)?
- None. p(y | x) is part of standard LaTeX, so it compiles with nothing in the preamble but the document class.
- Can I use p(y | x) in text mode, or only in math mode?
- Both. p(y | x) compiles in running text as well as inside $...$; in a formula keep it in math mode so it gets math fonts and spacing.