Cross Entropy in LaTeX (H(p, q))
- LaTeX command
H(p, q)- Package
- No package needed: built into LaTeX
- Mode
- Text and math mode
Where it is used
Cross-entropy between a true distribution p and a model q: the expected code length when coding p with q.
Cross-entropy is H(p, q) = -\sum_x p(x) \log q(x), and it is the classification loss: with one-hot labels it reduces to -\log q(y). It decomposes as H(p, q) = H(p) + D_{\text{KL}}(p \| q), which explains why minimizing it over q also minimizes KL divergence. Watch the notation clash: H(X, Y) with random variables usually means joint entropy, so some authors write H_\times(p, q) or \mathrm{CE}(p, q) for clarity. The comma has normal punctuation spacing, so no manual adjustment is needed.
Minimal compilable example
Paste this into an empty .tex file and compile it with pdfLaTeX, XeLaTeX or LuaLaTeX.
\documentclass{article}
\usepackage{amsmath}
\begin{document}
Cross Entropy: $H(p, q)$
\[ H(p, q) = -\sum_{x} p(x) \log q(x) = H(p) + D_{\text{KL}}(p \| q) \]
\end{document}Related symbols
- Entropy
H(X) - Bias Vector
\mathbf{b} - Mutual Information
I(X; Y) - Weight Matrix
\mathbf{W} - Log Likelihood
\log p(x | \theta) - Theta Star
\theta^*
Frequently asked questions
- How do I write Cross Entropy in LaTeX?
- Type H(p, q) in math mode, for example $H(p, q) = -\sum_{x} p(x) \log q(x) = H(p) + D_{\text{KL}}(p \| q)$. It works in plain LaTeX without loading any package.
- Which package do I need for H(p, q)?
- None. H(p, q) is part of standard LaTeX, so it compiles with nothing in the preamble but the document class.
- Can I use H(p, q) in text mode, or only in math mode?
- Both. H(p, q) compiles in running text as well as inside $...$; in a formula keep it in math mode so it gets math fonts and spacing.
Math poweredAI로 LaTeX 작성
최고의 AI LaTeX 편집기, Overleaf 대안
Octree는 15개 이상의 대학의 연구자들이 AI를 사용하여 논문을 더 빠르게 작성하도록 도움
- AI로 아름다운 TikZ 다이어그램 생성
- 이미지를 업로드하고 LaTeX로 원활하게 변환
- 논문 작성 및 서식에 대한 즉각적인 지원 받기