Divide a graph into several splits. Parameters: graph_file (str): graph file files (list of str): file names portions (list of float): split portions
(self, graph_file, files, portions)
| 293 | fout.write("%s\t%s\n" % (u, v)) |
| 294 | |
| 295 | def edge_split(self, graph_file, files, portions): |
| 296 | """ |
| 297 | Divide a graph into several splits. |
| 298 | |
| 299 | Parameters: |
| 300 | graph_file (str): graph file |
| 301 | files (list of str): file names |
| 302 | portions (list of float): split portions |
| 303 | """ |
| 304 | assert len(files) == len(portions) |
| 305 | logger.info("splitting graph %s into %s" % |
| 306 | (self.relpath(graph_file), ", ".join([self.relpath(file) for file in files]))) |
| 307 | np.random.seed(1024) |
| 308 | |
| 309 | portions = np.cumsum(portions, dtype=np.float32) / np.sum(portions) |
| 310 | files = [open(file, "w") for file in files] |
| 311 | with open(graph_file, "r") as fin: |
| 312 | for line in fin: |
| 313 | i = np.searchsorted(portions, np.random.rand()) |
| 314 | files[i].write(line) |
| 315 | for file in files: |
| 316 | file.close() |
| 317 | |
| 318 | def link_prediction_split(self, graph_file, files, portions): |
| 319 | """ |