File size: 4,570 Bytes
5db14ec
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e089f7b
5db14ec
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e089f7b
5db14ec
e089f7b
5db14ec
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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
---
language: en
license: mit
size_categories:
- 10K<n<100K
task_categories:
- graph-ml
tags:
- graphs
- synthetic
- erdos-renyi
- barabasi-albert
- watts-strogatz
- stochastic-block-model
- complete-graph
- graph-qa
---

# Graph Dataset with Task Labels

A synthetic graph dataset containing graphs generated using five different algorithms, with pre-computed answers for 9 graph reasoning tasks.

## Dataset Description

This dataset contains synthetic graphs represented as edge lists, along with ground-truth answers for various graph reasoning tasks. The graphs are generated using five classical random graph models:

- **Erdős–Rényi**: Random graphs where each edge is included independently with probability p
- **Barabási–Albert**: Scale-free networks generated using preferential attachment
- **Watts–Strogatz**: Small-world networks with high clustering and short path lengths
- **Stochastic Block Model**: Community-structured graphs with 2-4 communities, higher edge probability within communities than between
- **Complete Graph**: Fully connected graphs where every pair of nodes is connected

## Dataset Structure

### Data Fields

| Field | Type | Description |
|-------|------|-------------|
| `algorithm` | string | Graph generation algorithm: `erdos_renyi`, `barabasi_albert`, `watts_strogatz`, `stochastic_block_model`, or `complete` |
| `edge_list` | string | Edge list in format `[(u, v), (x, y), ...]` |

#### Task Columns

| Task | Fields | Description |
|------|--------|-------------|
| **node_count** | `node_count` (int) | Number of nodes in the graph |
| **edge_count** | `edge_count` (int) | Number of edges in the graph |
| **node_degree** | `node_degree_node` (int), `node_degree` (int) | Sampled node and its degree |
| **edge_existence** | `edge_existence_src` (int), `edge_existence_dst` (int), `edge_existence` (bool) | Two sampled nodes and whether an edge exists between them |
| **cycle_check** | `cycle_check` (bool) | Whether the graph contains a cycle |
| **triangle_counting** | `triangle_count` (int) | Number of triangles in the graph |
| **connected_nodes** | `connected_nodes_node` (int), `connected_nodes` (string) | Sampled node and comma-separated list of its neighbors |
| **reachability** | `reachability_src` (int), `reachability_dst` (int), `reachability` (bool) | Two sampled nodes and whether a path exists between them |
| **shortest_path** | `shortest_path_src` (int), `shortest_path_dst` (int), `shortest_path` (int) | Two sampled nodes and shortest path length (-1 if no path exists) |

### Data Splits

| Split | Number of Examples |
|-------|-------------------|
| train | 10000 |
| validation | 1000 |
| test | 1000 |

### Graph Statistics

- **Node range**: [5, 25]
- **Algorithms**: Balanced across all five types (cycled)

## Usage

```python
from datasets import load_dataset

dataset = load_dataset("vstenby/random-graphs")

# Access a sample
sample = dataset["train"][0]
print(f"Algorithm: {sample['algorithm']}")
print(f"Node count: {sample['node_count']}")
print(f"Edge count: {sample['edge_count']}")
print(f"Has cycle: {sample['cycle_check']}")
print(f"Triangle count: {sample['triangle_count']}")

# Node-specific tasks
print(f"Node {sample['node_degree_node']} has degree {sample['node_degree']}")
print(f"Node {sample['connected_nodes_node']} is connected to: {sample['connected_nodes']}")

# Edge/path tasks
print(f"Edge between {sample['edge_existence_src']} and {sample['edge_existence_dst']}: {sample['edge_existence']}")
print(f"Path from {sample['reachability_src']} to {sample['reachability_dst']}: {sample['reachability']}")
print(f"Shortest path from {sample['shortest_path_src']} to {sample['shortest_path_dst']}: {sample['shortest_path']}")
```

### Converting to NetworkX

```python
import networkx as nx
import ast

def parse_edge_list(edge_list_str):
    """Parse edge list string to list of tuples."""
    if not edge_list_str or edge_list_str == "[]":
        return []
    return ast.literal_eval(edge_list_str)

sample = dataset["train"][0]
edges = parse_edge_list(sample["edge_list"])
G = nx.Graph()
G.add_nodes_from(range(sample["node_count"]))
G.add_edges_from(edges)
```

## Generation Details

- **Random seed**: 42 (train), 43 (validation), 44 (test)
- **Generation method**: Each graph has a random number of nodes uniformly sampled from [5, 25]
- **Task sampling**: For tasks requiring node/edge sampling (node_degree, edge_existence, connected_nodes, reachability, shortest_path), nodes are sampled uniformly at random

## License

MIT License

MIT License