Exemplo n.º 1
0
 def sample(self, size=None, replace=True):
     value_indices = np.random.choice(range(len(self)), size, replace,
                                      self.normalize())
     if isinstance(value_indices, Iterable):
         to_value = np.vectorize(lambda idx: data.Value(self.variable, idx))
         return to_value(value_indices)
     return data.Value(self.variable, value_indices)
Exemplo n.º 2
0
 def random(self):
     v = random.random() * np.sum(self)
     s = i = 0
     for i, e in enumerate(self):
         s += e
         if s > v:
             break
     return data.Value(self.variable, i) if self.variable is not None else i
Exemplo n.º 3
0
 def modus(self):
     val = np.argmax(self)
     return data.Value(self.variable,
                       val) if self.variable is not None else val