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)
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
def modus(self): val = np.argmax(self) return data.Value(self.variable, val) if self.variable is not None else val