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)
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()})
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})
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})