Skip to content

Commit

Permalink
Fix rolling avg (#537)
Browse files Browse the repository at this point in the history
* attempt to fix rolling avg stability

* skipping failing stddev updates

* fully compute window stats if rolling stats introduced numerical problem

* improve warning message

* removed warning message
  • Loading branch information
msperber committed Nov 14, 2018
1 parent 8a8f0cd commit c2028c7
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion xnmt/utils.py
Expand Up @@ -79,7 +79,13 @@ def update(self, new):
newavg = oldavg + (new - old) / self.N
self.average = newavg
self.variance += (new - old) * (new - newavg + old - oldavg) / (self.N - 1)
self.stddev = math.sqrt(self.variance)
try:
self.stddev = math.sqrt(self.variance)
except ValueError:
# This happens in case of numerical issues in computation of rolling stddev, but we can easily resolve this
# through full re-computation
self.variance = np.var(self.vals)
self.stddev = math.sqrt(self.variance)
else:
assert len(self.vals) < self.N

Expand Down

0 comments on commit c2028c7

Please sign in to comment.