Skip to content

Normalize scattering CDFs before inverse angle sampling - #34

Merged
scottprahl merged 2 commits into
scottprahl:mainfrom
antonsoo:fix/physical-scattering-cdf
Oct 28, 2026
Merged

scottprahl merged 2 commits into
scottprahl:mainfrom
antonsoo:fix/physical-scattering-cdf

Conversation

@antonsoo

Copy link
Copy Markdown
Contributor

The phase sum starts above zero and overshoots one. For mu_with_uniform_cdf(1.33, .001, 4096), low-probability interpolation crosses between the first and last entries: the table contains cosines below -1, giving NaNs in arccos.

Use cumulative trapezoidal integration from zero, normalize its endpoint to one, and require two or more points. Add analytic Rayleigh/physical-angle regressions and replace the tests that pinned the old endpoint error. The fixed 2000-point integration grid and random sampler are unchanged.

Both backend suites pass on Python 3.12 and 3.14; configured lint and combined coverage pass. Droplet sampling agrees with independent native Scattnlay quadrature, preserving the original optical outputs and draws from a fixed supplied table. The installed wheel gives identical results. Other platforms and notebooks were not run.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 25, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ⚠️ Failed 2026-10-25T20:57:43.123961Z
We couldn’t complete this review. Comment @codex review to try again.
62df1f4 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

Follow-ups from review of the CDF normalization fix:

- warn when cdf's raw trapezoidal integral is off from 1 by more than 1%,
  since normalizing silently hid an under-resolved forward peak
- size mu_with_uniform_cdf's internal table as max(2000, 5*x**2) so
  large spheres sample correctly (x=100 mean cosine 0.930 -> 0.869, g=0.868)
- replace the inversion loop with np.interp, removing the big_k - 1 index
- raise ValueError when the phase function is not finite
- point the warning at the caller via a private _trapezoid_cdf helper
- rewrite the module, cdf and mu_with_uniform_cdf docstrings, with
  doctested sampling examples
- restore a convergence test, add warning, NaN and asymmetry tests, and
  drop a redundant arccos check
- changelog entries, crediting @antonsoo for the original fix

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@scottprahl
scottprahl merged commit 5073892 into scottprahl:main Oct 28, 2026
11 checks passed
@scottprahl

Copy link
Copy Markdown
Owner

thanks for your contribution. I added a bit to your PR since this is the first time I have looked at the CDF code in a while.

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