Skip to content

Preset

κ_lips(x, y)

Lipschitz kernel: \(κ(x, y) = \frac{10 \sqrt{x^2 + y^2}}{1 + \sqrt{|x - y|}}\)

Parameters:

Name Type Description Default
x VertexType

An array of vertex types.

required
y VertexType

An array of vertex types.

required

Returns:

Type Description
Array

An array of kernel values.

Source code in src/bprg/preset.py
def κ_lips(x: VertexType, y: VertexType) -> Array:
    r"""Lipschitz kernel:
    $κ(x, y) = \frac{10 \sqrt{x^2 + y^2}}{1 + \sqrt{|x - y|}}$

    Args:
        x: An array of vertex types.
        y: An array of vertex types.

    Returns:
        An array of kernel values.
    """
    return 10 * jnp.sqrt(x**2 + y**2) / (1 + jnp.sqrt(jnp.abs(x - y)))

κ_expo(x, y)

Exponential kernel: \(κ(x, y) = \frac{5 (e^{x + 0.5 y} - 1)}{1 + \sqrt{|x - y|}}\)

Parameters:

Name Type Description Default
x VertexType

An array of vertex types.

required
y VertexType

An array of vertex types.

required

Returns:

Type Description
Array

An array of kernel values.

Source code in src/bprg/preset.py
def κ_expo(x: VertexType, y: VertexType) -> Array:
    r"""Exponential kernel:
    $κ(x, y) = \frac{5 (e^{x + 0.5 y} - 1)}{1 + \sqrt{|x - y|}}$

    Args:
        x: An array of vertex types.
        y: An array of vertex types.

    Returns:
        An array of kernel values.
    """
    return 5 * (jnp.exp(x + 0.5 * y) - 1) / (1 + jnp.sqrt(jnp.abs(x - y)))

κ_sing(x, y)

Kernel with singularity: \(κ(x, y) = \frac{x + y}{|x - y| + |x - 1| + |y - 1|}\)

Parameters:

Name Type Description Default
x VertexType

An array of vertex types.

required
y VertexType

An array of vertex types.

required

Returns:

Type Description
Array

An array of kernel values.

Source code in src/bprg/preset.py
def κ_sing(x: VertexType, y: VertexType) -> Array:
    r"""Kernel with singularity:
    $κ(x, y) = \frac{x + y}{|x - y| + |x - 1| + |y - 1|}$

    Args:
        x: An array of vertex types.
        y: An array of vertex types.

    Returns:
        An array of kernel values.
    """
    return (x + y) / (jnp.abs(x - y) + jnp.abs(x - 1) + jnp.abs(y - 1))

μ_lebe(x)

Vertex type Lebesgue measure: \(μ(I) = |I|\)

Parameters:

Name Type Description Default
x VertexType

An array of vertex types.

required

Returns:

Type Description
Array

An array of measure values.

Source code in src/bprg/preset.py
def μ_lebe(x: VertexType) -> Array:
    r"""Vertex type Lebesgue measure:
    $μ(I) = |I|$

    Args:
        x: An array of vertex types.

    Returns:
        An array of measure values.
    """
    Δμ = jnp.empty_like(x)
    Δμ = Δμ.at[0].set(x[1] - x[0])
    Δμ = Δμ.at[-1].set(x[-1] - x[-2])
    Δμ = Δμ.at[1:-1].set((x[2:] - x[:-2]) / 2)
    Δμ = Δμ / Δμ.sum()  # Normalize
    return Δμ

make_η_constant(margin)

Create a constant vertex threshold measure function that is independent of the vertex type.

Parameters:

Name Type Description Default
margin Simplex

Probability distribution of vertex thresholds (sums to 1).

required

Returns:

Name Type Description
ThresholdMeasure ThresholdMeasure

A function that takes a vertex type and returns the threshold distribution.

Source code in src/bprg/preset.py
def make_η_constant(margin: Simplex) -> ThresholdMeasure:
    r"""Create a constant vertex threshold measure function that is independent of the vertex type.

    Args:
        margin: Probability distribution of vertex thresholds (sums to 1).

    Returns:
        ThresholdMeasure: A function that takes a vertex type and returns the threshold distribution.
    """
    assert jnp.allclose(margin.sum(), 1.0), "margin must be a probability distribution (sum to 1)"

    def _η_constant(x: VertexType) -> Simplex:
        return jnp.array(margin)

    η_const_vmap = jax.vmap(_η_constant, in_axes=0, out_axes=0)

    # Generate LaTeX cases from margin
    cases = " \\\\\n            ".join([f"{float(m):.1f}, & k = {i}" for i, m in enumerate(margin)])
    η_const_vmap.__doc__ = f"""Vertex threshold measure:
            $$η_k(s) ≡ \\begin{{cases}}
            {cases}
            \\end{{cases}}$$
            """
    return η_const_vmap