Peak Models Module
Analytical peak functions and polynomial models using PyTorch.
This module defines several 1D peak profiles (e.g., Gaussian, Lorentzian, Pseudo-Voigt) and polynomial bases commonly used in signal processing, spectroscopy, and diffraction analysis. These functions are differentiable and compatible with PyTorch-based optimization and learning workflows.
Author: Antony Vamvakeros
- nDTomo.pytorch.peak_models_torch.chebyshev_polynomial(x, n_terms)[source]
Generate a Chebyshev polynomial of the first kind Tₙ(x), evaluated using recurrence relations.
- The Chebyshev polynomials of the first kind are defined by:
T₀(x) = 1 T₁(x) = x Tₙ₊₁(x) = 2x·Tₙ(x) - Tₙ₋₁(x)
- Parameters:
x (torch.Tensor) – Input tensor of x values.
n_terms (int) – Number of terms or the target degree of the polynomial.
- Returns:
The Chebyshev polynomial of the first kind Tₙ(x) evaluated at x.
- Return type:
torch.Tensor
Notes
This implementation returns the dot product of the coefficient vector and the final recurrence value. It does not return the full basis expansion.
- nDTomo.pytorch.peak_models_torch.doniach_sunjic_peak(x, amplitude, x0, sigma, b)[source]
Generate a Doniach-Šunjić peak with asymmetric broadening.
- nDTomo.pytorch.peak_models_torch.exponential_power_peak(x, amplitude, x0, sigma, alpha, beta)[source]
Generate a skewed peak based on an exponential power law.
- Parameters:
- Returns:
Peak evaluated at x using the exponential power law form.
- Return type:
torch.Tensor
- nDTomo.pytorch.peak_models_torch.gaussian_peak(x, amplitude, mean, std)[source]
Generate a Gaussian peak.
- nDTomo.pytorch.peak_models_torch.lorentzian_peak(x, amplitude, x0, gamma)[source]
Generate a Lorentzian peak.
- nDTomo.pytorch.peak_models_torch.pearson7_peak(x, amplitude, x0, sigma, m, a, b, c)[source]
Generate a Pearson VII-type peak with flexible tailing.
- Parameters:
- Returns:
Pearson VII profile evaluated at x.
- Return type:
torch.Tensor
- nDTomo.pytorch.peak_models_torch.polynomial(x, coefficients)[source]
Evaluate a 1D polynomial at the given x values using provided coefficients.
- The polynomial is of the form:
y = c₀ + c₁·x + c₂·x² + … + cₙ·xⁿ
- Parameters:
x (torch.Tensor) – Input tensor of x values at which to evaluate the polynomial.
coefficients (list or torch.Tensor) – Sequence of polynomial coefficients [c₀, c₁, …, cₙ].
- Returns:
Evaluated polynomial y(x).
- Return type:
torch.Tensor
- nDTomo.pytorch.peak_models_torch.pseudo_voigt_peak(x, amplitude, x0, sigma, fraction)[source]
Generate a symmetric Pseudo-Voigt peak composed of a linear combination of Gaussian and Lorentzian components with equal width.
- Parameters:
x (torch.Tensor) – Input axis values.
amplitude (float or torch.Tensor) – Peak amplitude.
x0 (float or torch.Tensor) – Peak center position.
sigma (float or torch.Tensor) – Common width used for both Gaussian and Lorentzian components.
fraction (float) – Mixing ratio of the Gaussian component. Must be in [0, 1]. The Lorentzian component weight is (1 - fraction).
- Returns:
Pseudo-Voigt peak evaluated at x.
- Return type:
torch.Tensor
- nDTomo.pytorch.peak_models_torch.pseudo_voigt_peak_t(x, A, xo, st, fraction, sl, i)[source]
Time-efficient version of a Pseudo-Voigt peak with a linear background.
- Parameters:
x (torch.Tensor) – Input axis values.
A (float) – Amplitude of the peak.
xo (float) – Center position.
st (float) – Width of the Gaussian/Lorentzian components.
fraction (float) – Gaussian fraction; (1 - fraction) is Lorentzian fraction.
sl (float) – Slope of the linear background.
i (float) – Intercept of the linear background.
- Returns:
Composite Pseudo-Voigt + linear background evaluated at x.
- Return type:
torch.Tensor
- nDTomo.pytorch.peak_models_torch.split_pearson_peak(x, amplitude, x0, sigma1, sigma2, m1, m2, a1, a2, b1, b2, c1, c2)[source]
Generate a two-component asymmetric Pearson peak.
- Parameters:
x (torch.Tensor) – Input axis values.
amplitude (float) – Peak amplitude.
x0 (float) – Peak center.
sigma1 (float) – Widths for left and right peak components.
sigma2 (float) – Widths for left and right peak components.
m1 (float) – Tail parameters for left and right components.
m2 (float) – Tail parameters for left and right components.
a1 (float) – Tail parameters for left and right components.
a2 (float) – Tail parameters for left and right components.
b1 (float) – Tail parameters for left and right components.
b2 (float) – Tail parameters for left and right components.
c1 (float) – Tail parameters for left and right components.
c2 (float) – Tail parameters for left and right components.
- Returns:
Asymmetric Pearson profile evaluated at x.
- Return type:
torch.Tensor