mirror of
https://github.com/vale981/ray
synced 2025-03-06 10:31:39 -05:00

* WindowStat error catching, which processes NaNs properly instead of erroring. This ought to resolve issue #7910. https://github.com/ray-project/ray/issues/7910
28 lines
827 B
Python
28 lines
827 B
Python
import numpy as np
|
|
|
|
|
|
class WindowStat:
|
|
def __init__(self, name, n):
|
|
self.name = name
|
|
self.items = [None] * n
|
|
self.idx = 0
|
|
self.count = 0
|
|
|
|
def push(self, obj):
|
|
self.items[self.idx] = obj
|
|
self.idx += 1
|
|
self.count += 1
|
|
self.idx %= len(self.items)
|
|
|
|
def stats(self):
|
|
if not self.count:
|
|
_quantiles = []
|
|
else:
|
|
_quantiles = np.nanpercentile(self.items[:self.count],
|
|
[0, 10, 50, 90, 100]).tolist()
|
|
return {
|
|
self.name + "_count": int(self.count),
|
|
self.name + "_mean": float(np.nanmean(self.items[:self.count])),
|
|
self.name + "_std": float(np.nanstd(self.items[:self.count])),
|
|
self.name + "_quantiles": _quantiles,
|
|
}
|