Utils¶
- ife_surrogate.utils.train_test_split(X, Y, f=Array([], shape=(0,), dtype=float32), dense=False, *, split=(0.8, 0.2, 0.0), key)¶
Splits the dataset into training, testing, and validation sets.
- Parameters:
X (Array) – Input feature array.
Y (Array) – Target value array.
f (Array) – Additional feature array.
dense (bool, optional) – If True, the input features are repeated and concatenated with
f. Default is False.split (Tuple[float, float, float], optional) – Ratios for splitting the data into (train, test, validation). Default is
(0.8, 0.2, 0.0).key (Key) – Random key for shuffling the data.
- Returns:
A tuple of three pairs:
(X_train, Y_train),(X_test, Y_test), and(X_val, Y_val).- Return type:
Tuple[Tuple[Array, Array], Tuple[Array, Array], Tuple[Array, Array]]
- ife_surrogate.utils.nrms(test_y, prediction)¶
Calculates the Normalized Root Mean Square Error.
\[\text{NRMS} = \frac{\sqrt{\frac{1}{N}\sum_{i=1}^{N} (y_i - \hat{y}_i)^2}}{\max(y) - \min(y)}\]- Parameters:
test_y (ndarray) – The true output values of shape (n, p).
prediction (ndarray) – The predicted output values of shape (n, p).
- Returns:
The Root Mean Square Percentage Error.
- Return type:
float
- ife_surrogate.utils.rmse(test_y, prediction)¶
Calculates the Root Mean Square Error.
\[RMSPE = \sqrt{\frac{1}{n} \sum_{i=1}^{n} \left( \frac{y_i - \hat{y}_i}{y_i} \right)^2}\]- Parameters:
test_y (ndarray) – The true output values of shape (n, p).
prediction (ndarray) – The predicted output values of shape (n, p).
- Returns:
The Root Mean Square Error.
- Return type:
Array
- class ife_surrogate.utils.Visualizer¶
Bases:
objectContainer class for useful plotting functions. Can also export figures to a PDF-File.
- save_to_page(figures, file_name='output.pdf')¶
Function to export matplotlib figures to PDF
- Parameters:
figures (iterable[matplotlib.pyplot.figure]) – List of matplotlib figures, each figure adds a new page to the output PDF Also allows single figure.
file_name (str, optional) – Path and name of the PDF Defaults to “output.pdf”.
- plot_bounded_error(x, y, error, function_color='blue', error_color='lightblue', highlight_threshold=0, highlight_color='red')¶
Default bounded error plot.
- Parameters:
x (_type_) – _description_
y (_type_) – _description_
error (_type_) – _description_
- Returns:
figure can be adjusted afterwards.
- Return type:
matplotlib.pyplot.figure
- plot_sns()¶
- plot_testset(frequency, test_y, prediction, var_pred=None, grid=(4, 4), figsize=(15, 15), log_scale=True, error='nrms')¶
Plot predicted vs true curves for a test set.
Each subplot shows the true and predicted frequency response for one test sample. If predictive variance is given, 95% confidence intervals (±2 std) are shown.
- Parameters:
frequency (Array) – 1D array of frequency values of shape (p,).
test_y (Array) – True output values of shape (n_test, p).
prediction (Array) – Predicted output values of shape (n_test, p).
var_pred (Array, optional) – Predictive variances of shape (n_test, p). If provided, uncertainty bands are shown.
grid (tuple) – Grid size as (rows, cols) to arrange the subplots.
figsize (tuple) – Size of the overall figure.
log_scale (bool) – If True, x-axis is displayed in logarithmic scale.
error (str) – Type of error metric to show in the title of each plot. Currently only supports “rmse” and “nrms.
- Returns:
The generated matplotlib figure.
- Return type:
matplotlib.figure.Figure
- static quickplot(data_dict, fig_height=2, fig_width=7)¶
- Parameters:
data_dict (dict)
- ife_surrogate.utils.apply_fsv(Y_test, Y_pred, score_strings=False)¶
Batch FSV: apply across multiple test/pred pairs. Calculates the FSV parameters as described in [1]
[1] A. P. Duffy, A. J. M. Martin, A. Orlandi, G. Antonini, T. M. Benson, and M. S. Woolfson, “Feature Selective Validation (FSV) for Validation of Computational Electromagnetics (CEM). Part I—The FSV Method,” IEEE Trans. Electromagnetic Compatibility, vol. 48, no. 3, pp. 449-458, Aug. 2006, doi:10.1109/TEMC.2006.879358
- Parameters:
Y_test (ndarray) – array of shape (M, N) or list of arrays
Y_pred (ndarray) – same shape as Y_test
score_string – returns the labels instead of the numerical scores
score_strings (bool)
- Returns:
arrays of length M
- Return type:
ADM_list, FDM_list, GDM_list
- ife_surrogate.utils.zero_mean_unit_var_axis0(Y, eps=1e-08)¶
Standardize Y along axis 0 (samples) so each feature/output has zero mean and unit variance.
- Parameters:
Y (array, shape (N, P)) – Input data (N samples, P outputs).
eps (float) – Small constant to avoid division by zero.
- Returns:
Y_scaled (array, shape (N, P)) – Standardized data.
mean (array, shape (1, P)) – Mean of each output across samples.
std (array, shape (1, P)) – Std of each output across samples.