Skip to content

Fixes to long-running issues in fitting example - #9

Merged
mjlarson merged 1 commit into
mainfrom
mlarson/fix_fit_examples
Oct 6, 2026
Merged

mjlarson merged 1 commit into
mainfrom
mlarson/fix_fit_examples

Conversation

@mjlarson

@mjlarson mjlarson commented Oct 6, 2026

Copy link
Copy Markdown
Collaborator

Bennett pointed out that there was something wonky in the fitting example code regarding the plotting. This turned out to be due to a rescaling of the PDF to match the peak of the distribution. This was fixed with a rewrite: we're now just plotting the per-sterradian PDF directly instead of trying to screw around with scaling factors. This works pretty well and we can make reasonable looking plots now.

Along the way, there was also some simplification to make sure the fitting and likelihood code use the same method to assign events to bins.the same code to assign events to bins.

Copilot AI balanced review requested due to automatic review settings October 6, 2026 02:50
@codecov-commenter

codecov-commenter commented Oct 6, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 40.90909% with 13 lines in your changes missing coverage. Please review.
✅ Project coverage is 78.87%. Comparing base (7aa4e90) to head (981e816).

Files with missing lines Patch % Lines
kingmaker/fitting.py 27.77% 13 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main       #9      +/-   ##
==========================================
- Coverage   79.37%   78.87%   -0.50%     
==========================================
  Files           6        6              
  Lines         921      923       +2     
==========================================
- Hits          731      728       -3     
- Misses        190      195       +5     
Flag Coverage Δ
test_basic 14.62% <18.18%> (+0.07%) ⬆️
test_fitting 38.13% <36.36%> (-0.09%) ⬇️
test_king_pdf 27.95% <18.18%> (+0.04%) ⬆️
test_template_smeared_king_pdf 26.11% <18.18%> (+0.05%) ⬆️
test_utils 16.25% <22.72%> (+0.18%) ⬆️
test_wrapper 38.46% <27.27%> (-0.20%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Plot bin indices currently wrap invalid values and can silently display the wrong fit.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)
What changed in this PR

Updates PSF fitting plots to show physical per-steradian densities and aligns event-bin assignment between fitting and likelihood evaluation.

Changes:

  • Adds shared edge-based, clamped bin lookup.
  • Reworks fit plots with PDF densities and bin averages.
  • Adds regression tests for bin assignment and repeated percentile values.
File Description
kingmaker/​utils.py Adds shared bin-index helper.
kingmaker/​fitting.py Uses shared binning and revises plotting.
kingmaker/​wrapper.py Uses edge-based event-bin lookup.
tests/​test_utils.py Tests bin lookup boundaries and clamping.
tests/​test_fitting.py Tests repeated-value percentile bins.
tests/​test_wrapper.py Tests unequal-width bin assignment.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread kingmaker/fitting.py
Comment on lines +649 to +651
bin_indices = tuple(
int(i) % n for i, n in zip(bin_indices, self.parametrization_shape, strict=True)
)
@mjlarson
mjlarson merged commit 7341c57 into main Oct 6, 2026
11 checks passed
@mjlarson
mjlarson deleted the mlarson/fix_fit_examples branch October 6, 2026 02:56
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.

3 participants