.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/6-Poisson-fLDS.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_6-Poisson-fLDS.py: Poisson fLDS ============ .. GENERATED FROM PYTHON SOURCE LINES 19-147 .. rst-class:: sphx-glr-horizontal * .. image-sg:: /auto_examples/images/sphx_glr_6-Poisson-fLDS_001.png :alt: Simulated latent trajectories :srcset: /auto_examples/images/sphx_glr_6-Poisson-fLDS_001.png :class: sphx-glr-multi-img * .. image-sg:: /auto_examples/images/sphx_glr_6-Poisson-fLDS_002.png :alt: Simulated firing rates :srcset: /auto_examples/images/sphx_glr_6-Poisson-fLDS_002.png :class: sphx-glr-multi-img * .. image-sg:: /auto_examples/images/sphx_glr_6-Poisson-fLDS_003.png :alt: Neuron 1, Neuron 2, Neuron 3, Neuron 4, Neuron 5, Neuron 6, Neuron 7, Neuron 8, Neuron 9 :srcset: /auto_examples/images/sphx_glr_6-Poisson-fLDS_003.png :class: sphx-glr-multi-img * .. image-sg:: /auto_examples/images/sphx_glr_6-Poisson-fLDS_004.png :alt: Batch 1 :srcset: /auto_examples/images/sphx_glr_6-Poisson-fLDS_004.png :class: sphx-glr-multi-img * .. image-sg:: /auto_examples/images/sphx_glr_6-Poisson-fLDS_005.png :alt: Batch 2 :srcset: /auto_examples/images/sphx_glr_6-Poisson-fLDS_005.png :class: sphx-glr-multi-img * .. image-sg:: /auto_examples/images/sphx_glr_6-Poisson-fLDS_006.png :alt: Batch 3 :srcset: /auto_examples/images/sphx_glr_6-Poisson-fLDS_006.png :class: sphx-glr-multi-img * .. image-sg:: /auto_examples/images/sphx_glr_6-Poisson-fLDS_007.png :alt: Batch 4 :srcset: /auto_examples/images/sphx_glr_6-Poisson-fLDS_007.png :class: sphx-glr-multi-img * .. image-sg:: /auto_examples/images/sphx_glr_6-Poisson-fLDS_008.png :alt: Batch 5 :srcset: /auto_examples/images/sphx_glr_6-Poisson-fLDS_008.png :class: sphx-glr-multi-img * .. image-sg:: /auto_examples/images/sphx_glr_6-Poisson-fLDS_009.png :alt: 6 Poisson fLDS :srcset: /auto_examples/images/sphx_glr_6-Poisson-fLDS_009.png :class: sphx-glr-multi-img * .. image-sg:: /auto_examples/images/sphx_glr_6-Poisson-fLDS_010.png :alt: 6 Poisson fLDS :srcset: /auto_examples/images/sphx_glr_6-Poisson-fLDS_010.png :class: sphx-glr-multi-img .. rst-class:: sphx-glr-script-out .. code-block:: none Fitting LDS with SVI 0%| | 0/10000 [00:00 0 ) vmax = 1.1 * tuning_curves.max() plt.figure(figsize=(12, 12)) splt = 3 for i in range(splt): for j in range(splt): n = i * splt + j if n < N: ax = plt.subplot(splt, splt, n+1) im = plt.imshow(tuning_curves[:, n].reshape((npts, npts)), vmin=0, vmax=vmax, cmap="Greys") if i == splt-1: plt.xlabel("$x_1$") if j == 0: plt.ylabel("$x_2$") plt.title("Neuron {}".format(n+1)) divider = make_axes_locatable(ax) cax = divider.append_axes("right", size="5%", pad=0.05) plt.colorbar(im, cax=cax) plt.tight_layout() for b in range(5): plt.figure() plt.imshow(ys[b].T, aspect="auto", interpolation="none") plt.xlabel("time") plt.ylabel("neuron") plt.title("Batch {}".format(b+1)) plt.colorbar() # + print("Fitting LDS with SVI") lds = ssm.LDS(N, D, emissions="poisson_nn", emission_kwargs=dict(link="softplus", hidden_layer_sizes=(50, 50)) ) lds.initialize(ys) lds_elbos, q = lds.fit(ys, method="bbvi", variational_posterior="mf", num_iters=10000, print_intvl=100, initialize=False) lds_xs = q.mean # - plt.plot(lds_elbos) plt.xlabel("SVI Iteration") plt.ylabel("ELBO") # Smooth the observations lds_ys = [lds.smooth(x, y) for x, y in zip(lds_xs, ys)] plt.figure(figsize=(8,4)) plt.plot(xs[0], '-k') plt.plot(lds_xs[0], '-') plt.ylabel("$x$") plt.xlim(0, T) # Plot the smoothed observations plt.figure(figsize=(8,4)) plt.plot(rates[0] + 10 * np.arange(N), '-k', lw=2) plt.plot(lds_ys[0] + 10 * np.arange(N), '-', lw=2) plt.ylabel("$y$") plt.xlabel("time") plt.xlim(0, T) .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 10 minutes 41.698 seconds) .. _sphx_glr_download_auto_examples_6-Poisson-fLDS.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: 6-Poisson-fLDS.py <6-Poisson-fLDS.py>` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: 6-Poisson-fLDS.ipynb <6-Poisson-fLDS.ipynb>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_