예제 #1
0
 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))
예제 #2
0
 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')
예제 #3
0
 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')
예제 #4
0
 def __sub__(self, value):
     return Chance(
         self.pspace,
         OrderedDict((event, subtree - value)
                     for event, subtree in self.iteritems()))
예제 #5
0
 def __sub__(self, value):
     return Decision(
         OrderedDict((decision, subtree - value)
                     for decision, subtree in self.iteritems()))