Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Show the effect of different decaying averages
import random
import math
multipliers = (0.5, 0.8, 0.95, 0.99, 0.995)
values = [1] * len(multipliers)
for x in xrange(400):
numberline = ["-"] * 101
for index, multiplier in enumerate(multipliers):
if index == 0:
values[index] = 1 if math.sin(x/5.0) + math.cos(x/2.0) + random.uniform(-1, 1) > 0 else 0
else:
values[index] = values[index] * multiplier + values[0] * (1 - multiplier)
numberline[int(values[index] * 100)] = str(index)
print "".join(numberline)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.