Skip to content

Conversation

@RichardWaiteSTFC
Copy link
Collaborator

@RichardWaiteSTFC RichardWaiteSTFC commented Jan 14, 2025

Description

Various bugs and small features:

  • Fix bug in scale factor estimation
  • Add new function to fit bg and scale to all data (fixing model)
  • Support any ndbase optimizer in fit_background
  • Add methods to set and clear background region
  • Add method to plot background region
  • Initialise background parameters with sensible values when switching background strategy
  • Handle edges/nans properly in avg. of error when taking 1D cuts
  • Support general polynomial background in Q and en
  • Use 2D data Q bins when replace with 1D cuts (previously just used nQ bins between qmin and qmax)
  • Update tutorial
  • Add method to export data into structs (or array of structs for 1D) - for fitbenchmarking
  • Add ability to set background parameters, bounds etc. by string label
  • Add method to print parameters nicely

To Test
(1) Run tutorial 39 file

@codecov-commenter
Copy link

codecov-commenter commented Jan 14, 2025

Codecov Report

❌ Patch coverage is 57.60369% with 92 lines in your changes missing coverage. Please review.
✅ Project coverage is 43.42%. Comparing base (7e87dee) to head (6ae56d9).
⚠️ Report is 8 commits behind head on master.

Files with missing lines Patch % Lines
swfiles/sw_fitpowder.m 57.00% 92 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #210      +/-   ##
==========================================
+ Coverage   43.29%   43.42%   +0.13%     
==========================================
  Files         243      243              
  Lines       16383    16552     +169     
==========================================
+ Hits         7093     7188      +95     
- Misses       9290     9364      +74     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions
Copy link

github-actions bot commented Jan 14, 2025

Test Results

    4 files  ± 0    124 suites  ±0   5m 44s ⏱️ +45s
  851 tests +19    833 ✅ +19  18 💤 ±0  0 ❌ ±0 
2 404 runs  +76  2 368 ✅ +76  36 💤 ±0  0 ❌ ±0 

Results for commit 6ae56d9. ± Comparison against base commit eacac5a.

This pull request removes 3 and adds 22 tests. Note that renamed tests count towards both.
sw_tests.unit_tests.unittest_ndbase_optimisers ‑ test_optimise_rosen_parameter_fixed_minimum_not_accessible_with([email protected])
sw_tests.unit_tests.unittest_ndbase_optimisers ‑ test_optimise_rosen_parameter_fixed_minimum_not_accessible_with([email protected])
sw_tests.unit_tests.unittest_sw_fitpowder ‑ test_set_background_strategy
sw_tests.unit_tests.unittest_ndbase_optimisers ‑ test_optimise_rosen_parameter_fixed_minimum_not_accessible_with_vary_arg([email protected])
sw_tests.unit_tests.unittest_ndbase_optimisers ‑ test_optimise_rosen_parameter_fixed_minimum_not_accessible_with_vary_arg([email protected])
sw_tests.unit_tests.unittest_sw_fitpowder ‑ test_add_1Dcuts_withs_qs_specified
sw_tests.unit_tests.unittest_sw_fitpowder ‑ test_export_data_1d
sw_tests.unit_tests.unittest_sw_fitpowder ‑ test_export_data_2d
sw_tests.unit_tests.unittest_sw_fitpowder ‑ test_export_data_2d_with_filename
sw_tests.unit_tests.unittest_sw_fitpowder ‑ test_fit_background_and_scale
sw_tests.unit_tests.unittest_sw_fitpowder ‑ test_fix_bg_param_with_array_of_names
sw_tests.unit_tests.unittest_sw_fitpowder ‑ test_set_background_strategy_to_indep
sw_tests.unit_tests.unittest_sw_fitpowder ‑ test_set_background_strategy_to_planar
…

♻️ This comment has been updated with latest results.

