Skip to content

Instantly share code, notes, and snippets.

@bradbeattie
Created June 27, 2014 21:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bradbeattie/b409e1594084027581f5 to your computer and use it in GitHub Desktop.
Save bradbeattie/b409e1594084027581f5 to your computer and use it in GitHub Desktop.
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