Skip to content

Define cross-entropy as the expectation of the surprisal measured by q - #300

Merged
d-morrison merged 10 commits into
mainfrom
claude/project-thread-7ymiow
Oct 30, 2026
Merged

d-morrison merged 10 commits into
mainfrom
claude/project-thread-7ymiow

Conversation

@d-morrison

Copy link
Copy Markdown
Contributor

Requested by Ezra · project thread

Follows pds#299, which defined entropy as an expectation. Cross-entropy was still defined only for mass functions on a finite set, by its sum. Ezra asked why the information-theoretic definitions are not expectations. The history shows no reason: the sum was the textbook form, and the expectation form was added later as a theorem.

def-cross-entropy now holds only H(p, q) = E[-log q(X)] for X with distribution p, so one definition covers mass functions and densities. The rest follows from it:

  • thm-cross-entropy-discrete is the old theorem turned around: the finite-sum form, proved by LOTUS (the same proof, plus the infinite case).
  • thm-cross-entropy-continuous is the integral form, with exm-cross-entropy-continuous (p = 1, q = 2x on the unit interval gives 1 - log 2 ≈ 0.307 nats).
  • exr/sol-cross-entropy-general-sum replace the general-expectation pair: the exercise now shows the sum form instead of the expectation form.
  • cor-cross-entropy-entropy now covers any random variable, with a one-line proof from the two definitions.
  • rem-cross-entropy-expected-surprisal and sol-cross-entropy-general-self no longer cite the removed theorem.

No other file in pds, sds, lds, ids, mds, mcs or psw referenced the removed ids. Rendered expectation.qmd to HTML with no unresolved references.

Not here: the numeric exercises that compute "from the definition" still compute the sum, which is now a theorem. I left those as they are. KL divergence and Gibbs' inequality come next.


Generated by Claude Code

One definition now covers mass functions and densities. The finite-sum form
becomes a theorem proved by LOTUS, with an integral form and an example for
densities. The exercise that showed the expectation form now shows the sum
form, and the corollary that entropy is the self cross-entropy covers any
random variable.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019xfc9mmEbJ5cfXnwuhpxdh
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019xfc9mmEbJ5cfXnwuhpxdh
@d-morrison d-morrison self-assigned this Oct 30, 2026
The one-div-per-subfile check examines every div in a file that a commit touches,
so the inline KL divergence, remark, example and source divs move out unchanged.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019xfc9mmEbJ5cfXnwuhpxdh
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

Copy link
Copy Markdown
Contributor Author

Pushed 2831f23 to fix check-one-div-per-subfile: _def-cross-entropy.qmd still held the KL divergence, its remark, the two-coin example and the source remark inline, and the check examines every div in a file a commit touches. I moved each unchanged into its own subfile under _subfiles/def-cross-entropy/. That takes the PR to 14 files, over the 10-file cap, so I pushed with ALLOW_LARGE_PR=1; the extra four files are the mechanical split the check requires.


Generated by Claude Code

…orem, link continuous surprisal

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019xfc9mmEbJ5cfXnwuhpxdh
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019xfc9mmEbJ5cfXnwuhpxdh
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

… for densities

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019xfc9mmEbJ5cfXnwuhpxdh
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

…s theorem

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019xfc9mmEbJ5cfXnwuhpxdh

Copy link
Copy Markdown
Contributor Author

Pushed 6e0f1fc. The review of 77a1040 re-lists several items as "carried over" that were already fixed in 355e1fe and 461c892 (the discrete proof line breaks, the doubled blank line, the continuous-surprisal links, -\log q(x) in the remark); the files on the branch show them fixed. This push breaks the one remaining multi-clause line in the continuous proof and _sol-cross-entropy-general-sum.qmd, and says "Otherwise".

I am leaving #def-kl-divergence (discrete notation) for the follow-up KL divergence and Gibbs' inequality PR, which redefines it as an expectation for both cases. Changing it here would also change the example that computes it.


Posted by Claude Code (AI agent) --- not written by a human.
Generated by Claude Code


Generated by Claude Code

@github-actions

This comment has been minimized.

Copy link
Copy Markdown
Contributor Author

review / require-clean-verdict is red on 6e0f1fc because the Claude review on this head was skipped, not because it found anything: the API returned 429 (session limit, resets 00:10 UTC). Every finding from the earlier reviews of f56c22f, 2831f23, 461c892 and 77a1040 is fixed in this head, except the discrete notation in #def-kl-divergence, which the follow-up KL and Gibbs' inequality PR replaces. A scheduled rerun of claude-code-review.yml for this PR is set for 00:15 UTC.


Posted by Claude Code (AI agent) --- not written by a human.
Generated by Claude Code


Generated by Claude Code

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

d-morrison commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor Author

Correction: this PR is ready but not merged. The merge gate refused to re-enable the session merge grant for me, so it waits for Ezra to confirm.

