Here is an intuitional model:
t = np.arange(0, 300)
y = np.random.randn(300)
y[0:100] += 10 # breakpoint one at 100
y[200:299] += 20 # breakpoint two at 200
mod=pm.Model()
with mod:
bk1=pm.DiscreteUniform(‘bk1’,lower=1,upper=200)
bk2=pm.DiscreteUniform(‘bk2’,lower=bk1,upper=300)
slopes=pm.Normal(‘slopes’,mu=0,sigma=3,shape=3)
betas=pm.Normal(‘betas’,mu=0,sigma=3,shape=3)
res=pm.HalfNormal(‘res’,3)
t1=t[0:bk1]
t2=t[bk1+1:bk2]
t3=t[bk2+2:299]
y1=slopes[0]+betas[0]*t1
y2=slopes[1]+betas[1]*t2
y2=slopes[2]+betas[2]*t3
mu=np.hstack([y1,y2,y3])
y_obs=pm.Normal('yobs',mu=mu,sigma=res,observed=y)
TypeError: slice indices must be integers or None or have an index method: t1=t[0:bk1]
I couldn’t figure it out.