thin_plate_spline module¶
Thin plate spline regression.
- class gemseo_mlearning.regression.thin_plate_spline.TPSRegressor(data, transformer=None, input_names=None, output_names=None, smooth=0.0, norm='euclidean', **parameters)[source]¶
Bases:
RBFRegressor
Thin plate spline (TPS) regression.
- Parameters:
data (Dataset) – The learning dataset.
transformer (Mapping[str, TransformerType] | None) – The strategies to transform the variables. The values are instances of
Transformer
while the keys are the names of either the variables or the groups of variables, e.g."inputs"
or"outputs"
in the case of the regression algorithms. If a group is specified, theTransformer
will be applied to all the variables of this group. IfIDENTITY
, do not transform the variables.input_names (Iterable[str] | None) – The names of the input variables. If
None
, consider all the input variables of the learning dataset.output_names (Iterable[str] | None) – The names of the output variables. If
None
, consider all the output variables of the learning dataset.smooth (float) –
The degree of smoothness,
0
involving an interpolation of the learning points.By default it is set to 0.0.
norm (str | Callable[[ndarray, ndarray], float]) –
The distance metric to be used, either a distance function name known by SciPy or a function that computes the distance between two points.
By default it is set to “euclidean”.
**parameters (Any) – The description is missing.
- Raises:
ValueError – When both the variable and the group it belongs to have a transformer.
- DataFormatters¶
alias of
RegressionDataFormatters
- class Function(value)¶
Bases:
StrEnum
The radial basis functions.
- CUBIC = 'cubic'¶
- GAUSSIAN = 'gaussian'¶
- INVERSE_MULTIQUADRIC = 'inverse_multiquadric'¶
- LINEAR = 'linear'¶
- MULTIQUADRIC = 'multiquadric'¶
- QUINTIC = 'quintic'¶
- THIN_PLATE = 'thin_plate'¶
- class RBFDerivatives¶
Bases:
object
Derivatives of functions used in
RBFRegressor
.For an RBF of the form \(f(r)\), \(r\) scalar, the derivative functions are defined by \(d(f(r))/dx\), with \(r=|x|/\epsilon\). The functions are thus defined by \(df/dx = \epsilon^{-1} x/|x| f'(|x|/\epsilon)\). This convention is chosen to avoid division by \(|x|\) when the terms may be cancelled out, as \(f'(r)\) often has a term in \(r\).
- classmethod der_cubic(input_data, norm_input_data, eps)¶
Compute derivative w.r.t. \(x\) of the function \(f(r) = r^3\).
- classmethod der_gaussian(input_data, norm_input_data, eps)¶
Compute derivative of \(f(r)=\exp(-r^2)\) w.r.t. \(x\).
- classmethod der_inverse_multiquadric(input_data, norm_input_data, eps)¶
Compute derivative of \(f(r)=1/\sqrt{r^2 + 1}\) w.r.t. \(x\).
- classmethod der_linear(input_data, norm_input_data, eps)¶
Compute derivative of \(f(r)=r\) w.r.t. \(x\).
If \(x=0\), return 0 (determined up to a tolerance).
- classmethod der_multiquadric(input_data, norm_input_data, eps)¶
Compute derivative of \(f(r) = \sqrt{r^2 + 1}\) w.r.t. \(x\).
- classmethod der_quintic(input_data, norm_input_data, eps)¶
Compute derivative w.r.t. \(x\) of the function \(f(r) = r^5\).
- classmethod der_thin_plate(input_data, norm_input_data, eps)¶
Compute derivative of \(f(r) = r^2\log(r)\) w.r.t. \(x\).
If \(x=0\), return 0 (determined up to a tolerance).
- TOL = 2.220446049250313e-16¶
- learn(samples=None, fit_transformers=True)¶
Train the machine learning algorithm from the learning dataset.
- load_algo(directory)¶
Load a machine learning algorithm from a directory.
- Parameters:
directory (str | Path) – The path to the directory where the machine learning algorithm is saved.
- Return type:
None
- predict(input_data, *args, **kwargs)¶
Evaluate
func
with either array or dictionary-based input data.Firstly, the pre-processing stage converts the input data to a NumPy data array, if these data are expressed as a dictionary of NumPy data arrays.
Then, the processing evaluates the function
func
from this NumPy input data array.Lastly, the post-processing transforms the output data to a dictionary of output NumPy data array if the input data were passed as a dictionary of NumPy data arrays.
- Parameters:
algo (MLSupervisedAlgo) – The supervised learning algorithm.
input_data (DataType) – The input data.
*args (Any) – The positional arguments of the function
func
.**kwargs (Any) – The keyword arguments of the function
func
.
- Returns:
The output data with the same type as the input one.
- Return type:
- predict_jacobian(input_data, *args, **kwargs)¶
Evaluate
func
with either array or dictionary-based data.Firstly, the pre-processing stage converts the input data to a NumPy data array, if these data are expressed as a dictionary of NumPy data arrays.
Then, the processing evaluates the function
func
from this NumPy input data array.Lastly, the post-processing transforms the output data to a dictionary of output NumPy data array if the input data were passed as a dictionary of NumPy data arrays.
- Parameters:
algo (MLRegressionAlgo) – The regression algorithm.
input_data (DataType) – The input data.
*args (Any) – The positional arguments of the function
func
.**kwargs (Any) – The keyword arguments of the function
func
.
- Returns:
The output data with the same type as the input one.
- Return type:
- predict_raw(input_data)¶
Predict output data from input data.
- Parameters:
input_data (ndarray) – The input data with shape (n_samples, n_inputs).
- Returns:
The predicted output data with shape (n_samples, n_outputs).
- Return type:
ndarray
- to_pickle(directory=None, path='.', save_learning_set=False)¶
Save the machine learning algorithm.
- Parameters:
directory (str | None) – The name of the directory to save the algorithm.
path (str | Path) –
The path to parent directory where to create the directory.
By default it is set to “.”.
save_learning_set (bool) –
Whether to save the learning set or get rid of it to lighten the saved files.
By default it is set to False.
- Returns:
The path to the directory where the algorithm is saved.
- Return type:
- DEFAULT_TRANSFORMER: DefaultTransformerType = mappingproxy({'inputs': <gemseo.mlearning.transformers.scaler.min_max_scaler.MinMaxScaler object>, 'outputs': <gemseo.mlearning.transformers.scaler.min_max_scaler.MinMaxScaler object>})¶
The default transformer for the input and output data, if any.
- IDENTITY: Final[DefaultTransformerType] = mappingproxy({})¶
A transformer leaving the input and output variables as they are.
- SHORT_ALGO_NAME: ClassVar[str] = 'TPS'¶
The short name of the machine learning algorithm, often an acronym.
Typically used for composite names, e.g.
f"{algo.SHORT_ALGO_NAME}_{dataset.name}"
orf"{algo.SHORT_ALGO_NAME}_{discipline.name}"
.
- algo: Any¶
The interfaced machine learning algorithm.
- der_function: Callable[[ndarray], ndarray]¶
The derivative of the radial basis function.
- property function: str¶
The name of the kernel function.
The name is possibly different from self.parameters[‘function’], as it is mapped (scipy). Examples:
‘inverse’ -> ‘inverse_multiquadric’ ‘InverSE MULtiQuadRIC’ -> ‘inverse_multiquadric’
- property learning_samples_indices: Sequence[int]¶
The indices of the learning samples used for the training.
- resampling_results: dict[str, tuple[Resampler, list[MLAlgo], list[ndarray] | ndarray]]¶
The resampler class names bound to the resampling results.
A resampling result is formatted as
(resampler, ml_algos, predictions)
whereresampler
is aResampler
,ml_algos
is the list of the associated machine learning algorithms built during the resampling stage andpredictions
are the predictions obtained with the latter.resampling_results
stores only one resampling result per resampler type (e.g.,"CrossValidation"
,"LeaveOneOut"
and"Boostrap"
).
- transformer: dict[str, Transformer]¶
The strategies to transform the variables, if any.
The values are instances of
Transformer
while the keys are the names of either the variables or the groups of variables, e.g. “inputs” or “outputs” in the case of the regression algorithms. If a group is specified, theTransformer
will be applied to all the variables of this group.
- y_average: ndarray¶
The mean of the learning output data.