def reversed(self): """Create a connectivity matrix where each incoming edge becomes outgoing.""" n_rows = len(self) reversed = DirectedAdjacencyMatrix(n_rows, self.dtype) for r, row in enumerate(py.prog_iter(self)): for c in row: reversed[c].append(r) return reversed
def connect_randomly(self, p, xxx_todo_changeme=(0, None), xxx_todo_changeme1=(0, None)): (src_start, src_end) = xxx_todo_changeme (target_start, target_end) = xxx_todo_changeme1 rows = len(self) if src_end is None: src_end = rows if target_end is None: target_end = rows assert 0 <= src_start <= src_end <= rows assert 0 <= target_start <= target_end <= rows assert 0.0 <= p <= 1.0 src_num = src_end - src_start target_num = target_end - target_start degree = numpy.random.binomial(target_num, p, src_num) for i in py.prog_iter(list(range(src_num))): sample = random.sample(list(range(target_start, target_end)), degree[i]) py.include_many(self[src_start + i], sample)
def connect_randomly(self, p, (src_start, src_end)=(0, None), (target_start, target_end)=(0, None)): rows = len(self) if src_end is None: src_end = rows if target_end is None: target_end = rows assert 0 <= src_start <= src_end <= rows assert 0 <= target_start <= target_end <= rows assert 0.0 <= p <= 1.0 src_num = src_end - src_start target_num = target_end - target_start degree = numpy.random.binomial(target_num, p, src_num) for i in py.prog_iter(xrange(src_num)): sample = random.sample(xrange(target_start, target_end), degree[i]) py.include_many(self[src_start + i], sample) @property def packed(self): """ each row is placed side-by-side with the length of the row interlaced the head of the packed matrix contains offsets to this length e.g. [[11, 22, 33], [44, 55], []] => [3, 7, 10, 3, 11, 22, 33, 2, 44, 55, 0] """ # not the most efficient implementation atm but whatever n_rows = len(self) size = len(self)*2 + self.n_edges packed = numpy.empty(size, self.dtype) offset = n_rows