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

.. py:module:: desdeo_emo.utilities.ReferenceVectors


Module Contents
---------------

Classes
~~~~~~~

.. autoapisummary::

   desdeo_emo.utilities.ReferenceVectors.ReferenceVectors



Functions
~~~~~~~~~

.. autoapisummary::

   desdeo_emo.utilities.ReferenceVectors.normalize
   desdeo_emo.utilities.ReferenceVectors.shear
   desdeo_emo.utilities.ReferenceVectors.rotate
   desdeo_emo.utilities.ReferenceVectors.householder
   desdeo_emo.utilities.ReferenceVectors.rotate_toward



.. py:function:: normalize(vectors)

   Normalize a set of vectors.

   The length of the returned vectors will be unity.

   :param vectors: Set of vectors of any length, except zero.
   :type vectors: np.ndarray


.. py:function:: shear(vectors, degrees: float = 5)

   Shear a set of vectors lying on the plane z=0 towards the z-axis, such that the
   resulting vectors 'degrees' angle away from the z axis.

   z is the last element of the vector, and has to be equal to zero.

   :param vectors: The final element of each vector should be zero.
   :type vectors: numpy.ndarray
   :param degrees: The angle that the resultant vectors make with the z axis. Unit is radians.
                   (the default is 5)
   :type degrees: float, optional


.. py:function:: rotate(initial_vector, rotated_vector, other_vectors)

   Calculate the rotation matrix that rotates the initial_vector to the
   rotated_vector. Apply that rotation on other_vectors and return.
   Uses Householder reflections twice to achieve this.


.. py:function:: householder(vector)

   Return reflection matrix via householder transformation.


.. py:function:: rotate_toward(initial_vector, final_vector, other_vectors, degrees: float = 5)

   Rotate other_vectors (with the centre at initial_vector) towards final_vector
   by an angle degrees.

   :param initial_vector: Centre of the vectors to be rotated.
   :type initial_vector: np.ndarray
   :param final_vector: The final position of the center of other_vectors.
   :type final_vector: np.ndarray
   :param other_vectors: The array of vectors to be rotated
   :type other_vectors: np.ndarray
   :param degrees: The amount of rotation (the default is 5)
   :type degrees: float, optional

   :returns: * **rotated_vectors** (*np.ndarray*) -- The rotated vectors
             * **reached** (*bool*) -- True if final_vector has been reached


.. 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.




