Skip to content

Remove automatic normalization in Multinomial and Categorical #5331

Closed
@ricardoV94

Description

@ricardoV94

Discussed in #5246

Originally posted by ricardoV94 December 8, 2021
This cropped up in #5234

Should we stop doing automatic normalization of the p parameter? This can hide very wrong inputs such as

import pymc as pm

with pm.Model() as m:
  x = pm.Multinomial('x', n=5, p=[-2, -2, -2, -2])

m.logp({x: [3, 2, 0, 0]})
# array(-4.62888666)

If we decide to keep the automatic normalization, we can at least remove some checks in the logp definition, since they cannot be triggered in this case.


I think this caused some problems e.g. if you a user specifies [.3, .3, .3] where things almost line up.

Originally posted by @twiecki in #5246 (comment)


Whenever the user creates a Multinomial / Categorical distribution with concrete (numpy) values we check if they are valid and if not we normalize them but also issue a UserWarning along the lines of:

p values sum up to 0.9, instead of 1.0. They will be automatically rescaled. You can rescale them directly to get rid of this warning.

In the logp or whenever we have symbolic inputs we don't do any invisible normalization, and let it evaluate to -inf as with invalid parameters in other distributions.

I think this covers most of the user cases and does not have big backwards compat issues.

Originally posted by @ricardoV94 in #5246 (comment)

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions