
.. DO NOT EDIT.
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
.. "examples/learning_ml/example_tpgmm.py"
.. LINE NUMBERS ARE GIVEN BELOW.

.. only:: html

    .. note::
        :class: sphx-glr-download-link-note

        :ref:`Go to the end <sphx_glr_download_examples_learning_ml_example_tpgmm.py>`
        to download the full example code

.. rst-class:: sphx-glr-example-title

.. _sphx_glr_examples_learning_ml_example_tpgmm.py:


TP-GMM
=================

This example shows how to use the TP-GMM to learn a human demonstration motion.

.. GENERATED FROM PYTHON SOURCE LINES 7-32

.. code-block:: default

    import numpy as np

    import rofunc as rf

    raw_demo = np.load('../data/LFD_ML/LeftHand.npy')
    demos_x = [raw_demo[500:635, :], raw_demo[635:770, :], raw_demo[770:905, :]]

    # --- TP-GMM ---
    # Define the task parameters
    start_xdx = [demos_x[i][0] for i in range(len(demos_x))]  # TODO: change to xdx
    end_xdx = [demos_x[i][-1] for i in range(len(demos_x))]
    task_params = {'frame_origins': [start_xdx, end_xdx], 'frame_names': ['start', 'end']}
    # Fit the model
    Repr = rf.ml.TPGMM(demos_x, task_params, plot=True)
    model = Repr.fit()

    # Reproductions for the same situations
    traj, _ = Repr.reproduce(model, show_demo_idx=2)

    # Reproductions for new situations: set the endpoint as the start point to make a cycled motion
    ref_demo_idx = 2
    start_xdx = [Repr.demos_xdx[ref_demo_idx][9]]
    end_xdx = [Repr.demos_xdx[ref_demo_idx][9]]
    Repr.task_params = {'frame_origins': [start_xdx, end_xdx], 'frame_names': ['start', 'end']}
    traj, _ = Repr.generate(model, ref_demo_idx)


.. rst-class:: sphx-glr-timing

   **Total running time of the script:** (0 minutes 0.000 seconds)


.. _sphx_glr_download_examples_learning_ml_example_tpgmm.py:

.. only:: html

  .. container:: sphx-glr-footer sphx-glr-footer-example




    .. container:: sphx-glr-download sphx-glr-download-python

      :download:`Download Python source code: example_tpgmm.py <example_tpgmm.py>`

    .. container:: sphx-glr-download sphx-glr-download-jupyter

      :download:`Download Jupyter notebook: example_tpgmm.ipynb <example_tpgmm.ipynb>`


.. only:: html

 .. rst-class:: sphx-glr-signature

    `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_
