Skip to content

Instantly share code, notes, and snippets.

Created October 16, 2013 16:34
Show Gist options
  • Save anonymous/7010817 to your computer and use it in GitHub Desktop.
Save anonymous/7010817 to your computer and use it in GitHub Desktop.
import pylab
import random
import pandas as pd
import numpy as np
duration = 100
meanIncrease = 3.0
stDevIncrease = 3.
sdi = stDevIncrease
## Here we generate a fictional time series, for a
## variable that generally increases over time but
## has significant noise.
for j in range(100):
x = range(duration)
y = []
yNow = 0
tstype = random.randint(0,2) # 0, 1, 2
print tstype
if tstype == 0:
for i in x:
if i < 25:
mi = 0.5
sdi = 0.3
elif i < 50:
mi = 0.
sdi = 0.2
elif i < 70:
mi = 1.
sdi = 0.2
else:
mi = -1.
sdi = 0.2
nextDelta = random.normalvariate(mi, sdi)
yNow += nextDelta
y.append( max(0, min(yNow, 20)) )
elif tstype == 1:
for i in x:
if i < 25:
mi = 0.5
sdi = 0.3
elif i < 50:
mi = -0.5
sdi = 0.3
elif i < 70:
mi = 1.
sdi = 0.3
else:
mi = -1.
sdi = 0.3
nextDelta = random.normalvariate(mi, sdi)
yNow += nextDelta
y.append( max(0, min(yNow, 20)) )
else:
for i in x:
if i < 25:
mi = 0.5
sdi = 0.3
elif i < 50:
mi = -0.5
sdi = 0.3
elif i < 70:
if yNow < 10:
mi = 1.5
else:
mi = 0.
sdi = 0.1
else:
if yNow < 10:
mi = 1.5
else:
mi = 0.
sdi = 0.1
nextDelta = random.normalvariate(mi, sdi)
yNow += nextDelta
y.append( max(0, min(yNow, 20)) )
yy = pd.Series(y)
when = pd.date_range(start=pd.datetime(2013,1,1), freq='S', periods=len(x))
xxt = pd.Series(yy.values, index=when)
print xxt
xxt.to_csv('./xxt.csv')
pylab.plot(x,y)
pylab.xlabel("Time")
pylab.ylabel("Value")
pylab.savefig("lineGraph.png")
pylab.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment