gemseo.disciplines.surrogate module#

Surrogate discipline.

class SurrogateDiscipline(surrogate, data=None, transformer=mappingproxy({'inputs': <gemseo.mlearning.transformers.scaler.min_max_scaler.MinMaxScaler object>, 'outputs': <gemseo.mlearning.transformers.scaler.min_max_scaler.MinMaxScaler object>}), disc_name='', default_input_data=mappingproxy({}), input_names=(), output_names=(), **settings)[source]#

Bases: Discipline

A discipline wrapping a regression model built from a dataset.

Examples

>>> import numpy as np
>>> from gemseo.datasets.io_dataset import IODataset
>>> from gemseo.disciplines.surrogate import SurrogateDiscipline
>>>
>>> # Create an input-output dataset.
>>> dataset = IODataset()
>>> dataset.add_input_variable("x", np.array([[1.0], [2.0], [3.0]]))
>>> dataset.add_output_variable("y", np.array([[3.0], [5.0], [6.0]]))
>>>
>>> # Build a surrogate discipline relying on a linear regression model.
>>> surrogate_discipline = SurrogateDiscipline("LinearRegressor", dataset)
>>>
>>> # Assess its quality with the R2 measure.
>>> r2 = surrogate_discipline.get_error_measure("R2Measure")
>>> learning_r2 = r2.compute_learning_measure()
>>>
>>> # Execute the surrogate discipline, with default or custom input values.
>>> surrogate_discipline.execute()
>>> surrogate_discipline.execute({"x": np.array([1.5])})

Initialize self. See help(type(self)) for accurate signature.

Parameters:
  • surrogate (str | BaseRegressor) -- Either the name of a subclass of BaseRegressor or an instance of this subclass.

  • data (IODataset | None) -- The training dataset to train the regression model. If None, the regression model is supposed to be trained.

  • transformer (TransformerType) --

    The strategies to transform the variables. This argument is ignored when surrogate is a BaseRegressor; in this case, these strategies are defined with the transformer argument of this BaseRegressor, whose default value is BaseMLAlgo.IDENTITY, which means no transformation. In the other cases, the values of the dictionary are instances of BaseTransformer while the keys can be variable names, the group name "inputs" or the group name "outputs". If a group name is specified, the BaseTransformer will be applied to all the variables of this group. If BaseMLAlgo.IDENTITY, do not transform the variables. The BaseRegressor.DEFAULT_TRANSFORMER uses the MinMaxScaler strategy for both input and output variables.

    By default it is set to {'inputs': <gemseo.mlearning.transformers.scaler.min_max_scaler.MinMaxScaler object at 0x7f95bbc65d60>, 'outputs': <gemseo.mlearning.transformers.scaler.min_max_scaler.MinMaxScaler object at 0x7f95bbc66780>}.

  • disc_name (str) --

    The name to be given to the surrogate discipline. If empty, the name will be f"{surrogate.SHORT_ALGO_NAME}_{data.name}.

    By default it is set to "".

  • default_input_data (dict[str, ndarray]) --

    The default values of the input variables. If empty, use the center of the learning input space.

    By default it is set to {}.

  • input_names (Iterable[str]) --

    The names of the input variables. If empty, consider all input variables mentioned in the training dataset.

    By default it is set to ().

  • output_names (Iterable[str]) --

    The names of the output variables. If empty, consider all input variables mentioned in the training dataset.

    By default it is set to ().

  • **settings (MLAlgoSettingsType) -- The settings of the machine learning algorithm.

Raises:

ValueError -- If the training dataset is missing whilst the regression model is not trained.

get_error_measure(measure_name, **measure_options)[source]#

Return an error measure.

Parameters:
  • measure_name (str) -- The class name of the error measure.

  • **measure_options (Any) -- The options of the error measure.

Returns:

The error measure.

Return type:

BaseRegressorQuality

get_quality_viewer()[source]#

Return a viewer of the quality of the underlying regressor.

Returns:

A viewer of the quality of the underlying regressor.

Return type:

MLRegressorQualityViewer

regression_model: BaseRegressor#

The regression model called by the surrogate discipline.