.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/other/plot_simulate_motif.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_other_plot_simulate_motif.py: ======================= MoTIF on simulated data ======================= This example demonstrates MoTIF [1] on simulated data. In the alphacsc module, we are offering all the alternatives for the users to try. Please cite our paper [2] if you use this implementation. [1] Jost, Philippe, et al. "MoTIF: An efficient algorithm for learning translation invariant dictionaries." Acoustics, Speech and Signal Processing, 2006. ICASSP 2006 Proceedings. 2006 IEEE International Conference on. Vol. 5. IEEE, 2006. [2] Jas, M., Dupr'e La Tour, T., Simsekli, U., & Gramfort, A. (2017). Learning the Morphology of Brain Signals Using Alpha-Stable Convolutional Sparse Coding. arXiv preprint arXiv:1705.08006. .. GENERATED FROM PYTHON SOURCE LINES 19-27 .. code-block:: Python # Authors: Mainak Jas # Tom Dupre La Tour # Umut Simsekli # Alexandre Gramfort # # License: BSD (3-clause) .. GENERATED FROM PYTHON SOURCE LINES 28-29 Let us first import the modules. .. GENERATED FROM PYTHON SOURCE LINES 29-34 .. code-block:: Python import matplotlib.pyplot as plt from alphacsc.simulate import simulate_data from alphacsc.other.motif import learn_atoms .. GENERATED FROM PYTHON SOURCE LINES 35-37 and define the relevant parameters. Note we choose a large n_times to avoid overlapping atoms which MoTIF cannot handle .. GENERATED FROM PYTHON SOURCE LINES 37-43 .. code-block:: Python n_times_atom = 64 # L n_times = 5000 # T n_atoms = 2 # K n_trials = 10 # N .. GENERATED FROM PYTHON SOURCE LINES 44-45 simulate the data. .. GENERATED FROM PYTHON SOURCE LINES 45-55 .. code-block:: Python random_state_simulate = 1 X, ds_true, z_true = simulate_data(n_trials, n_times, n_times_atom, n_atoms, random_state_simulate, constant_amplitude=True) n_times_atom = n_times_atom * 7 # XXX: hack n_iter = 10 max_shift = 11 # after this, the algorithm breaks .. GENERATED FROM PYTHON SOURCE LINES 56-62 Note, how we use constant_amplitude=True since MoTIF cannot handle atoms of varying amplitudes. Check out our examples on :ref:`vanilla CSC ` and :ref:`alphaCSC ` to learn how to deal with such cases. Finally, let us estimate the atoms. .. GENERATED FROM PYTHON SOURCE LINES 62-67 .. code-block:: Python ds_hat = learn_atoms(X, n_atoms, n_times_atom, n_iter=n_iter, max_shift=max_shift, random_state=42) plt.plot(ds_hat.T) .. image-sg:: /auto_examples/other/images/sphx_glr_plot_simulate_motif_001.png :alt: plot simulate motif :srcset: /auto_examples/other/images/sphx_glr_plot_simulate_motif_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none [seed 42] Atom 0 Iteration 0 [seed 42] Atom 0 Iteration 1 [seed 42] Atom 0 Iteration 2 [seed 42] Atom 0 Iteration 3 [seed 42] Atom 0 Iteration 4 [seed 42] Atom 0 Iteration 5 [seed 42] Atom 0 Iteration 6 [seed 42] Atom 0 Iteration 7 [seed 42] Atom 0 Iteration 8 [seed 42] Atom 0 Iteration 9 [seed 42] Atom 1 Iteration 0 [seed 42] Atom 1 Iteration 1 [seed 42] Atom 1 Iteration 2 [seed 42] Atom 1 Iteration 3 [seed 42] Atom 1 Iteration 4 [seed 42] Atom 1 Iteration 5 [seed 42] Atom 1 Iteration 6 [seed 42] Atom 1 Iteration 7 [seed 42] Atom 1 Iteration 8 [seed 42] Atom 1 Iteration 9 [, ] .. GENERATED FROM PYTHON SOURCE LINES 68-69 Compare this to the original atoms .. GENERATED FROM PYTHON SOURCE LINES 69-72 .. code-block:: Python plt.figure() plt.plot(ds_true.T) plt.show() .. image-sg:: /auto_examples/other/images/sphx_glr_plot_simulate_motif_002.png :alt: plot simulate motif :srcset: /auto_examples/other/images/sphx_glr_plot_simulate_motif_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 2.010 seconds) .. _sphx_glr_download_auto_examples_other_plot_simulate_motif.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_simulate_motif.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_simulate_motif.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_simulate_motif.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_