path_data
PathData
¶
Class that can be used to store multiple observations of node sequences representing paths or walks
Examples:
>>> import pathpyG as pp
>>> # Generate toy example graph
>>> g = pp.Graph.from_edge_list([('a', 'c'),
>>> ('b', 'c'),
>>> ('c', 'd'),
>>> ('c', 'e')])
>>> # Store observations of walks using the index mapping
>>> # from the graph above
>>> paths = pp.PathData(g.mapping)
>>> paths.append_walk(('a', 'c', 'd'), weight=2.0)
>>> paths.append_walk(('b', 'c', 'e'), weight=2.0)
>>> print(paths)
PathData with 2 paths with total weight 4.0
Source code in src/pathpyG/core/path_data.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 |
|
num_paths
property
¶
Return the number of stored paths.
__str__
¶
Return a string representation of the PathData object.
append_walk
¶
Add an observation of a walk based on a list or tuple of node IDs or indices
Parameters:
Name | Type | Description | Default |
---|---|---|---|
node_seq
|
list | tuple
|
List or tuple of node IDs |
required |
weight
|
float
|
Weight of the walk |
1.0
|
Examples:
>>> import pathpyG as pp
>>> mapping = pp.IndexMap(['a', 'b', 'c', 'd', 'e'])
>>> walks = pp.PathData(mapping)
>>> walks.append_walk(('a', 'c', 'd'), weight=2.0)
>>> paths.append_walk(('b', 'c', 'e'), weight=1.0)
Source code in src/pathpyG/core/path_data.py
append_walks
¶
Add multiple observations of walks based on lists or tuples of node IDs or indices
Parameters:
Name | Type | Description | Default |
---|---|---|---|
node_seqs
|
list | tuple
|
List or tuple of lists or tuples of node IDs |
required |
weights
|
list | tuple
|
List or tuple of weights for each walk |
required |
Examples:
>>> import pathpyG as pp
>>> mapping = pp.IndexMap(['a', 'b', 'c', 'd', 'e'])
>>> walks = pp.PathData(mapping)
>>> walks.append_walks([['a', 'c', 'd'], ['b', 'c', 'e']], [2.0, 1.0])
Source code in src/pathpyG/core/path_data.py
get_walk
¶
Return the i-th walk (based on when it was appended) as a tuple of node IDs
Parameters:
Name | Type | Description | Default |
---|---|---|---|
i
|
int
|
Index of the walk to retrieve |
required |
Returns:
Type | Description |
---|---|
tuple
|
Tuple of node IDs representing the i-th walk |
Examples:
>>> import pathpyG as pp
>>> mapping = pp.IndexMap(['a', 'b', 'c', 'd', 'e'])
>>> walks = pp.PathData(mapping)
>>> walks.append_walk(('a', 'c', 'd'), weight=2.0)
>>> walks.get_walk(0)
('a', 'c', 'd')
Source code in src/pathpyG/core/path_data.py
map_node_seq
¶
Map a sequence of node indices (e.g. representing a higher-order node) to node IDs