ws = np.array( [np.exp(-(rg - 3)**2 / 2 / 0.8**2), np.exp(-(rg - 7)**2 / 2 / 1.0**2)]).T #filters W = np.outer(a, ws[:, 0]) + np.outer((1 - a), ws[:, 1]) eta = (X * W).sum(1) - 1 #emission p = 1 / (1 + np.exp(-eta)) #nonlinearity y = (p > np.random.rand(len(p))) plt.plot(y) plt.figure() plt.plot(ws) # %% full GLM-HMM inference glmopts = DotMap() glmopts.family = 'binomlogit' glmopts.familyextra = 1 glmopts.regularize = 10 glmopts.thresh = 10**-5 glmopts.niter = 100 #maximum iteration glmopts.baseline = 1 glmopts.algo = 1 glmopts.Display = 1 K0 = np.random.rand(K.shape[0], K.shape[1], K.shape[2]) w0 = np.random.randn(ws.shape[0], ws.shape[1]) * 1 + ws glmopts.w0 = w0.copy() results = GLMHMM(y, X, w0, K0, glmopts) plt.figure() plt.plot(results.W)