Skip to content

Commit 4109f24

Browse files
authored
Add option to not cool beta in the Irls directive (#63)
Add `cool_beta` optional argument to `Irls` directive. If False, then beta won't get cooled down. Add a public `beta_cooling_factor` property to `Irls` directive
1 parent 97d66a2 commit 4109f24

File tree

1 file changed

+39
-13
lines changed

1 file changed

+39
-13
lines changed

src/inversion_ideas/directives.py

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,16 @@ class Irls(Directive):
9696
Relative tolerance for the data misfit.
9797
Used to compare the current value of the data misfit with its value after the
9898
stage one is finished.
99+
cool_beta : bool, optional
100+
Whether to cool down beta during the IRLS process.
101+
If False, make sure you handle beta cooling in other way, like through other
102+
directive.
103+
104+
.. warning::
105+
If False, the Irls directive won't cool down beta during the inversions.
106+
This might prevent from reaching convergence.
107+
Make sure you handle beta cooling in other way, like through other
108+
directive.
99109
"""
100110

101111
def __init__(
@@ -106,6 +116,7 @@ def __init__(
106116
chi_l2_target=1.0,
107117
beta_cooling_factor=2.0,
108118
data_misfit_rtol=1e-1,
119+
cool_beta=True,
109120
):
110121
if len(args) == 0:
111122
msg = (
@@ -153,12 +164,15 @@ def __init__(
153164
raise TypeError(msg)
154165

155166
self.data_misfit_rtol = data_misfit_rtol
156-
self.beta_cooling_factor = beta_cooling_factor
157167
self.chi_l2_target = chi_l2_target
158168

159169
# Define a beta cooler
160-
self._beta_cooler = MultiplierCooler(
161-
self.regularization_with_beta, cooling_factor=self.beta_cooling_factor
170+
self._beta_cooler = (
171+
MultiplierCooler(
172+
self.regularization_with_beta, cooling_factor=beta_cooling_factor
173+
)
174+
if cool_beta
175+
else None
162176
)
163177

164178
# Define a condition for the data misfit.
@@ -168,6 +182,15 @@ def __init__(
168182
data_misfit, rtol=self.data_misfit_rtol
169183
)
170184

185+
@property
186+
def beta_cooling_factor(self) -> float | None:
187+
"""
188+
Current beta cooling factor.
189+
"""
190+
if self._beta_cooler is None:
191+
return None
192+
return self._beta_cooler.cooling_factor
193+
171194
def __call__(self, model: Model, iteration: int):
172195
"""
173196
Apply IRLS.
@@ -195,7 +218,8 @@ def _stage_one(self, model: Model, iteration: int):
195218
return
196219

197220
# Cool down beta otherwise
198-
self._beta_cooler(model, iteration)
221+
if self._beta_cooler is not None:
222+
self._beta_cooler(model, iteration)
199223

200224
def _stage_two(self, model: Model, iteration: int):
201225
"""
@@ -206,15 +230,17 @@ def _stage_two(self, model: Model, iteration: int):
206230
phi_d = self.data_misfit(model)
207231
# Adjust the cooling factor
208232
# (following current implementation of UpdateIRLS)
209-
if phi_d > self._dmisfit_l2:
210-
self._beta_cooler.cooling_factor = float(
211-
1 / np.mean([0.75, self._dmisfit_l2 / phi_d])
212-
)
213-
else:
214-
self._beta_cooler.cooling_factor = float(
215-
1 / np.mean([2.0, self._dmisfit_l2 / phi_d])
216-
)
217-
self._beta_cooler(model, iteration)
233+
if self._beta_cooler is not None:
234+
if self._beta_cooler.cooling_factor != 1:
235+
if phi_d > self._dmisfit_l2:
236+
self._beta_cooler.cooling_factor = float(
237+
1 / np.mean([0.75, self._dmisfit_l2 / phi_d])
238+
)
239+
else:
240+
self._beta_cooler.cooling_factor = float(
241+
1 / np.mean([2.0, self._dmisfit_l2 / phi_d])
242+
)
243+
self._beta_cooler(model, iteration)
218244
else:
219245
# Update the IRLS
220246
for sparse_reg in self.sparse_regs:

0 commit comments

Comments
 (0)