Skip to content

feat: optimize stretch using a Hessian matrix#204

Open
john-halloran wants to merge 3 commits into
diffpy:mainfrom
john-halloran:hessian-fix
Open

feat: optimize stretch using a Hessian matrix#204
john-halloran wants to merge 3 commits into
diffpy:mainfrom
john-halloran:hessian-fix

Conversation

@john-halloran

Copy link
Copy Markdown
Contributor

This is another PR bringing us closer to parity with MATLAB. Proper use of a Hessian was key to the speed and quality of convergence they were able to obtain. I had tried this a few times before, but it never worked even though the Hessian had the right shape. By properly regularizing, it now works.

@codecov

codecov Bot commented Jun 22, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.00%. Comparing base (d7586bc) to head (a325294).
⚠️ Report is 12 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #204      +/-   ##
==========================================
+ Coverage   77.50%   82.00%   +4.50%     
==========================================
  Files           3        3              
  Lines          40       50      +10     
==========================================
+ Hits           31       41      +10     
  Misses          9        9              
Files with missing lines Coverage Δ
tests/test_snmf_optimizer.py 100.00% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@sbillinge sbillinge 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.

pls see comment

gra = gra.flatten()
return fun, gra

def hessian(stretch_vec):

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.

do we need a test for this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good idea. I have added a test checking for some of the expected properties (right shape, symmetric, correct ordering/cross-coupling).

@sbillinge sbillinge 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.

please see comment

return fun, gra

def _regularize_function_hessian(self, stretch):
residuals, d_stretch_comps, dd_stretch_comps = (

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.

this could use some dicumentation and also maybe a more descriptive variable name. Stretch is a verb usually and I would expect a noun here.

We were pretty lazy about documenting code in the early part of the project because we wanted it to get going from a low place, but we are at the point of the project where we can take the time to make the code more maintainable moving forward.

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