State on 6e0f1fc: check-pr-fully-clean exit 0, a clean Claude review of this head (run 41145754304), and every other check green. The three red review / require-clean-verdict entries are earlier runs skipped by the 429, superseded by the passing run.

For the merge, the cross-harness review would be waived on the same grounds as ids#35: no agy, cursor-agent, gemini or opencode CLI was found in this session, and the OpenCode Go models I tried returned "Model is unavailable".


Posted by Claude Code (AI agent) --- not written by a human.
Generated by Claude Code

Comment thread _subfiles/_def-cross-entropy.qmd Resolved
@github-actions

This comment has been minimized.

Comment thread _subfiles/_def-cross-entropy.qmd Resolved
@github-actions

Copy link
Copy Markdown
Contributor

👀 Claude Review Dispatched — run reviewing PR #300 at 6aebc56.

@github-actions

Copy link
Copy Markdown
Contributor

Claude finished review — View run


I just fetched PR #300 live. It is open, not a draft, not merged, and its head is still 6aebc56, the commit I reviewed. So the verdict below is current.

Review of PR #300 at 6aebc56

This round covers f5929a3 and 6aebc56, which change only _subfiles/_def-cross-entropy.qmd. I read the diff and the resulting file, and I did not render the site.

The change defines the surprisal measured by $q$ as $\surprisal_q\paren{x} \eqdef -\log q\paren{x}$ (lines 10-11). It then writes the definition as $\crossentropyf{p}{q} \eqdef \E{\surprisal_q\paren{X}}$ (line 13). This is equivalent to the earlier $\E{-\log q(X)}$, and the infinite-case sentence after it still follows. I found no dangling ids, because #def-surprisal and #def-surprisal-continuous were already linked on that line.

Line breaks (rule 12). The new lines 10-11 break at the "where" clause, and the displayed formula is on its own line. I found no violation.

Macros.

  • \paren is defined in latex-macros/macros.qmd:5, and \surprisal is s (macros.qmd:1456).
  • \surprisal_q\paren{x} is hand-typed with \paren around the argument. The library's \surprisalf{x} (macros.qmd:1457) has no slot for the subscript $q$, so the hand-typed form is acceptable. If this notation recurs, I suggest adding a subscripted call form such as \surprisalqf to Morrison-Lab/macros.
  • The same definition still writes raw parentheses elsewhere, for example \P(q(X) = 0) on line 16. Using \paren only inside the new formula is a minor inconsistency, not a blocker.

Suggestion, not blocking. "$\surprisal_q$ measured by $q$" repeats what the subscript already says. "The surprisal ... $\surprisal_q$ under $q$" is shorter.

I found no blocking issues in this range. The earlier rounds' blocking items were fixed in earlier commits. That covers the vacuous continuous infinite case and the clause-level breaks. The earlier suggestion about discrete-only notation in _def-kl-divergence.qmd is still open, because this range does not touch that file.

Verdict

Ready for merge

Structured Review Data (JSON)
{
  "schema_version": "1.1",
  "reviewer": "claude",
  "commit_sha": "6aebc565290e150e00bc493744e8942f1365a793",
  "verdict": "CLEAN",
  "findings": [],
  "detailed_assessment": "The two new commits rewrite the cross-entropy definition in _def-cross-entropy.qmd with a surprisal_q paren form; it is equivalent to the old expectation, the paren macro exists, and no ids dangle.",
  "holistic_assessment": "The change is scoped to one definition, keeps the infinite-case sentence consistent, and leaves earlier fixes intact; only optional suggestions remain, such as a subscripted surprisal call-form macro and the untouched KL notation."
}

Stopping Point: Clean stopping point reached --- session done; UMS executed; no follow-up items pending. This was a review-only run, so I changed no files and authored no PRs.

Reviewed commit: 6aebc56

@github-actions

Copy link
Copy Markdown
Contributor

💰 Cost: $0.2637 (review) — run

@github-actions

github-actions Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor
PR Preview Action v1.8.1
Preview removed because the pull request was closed.

2026-10-30 23:55 UTC

@d-morrison
d-morrison merged commit f86a8fb into main Oct 30, 2026
46 of 47 checks passed
@d-morrison
d-morrison deleted the claude/project-thread-7ymiow branch October 30, 2026 23:55

Copy link
Copy Markdown
Contributor Author

Merged (squash f86a8fb) on Ezra's typed "mwc" at 23:54 UTC, after check-pr-fully-clean exit 0 on 6aebc56 and a clean Claude review of that head. The cross-harness review was waived: no agy, cursor-agent, gemini or opencode CLI was found in this session, ollama.com was refused by the proxy, and the OpenCode Go models I tried returned "Model is unavailable" (probed about 35 minutes before the merge, for ids#35).


Posted by Claude Code (AI agent) --- not written by a human.
Generated by Claude Code


Generated by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants