A set of cones
type data: a non-Mapping Iterable Container of arguments accepted by the Cone constructor. >>> assert ( ... DesirSet('abc') == ... DesirSet({Cone({Ray({'b': 1})}), ... Cone({Ray({'c': 1})}), Cone({Ray({'a': 1})})}) ... ) >>> assert ( ... DesirSet(['abc']) == ... DesirSet({Cone({Ray({'a': 1}), Ray({'b': 1}), Ray({'c': 1})})}) ... ) >>> assert ( ... DesirSet([['abc']]) == ... DesirSet({Cone({Ray({'a': 1, 'c': 1, 'b': 1})})}) ... )
This class derives from set, so its methods apply here as well.
Todo
test all set methods and fix, or elegantly deal with, broken ones
Additional and changed methods:
Lower and upper (conditional) expectations can be calculated, using the * and ** operators, respectively.
>>> D = DesirSet([[Gamble({'a': -1, 'c': '7/90'}),
... Gamble({'a': 1, 'c': '-1/30'}),
... Gamble({'a': -1, 'c': '1/9', 'b': -1}),
... Gamble({'a': 1, 'c': '-1/9', 'b': 1})]])
>>> f = Gamble({'a': -1, 'b': 1, 'c': 0})
>>> D * f
Fraction(-1, 25)
>>> D ** f
Fraction(1, 25)
>>> D * (f | f.support())
Fraction(-2, 5)
>>> D ** (f | f.support())
Fraction(2, 5)
Note
The domain of the gamble determines the conditioning event.
We can deal with situations in which the gamble lies on a facet of the set of desirable gambles that corresponds to a conditioning event of (lower and/or upper) probability zero.
>>> D = DesirSet()
>>> D.set_pr('a', 1)
>>> D * (Gamble('c') | {'b', 'c'})
0
>>> D * (Gamble('c') | {'a', 'b', 'c'})
0
>>> D.set_pr(Gamble('b') | {'b', 'c'}, '1/2')
>>> D * (Gamble('c') | {'b', 'c'})
Fraction(1, 2)
Add a cone to the set of desirable gambles
type data: arguments accepted by the Cone constructor
>>> D = DesirSet()
>>> assert D == DesirSet()
>>> D.add([Gamble({'a': -.06, 'b': .14, 'c': 1.8, 'd': 0})])
>>> assert (
... D ==
... DesirSet({Cone({Ray({'a': '-1/30', 'c': 1, 'b': '7/90'})})})
... )
Todo
see whether all set functionality is carried over
Remove a cone from the set of desirable gambles
type data: arguments accepted by the Cone constructor
>>> D = DesirSet({'a','b'})
>>> assert (
... D == DesirSet({Cone({Ray({'b': 1})}), Cone({Ray({'a': 1})})})
... )
>>> D.discard([Ray({'a'})])
>>> assert D == DesirSet({Cone({Ray({'b': 1})})})
Todo
see whether all set functionality is carried over
The possibility space of the set of desirable gambles
returns: the possibility space of the set of desirable gambles, i.e., the union of the domains of the cones it contains rtype: frozenset
>>> D = DesirSet(['abc'])
>>> r = Ray({'c': .03, 'd': -.07})
>>> s = Ray({'a': .07, 'e': -.03})
>>> D.add([r, s])
>>> assert D.pspace() == frozenset({'a', 'c', 'b', 'e', 'd'})
Set the lower probability/prevision (expectation) of an event/gamble
The nontrivial cone corresponing to the prevision specification is calculated and added to the set of desirable gambles.
>>> D = DesirSet()
>>> D.set_lower_pr(Gamble({'a', 'b'}) | {'a', 'b', 'c'}, .4)
>>> assert (
... D ==
... DesirSet({Cone({Ray({'a': 1, 'c': '-2/3', 'b': 1}),
... Ray({'a': 1, 'c': 1, 'b': 1})})})
... )
Note
The domain of the input gamble determines the conditioning event.
Set the upper probability/prevision (expectation) of an event/gamble
The nontrivial cone corresponing to the prevision specification is calculated and added to the set of desirable gambles.
>>> D = DesirSet()
>>> D.set_upper_pr(Gamble({'a', 'b'}) | {'a', 'b', 'c'}, .4)
>>> assert (
... D ==
... DesirSet({Cone({Ray({'a': -1, 'c': '2/3', 'b': -1}),
... Ray({'a': 1, 'c': 1, 'b': 1})})})
... )
Note
The domain of the input gamble determines the conditioning event.
Set the probability/prevision (expectation) of an event/gamble
This is identical to setting the lower and upper prevision to the same value.
>>> D = DesirSet()
>>> D.set_pr(Gamble({'a', 'b'}) | {'a', 'b', 'c'}, .4)
>>> assert (
... D ==
... DesirSet({Cone({Ray({'a': -1, 'c': '2/3', 'b': -1}),
... Ray({'a': 1, 'c': 1, 'b': 1})}),
... Cone({Ray({'a': 1, 'c': '-2/3', 'b': 1}),
... Ray({'a': 1, 'c': 1, 'b': 1})})})
... )
Note
The domain of the input gamble determines the conditioning event.
Check whether the set of desirable gambles avoids sure loss
rtype: bool
A set of desirable gambles does not avoid sure loss if and only if some nonnegative linear combination of desirable gambles is everywhere negative.
>>> D = DesirSet()
>>> D.add([{'a': -1, 'b': -1, 'c': 1}])
>>> D.add([{'a': 1, 'b': -1, 'c': -1}])
>>> D.asl()
True
>>> D.add([{'a': -1, 'b': 1, 'c': -1}])
>>> D.asl()
False
>>> D = DesirSet('ab')
>>> D.add([{'b': -1}])
>>> D.asl()
True
Check whether the set of desirable gambles avoids partial loss
rtype: bool
A set of desirable gambles does not avoid partial loss if and only if some nonnegative linear combination of desirable gambles is everywhere nonpositive and somewhere negative.
>>> D = DesirSet()
>>> D.add([{'a': -1, 'b': -1, 'c': 1}])
>>> D.apl()
True
>>> D.add([{'a': -1, 'b': 1, 'c': -1}])
>>> D.apl()
False
We can deal correctly with non-closed sets of desirable gambles, i.e., containing non-singleton cones:
>>> D = DesirSet()
>>> D.set_pr(Gamble('b') | {'a', 'b'}, 0)
>>> assert (
... D ==
... DesirSet({Cone({Ray({'a': 1, 'b': 1}), Ray({'b': 1})}),
... Cone({Ray({'a': 1, 'b': 1}), Ray({'b': -1})})})
... )
>>> D.apl()
True
Generate the corresponding (closed) credal set
returns: the (closed) credal set that corresponds as an uncertainty model rtype: CredalSet
>>> D = DesirSet(['abc'])
>>> D.set_lower_pr({'a': 1, 'b': 0, 'c': 1}, .5)
>>> assert (
... D.get_credal() ==
... CredalSet({PMFunc({'a': '1/2', 'b': '1/2'}),
... PMFunc({'c': '1/2', 'b': '1/2'}),
... PMFunc({'a': 1}), PMFunc({'c': 1})})
... )