Skip to content

gaussian

gaussian #

A Gaussian kernel for converting distances to energy values.

Sessions within sigma distance have significant mutual influence.

gaussian(sigma) #

Create a Gaussian energy function with the given bandwidth.

The Gaussian kernel provides smooth distance-to-energy conversion: energy(d) = exp(-d² / σ²). It is applied to whole numpy distance matrices, so it maps an array of distances to an array of energies elementwise.

Properties
  • energy(0) = 1.0 (identical points have maximum energy)
  • energy(σ) ≈ 0.368 (at sigma distance, ~37% energy remains)
  • energy(2σ) ≈ 0.018 (at twice sigma, energy is nearly zero)

Parameters:

Name Type Description Default
sigma float

Bandwidth parameter controlling how far influence extends. Smaller sigma = more local influence, larger sigma = wider influence.

required

Returns:

Type Description
Callable[[_Distance], _Distance]

A function distances -> energies for use with select_sessions.

Source code in capturegraph-lib/capturegraph/scheduling/energy/gaussian.py
def gaussian(sigma: float) -> Callable[[_Distance], _Distance]:
    """Create a Gaussian energy function with the given bandwidth.

    The Gaussian kernel provides smooth distance-to-energy conversion:
    `energy(d) = exp(-d² / σ²)`. It is applied to whole numpy distance matrices,
    so it maps an array of distances to an array of energies elementwise.

    Properties:
        - energy(0) = 1.0 (identical points have maximum energy)
        - energy(σ) ≈ 0.368 (at sigma distance, ~37% energy remains)
        - energy(2σ) ≈ 0.018 (at twice sigma, energy is nearly zero)

    Args:
        sigma: Bandwidth parameter controlling how far influence extends.
            Smaller sigma = more local influence, larger sigma = wider influence.

    Returns:
        A function `distances -> energies` for use with `select_sessions`.
    """

    def energy(distances: _Distance) -> _Distance:
        return cast(_Distance, np.exp(-np.square(distances / sigma)))

    return energy