예제 #1
0
 def __mul__(self, other):
     """Pointwise multiplication of gambles"""
     if isinstance(other, Gamble):
         return type(self)({x: self[x] * other[x]
                            for x in self._domain_joiner(other)})
     else:
         return Vector.__mul__(self, other)
예제 #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 __init__(self, data={}):
     """Create a unit mass function"""
     if isinstance(data, Mapping):  # Hashable Mapping to Rational
         umfunc = Vector(data).sum_normalized()
         if umfunc == None:
             raise ValueError("no UMFunc can be constructed from a Mapping "
                             + str(data) + " with a total mass of zero")
         Vector.__init__(self, umfunc | umfunc.support())
     else: # uniform over Hashable Container
         Vector.__init__(self, {component: Fraction(1, len(data))
                                for component in data})
예제 #4
0
 def __init__(self, data={}):
     """Create a gamble"""
     if isinstance(data, Mapping):  # Hashable Mapping to Rational
         Vector.__init__(self, data)
     else: # indicator over Hashable Container
         Vector.__init__(self, {component: 1 for component in data})