@@ -0,0 +1,1174 @@
+from __future__ import print_function%0Afrom __future__ import unicode_literals%0Afrom __future__ import division%0Afrom __future__ import absolute_import%0Afrom future import standard_library%0Astandard_library.install_aliases()%0A%0A%0Aclass NormalizedRewardFilter(object):%0A%0A    def __init__(self, tau=1e-3, scale=1, eps=1e-1):%0A        self.tau = tau%0A        self.scale = scale%0A        self.average_reward = 0%0A        self.average_reward_squared = 0%0A        self.eps = eps%0A%0A    def __call__(self, reward):%0A        self.average_reward *= 1 - self.tau%0A        self.average_reward += self.tau * reward%0A        self.average_reward_squared *= 1 - self.tau%0A        self.average_reward_squared += self.tau * reward ** 2%0A        var = self.average_reward_squared - self.average_reward ** 2%0A        stdev = min(var, self.eps) ** 0.5%0A        return self.scale * (reward - self.average_reward) / stdev%0A%0A%0Aclass AverageRewardFilter(object):%0A%0A    def __init__(self, tau=1e-3):%0A        self.tau = tau%0A        self.average_reward = 0%0A%0A    def __call__(self, reward):%0A        self.average_reward *= 1 - self.tau%0A        self.average_reward += self.tau * reward%0A        return reward - self.average_reward%0A

Add reward filters to use average rewards