def _get_norm_back_opt(self, opt=None, event=True): number_type = self.get_number_type() # note: this implementation depends on the fact that # iterating self.itervalues() and # self.iterkeys() correspond to each other all_normal_forms = itertools.product(*[ tuple(subtree.get_norm_back_opt(opt, event)) for subtree in self.itervalues() ]) for normal_forms in all_normal_forms: data = {} tree = OrderedDict() for event, (gamble, normal_subtree) in itertools.izip( self.iterkeys(), normal_forms): for omega in event: if isinstance(gamble, numbers.Real): data[omega] = gamble elif isinstance(gamble, Gamble): data[omega] = gamble[omega] else: raise RuntimeError( "expected int, long, float, or Gamble") tree[event] = normal_subtree yield (Gamble(pspace=self.pspace, data=data, number_type=number_type), Chance(pspace=self.pspace, data=tree))
def __init__(self, data=None): self._data = OrderedDict() # check type if isinstance(data, collections.Mapping): for key, value in data.iteritems(): self[key] = value elif data is not None: raise TypeError('specify a mapping')
def __init__(self, pspace, data=None): self._data = OrderedDict() self._pspace = PSpace.make(pspace) # extract data if isinstance(data, collections.Mapping): for key, value in data.iteritems(): self[key] = value elif data is not None: raise TypeError('data must be a mapping')
def __sub__(self, value): return Chance( self.pspace, OrderedDict((event, subtree - value) for event, subtree in self.iteritems()))
def __sub__(self, value): return Decision( OrderedDict((decision, subtree - value) for decision, subtree in self.iteritems()))