- edited description
Have a short convenience method to get probability of truth
By default, Lea does not display individual probabilities but probability distributions; this is so even for boolean variables (i.e. probability of False and probability of True). For boolean variables, it's very common and natural to require only the probability of True, as a fraction or float. Lea provides general methods to do that: p
(fraction) and pmf
(float):
>>> rain = Lea.boolProb(1,4)
>>> rain.p(True)
1/4
>>> rain.pmf(True)
0.25
>>> die = Lea.interval(1,6)
>>> ((2 <= die) & (die < 6)).p(True)
2/3
>>> ((2 <= die) & (die < 6)).pmf(True)
0.6666666666666666
It would be nice to allow for a shorter, handy, syntax, that avoids the True
argument. The following is suggested (note the capital P
to avoid confusion with p
method):
>>> rain.P
1/4
>>> rain.Pf
0.25
>>> ((2 <= die) & (die < 6)).P
2/3
>>> ((2 <= die) & (die < 6)).Pf
0.6666666666666666
Also, these methods could be provided as pure functions, enabling a syntax close to standard mathematical notations:
>>> P(rain)
1/4
>>> Pf(rain)
0.25
>>> P((2 <= die) & (die < 6))
2/3
>>> Pf((2 <= die) & (die < 6))
0.6666666666666666
Syntactic sugar matters!
Comments (7)
-
reporter -
reporter - edited description
-
reporter - edited description
-
reporter Add P and Pf, as methods and functions (refs
#23)→ <<cset fc9936f13cc8>>
-
reporter - changed status to resolved
done in Lea 2.2.0
-
reporter - changed status to closed
-
reporter Add P and Pf, as methods and functions (refs
#23)→ <<cset d12c05642b78>>
- Log in to comment