surgenet package
Submodules
surgenet.gat module
surgenet.gcn module
surgenet.swegnn module
surgenet.toy_example module
Toy Example: Extrapolation Behaviour of ReLU NN Emulators
The Gaussian PDF of x, relates x to y as y = -PDF(x). This script compares the empirical exceedance probability of an NN emulator to the true analytical exceedance probability derived from the known input PDF.
- Equation:
y = -N(mu, sigma^2)(x) and PDF of x: f_x = N(mu, sigma^2)(x)
True analytical exceedance probability P(Y > t) is derived based on X ~ N(mu, sigma^2) and Y = -f_x(X). For t >= 0, P(Y > t) = 0. For -f_x(mu) < t < 0, P(Y > t) = 2 * (1 - Phi(sigma * sqrt(-2 * ln(-t * sqrt(2*pi*sigma^2)))) / sigma)
= 2 * (1 - Phi(sqrt(-2 * ln(-t * sqrt(2*pi*sigma^2)))))
where Phi is the standard normal CDF. For t <= -f_x(mu), P(Y > t) = 1. f_x(mu) = 1 / sqrt(2*pi*sigma^2) is the maximum value of the PDF, and -f_x(mu) is the minimum value of Y.
- surgenet.toy_example.build_relu_nn_model(input_shape, n_hidden_layers, n_neurons)
Builds a Keras Sequential model with ReLU hidden layers and a linear output layer.
- surgenet.toy_example.calculate_true_exceedance(t_values, mu, sigma)
Calculates the true analytical exceedance probability P(Y > t) for Y = -N(mu, sigma^2)(X), X ~ N(mu, sigma^2).
- surgenet.toy_example.generate_data(mu, sigma, n_samples, random_seed, run_id, save_path_prefix='')
Generates input samples x from N(mu, sigma^2) and true outputs y = -PDF(x).
- Parameters:
mu (float) – Mean of the Gaussian distribution.
sigma (float) – Standard deviation of the Gaussian distribution.
n_samples (int) – Number of samples to generate.
random_seed (int) – Seed for reproducibility.
run_id (int) – Identifier for the current experimental run.
save_path_prefix (str, optional) – Prefix for saving output files. Defaults to “”.
- Returns:
- Contains:
x_samples (np.ndarray): 1D array of input samples.
y_true (np.ndarray): 1D array of true function outputs.
x_samples_nn (np.ndarray): 2D array of input samples (for NN).
y_true_nn (np.ndarray): 2D array of true outputs (for NN).
- Return type:
- surgenet.toy_example.manual_ecdf_exceedance(data_array)
Calculates empirical exceedance probability (1 - ECDF).
- surgenet.toy_example.plot_all_emulator_exceedance_curves(all_y_pred, mu, sigma, n_runs, save_path='')
Plots the true analytical exceedance curve against all empirical emulator curves.
- surgenet.toy_example.plot_emulator_fit(x_samples, y_true, y_pred, mu, sigma, n_samples, run_id, save_path='')
Plots the true function, sample data, and emulator predictions.
- surgenet.toy_example.plot_exceedance_probabilities(y_true, y_pred, mu, sigma, run_id, save_path='')
Calculates and plots empirical and true analytical exceedance probabilities.
- surgenet.toy_example.plot_initial_data(x_samples, y_true, mu, sigma, n_samples, run_id, save_path='')
Plots the generated data and the true function y = -Gaussian PDF(x).
- Parameters:
x_samples (np.ndarray) – 1D array of input samples.
y_true (np.ndarray) – 1D array of true function outputs.
mu (float) – Mean of the Gaussian PDF.
sigma (float) – Standard deviation of the Gaussian PDF.
n_samples (int) – Number of samples.
run_id (int) – Identifier for the current experimental run.
save_path (str, optional) – Path to save the plot. If empty, plot is not saved.
- surgenet.toy_example.plot_problem_setup_explanation(mu, sigma, save_path='')
Plots the true input PDF f_x(x) and the true target function y = -f_x(x) to explain the experiment setup, sharing the x-axis.
- surgenet.toy_example.predict_with_model(model, x_data, run_id, save_path_prefix='')
Generates predictions using the trained model.
- surgenet.toy_example.train_model(model, x_train, y_train, learning_rate, epochs, batch_size, validation_split, random_seed_nn, run_id, save_path_prefix='')
Compiles and trains the Keras model.