Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Normalizing distrax.Categorical #167

Closed
patel-zeel opened this issue May 26, 2022 · 2 comments
Closed

Normalizing distrax.Categorical #167

patel-zeel opened this issue May 26, 2022 · 2 comments

Comments

@patel-zeel
Copy link

Hi, I have noticed that distrax.Categorical normalizes the probabilities by their summation. For example,

import distrax
dist = distrax.Categorical(probs=[0.8, 1.2])
print(dist.probs)

output

[0.4 0.6]

This can go wrong at places, especially while fitting the parameters of this distribution to data. For example,

import distrax
dist = distrax.Categorical(probs=[-0.8, 1.2])
print(dist.probs)

output

[-1.9999999  2.9999998]

And now,

dist.sample(seed=jax.random.PRNGKey(0), sample_shape=(10,))

gives,

DeviceArray([-1, -1, -1, -1, -1, -1, -1, -1, -1, -1], dtype=int32)

I am not sure if this is done on purpose due to some benefits or this distribution can be improved to correct this behaviour.

@franrruiz
Copy link
Collaborator

Hi - This is intentional. The input probabilities are (of course) not allowed to be negative. To indicate that there's a mistake with the inputs, the samples are -1 when that is the case.

Note that the logits can be either negative or positive, so when fitting parameters to data, you may want to optimize with respect to the logits if you prefer to have unconstrained optimization.

I am closing the issue.

@patel-zeel
Copy link
Author

Thank you for the clarification @franrruiz :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants