:py:mod:`desdeo_emo.surrogatemodels`
====================================

.. py:module:: desdeo_emo.surrogatemodels

.. autoapi-nested-parse::

   This module provides implementations of EAs which can be used for training
   surrogate models.



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

   BioGP/index.rst
   EvoDN2/index.rst
   EvoNN/index.rst
   Problem/index.rst


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

Classes
~~~~~~~

.. autoapisummary::

   desdeo_emo.surrogatemodels.BioGP
   desdeo_emo.surrogatemodels.EvoNN
   desdeo_emo.surrogatemodels.EvoDN2
   desdeo_emo.surrogatemodels.surrogateProblem




.. py:class:: BioGP(training_algorithm: Type[desdeo_emo.EAs.BaseEA.BaseEA] = PPGA, pop_size: int = 500, probability_crossover: float = 0.9, probability_mutation: float = 0.3, max_depth: int = 5, max_subtrees: int = 4, prob_terminal: float = 0.5, complexity_scalar: float = 0.5, error_lim: float = 0.001, init_method: str = 'ramped_half_and_half', model_selection_criterion: str = 'min_error', loss_function: str = 'mse', single_obj_generations: int = 10, function_set=('add', 'sub', 'mul', 'div'), terminal_set=None)

   Bases: :py:obj:`desdeo_problem.surrogatemodels.SurrogateModels.BaseRegressor`

   Helper class that provides a standard way to create an ABC using
   inheritance.

   .. py:method:: fit(X: pandas.DataFrame, y: pandas.DataFrame)


   .. py:method:: _create_individuals()


   .. py:method:: _model_performance(trees: LinearNode, X: numpy.ndarray = None, y: numpy.ndarray = None)


   .. py:method:: predict(X: numpy.ndarray)


   .. py:method:: select()


   .. py:method:: add(x, y)
      :staticmethod:


   .. py:method:: sub(x, y)
      :staticmethod:


   .. py:method:: mul(x, y)
      :staticmethod:


   .. py:method:: div(x, y)
      :staticmethod:


   .. py:method:: sqrt(x)
      :staticmethod:


   .. py:method:: log(x)
      :staticmethod:


   .. py:method:: sin(x)
      :staticmethod:


   .. py:method:: cos(x)
      :staticmethod:


   .. py:method:: tan(x)
      :staticmethod:


   .. py:method:: neg(x)
      :staticmethod:



.. py:class:: EvoNN(num_hidden_nodes: int = 20, p_omit: float = 0.2, w_low: float = -5.0, w_high: float = 5.0, activation_function: str = 'sigmoid', loss_function: str = 'mse', training_algorithm: Type[desdeo_emo.EAs.BaseEA.BaseEA] = PPGA, pop_size: int = 500, model_selection_criterion: str = 'akaike_corrected', recombination_type: str = 'evonn_xover_mutation', crossover_type: str = 'standard', mutation_type: str = 'gaussian')

   Bases: :py:obj:`desdeo_problem.surrogatemodels.SurrogateModels.BaseRegressor`

   Helper class that provides a standard way to create an ABC using
   inheritance.

   .. py:method:: fit(X: numpy.ndarray, y: numpy.ndarray)


   .. py:method:: _model_performance(first_layer: numpy.ndarray = None, X: numpy.ndarray = None, y_true: numpy.ndarray = None)


   .. py:method:: predict(X: numpy.ndarray = None, first_layer: numpy.ndarray = None, training: bool = False)


   .. py:method:: activate(x)


   .. py:method:: calculate_linear(previous_layer_output)

      Calculate the final layer using LLSQ or

      :param non_linear_layer: Output of the activation function
      :type non_linear_layer: np.ndarray

      :returns: * **linear_layer** (*np.ndarray*) -- The optimized weight matrix of the upper part of the network
                * **predicted_values** (*np.ndarray*) -- The prediction of the model
                * **training_error** (*float*) -- The model's training error


   .. py:method:: _create_individuals()


   .. py:method:: select()



