Lower Probabilities

class improb.lowprev.lowprob.LowProb(pspace=None, mapping=None, lprev=None, uprev=None, prev=None, lprob=None, uprob=None, prob=None, bba=None, credalset=None, number_type=None)

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
classmethod get_constraints_n_monotone(pspace, monotonicity=None)

Yields constraints for lower probabilities with given monotonicity.

Parameters:
  • pspace (list or similar; see Possibility Spaces) – The possibility space.
  • monotonicity (int or collections.Iterable of int) – Requested level of monotonicity (see notes below for details).

As described in get_constraints_bba_n_monotone(), the n-monotonicity constraints on basic belief assignment are:

\sum_{B\colon C\subseteq B\subseteq A}m(B)\ge 0

for all C\subseteq A\subseteq\Omega, with 1\le|C|\le n.

By the Mobius transform, this is equivalent to:

\sum_{B\colon C\subseteq B\subseteq A}
\sum_{D\colon D\subseteq B}(-1)^{|B\setminus D|}
\underline{P}(D)\ge 0

Once noted that

(C\subseteq B\subseteq A\quad \& \quad D\subseteq B)
\iff
(C\cup D\subseteq B\subseteq A\quad \& \quad D\subseteq A),

we can conveniently rewrite the sum as:

\sum_{D\colon D\subseteq A}
\sum_{B\colon C\cup D\subseteq B\subseteq A}(-1)^{|B\setminus D|}
\underline{P}(D)\ge 0

This implementation iterates over all C\subseteq
A\subseteq\Omega, with |C|=n, 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 |C| 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  
is_completely_monotone()

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
is_n_monotone(monotonicity=None)

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.

classmethod make_extreme_n_monotone(pspace, monotonicity=None)

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))
classmethod make_random(pspace=None, division=None, zero=True, number_type='float')

Generate a random coherent lower probability.

mobius

The mobius transform of the assigned unconditional lower probabilities, as SetFunction.

See also

improb.setfunction.SetFunction.get_mobius()
Mobius transform calculation of an arbitrary set function.
improb.lowprev.belfunc.BelFunc
Belief functions.
set_function

The lower probability as SetFunction.

Previous topic

Polyhedral Lower Previsions

Next topic

Belief Functions

This Page