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 kernel is energy(d) = exp(-d² / σ²): 1 at zero distance, ~0.37 at σ, ~0.02 at 2σ. It maps a numpy array of distances to an array of energies elementwise.

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
EnergyFunction

A function distances -> energies for use with select_sessions.

Source code in capturegraph-recipes/capturegraph_recipes/scheduling/energy/gaussian.py
def gaussian(sigma: float) -> EnergyFunction:
    """Create a Gaussian energy function with the given bandwidth.

    The kernel is `energy(d) = exp(-d² / σ²)`: 1 at zero distance, ~0.37 at
    `σ`, ~0.02 at `2σ`. It maps a numpy array of distances to an array of
    energies elementwise.

    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: np.ndarray) -> np.ndarray:
        return np.exp(-np.square(distances / sigma))

    return energy