Adding constraint to the parameter

The problem with p = p/p.sum() is that the solution will not be unique: [.1, .1, .1] == [.2, .2, .2] under that setup.
Setting one of the p’s to 1. would make it unique :

p_ = tt.concatenate([pm.HalfFlat('p_', shape=2), np.array([1.])])
p = pm.Deterministic('p', p_/p_.sum())

Sorry, not the most beautiful code.
You could also use a masked array with the observed parameter of pm.HalfFlat.

1 Like