Note
Go to the end to download the full example code
Error from surrogate discipline¶
from numpy import array
from numpy import newaxis
from numpy import sin
from gemseo.datasets.io_dataset import IODataset
from gemseo.disciplines.surrogate import SurrogateDiscipline
The quality of a SurrogateDiscipline
can easily be quantified
from its methods get_error_measure()
.
To illustrate this point, let us consider the function \(f(x)=(6x-2)^2\sin(12x-4)\) [FSK08]:
def f(x):
return (6 * x - 2) ** 2 * sin(12 * x - 4)
and try to approximate it with an RBFRegressor
.
For this, we can take these 7 learning input points
x_train = array([0.1, 0.3, 0.5, 0.6, 0.8, 0.9, 0.95])
and evaluate the model f
over this design of experiments (DOE):
y_train = f(x_train)
Then,
we create an IODataset
from these 7 learning samples:
dataset_train = IODataset()
dataset_train.add_input_group(x_train[:, newaxis], ["x"])
dataset_train.add_output_group(y_train[:, newaxis], ["y"])
and build a SurrogateDiscipline
from it:
surrogate_discipline = SurrogateDiscipline("RBFRegressor", dataset_train)
Lastly,
we can get its R2Measure
r2 = surrogate_discipline.get_error_measure("R2Measure")
and evaluate it:
r2.compute_learning_measure()
array([1.])
In presence of additional data, the generalization quality can also be approximated:
x_test = array([0.2, 0.4, 0.7])
y_test = f(x_test)
dataset_test = IODataset()
dataset_test.add_input_group(x_test[:, newaxis], ["x"])
dataset_test.add_output_group(y_test[:, newaxis], ["y"])
result = r2.compute_test_measure(dataset_test)
r2.compute_test_measure(dataset_test)
array([0.98752693])
We can conclude that
the regression model on which the SurrogateDiscipline
is based
is a very good approximation of the original function \(f\).
Total running time of the script: (0 minutes 0.031 seconds)