def normalize(self): if not self._objects: return if max(self._weights) > self._max_weight: self._decrease_all() while avg(self._weights) > self._average_weight: self._decrease_all()
def make_samples(threshold, message): assert message, "Message can't be empty" active_impulses = [ [i for i, a in enumerate(row) if a >= threshold] + [None] for row in message.rows() ] for sample in product(*active_impulses): values = [message.get(y, x) if x is not None else 0 for y, x in enumerate(sample)] activity = avg(values) if activity: yield sample, activity
def similarity(it1, it2): return avg(int(x == y) for x, y in zip(it1, it2))