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:
DisciplineA 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 | BaseRegressorSettings) -- Either a regressor class name, a regressor instance or regressor settings.
data (IODataset | None) -- The 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
surrogateis aBaseRegressor; in this case, these strategies are defined with thetransformerargument of thisBaseRegressor, whose default value isBaseMLAlgo.IDENTITY, which means no transformation. In the other cases, the values of the dictionary are instances ofBaseTransformerwhile the keys can be variable names, the group name"inputs"or the group name"outputs". If a group name is specified, theBaseTransformerwill be applied to all the variables of this group. IfBaseMLAlgo.IDENTITY, do not transform the variables. TheBaseRegressor.DEFAULT_TRANSFORMERuses theMinMaxScalerstrategy for both input and output variables. This argument is ignored when the type ofsurrogateisBaseRegressorSettings.By default it is set to {'inputs': <gemseo.mlearning.transformers.scaler.min_max_scaler.MinMaxScaler object at 0x7c2f6f74c140>, 'outputs': <gemseo.mlearning.transformers.scaler.min_max_scaler.MinMaxScaler object at 0x7c2f6f74eb40>}.
disc_name (str) --
The name of the discipline. If empty, the concatenation of the short name of the surrogate algorithm and the name of the training dataset is used.
By default it is set to "".
default_input_data (dict[str, ndarray]) --
The default values of the input variables. If empty, the center of the learning input space is used.
By default it is set to {}.
input_names (Sequence[str]) --
The names of the input variables of the discipline. If empty and
surrogateis a regressor instance, all input variables of the regressor are used. If empty andsurrogateis not a regressor instance, all input variables mentioned in the training dataset are used. If the type ofsurrogateisBaseRegressorSettings,surrogate.input_namesis ignored and replaced byinput_names.By default it is set to ().
output_names (Sequence[str]) --
The names of the output variables of the discipline. If empty and
surrogateis a regressor instance, all output variables of the regressor are used. If empty andsurrogateis not a regressor instance, all output variables mentioned in the training dataset are used. If the type ofsurrogateisBaseRegressorSettings,surrogate.output_namesis ignored and replaced byoutput_names.By default it is set to ().
**settings (Any) -- The settings of the machine learning algorithm. These arguments are ignored when the type of
surrogateisBaseRegressorSettings.
- 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:
- 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:
- regression_model: BaseRegressor#
The regression model called by the surrogate discipline.