示例#1
0
 def __init__(self, mapping={}):
     """Create a rational-valued function"""
     if isinstance(mapping, Mapping):
         self._mapping = {arg: _make_rational(value)
                          for arg, value in mapping.iteritems()}
     else:
         raise TypeError("specify a mapping")
示例#2
0
 def __add__(self, other):
     """Also allow addition of gambles and scalars"""
     if isinstance(other, Gamble):
         return Vector.__add__(self, other)
     else:
         other = _make_rational(other)
         return type(self)({arg: value + other
                            for arg, value in self.iteritems()})
示例#3
0
    def set_upper_pr(self, data, val):
        """Set the upper probability/prevision (expectation) of an event/gamble

          :arg `data`: the gamble for which a probability/prevision value is given
          :type `data`: arguments accepted by the :class:`~murasyp.gambles.Gamble`
            constructor
          :arg `val`: the probability/prevision value
          :type `val`: a representation of :class:`~numbers.Real`

        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)
        >>> D
        DesirSet([Cone([Ray({'a': 1, 'c': 1, 'b': 1}), Ray({'a': -1, 'c': '2/3', 'b': -1})])])

        .. note::

          The domain of the input gamble determines the conditioning event.

        """
        self.set_lower_pr(-Gamble(data), -_make_rational(val))
示例#4
0
 def __div__(self, other):
     """Scalar division of rational-valued functions"""
     other = _make_rational(other)
     return type(self)({arg: value / other
                        for arg, value in self.iteritems()})
示例#5
0
 def __mul__(self, other):
     """Scalar multiplication of rational-valued functions"""
     other = _make_rational(other)
     return type(self)({arg: value * other
                        for arg, value in self.iteritems()})
示例#6
0
 def __div__(self, other):
     """Scalar division of rays"""
     other = _make_rational(other)
     return Gamble(self) / other
示例#7
0
 def __div__(self, other):
     """Scalar division of mass assignments"""
     other = _make_rational(other)
     return Vector(self) / other