unable to directly obtain probability masses of joint distributions

Issue #20 closed
Former user created an issue

when i define a multivariate distribution as

joint = lea.Lea.fromValFreqs( ((1,2),10), ((1,3),9), ((2,2),8) ).asJoint('A','B')

i cannot use the pmf or p method since something like

joint.pmf((1,3))

raises an error. instead i currently use

joint.B.given(self.joint.A==1).pmf(3) * A.pmf(1)

should the pmf and p methods be able to handle multivariate arguments or is there another way to directly access the probability masses of multivariate distributions?

Comments (7)

  1. Pierre Denis repo owner

    Thank you for reporting! There are two cleaner ways to solve this issue, with the current version of Lea (2.1.2 or before):

    1) use Lea cartesian product method to get tuples:

    tupleJoint = Lea.cprod(joint.A,joint.B)
    tupleJoint.pmf((1,2))  
    # 0.37037037037037035
    

    2) (preferred) use Python's named tuples instead of Lea's joint:

    from collections import namedtuple
    J = namedtuple('J',('A','B'))
    joint = Lea.fromValFreqs( (J(1,2),10), (J(1,3),9), (J(2,2),8) )
    joint.pmf((1,2))
    # 0.37037037037037035
    

    Note that the joint variable works as before (i.e you can access joint.A and joint.B)

    In forthcoming version of Lea, I will most probably change the implementation of asJoint method such that it uses Python's named tuples. Then, your expression joint.pmf((1,3)) will work fine.

  2. Pierre Denis repo owner

    Done. asJoint is now implemented with namedtuple (see comment above). Shall be available in Lea 2.2.

  3. Log in to comment