tensorflow / tensorflow/probability

jax version of GeneralizedExtremeValue distribution has wrong support for concentration=0

Open
#1,839 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Jupyter Notebook
Stars
4.4k
Forks
1.1k
PR merge metrics
No merged PRs in 30d

Description

It seems like the support of the GEV is (-1.0, inf) for concentration=0, rather than the expected (-inf, inf). I am using:

  • tensorflow-probability 0.24.0
  • jax 0.4.30

I only tested this for the tensorflow_probability.substrates.jax.distributions version.

Otherwise, the support seems to be fine. Here's a little experiment for reproducing my findings:

import tensorflow_probability.substrates.jax.distributions as tfd
import jax.numpy as jnp
import pandas as pd
from itertools import product

def nominal_gev_support(loc, scale, concentration):
    if jnp.allclose(concentration, 0.0):
        return (-jnp.inf, jnp.inf)
    
    if concentration > 0.0:
        return (loc - scale / concentration, jnp.inf)
    
    if concentration < 0.0:
        return (-jnp.inf, loc - scale / concentration)

x = jnp.linspace(-5, 5, 1000)
cases = []

locs = [0.0]
scales = [1.0]
concentrations = list(jnp.linspace(-2, 2, 9))

for loc, scale, concentration in product(locs, scales, concentrations):
    cases.append({"loc": loc, "scale": scale, "concentration": concentration})


dfs = []
for case in cases:
    gev = tfd.GeneralizedExtremeValue(
        loc=case["loc"], scale=case["scale"], concentration=case["concentration"]
    )

    lp = gev.log_prob(x)
    not_nan_indices = jnp.argwhere(~jnp.isinf(lp))

    nominal_min, nominal_max = nominal_gev_support(
        loc=case["loc"], scale=case["scale"], concentration=case["concentration"]
    )

    data = {
        "nominal_min": nominal_min,
        "nominal_max": nominal_max,
        "observed_min": x[not_nan_indices].min(),
        "observed_max": x[not_nan_indices].max()
    }
    
    data |= case

    df = pd.DataFrame(data, index=[0])
    dfs.append(df)

results = pd.concat(dfs)

results

Bildschirmfoto 2024-09-20 um 12 04 15

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with tfd.GeneralizedExtremeValue in tensorflow_probability.substrates.jax.distributions and run the provided JAX reproduction for concentration values around zero. Compare the reported support and log_prob behavior at concentration=0 with the expected unbounded support; the issue is done when the JAX substrate handles that case consistently with the stated expectation and the relevant behavior is covered by a regression test.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
machine-learning
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.