In this notebook, I shall be simulating some appliance data to see how well we are able to find the change points.
In [39]:
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
%matplotlib inline
In [40]:
test_signal = np.array([0,0,0,2,3,100,100,110,110,112,113,115,120,130,5,4,0])
In [41]:
plt.plot(test_signal);
In [42]:
from bayesianchangepoint import bcp
In [43]:
hazard_func = lambda r: bcp.constant_hazard(r, _lambda=200)
In [44]:
beliefs, maxes = bcp.inference(test_signal, hazard_func)
In [46]:
fig, ax = plt.subplots(nrows = 2, sharex = True)
ax[0].plot(test_signal)
ax[1].imshow(-np.log(beliefs), interpolation='none', aspect='auto',
origin='lower', cmap=plt.cm.Blues)
ax[1].plot(maxes, color='r')
ax[1].set_xlim([0, len(test_signal)])
ax[1].set_ylim([0, ax[1].get_ylim()[1]])
ax[0].grid()
ax[1].grid()
index_changes = np.where(np.diff(maxes.T[0])<0)[0]
ax[0].scatter(index_changes, test_signal[index_changes]);
Looks decent! I am not very sure about why maxes is same for all index positions. I just used maxes[0] for marking the change points. This needs confirmation though.