:py:mod:`desdeo_emo.utilities`
==============================

.. py:module:: desdeo_emo.utilities

.. autoapi-nested-parse::

   This module provides miscellaneous tools



Submodules
----------
.. toctree::
   :titlesonly:
   :maxdepth: 1

   IsNotebook/index.rst
   ReferenceVectors/index.rst
   model_management/index.rst
   newRV/index.rst
   non_dominated/index.rst
   plotlyanimate/index.rst
   symmetric_vectors/index.rst


Package Contents
----------------

Classes
~~~~~~~

.. autoapisummary::

   desdeo_emo.utilities.ReferenceVectors



Functions
~~~~~~~~~

.. autoapisummary::

   desdeo_emo.utilities.IsNotebook
   desdeo_emo.utilities.animate_init_
   desdeo_emo.utilities.animate_next_



.. py:function:: IsNotebook() -> bool

   Checks if the current environment is a Jupyter Notebook or a console.

   :returns: True if notebook. False if console
   :rtype: bool


.. py:function:: animate_init_(data: Union[numpy.ndarray, pandas.DataFrame, list], filename: str) -> dict

   Plot the first (or zeroth) iteration of a population.

   Intended as a frames object. Plots Scatter for 2D and 3D data.
   Plots parallel coordinate plot for higher dimensional data.

   :param data: Contains the data to be plotted. Each row is an individual's objective values.
   :type data: Union[np.ndarray, pd.DataFrame, list]
   :param filename: Contains the name of the file to which the plot is saved.
   :type filename: str

   :returns: Plotly figure object
   :rtype: dict


.. py:function:: animate_next_(data: Union[numpy.ndarray, pandas.DataFrame, list], figure: dict, filename: str, generation: int = None) -> dict

   Plot the next set of individuals in an animation.

   Plots scatter for 2D and 3D data, parallel coordinate plot for 4D and up.

   :param data: The objective values to be plotted
   :type data: Union[np.ndarray, pd.DataFrame, list]
   :param figure: Plotly figure object compatible dict
   :type figure: dict
   :param filename: Name of the file to which the plot is saved
   :type filename: str
   :param generation: Iteration Number
   :type generation: int

   :returns: Plotly Figure Object
   :rtype: dict


.. py:class:: ReferenceVectors(lattice_resolution: int = None, number_of_vectors: int = None, number_of_objectives: int = None, creation_type: str = 'Uniform', vector_type: str = 'Spherical', ref_point: list = None)

   Class object for reference vectors.

   .. py:method:: _create(creation_type: str = 'Uniform')

      Create the reference vectors.

      :param creation_type: 'Uniform' creates the reference vectors uniformly using simplex lattice
                            design. 'Focused' creates reference vectors symmetrically around a central
                            reference vector. By default 'Uniform'.
      :type creation_type: str, optional


   .. py:method:: normalize()

      Normalize the reference vectors to a unit hypersphere.


   .. py:method:: neighbouring_angles() -> numpy.ndarray

      Calculate neighbouring angles for normalization.


   .. py:method:: adapt(fitness: numpy.ndarray)

      Adapt reference vectors. Then normalize.

      :param fitness:
      :type fitness: np.ndarray


   .. py:method:: interactive_adapt_1(z: numpy.ndarray, n_solutions: int, translation_param: float = 0.2) -> None

      Adapt reference vectors using the information about prefererred solution(s) selected by the Decision maker.

      :param z: Preferred solution(s).
      :type z: np.ndarray
      :param n_solutions: Number of solutions in total.
      :type n_solutions: int
      :param translation_param: Parameter determining how close the reference vectors are to the central vector
      :type translation_param: float
      :param \*\*v** defined by using the selected solution:
      :type \*\*v** defined by using the selected solution: s

      Returns:



   .. py:method:: interactive_adapt_2(z: numpy.ndarray, n_solutions: int, predefined_distance: float = 0.2) -> None

      Adapt reference vectors by using the information about non-preferred solution(s) selected by the Decision maker.
      After the Decision maker has specified non-preferred solution(s), Euclidian distance between normalized solution
      vector(s) and each of the reference vectors are calculated. Those reference vectors that are **closer** than a
      predefined distance are either **removed** or **re-positioned** somewhere else.

      .. note::

         At the moment, only the **removal** of reference vectors is supported. Repositioning of the reference
         vectors is **not** supported.

      .. note::

         In case the Decision maker specifies multiple non-preferred solutions, the reference vector(s) for which the
         distance to **any** of the non-preferred solutions is less than predefined distance are removed.

      .. note::

         Future developer should implement a way for a user to say: "Remove some percentage of
         objecive space/reference vectors" rather than giving a predefined distance value.

      :param z: Non-preferred solution(s).
      :type z: np.ndarray
      :param n_solutions: Number of solutions in total.
      :type n_solutions: int
      :param predefined_distance: The reference vectors that are closer than this distance are either removed or
      :type predefined_distance: float
      :param re-positioned somewhere else.:
      :param Default value: 0.2

      Returns:



   .. py:method:: iteractive_adapt_3(ref_point, translation_param=0.2)

      Adapt reference vectors linearly towards a reference point. Then normalize.

      The details can be found in the following paper: Hakanen, Jussi &
      Chugh, Tinkle & Sindhya, Karthik & Jin, Yaochu & Miettinen, Kaisa.
      (2016). Connections of Reference Vectors and Different Types of
      Preference Information in Interactive Multiobjective Evolutionary
      Algorithms.

      :param ref_point:
      :param translation_param: (Default value = 0.2)


   .. py:method:: interactive_adapt_4(preferred_ranges: numpy.ndarray) -> None

      Adapt reference vectors by using the information about the Decision maker's preferred range for each of the
      objective. Using these ranges, Latin hypercube sampling is applied to generate m number of samples between
      within these ranges, where m is the number of reference vectors. Normalized vectors constructed of these samples
      are then set as new reference vectors.

      :param preferred_ranges: Preferred lower and upper bound for each of the objective function values.
      :type preferred_ranges: np.ndarray

      Returns:



   .. py:method:: slow_interactive_adapt(ref_point)

      Basically a wrapper around rotate_toward. Slowly rotate ref vectors toward
      ref_point. Return a boolean value to tell if the ref_point has been reached.

      :param ref_point: The reference vectors will slowly move towards the ref_point.
      :type ref_point: list or np.ndarray

      :returns: True if ref_point has been reached. False otherwise.
      :rtype: boolean


   .. py:method:: add_edge_vectors()

      Add edge vectors to the list of reference vectors.

      Used to cover the entire orthant when preference information is
      provided.




