Bases: improb.lowprev.lowpoly.LowPoly
An unconditional lower probability. This class is identical to LowPoly, except that only unconditional assessments on events are allowed.
>>> print(LowProb(3, lprob={(0, 1): '0.1', (1, 2): '0.2'}))
0 1 : 1/10
1 2 : 1/5
>>> print(LowProb(3, lprev={(3, 1, 0): 1}))
Traceback (most recent call last):
...
ValueError: not an indicator gamble
>>> print(LowProb(3, uprob={(0, 1): '0.1'}))
Traceback (most recent call last):
...
ValueError: cannot specify upper prevision
>>> print(LowProb(3, mapping={((3, 1, 0), (0, 1)): (1.4, None)}))
Traceback (most recent call last):
...
ValueError: not unconditional
>>> lpr = LowProb(3, lprob={(0, 1): '0.1', (1, 2): '0.2', (2,): '0.05'})
>>> lpr.extend()
>>> print(lpr)
: 0
0 : 0
1 : 0
2 : 1/20
0 1 : 1/10
0 2 : 1/20
1 2 : 1/5
0 1 2 : 1
>>> print(lpr.mobius)
: 0
0 : 0
1 : 0
2 : 1/20
0 1 : 1/10
0 2 : 0
1 2 : 3/20
0 1 2 : 7/10
Yields constraints for lower probabilities with given monotonicity.
Parameters: |
|
---|
As described in get_constraints_bba_n_monotone(), the n-monotonicity constraints on basic belief assignment are:
for all , with
.
By the Mobius transform, this is equivalent to:
Once noted that
we can conveniently rewrite the sum as:
This implementation iterates over all , with
, and yields each
constraint as an iterable of (event, coefficient) pairs, where
zero coefficients are omitted.
Note
As just mentioned, this method returns the constraints
corresponding to the latter equation for
equal to monotonicity. To get all the
constraints for n-monotonicity, call this method with
monotonicity=xrange(1, n + 1).
The rationale for this approach is that, in case you already know that (n-1)-monotonicity is satisfied, then you only need the constraints for monotonicity=n to check for n-monotonicity.
Note
The trivial constraints that the empty set must have lower probability zero, and that the possibility space must have lower probability one, are not included: so for monotonicity=0 this method returns an empty iterator.
>>> pspace = PSpace("abc")
>>> for mono in xrange(1, len(pspace) + 1):
... print("{0} monotonicity:".format(mono))
... print(" ".join("{0:<{1}}".format("".join(i for i in event), len(pspace))
... for event in pspace.subsets()))
... constraints = [
... dict(constraint) for constraint in
... LowProb.get_constraints_n_monotone(pspace, mono)]
... constraints = [
... [constraint.get(event, 0) for event in pspace.subsets()]
... for constraint in constraints]
... for constraint in sorted(constraints):
... print(" ".join("{0:<{1}}".format(value, len(pspace))
... for value in constraint))
1 monotonicity:
a b c ab ac bc abc
-1 0 0 1 0 0 0 0
-1 0 1 0 0 0 0 0
-1 1 0 0 0 0 0 0
0 -1 0 0 0 1 0 0
0 -1 0 0 1 0 0 0
0 0 -1 0 0 0 1 0
0 0 -1 0 1 0 0 0
0 0 0 -1 0 0 1 0
0 0 0 -1 0 1 0 0
0 0 0 0 -1 0 0 1
0 0 0 0 0 -1 0 1
0 0 0 0 0 0 -1 1
2 monotonicity:
a b c ab ac bc abc
0 0 0 1 0 -1 -1 1
0 0 1 0 -1 0 -1 1
0 1 0 0 -1 -1 0 1
1 -1 -1 0 1 0 0 0
1 -1 0 -1 0 1 0 0
1 0 -1 -1 0 0 1 0
3 monotonicity:
a b c ab ac bc abc
-1 1 1 1 -1 -1 -1 1
Checks whether the lower probability is completely monotone or not.
Warning
The lower probability must be defined for all events. If needed, call extend() first.
>>> lpr = LowProb(
... pspace='abcd',
... lprob={'ab': '0.2', 'bc': '0.2', 'abc': '0.2', 'b': '0.1'})
>>> lpr.extend()
>>> print(lpr)
: 0
a : 0
b : 1/10
c : 0
d : 0
a b : 1/5
a c : 0
a d : 0
b c : 1/5
b d : 1/10
c d : 0
a b c : 1/5
a b d : 1/5
a c d : 0
b c d : 1/5
a b c d : 1
>>> print(lpr.mobius)
: 0
a : 0
b : 1/10
c : 0
d : 0
a b : 1/10
a c : 0
a d : 0
b c : 1/10
b d : 0
c d : 0
a b c : -1/10
a b d : 0
a c d : 0
b c d : 0
a b c d : 4/5
>>> lpr.is_completely_monotone() # (it is in fact not even 2-monotone)
False
>>> lpr = LowProb(
... pspace='abcd',
... lprob={'ab': '0.2', 'bc': '0.2', 'abc': '0.3', 'b': '0.1'})
>>> lpr.extend()
>>> print(lpr)
: 0
a : 0
b : 1/10
c : 0
d : 0
a b : 1/5
a c : 0
a d : 0
b c : 1/5
b d : 1/10
c d : 0
a b c : 3/10
a b d : 1/5
a c d : 0
b c d : 1/5
a b c d : 1
>>> print(lpr.mobius)
: 0
a : 0
b : 1/10
c : 0
d : 0
a b : 1/10
a c : 0
a d : 0
b c : 1/10
b d : 0
c d : 0
a b c : 0
a b d : 0
a c d : 0
b c d : 0
a b c d : 7/10
>>> lpr.is_completely_monotone()
True
Given that the lower probability is (n-1)-monotone, is the lower probability n-monotone?
Note
To check for n-monotonicity, call this method with monotonicity=xrange(n + 1).
Note
For convenience, 0-montonicity is defined as empty set and possibility space having lower probability 0 and 1 respectively.
Warning
The lower probability must be defined for all events. If needed, call extend() first.
Warning
For large levels of monotonicity, it is slightly more efficient to call is_bba_n_monotone() on mobius.
Yield extreme lower probabilities with given monotonicity.
Warning
Currently this doesn’t work very well except for the cases below.
>>> lprs = list(LowProb.make_extreme_n_monotone('abc', monotonicity=2))
>>> len(lprs)
8
>>> all(lpr.is_coherent() for lpr in lprs)
True
>>> all(lpr.is_n_monotone(2) for lpr in lprs)
True
>>> all(lpr.is_n_monotone(3) for lpr in lprs)
False
>>> lprs = list(LowProb.make_extreme_n_monotone('abc', monotonicity=3))
>>> len(lprs)
7
>>> all(lpr.is_coherent() for lpr in lprs)
True
>>> all(lpr.is_n_monotone(2) for lpr in lprs)
True
>>> all(lpr.is_n_monotone(3) for lpr in lprs)
True
>>> lprs = list(LowProb.make_extreme_n_monotone('abcd', monotonicity=2))
>>> len(lprs)
41
>>> all(lpr.is_coherent() for lpr in lprs)
True
>>> all(lpr.is_n_monotone(2) for lpr in lprs)
True
>>> all(lpr.is_n_monotone(3) for lpr in lprs)
False
>>> all(lpr.is_n_monotone(4) for lpr in lprs)
False
>>> lprs = list(LowProb.make_extreme_n_monotone('abcd', monotonicity=3))
>>> len(lprs)
16
>>> all(lpr.is_coherent() for lpr in lprs)
True
>>> all(lpr.is_n_monotone(2) for lpr in lprs)
True
>>> all(lpr.is_n_monotone(3) for lpr in lprs)
True
>>> all(lpr.is_n_monotone(4) for lpr in lprs)
False
>>> lprs = list(LowProb.make_extreme_n_monotone('abcd', monotonicity=4))
>>> len(lprs)
15
>>> all(lpr.is_coherent() for lpr in lprs)
True
>>> all(lpr.is_n_monotone(2) for lpr in lprs)
True
>>> all(lpr.is_n_monotone(3) for lpr in lprs)
True
>>> all(lpr.is_n_monotone(4) for lpr in lprs)
True
>>> # cddlib hangs on larger possibility spaces
>>> #lprs = list(LowProb.make_extreme_n_monotone('abcde', monotonicity=2))
Generate a random coherent lower probability.
The mobius transform of the assigned unconditional lower probabilities, as SetFunction.
See also
The lower probability as SetFunction.