Created
June 27, 2014 21:36
-
-
Save bradbeattie/b409e1594084027581f5 to your computer and use it in GitHub Desktop.
Show the effect of different decaying averages
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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