code: def mod_categorical_expval(p):
      
      p = extend_dirichlet(p)
      return np.sum([p * i for i, p in enumerate(p)])
docs: Expected value of categorical distribution with parent p of length k-1.
  
      An implicit k'th category  is assumed to exist with associated
      probability 1-sum(p).