
.. DO NOT EDIT.
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
.. "examples/learning_ml/example_tpgmmbi_RPCtrl.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_tpgmmbi_RPCtrl.py>`
        to download the full example code

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

.. _sphx_glr_examples_learning_ml_example_tpgmmbi_RPCtrl.py:


TP-GMMBi with Relative Parameterization in Control
===================================================

This example shows how to use the TP-GMM in bimanual setting with Relative Parameterization in Control.

.. GENERATED FROM PYTHON SOURCE LINES 7-47

.. code-block:: default

    import numpy as np

    import rofunc as rf
    from rofunc.utils.datalab.data_generator.bezier import multi_bezier_demos

    left_demo_points = np.array([[[0, 0], [-1, 8], [4, 3], [2, 1], [4, 3]],
                                 [[0, -2], [-1, 7], [3, 2.5], [2, 1.6], [4, 3]],
                                 [[0, -1], [-1, 8], [4, 5.2], [2, 1.1], [4, 3.5]]])
    right_demo_points = np.array([[[8, 8], [7, 1], [4, 3], [6, 8], [4, 3]],
                                  [[8, 7], [7, 1], [3, 3], [6, 6], [4, 3]],
                                  [[8, 8], [7, 1], [4, 5], [6, 8], [4, 3.5]]])
    demos_left_x = multi_bezier_demos(left_demo_points)  # (3, 50, 2): 3 demos, each has 50 points
    demos_right_x = multi_bezier_demos(right_demo_points)

    # --- TP-GMMBi with Relative Parameterization in Control ---
    # Define the task parameters
    start_xdx_l = [demos_left_x[i][0] for i in range(len(demos_left_x))]  # TODO: change to xdx
    end_xdx_l = [demos_left_x[i][-1] for i in range(len(demos_left_x))]
    start_xdx_r = [demos_right_x[i][0] for i in range(len(demos_right_x))]
    end_xdx_r = [demos_right_x[i][-1] for i in range(len(demos_right_x))]
    task_params = {'left': {'frame_origins': [start_xdx_l, end_xdx_l], 'frame_names': ['start', 'end']},
                   'right': {'frame_origins': [start_xdx_r, end_xdx_r], 'frame_names': ['start', 'end']}}
    # Fit the model
    Repr = rf.ml.TPGMM_RPCtrl(demos_left_x, demos_right_x, task_params, plot=True)
    model_l, model_r, model_c = Repr.fit()

    # Reproductions for the same situations
    Repr.reproduce([model_l, model_r, model_c], show_demo_idx=2)

    # Reproductions for new situations
    start_xdx_l = [np.array([-0.5, 1, 0, 0])]
    end_xdx_l = [np.array([5, 4, 0, 0])]
    start_xdx_r = [np.array([6.5, 7, 0, 0])]
    end_xdx_r = end_xdx_l

    Repr.task_params = {"left": {"frame_origins": [start_xdx_l, end_xdx_l], "frame_names": ["start", "end"]},
                        "right": {"frame_origins": [start_xdx_r, end_xdx_r], "frame_names": ["start", "end"]},
                        "relative": {"frame_origins": [[start_xdx_l[0] - start_xdx_r[0]], [end_xdx_l[0] - end_xdx_r[0]]],
                                     "frame_names": ["start", "end"]}}
    traj_l, traj_r, _, _ = Repr.generate([model_l, model_r, model_c], ref_demo_idx=1)


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

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


.. _sphx_glr_download_examples_learning_ml_example_tpgmmbi_RPCtrl.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_tpgmmbi_RPCtrl.py <example_tpgmmbi_RPCtrl.py>`

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

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


.. only:: html

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

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