diff options
author | aktersnurra <gustaf.rydholm@gmail.com> | 2020-06-23 22:39:54 +0200 |
---|---|---|
committer | aktersnurra <gustaf.rydholm@gmail.com> | 2020-06-23 22:39:54 +0200 |
commit | 7c4de6d88664d2ea1b084f316a11896dde3e1150 (patch) | |
tree | cbde7e64c8064e9b523dfb65cd6c487d061ec805 /src/training/util.py | |
parent | a7a9ce59fc37317dd74c3a52caf7c4e68e570ee8 (diff) |
latest
Diffstat (limited to 'src/training/util.py')
-rw-r--r-- | src/training/util.py | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/training/util.py b/src/training/util.py new file mode 100644 index 0000000..132b2dc --- /dev/null +++ b/src/training/util.py @@ -0,0 +1,19 @@ +"""Utility functions for training neural networks.""" + + +class RunningAverage: + """Maintains a running average.""" + + def __init__(self) -> None: + """Initializes the parameters.""" + self.steps = 0 + self.total = 0 + + def update(self, val: float) -> None: + """Updates the parameters.""" + self.total += val + self.steps += 1 + + def __call__(self) -> float: + """Computes the running average.""" + return self.total / float(self.steps) |