Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Kris Thielemans <[email protected]>
Co-authored-by: Casper da Costa-Luis <[email protected]>
  • Loading branch information
3 people authored Jul 4, 2024
1 parent dc6a478 commit fffc8bd
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions main_ISTA.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,17 @@ def __call__(self, algorithm: Algorithm):
raise StopIteration

class MyPreconditioner(Preconditioner):
# Use a preconditioner based on the row-sum of the Hessian of the log-likelihood as an example
# See:
# Tsai, Y.-J., Bousse, A., Ehrhardt, M.J., Stearns, C.W., Ahn, S., Hutton, B., Arridge, S., Thielemans, K., 2017.
# Fast Quasi-Newton Algorithms for Penalized Reconstruction in Emission Tomography and Further Improvements via Preconditioning.
# IEEE Transactions on Medical Imaging 1. https://doi.org/10.1109/tmi.2017.2786865
def __init__(self, kappa):
self.kappasq = kappa * kappa + 1e-5
# add an epsilon to avoid division by zero. This eps value probably should be made dependent on kappa though.
self.kappasq = kappa * kappa + 1e-6

def apply(self, algorithm, gradient, out):
out = gradient.divide(self.kappasq, out=out)
return out
def apply(self, algorithm, gradient, out=None):
return gradient.divide(self.kappasq, out=out)

class Submission(ISTA):
# note that `issubclass(ISTA, Algorithm) == True`
Expand All @@ -57,7 +58,7 @@ def __init__(self, data: Dataset, num_subsets: int = 7, step_size: float = 1e-6,
sampler = Sampler.random_without_replacement(len(obj_funs))
F = -SGFunction(obj_funs, sampler=sampler) # negative to turn minimiser into maximiser
step_size_rule = ConstantStepSize(step_size) # ISTA default step_size is 0.99*2.0/F.L
g = IndicatorBox(lower=1e-6, accelerated=False) # "non-negativity" constraint
g = IndicatorBox(lower=0, accelerated=False) # non-negativity constraint

my_preconditioner = MyPreconditioner(data.kappa)
super().__init__(initial=data.OSEM_image,
Expand Down

0 comments on commit fffc8bd

Please sign in to comment.