symop.modes.envelopes.gaussian_mixture¶
Gaussian mixtures of closed-form Gaussian time-domain envelopes.
This module defines
GaussianMixtureEnvelope,
a normalized mode descriptor formed as a linear combination of normalized
closed-form Gaussian components
(GaussianEnvelope).
Motivation¶
A single Gaussian envelope is often too restrictive to represent practical mode shapes (e.g., mildly asymmetric pulses, superpositions of separated lobes, or simple approximations to filtered / shaped wavepackets). A mixture of Gaussians provides a simple, numerically stable, and differentiable representation that still supports analytic overlaps when all components are in the same closed-form family.
Key properties¶
Each component is a normalized
GaussianEnvelopein the"gaussian_closed"formalism.The mixture itself is normalized such that \(\langle\zeta,\zeta\rangle=1\) (computed from closed-form pairwise overlaps).
Overlaps with another closed-form Gaussian envelope (single Gaussian or another mixture) are computed in closed form via finite sums.
Time and frequency evaluation are computed by linear superposition of the component evaluations.
Performance notes¶
Normalization and overlap between two mixtures both require pairwise overlaps. If the mixture has \(K\) components, normalization is \(O(K^2)\) and mixture-vs-mixture overlap is \(O(K^2)\). For small K this is typically negligible; for large K consider caching Gram matrices keyed by component signatures.
Fourier convention¶
This module follows the same Fourier convention as GaussianEnvelope:
The absolute overall scale of freq_eval() is intended to be consistent
within the package, but should not be treated as a universal physical
normalization unless the convention is standardized across all backends.
Examples
See examples/gaussian_mixture_overlap.py for:
- plotting the time-domain envelope of a mixture,
- overlap magnitude vs delay,
- and the spectral intensity profile.
Classes
|
Diagnostics for a function-to-mixture fit. |
|
Linear combination of normalized closed-form Gaussian envelopes. |
- class FitReport(tmin: float, tmax: float, n_samples: int, l2_rel: float, linf_rel: float, k_used: int) None¶
Bases:
objectDiagnostics for a function-to-mixture fit.
- tmin, tmax
Fit interval.
- n_samples¶
Number of samples used in the fit.
- l2_rel¶
Relative L2 error on the fit grid: ||f - f_hat||_2 / ||f||_2.
- linf_rel¶
Relative max error on the fit grid: max|f - f_hat| / max|f|.
- k_used¶
Number of Gaussian components used.
Notes
Errors are computed on the sampling grid used during fitting and are therefore fit-window dependent.
- class GaussianMixtureEnvelope(components: tuple[GaussianEnvelope, ...], weights: ndarray[tuple[Any, ...], dtype[complexfloating[Any, Any]]], report: FitReport | None = None) None¶
Bases:
BaseEnvelopeLinear combination of normalized closed-form Gaussian envelopes.
A Gaussian mixture envelope is defined as a finite superposition
\[\zeta(t) = \sum_{k=1}^{K} c_k\,g_k(t),\]where each \(g_k(t)\) is a normalized
GaussianEnvelope(same closed-form Gaussian family), and the complex weights \(c_k\) are stored inweights.Normalization¶
This class enforces that the mixture is a mode descriptor:
\[\langle \zeta, \zeta \rangle = 1.\]Since \(\zeta\) is a superposition, its norm depends on pairwise overlaps:
\[\|\zeta\|^2 = \sum_{i=1}^{K}\sum_{j=1}^{K} \overline{c_i}\,c_j\,\langle g_i, g_j\rangle.\]In
__post_init__(), the provided weights are rescaled by\[c_k \leftarrow \frac{c_k}{\sqrt{\|\zeta\|^2}}\]using closed-form overlaps \(\langle g_i, g_j\rangle\).
Overlaps¶
If the other envelope is in the same closed-form Gaussian family, overlaps are computed without numerical quadrature.
Mixture vs single Gaussian:
\[\langle \zeta, h\rangle = \sum_{i=1}^{K} \overline{c_i}\,\langle g_i, h\rangle.\]Mixture vs mixture:
\[\left\langle \sum_i c_i g_i,\ \sum_j d_j h_j \right\rangle = \sum_{i=1}^{K}\sum_{j=1}^{L} \overline{c_i}\,d_j\,\langle g_i, h_j\rangle.\]Here \(\langle g_i, h_j\rangle\) is evaluated by
GaussianEnvelope.overlap_gaussian_closed().Time and frequency evaluation¶
Evaluation is performed by linear superposition:
\[\zeta(t) = \sum_k c_k g_k(t), \qquad Z(\omega) = \sum_k c_k G_k(\omega).\]Heuristics¶
center_and_scale()returns a plotting/overlap heuristic. The center is a power-weighted average of component centers (\(|c_k|^2\) weights) and the scale is the maximum component \(\sigma_t\) (conservative window choice).- type components:
- param components:
Tuple of component
GaussianEnvelopeobjects. Must be non-empty.- type weights:
- param weights:
Complex 1D numpy array of shape
(K,). Length must matchlen(components). The array is copied/coerced to complex and then rescaled in__post_init__()to enforce unit norm.- type report:
- param report:
Optional
FitReportdescribing how the mixture was obtained (for example from a fit of a target function on a chosen time interval).- raises ValueError:
If
weightsis not 1D, if lengths mismatch, if components are empty, or if the computed norm is non-positive / non-finite.
- _abc_impl = <_abc._abc_data object>¶
- static _norm2_closed(weights: ndarray[tuple[Any, ...], dtype[complexfloating[Any, Any]]], comps: tuple[GaussianEnvelope, ...]) float¶
Compute the squared norm of a Gaussian mixture in closed form.
For a mixture
\[\zeta(t) = \sum_{k=1}^{K} c_k g_k(t),\]the squared norm is
\[\|\zeta\|^2 = \sum_{i=1}^{K}\sum_{j=1}^{K} \overline{c_i}\,c_j\,\langle g_i, g_j\rangle.\]This helper evaluates that quantity using analytic pairwise overlaps between the component
GaussianEnvelopeobjects.- Parameters:
- Returns:
Real-valued squared norm of the mixture.
- Return type:
Notes
The return value is the real part of the accumulated overlap sum. For physically consistent inputs this should be non-negative, up to small numerical error.
- approx_signature(*, decimals: int = 12, ignore_global_phase: bool = False) tuple[object, ...]¶
Approximate signature with rounded floating parameters.
- components: tuple[GaussianEnvelope, ...]¶
- delayed(dt: float) GaussianMixtureEnvelope¶
Return a copy delayed by dt.
- Parameters:
dt (
float) – Time shift to add to \(\tau\).- Returns:
Delayed envelope.
- Return type:
- freq_eval(w: ndarray[tuple[Any, ...], dtype[float64]]) ndarray[tuple[Any, ...], dtype[complex128]] | ndarray[tuple[Any, ...], dtype[float64]]¶
Evaluate the frequency-domain spectrum \(Z(\omega)\).
This returns a GaussianMixture spectrum consistent with the time-domain definition used in
time_eval(), up to an overall real scale factor.
- classmethod from_callable(func: Callable[[ndarray[tuple[Any, ...], dtype[float64]]], ndarray[tuple[Any, ...], dtype[complex128]] | ndarray[tuple[Any, ...], dtype[float64]]], *, tmin: float, tmax: float, k: int, omega0: float = 0.0, n_samples: int = 2000, sigma: float | None = None) GaussianMixtureEnvelope¶
Fit a Gaussian-mixture envelope to a time-domain target field.
This constructor fits a complex-valued time-domain amplitude \(f(t)\) on a uniform grid over
[tmin, tmax]using a linear combination ofGaussianEnvelopebasis functions:\[f(t) \approx \sum_{j=1}^{K} c_j g_j(t).\]The component centers are chosen uniformly across the fit interval, all components share the same carrier frequency
omega0, and a common widthsigmais used. Ifsigmais not provided, a simple window-based heuristic is used.- Parameters:
func (
Callable[[ndarray[tuple[Any,...],dtype[double]]],ndarray[tuple[Any,...],dtype[cdouble]] |ndarray[tuple[Any,...],dtype[double]]]) – Target time-domain complex field.tmin (
float) – Fit interval.tmax (
float) – Fit interval.k (
int) – Number of Gaussian basis components.omega0 (
float) – Shared carrier angular frequency for the basis components.n_samples (
int) – Number of uniform time samples used for the fit.sigma (
float|None) – Common temporal width of the basis Gaussians. If omitted, a heuristic based on the fit interval andkis used.
- Returns:
Normalized Gaussian mixture with an attached fit report.
- Return type:
- Raises:
ValueError – If the fit configuration is invalid.
- classmethod from_lorentzian(*, gamma: float, tau: float = 0.0, omega0: float = 0.0, phi0: float = 0.0, k: int = 8, n_samples: int = 2000, window_multiple: float = 8.0) GaussianMixtureEnvelope¶
Construct a Gaussian mixture approximation to a Lorentzian pulse.
This convenience constructor fits a Gaussian mixture to the time-domain target field
\[f(t) = e^{i\phi_0} \frac{1}{1 + \left(\frac{t-\tau}{\gamma}\right)^2} e^{i\omega_0 (t-\tau)}.\]The fit is performed on a symmetric time window around \(\tau\):
\[[\,\tau - m\gamma,\ \tau + m\gamma\,],\]where \(m\) is
window_multiple.- Parameters:
gamma (
float) – Lorentzian width parameter. Must be positive.tau (
float) – Center time of the pulse.omega0 (
float) – Carrier angular frequency.phi0 (
float) – Global phase offset.k (
int) – Number of Gaussian basis components used in the fit.n_samples (
int) – Number of time samples used for the fitting procedure.window_multiple (
float) – Half-window size expressed in multiples ofgamma.
- Returns:
Normalized Gaussian mixture approximating the Lorentzian target, with an attached fit report.
- Return type:
- Raises:
ValueError – If
gammais not positive.
Notes
This is a numerical approximation utility built on top of
from_callable(). The resulting mixture is normalized as a mode descriptor after fitting.
- overlap_gaussian_closed(other: SupportsGaussianClosedOverlap) complex¶
Compute the closed-form overlap with another Gaussian-closed envelope.
Supported cases are:
Mixture vs single Gaussian:
\[\langle \zeta, h\rangle = \sum_i \overline{c_i}\,\langle g_i, h\rangle.\]Mixture vs mixture:
\[\left\langle \sum_i c_i g_i,\ \sum_j d_j h_j \right\rangle = \sum_i \sum_j \overline{c_i}\,d_j\,\langle g_i, h_j\rangle.\]In both cases, pairwise overlaps are evaluated analytically using
GaussianEnvelope.overlap_gaussian_closed().- Parameters:
other (
SupportsGaussianClosedOverlap) – Another envelope in the same closed Gaussian formalism.- Returns:
Complex overlap \(\langle \text{self}, \text{other} \rangle\).
- Return type:
- Raises:
TypeError – If
otheris not a supported Gaussian-closed envelope type.
Notes
This method supports overlaps with
GaussianEnvelopeandGaussianMixtureEnvelope.
- phased(dphi: float) GaussianMixtureEnvelope¶
Return a copy with an added global phase.
- Parameters:
dphi (
float) – Phase increment to add to \(\phi_0\).- Returns:
Phased envelope.
- Return type:
- Parameters:
components (tuple[GaussianEnvelope, ...])
weights (ndarray[tuple[Any, ...], dtype[complexfloating[Any, Any]]])
report (FitReport | None)