.. py:class:: EvoDN2(num_subnets: int = 4, num_subsets: int = 4, max_layers: int = 4, max_nodes: int = 4, p_omit: float = 0.2, w_low: float = -5.0, w_high: float = 5.0, subsets: list = None, activation_function: str = 'sigmoid', loss_function: str = 'mse', training_algorithm: desdeo_emo.EAs.BaseEA.BaseEA = PPGA, pop_size: int = 500, model_selection_criterion: str = 'min_error', verbose: int = 0)

   Bases: :py:obj:`desdeo_problem.surrogatemodels.SurrogateModels.BaseRegressor`

   Helper class that provides a standard way to create an ABC using
   inheritance.

   .. py:method:: fit(X: numpy.ndarray, y: numpy.ndarray)


   .. py:method:: _model_performance(individuals: numpy.ndarray = None, X: numpy.ndarray = None, y_true: numpy.ndarray = None)


   .. py:method:: _feed_forward(subnets, X)


   .. py:method:: _calculate_linear(previous_layer_output)

      Calculate the final layer using LLSQ or

      :param non_linear_layer: Output of the activation function
      :type non_linear_layer: np.ndarray

      :returns: * **linear_layer** (*np.ndarray*) -- The optimized weight matrix of the upper part of the network
                * **predicted_values** (*np.ndarray*) -- The prediction of the model


   .. py:method:: activate(x)


   .. py:method:: predict(X)


   .. py:method:: select()


   .. py:method:: _create_individuals()



.. py:class:: surrogateProblem(performance_evaluator)

   Bases: :py:obj:`desdeo_problem.problem.ProblemBase`

   The base class for the problems.

   All other problem classes should be derived from this.

   .. attribute:: nadir

      Nadir values for the problem, initiated = None

      :type: np.ndarray

   .. attribute:: ideal

      Ideal values for the problem, initiated = None

      :type: np.ndarray

   .. attribute:: nadir_fitness

      Fitness values for nadir, initiated = None

      :type: np.ndarray

   .. attribute:: ideal_fitness

      Fitness values for ideal, initiated = None

      :type: np.ndarray

   .. attribute:: __n_of_objectives

      Number of objectives, initiated = 0

      :type: int

   .. attribute:: __n_of_variables

      Number of variables, initiated = 0

      :type: int

   .. attribute:: __decision_vectors

      Array of decision variable vectors,
      initiated = None

      :type: np.ndarray

   .. attribute:: __objective_vectors

      Array of objective variable vectors,
      initiated = None

      :type: np.ndarray

   .. py:method:: evaluate(model_parameters, use_surrogates=False)

      Abstract method to evaluate problem.

      Evaluates the problem using an ensemble of input vectors. Uses
      surrogate models if available. Otherwise, it uses the true evaluator.

      :param decision_vectors: An array of decision variable
      :type decision_vectors: np.ndarray
      :param input vectors.:
      :param use_surrogate: A bool to control whether to use the true, potentially
      :type use_surrogate: bool
      :param expensive function or a surrogate model to evaluate the objectives.:

      :returns:

                Dict with the following keys:
                    'objectives' (np.ndarray): The objective function values for each input
                        vector.
                    'constraints' (Union[np.ndarray, None]): The constraint values of the
                        problem corresponding each input vector.
                    'fitness' (np.ndarray): Equal to objective values if objective is to be
                        minimized. Multiplied by (-1) if objective to be maximized.
                    'uncertainity' (Union[np.ndarray, None]): The uncertainity in the
                        objective values.
      :rtype: (Dict)


   .. py:method:: evaluate_constraint_values()

      Abstract method to evaluate constraint values.

      Evaluate just the constraint function values using the attributes
      decision_vectors and objective_vectors

      .. note:: Currently not supported by ScalarMOProblem


   .. py:method:: get_variable_bounds()

      Abstract method to get variable bounds


   .. py:method:: get_objective_names()



