In [1]:
%pylab inline
In [2]:
# Large plots
import matplotlib.pylab as pylab
pylab.rcParams['figure.figsize'] = 16, 9 # that's default image size for this interactive session
In [3]:
import numpy as np
In [4]:
from hubbub.generator.generator import Simulator
from hubbub.generator.heartbeat import HeartBeatSimulator
from hubbub.datasets.simulations import SIMPLE_LOG
In [5]:
SIMPLE_LOG
Out[5]:
In [6]:
result_sm = Simulator(SIMPLE_LOG).run()
results_hb = [
HeartBeatSimulator(SIMPLE_LOG).run() for i in xrange(5)
# HeartBeatSimulator(SIMPLE_LOG).run(delay=lambda: 5) for i in xrange(10)
]
In [7]:
results_hb[0][:5]
Out[7]:
In [8]:
results_hb[0] == HeartBeatSimulator(SIMPLE_LOG).run()
Out[8]:
In [9]:
import time
def timestamp(n):
unix_time = time.mktime(n.timetuple())
return unix_time
In [10]:
start_time = timestamp(result_sm[0]['date'])
remap = np.array([start_time + i*5 for i in xrange(len(result_sm))])
remap
Out[10]:
In [11]:
r_real = np.array([timestamp(i['date']) for i in SIMPLE_LOG])
r_real
Out[11]:
Simple generator.
In [12]:
r_sm = np.array([timestamp(i['date']) for i in result_sm])
figure()
plot(r_sm[:50])
plot(remap[:50])
show()
In [13]:
r_hb = np.array([
np.array([timestamp(i['date']) for i in r])
for r in results_hb
])
type(r_hb[0])
Out[13]:
In [14]:
figure()
plot(remap[:50])
for r in r_hb[:5]:
plot(r[:50])
show()
figure()
for r in r_hb[:5]:
plot(r[:50] - remap[:50])
show()
figure()
for r in r_hb[:5]:
plot(r[1:51] - r[0:50], 'x-')
show()
Simple generator
In [15]:
r_real_sm = np.concatenate((r_sm, r_real))
r_real_sm.sort()
figure()
title('real + dummy')
plot(r_real_sm[:50])
plot(remap[:50])
show()
figure()
plot(r_real_sm[:50] - remap[:50])
show()
In [16]:
r_real_hb = [
np.concatenate((r_real, r_i))
for r_i in r_hb
]
for i in r_real_hb:
i.sort()
In [17]:
figure()
title('real + hb dummy')
plot(r_real_sm[:50])
plot(remap[:100])
for i in r_real_hb:
plot(i[:100], '-x')
legend(["simple", "remap", "heartbeat0", "heartbeat1", "heartbeat2"])
show()
#figure()
##plot(r_real_sm[:50] - remap[:50])
#for i in r_real_hb:
# plot(i[:100] - remap[:100], '-x')
#legend(["simple", "remap", "heartbeat0", "heartbeat1", "heartbeat2"])
#show()
In [33]:
# time delta
figure()
title('hb dummy only delay')
for i in r_hb:
plot(i[1:121] - i[0:120], 'o-')
delays = i[1:121] - i[0:120]
print '-', delays.mean()
print ' ', delays.std()
show()
In [35]:
# time delta
figure()
title('real + hb dummy delay')
for i in r_real_hb:
plot(i[1:121] - i[0:120], 'o-')
delays = i[1:121] - i[0:120]
print '-', delays.mean()
print ' ', delays.std()
show()
In [20]:
# Comparing average and simple
figure()
plot(r_real_sm[:50] - remap[:50])
plot(
np.sum(i[:50] for i in r_real_hb) / len(r_real_hb)
- remap[:50]
)
show()
In [21]:
from pandas import Series, DataFrame
In [22]:
dates_hb = [i['date'] for i in results_hb[0]]
s_hb = Series([1] * len(results_hb[0]), index=dates_hb)
s_hb.head()
Out[22]:
In [23]:
resampled_hb = s_hb[:1000].resample('1Min', how='sum')
plot(range(len(resampled_hb)), resampled_hb, 'o')
Out[23]:
In [23]:
In [23]: