I am trying to do modelling BSTS (Bayesian Structural Time Series) with Markov chain Monte Carlo (MCMC) method using stan especially pystan and also python to get the graphical result (picture 2). I finished modelling using pystan for plot the graphic estimated using BSTS or dotted line Baseline (picture 2), but I have trouble in modelling equations in python (picture 1) to get the observation graphic or Measurement data (picture 2).
picture 1:
picture 2:
This is reference that I used in this case.
Note: subscript t = 1,2,3,..,104 and subscript i = 0,1,2,...,7
#Generate dummy data for BSTS
SEED = 1234
NUM_SAMPLES_t = 250
NUM_SAMPLES_i = 7
def generate_data_dummy_bsts():
#x = 2*np.random.normal(250, 1, 150) - np.random.normal(250,1,150)
#xt = 2*np.array(range([NUM_SAMPLES_t - 1])) - np.array(range([NUM_SAMPLES_t - 2]))
#x[1] = -xt[-1] + np.random.normal(250, 1, 150)
A = 10
B = 10
KD = 10
xt_array = np.array(range(NUM_SAMPLES_t))
qt_array = np.array(range(NUM_SAMPLES_t))
qi_array = np.array(range(NUM_SAMPLES_i))
for t in range(xt_array):
x[t] = 2*x[t-1] - x[t-2] + np.random.normal(250, 1,150)
xt = x[t]
for t in range(qt_array):
if (NUM_SAMPLES_t < 65):
for i in range(qi_array):
q[i] = 0
else :
for i in range(qi_array):
tau[i] = A*np.log(c[i]) + B + np.random.normal(250,1,150)
Q[i] = a*c[i] / KD + c[i]
q[i] = (Q[i] - Q[i-1])(1 - np.exp(-t - 65 / tau[i]))
qt = np.sum(q)
#observation
y = xt + qt + np.random.normal(250, 1, 150)
When i try to plot this equation in def function to get the graphical result
fig,ax = plt.subplots(figsize=(10,3))
ax.plot(generate_data_dummy_bsts())
plt.show()
I have error message
TypeError Traceback (most recent call last)
<ipython-input-18-dc3e483a266e> in <module>()
1 fig,ax = plt.subplots(figsize=(10,3))
----> 2 ax.plot(generate_data_dummy_bsts())
3 plt.show()
<ipython-input-17-d188897a3bbb> in generate_data_dummy_bsts()
11 qi_array = np.array(range(NUM_SAMPLES_i))
12
---> 13 for t in range(xt_array):
14 x[t] = 2*x[t-1] - x[t-2] + np.random.normal(250, 1,150)
15 xt = x[t]
TypeError: only integer scalar arrays can be converted to a scalar index

