Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SIRT objective #1790

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

MargaretDuff
Copy link
Member

@MargaretDuff MargaretDuff commented Apr 23, 2024

Changes

  • Changed the SIRT objective_function to match the mathematics - it is now a weighted least squares calculation i.e. $0.5*(Ax-b)^M(Ax-b)$ were $M=\frac{1}{A*\mathbb{1}}$.
  • Updated the documentation to explain this
  • Changed some of our SIRT tests so they do not all use the identity

We might need to consider the efficiency of the objective calculation

Testing you performed

Please add any demo scripts to https://github.com/TomographicImaging/CIL-Demos/tree/main/misc
New unit tests added

Related issues/links

Closes #1787

Checklist

  • I have performed a self-review of my code
  • I have added docstrings in line with the guidance in the developer guide
  • I have updated the relevant documentation
  • I have implemented unit tests that cover any new or modified functionality
  • CHANGELOG.md has been updated with any functionality change
  • Request review from all relevant developers
  • Change pull request label to 'Waiting for review'

Contribution Notes

Please read and adhere to the developer guide and local patterns and conventions.

  • The content of this Pull Request (the Contribution) is intentionally submitted for inclusion in CIL (the Work) under the terms and conditions of the Apache-2.0 License
  • I confirm that the contribution does not violate any intellectual property rights of third parties

--->

@MargaretDuff MargaretDuff self-assigned this Apr 23, 2024
@MargaretDuff MargaretDuff added bug Something isn't working Waiting for review labels Apr 23, 2024
Copy link
Contributor

@epapoutsellis epapoutsellis left a comment

Choose a reason for hiding this comment

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

lgtm

MargaretDuff and others added 3 commits May 3, 2024 12:55
Signed-off-by: Margaret Duff <43645617+MargaretDuff@users.noreply.github.com>
@MargaretDuff MargaretDuff changed the title Bug fix for the SIRT objective SIRT objective Jul 5, 2024
Copy link
Contributor

@jakobsj jakobsj left a comment

Choose a reason for hiding this comment

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

Just a couple of minor things.

@@ -46,6 +46,8 @@ class SIRT(Algorithm):
:math:`\mathrm{prox}_{C}` is the projection over a set :math:`C`,
and :math:`\omega` is the relaxation parameter.

Note that SIRT is equivalent to gradient descent on a weighted least squares objective (weighted by :math:`M`) preconditioned by the sensitivity matrix (:math:`D`).
Thus the objective calculation for SIRT is the weighted least squares objective :math:`\frac{1}{2}\|A x - b\|^{2}_{M}`.
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add a line to define the formula for the M-norm.

Copy link
Contributor

Choose a reason for hiding this comment

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

In the docstring.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

y = self.operator.direct(self.x)
y.subtract(self.data, out = y)
wy=self.M.multiply(y)
self.objective.append(0.5* y.dot(wy))
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we want the 0.5? Could be omitted for (slight) speed-up and objective function rewritten to omit this. Should think about consistency with defaults in related operations including LeastSquares and CGLS though.

Copy link
Member Author

Choose a reason for hiding this comment

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

There isn't a 0.5 in CGLS (it uses \min || A x - b ||^2_2) and the default for least squares is 1.0. So in some ways, SIRT would be odd to include the 0.5. Mathematically, it is optimising the same thing. Shall we remove it?

Comment on lines +212 to +215
y = self.operator.direct(self.x)
y.subtract(self.data, out = y)
wy=self.M.multiply(y)
self.objective.append(0.5* y.dot(wy))
Copy link
Member

@gfardell gfardell Jul 10, 2024

Choose a reason for hiding this comment

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

This is adding an additional 2 copies of the data in to memory so we need to try to improve it.

wy is the same as the residuals r in update and this is still in memory. So instead I think we can square r (in place) and then weight it with M (again in place). As r is not reused by the algorithm it's ok using the memory for this. The first step of the algorithm recomputes the new residuals in to r.

Copy link
Member Author

Choose a reason for hiding this comment

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

I tried this but got numerical errors (effectively from dividing and multiplying by M). I will try to debug this again.

@gfardell gfardell added this to the v24.2.0 milestone Jul 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Waiting for review
Projects
No open projects
Status: Needs reviewing
Status: PRs to review
Development

Successfully merging this pull request may close these issues.

Incorrect objective calculation for SIRT
5 participants