Skip to content

Commit fb50d16

Browse files
authored
Fix logic with counter in Inversion (#56)
Fix bug introduced in the last commit. Now the counter is always set to the last iteration that was run. Before the zeroth iteration, the `Inversion` doesn't have any counter.
1 parent 3dcf21a commit fb50d16

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

src/inversion_ideas/inversion.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,14 +86,15 @@ def __init__(
8686
# Assign model as a copy of the initial model
8787
self.model = initial_model.copy()
8888

89-
# Initialize the counter
90-
self._counter = 0
91-
9289
def __next__(self):
9390
"""
9491
Run next iteration in the inversion.
9592
"""
96-
if self.counter == 0:
93+
# Zeroth iteration
94+
if not hasattr(self, "_counter"):
95+
# Initialize counter to zero
96+
self._counter = 0
97+
9798
# Add initial model to log (only on zeroth iteration)
9899
if self.log is not None:
99100
self.log.update(self.counter, self.model)
@@ -102,9 +103,6 @@ def __next__(self):
102103
if hasattr(self.stopping_criteria, "initialize"):
103104
self.stopping_criteria.initialize()
104105

105-
# Increase counter by one
106-
self._counter += 1
107-
108106
# Return the initial model in the zeroth iteration
109107
return self.model
110108

0 commit comments

Comments
 (0)