Analyzer

To assess the accuracy of your solver’s predictions, use the analyze function. This function compares the predicted source function with the input source function and the predicted boundary condition with the true boundary condition. If the numeric and predicted solution are provided, they are compared too.

The function calculates the following metrices and returns those as dictionary:

  • Source function 'f'
    • Mean Square Error 'MSE'

    • Root Mean Square Error 'RMSE'

    • Mean Absolute Error 'MAE'

    • Relative Mean Absolute Error 'rMAE'

    • Structural Similarity Index Measure 'SSIM'

    • Peak Signal-to-Noise Ratio 'PSNR'

    • Coefficient of Determination 'R2'

  • Boundary Condition 'bc'
    • 'MSE'

    • 'RMSE'

    • 'MAE'

    • 'rMAE'

  • Solution 'u'
    • 'MSE'

    • 'RMSE'

    • 'MAE'

    • 'rMAE'

    • 'SSIM'

    • 'PSNR'

    • 'R2'

Usage of analyze function is as follows:

from fast_poisson_solver import Solver, analyze

solver = Solver()
solver.precompute(x_pde, y_pde, x_bc, y_bc)
u_ml, u_ml_pde, u_ml_bc, f_ml, t_ml = solver.solve(f, u_bc)

error_metrics = analyze(f_ml, f, u_ml_bc, u_bc)

The default behavior is to normalize the input arrays before calculating the error metrics, which can be disabled by setting normalize=False.

error_metrics = analyze(f_pred, f, u_bc_pred, u_bc, normalize=False)

If the solution should also be evaluated, the numerical solution has to be calculted first.

from fast_poisson_solver import Solver, numeric_solve, analyze

solver = Solver()
solver.precompute(x_pde, y_pde, x_bc, y_bc)
u_ml, u_ml_pde, u_ml_bc, f_ml, t_ml = solver.solve(f, u_bc)
u_num = numeric_solve(f, x_pde, y_pde, u_bc, x_bc, y_bc)

error_metrics = analyze(f_ml, f, u_ml_bc, u_bc)

The output is a dictionary, with separate sub-dictionaries for the source term ('f'), solution ('u'), and boundary condition ('bc'), each containing the respective error metrics.

For more on analyze and its error metrics, see the detailed documentation below.

fast_poisson_solver.analyze(f_pred, f, u_bc_pred, u_bc, u_pred=None, u_num=None, normalize=True)

Analyze the performance of a Poisson equation solver by comparing predictions with true or numerical values.

This function calculates various error metrics including Mean Squared Error (MSE), Root Mean Squared Error (RMSE), Mean Absolute Error (MAE), Relative Mean Absolute Error (rMSE), Structural Similarity Index (SSIM), Peak Signal-to-Noise Ratio (PSNR), and R-Squared (R2) for each of the source term (f), solution (u), and boundary condition (bc) predictions.

The predicted source term ‘f_pred’ and boundary condition ‘u_bc_pred’ are compared with the true source term ‘f’ and true boundary condition ‘u_bc’. If provided, the predicted solution ‘u_pred’ is compared with the numerical solution ‘u_num’.

Parameters:
f_predarray-like

The predicted source term by the solver. Can be a list, numpy array or PyTorch tensor.

farray-like

The true source term of the Poisson equation. Can be a list, numpy array or PyTorch tensor.

u_bc_predarray-like

The predicted solution for the boundary condition. Can be a list, numpy array or PyTorch tensor.

u_bcarray-like

The true boundary condition. Can be a list, numpy array or PyTorch tensor.

u_predarray-like, optional

The predicted solution of the Poisson equation. Can be a list, numpy array or PyTorch tensor (default is None).

u_numarray-like, optional

The numerical solution of the Poisson equation. Can be a list, numpy array or PyTorch tensor (default is None).

normalizebool, optional

If True, normalize the input arrays before calculating the error metrics (default is True).

Returns:
dict

A dictionary containing the calculated error metrics for the corresponding part of the Poisson equation.

‘u’

A dictionary containing the error metrics for the predicted solution ‘u_pred’ compared to the numerical solution ‘u_num’ (only if ‘u_num’ and ‘u_pred’ are provided).

‘f’

A dictionary containing the error metrics for the predicted source term ‘f_pred’ compared to the true source term ‘f’.

‘bc’

A dictionary containing the error metrics for the predicted boundary condition ‘u_bc_pred’ compared to the true boundary condition ‘u_bc’.