WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
'''Base Callback to inherit from for use in :code:`Algorithm.run(callbacks: list[Callback])`.
@@ -154,56 +156,54 @@ class LogfileCallback(TextProgressCallback):
154
156
def__init__(self, log_file, mode='a', **kwargs):
155
157
self.fd=open(log_file, mode=mode)
156
158
super().__init__(file=self.fd, **kwargs)
157
-
159
+
158
160
classEarlyStoppingObjectiveValue(Callback):
159
161
'''Callback that stops iterations if the change in the objective value is less than a provided threshold value.
160
162
161
163
Parameters
162
164
----------
163
-
threshold: float, default 1e-6
165
+
threshold: float, default 1e-6
164
166
165
167
Note
166
168
-----
167
169
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.
'''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.
181
-
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.
182
-
182
+
'''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.
183
+
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.
184
+
183
185
Parameters
184
186
----------
185
-
epsilon: float, default 1e-6
187
+
epsilon: float, default 1e-6
186
188
Usually a small number: the algorithm to terminate if :math:`||A^T(Ax-b)||_2 < \epsilon||A^T(Ax_0-b)||_2`
187
-
omega: float, default 1e6
189
+
omega: float, default 1e6
188
190
Usually a large number: the algorithm will terminate if :math:`||x||_2> \omega`
189
-
191
+
190
192
Note
191
193
-----
192
-
This callback is implemented to replicate the automatic behaviour of CGLS in CIL versions <=24. It also replicates the behaviour of https://web.stanford.edu/group/SOL/software/cgls/.
194
+
This callback is implemented to replicate the automatic behaviour of CGLS in CIL versions <=24. It also replicates the behaviour of https://web.stanford.edu/group/SOL/software/cgls/.
193
195
'''
194
196
def__init__(self, epsilon=1e-6, omega=1e6):
195
197
self.epsilon=epsilon
196
198
self.omega=omega
197
-
198
-
199
+
200
+
199
201
def__call__(self, algorithm):
200
-
202
+
201
203
if (algorithm.norms<=algorithm.norms0*self.epsilon):
202
204
print('The norm of the residual is less than {} times the norm of the initial residual and so the algorithm is terminated'.format(self.epsilon))
203
205
raiseStopIteration
204
206
self.normx=algorithm.x.norm()
205
207
ifalgorithm.normx>=self.omega:
206
208
print('The norm of the solution is greater than {} and so the algorithm is terminated'.format(self.omega))
0 commit comments