@RichardWaiteSTFC RichardWaiteSTFC changed the title More usability improvements sw fitpowder (DRAFT IN PROG) More usability improvements sw fitpowder May 19, 2025
Copy link
Member

@mducle mducle left a comment

Choose a reason for hiding this comment

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

Looks good but I've got some change requests!

I really like the new parameter name setter and printer and the background region plotting options.

Also, do you think it might be better to split tutorial 39 into two? One with the basic fitting and another going into more depth about the background estimation?

Comment on lines +87 to +88
out.set_bg_parameters(2, 11, 1); % intercept = 4*2 + 3 for cut 1
out.set_bg_parameters(2, 13, 2); % intercept = 5*2 + 3 for cut 2
Copy link
Member

Choose a reason for hiding this comment

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

According to the comment in line 85, the intercept index is 3 - but here you're changing parameter index 2 (which should slope_q, right?)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks, just checked this and the comment on line 85 refers to the equivalent planar background (which are checked on line 91). The parameters being set here are for the individual 1D cuts - i.e. parameter 2 corresponds to E0 - this is what disp_params gives

---
BACKGROUND
---
Label	Index	Cut Index	Initial	
   E1	1	       1	       1	
   E0	2	       1	      11	
   E1	1	       2	       1	
   E0	2	       2	      13	

I will update the comment on line 85 to be clearer

Copy link
Member

Choose a reason for hiding this comment

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

Comment on lines +166 to +167
fbg_planar = @(en, modQ, p, npoly_modQ) polyval(p(npoly_modQ+1:end), en(:)) + ...
polyval([reshape(p(1:npoly_modQ),1,[]), 0], modQ(:)'); % q^n,..q^1, en^n,...en^1, const
Copy link
Member

Choose a reason for hiding this comment

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

Just from a code-reading perspective, I think it's a bit more obvious if this is changed to have two separate vectors of coefficients for the E- and Q-dependence rather than one vector and an offset, e.g.:

fbg_planar = @(en, modQ, poly_E, poly_modQ) polyval(poly_E, en(:)) + ...
             polyval([poly_modQ(:)', 0], modQ(:)'); % q^n,..q^1, en^n,...en^1, const

where the constant value is in poly_E.

This would then need changes to lines 257:

obj.fbg = @(en, modQ, p) obj.fbg_planar(en, modQ, p(end-obj.npoly_en+1:end), p(1:numel(p)-obj.npoly_en));

and 281:

intercepts = obj.fbg_planar(0, modQs, bg_pars(obj.npoly_modQ+1:end), bg_pars(1:obj.npoly_modQ));

The lines using this function are more verbose though... so it's up to you!

PS. I'm not sure the code in line 257 is correct - see comment below.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yep I think you're right, but would it be OK to address this in a separate PR?

Copy link
Member

Choose a reason for hiding this comment

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

Sure, I've created an issue for it so we don't forget...

Copy link
Member

@mducle mducle left a comment

Choose a reason for hiding this comment

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

Just the change to comments in the unit test... (and possibly the qs thing...) otherwise good to go!

Comment on lines +166 to +167
fbg_planar = @(en, modQ, p, npoly_modQ) polyval(p(npoly_modQ+1:end), en(:)) + ...
polyval([reshape(p(1:npoly_modQ),1,[]), 0], modQ(:)'); % q^n,..q^1, en^n,...en^1, const
Copy link
Member

Choose a reason for hiding this comment

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

Sure, I've created an issue for it so we don't forget...

Comment on lines +87 to +88
out.set_bg_parameters(2, 11, 1); % intercept = 4*2 + 3 for cut 1
out.set_bg_parameters(2, 13, 2); % intercept = 5*2 + 3 for cut 2
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

@mducle mducle left a comment

Choose a reason for hiding this comment

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

Looks good now. Thanks.

@RichardWaiteSTFC RichardWaiteSTFC merged commit dc06a4b into master Sep 10, 2025
12 checks passed
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.

4 participants