capytaine.tools.prony_decomposition module¶
Prony decomposition: tool to approximate a function as a sum of exponentials. Used in particular in the finite depth Green function.
- capytaine.tools.prony_decomposition.error_exponential_decomposition(X, F, a, lamda)[source]¶
Mean square error of the exponential decomposition defined by the coefficients a and lamda with respect to the reference values in F.
- Parameters:
X (1D array) – sampling points
F (1D array (same size as X)) – reference values
a (1D array) – coefficients of the exponentials
lamda (1D array (same size as a)) – growth rate of the exponentials
- Returns:
error – mean square error of the decomposition
- Return type:
float
- capytaine.tools.prony_decomposition.exponential_decomposition(X, F, m)[source]¶
Use Prony’s method to approximate the sampled real function F=f(X) as a sum of m exponential functions x → Σ a_i exp(lamda_i x).
- Parameters:
X (1D array) – sampling points.
F (1D array (same size as X)) – values of the function to approximate at the points of x.
m (integer) – number of exponential functions
- Returns:
a (1D array (size m)) – coefficients of the exponentials
lamda (1D array (size m)) – growth rate of the exponentials
- capytaine.tools.prony_decomposition.find_best_exponential_decomposition(f, x_min, x_max, n_exp_range, *, tol=0.0001, noise_on_domain_points_std=0.01)[source]¶
Tries to construct an exponential decompositoin of the function f on the domain [x_min, x_max] by testing the number of exponentials in n_exp_range.
- Parameters:
f (callable) – The function ℝ→ℝ to be approximated. Should support vectorized calls (that is passing a vector of inputs and get the vector of corresponding outputs)
x_min, x_max (floats) – The bounds of the domain of input in which f should be approximated
n_exp_range (iterable of ints) – The decomposition sizes that will be tested
tol (float, optional) – The target mean square error.
noise_on_domain_points_std (float, optional) – Introduces some random variability on the points where the function is evaluated. Set this parameter to zero to disable randomness.