tensorflow / tensorflow/probability
Scaled Dirichlet does not integrate to 1
Open
@srvasude is already working on this.
Since Nov 3, 2023.
- Dominant language
- Jupyter Notebook
- Stars
- 4.4k
- Forks
- 1.1k
- PR merge metrics
- No merged PRs in 30d
Description
I am not sure if it should, but when I scale a Dirichlet non-homogeneously, it seems to no longer integrate to 1:
import numpy as np
import tensorflow_probability as tfp
tfd = tfp.distributions
tfb = tfp.bijectors
# scale = [2.0, 2.0] # Integrates to 1
scale = [2.0, 3.0] # Does not integrate to 1
scaled_dir = tfd.TransformedDistribution(
distribution=tfd.Dirichlet([4.0, 4.0], force_probs_to_zero_outside_support=True),
bijector=tfb.Scale(scale),
)
x = np.linspace(0., scale[0], 10_000)
y = scale[1] - (scale[1]/scale[0])*x
np.testing.assert_allclose(x/scale[0] + y/scale[1], 1)
pts = np.concatenate((x[..., None], y[..., None]), -1)
integral = trapezoid(np.exp(scaled_dir.log_prob(pts)), x=x)
np.testing.assert_allclose(integral, 1, rtol=1e-6) # Fails
AssertionError:
Not equal to tolerance rtol=1e-06, atol=0
Mismatched elements: 1 / 1 (100%)
Max absolute difference: 0.21553527
Max relative difference: 0.21553527
x: array(0.784465)
y: array(1)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.