Skip to content

Commit

Permalink
Add all callbacks to documentation (#2067)
Browse files Browse the repository at this point in the history
---------

Co-authored-by: Margaret Duff <43645617+MargaretDuff@users.noreply.github.com>
  • Loading branch information
lauramurgatroyd and MargaretDuff authored Feb 18, 2025
1 parent 871fa83 commit 2097927
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
3 changes: 2 additions & 1 deletion Wrappers/Python/cil/optimisation/utilities/callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ class EarlyStoppingObjectiveValue(Callback):
-----
This callback only compares the last two calculated objective values. If `update_objective_interval` is greater than 1, the objective value is not calculated at each iteration (which is the default behaviour), only every `update_objective_interval` iterations.
'''
'''
def __init__(self, threshold=1e-6):
self.threshold=threshold

Expand All @@ -160,6 +160,7 @@ def __call__(self, algorithm):
class CGLSEarlyStopping(Callback):
'''Callback to work with CGLS. It causes the algorithm to terminate if :math:`||A^T(Ax-b)||_2 < \epsilon||A^T(Ax_0-b)||_2` where `epsilon` is set to default as '1e-6', :math:`x` is the current iterate and :math:`x_0` is the initial value.
It will also terminate if the algorithm begins to diverge i.e. if :math:`||x||_2> \omega`, where `omega` is set to default as 1e6.
Parameters
----------
epsilon: float, default 1e-6
Expand Down
8 changes: 7 additions & 1 deletion docs/source/optimisation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,7 @@ In addition, we provide a random sampling class which is a child class of `cil.
Callbacks
---------

A list of :code:`Callback` s to be executed each iteration can be passed to `Algorithms`_ :code:`run` method.
A list of :code:`Callback` s to be executed each iteration can be passed to `Algorithm`'s :code:`run` method.

.. code-block :: python
Expand All @@ -620,6 +620,12 @@ Built-in callbacks include:
.. autoclass:: cil.optimisation.utilities.callbacks.LogfileCallback
:members:

.. autoclass:: cil.optimisation.utilities.callbacks.EarlyStoppingObjectiveValue
:members:

.. autoclass:: cil.optimisation.utilities.callbacks.CGLSEarlyStopping
:members:

Users can also write custom callbacks.

Below is an example of a custom callback implementing early stopping.
Expand Down

0 comments on commit 2097927

Please sign in to comment.