Skip to content

Commit 3a1d1a6

Browse files
committed
Updated tutorials
1 parent f71003c commit 3a1d1a6

6 files changed

Lines changed: 56 additions & 26 deletions

File tree

docs/tutorials/basic_usage.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ We first load two datasets of graphs and then compare how similar these datasets
66
## Loading Datasets of Graphs
77

88
Polygraph comes with the most commonly used datasets in graph generation.
9-
We provide documentation for all provided datasets in [here](../datasets/index.md).
9+
We provide documentation for all provided datasets [here](../datasets/index.md).
1010
Below, we load two synthetic datasets and inspect an element from one of them:
1111

1212
```python
@@ -17,7 +17,7 @@ sbm = SBMGraphDataset("val")
1717
print(planar[0]) # PyG object: Data(edge_index=[2, 354], num_nodes=64)
1818
```
1919

20-
This will download the dataseets to your device and cache them. You may specify the download location by setting the environment variable `POLYGRAPH_CACHE_DIR`.
20+
This will download the datasets to your device and cache them. You may specify the download location by setting the environment variable `POLYGRAPH_CACHE_DIR`.
2121
All datasets in `polygraph` contain PyTorch-geometric objects.
2222
However, we may also access the graphs as NetworkX objects as follows:
2323

@@ -28,7 +28,7 @@ print(planar_nx[0]) # (Networkx) Graph with 64 nodes and 177 edges
2828

2929
## Comparing Distributions of Graphs
3030
When evaluating graph generative models, we want to compare a set of *generated* graphs to a set of *reference* graphs (typically the test set).
31-
In `polygraph`, we provide various different metrics to quantify how close these two sets of graphs are.
31+
In `polygraph`, we provide various different metrics to quantify how similar these two sets of graphs are.
3232
We usually pass collections of NetworkX graphs to metrics.
3333
Below, we demonstrate how a set of these metrics, combined in the [`MMD2CollectionGaussianTV`][polygraph.metrics.MMD2CollectionGaussianTV] benchmark may be computed:
3434

@@ -44,7 +44,7 @@ print(benchmark.compute(generated)) # Dictionary of different metrics
4444

4545
We discuss available metrics [in the next tutorial](metrics_overview.md).
4646

47-
All metrics are evaluated in a similar fashion:
47+
All metrics are evaluated in a similar fashion, as defined by the common [interface](../api_reference/metrics/interface.md):
4848

4949
- We first initialize a metric object via `benchmark = MMD2CollectionGaussianTV(reference)`. This fits the metric to the `reference` set, caching data that is required in later computations
5050
- We then compute the metric against the generated set via `benchmark.compute(generated)`

docs/tutorials/custom_metrics.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Defining Custom Metrics
2+
3+
## Custom Graph Descriptors
4+
5+
## Custom Graph Kernels
6+
7+
## Building Benchmarks

docs/tutorials/evaluating_models.md

Whitespace-only changes.

docs/tutorials/metrics_overview.md

Lines changed: 43 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@ For convenience, `polygraph` allows metrics that follow this interface to be bun
99

1010
```python
1111
from polygraph.metrics import MetricCollection
12-
from polygraph.metrics.gran import RBFOrbitMMD2, ClassifierOrbitMetric
12+
from polygraph.metrics import MMD2CollectionRBF, MMD2CollectionGaussianTV
1313
from polygraph.datasets import PlanarGraphDataset, SBMGraphDataset
1414

1515
reference_graphs = PlanarGraphDataset("val").to_nx()
1616
generated_graphs = SBMGraphDataset("val").to_nx()
1717

1818
metrics = MetricCollection(
1919
metrics={
20-
"rbf_orbit": RBFOrbitMMD2(reference_graphs=reference_graphs),
21-
"classifier_orbit": ClassifierOrbitMetric(reference_graphs=reference_graphs),
20+
"rbf_mmd": MMD2CollectionRBF(reference_graphs),
21+
"tv_mmd": MMD2CollectionGaussianTV(reference_graphs),
2222
}
2323
)
2424
print(metrics.compute(generated_graphs)) # Dictionary of metrics
@@ -28,19 +28,31 @@ We now proceed to give a high-level overview over the different types of metrics
2828

2929
## Maximum Mean Discrepancy
3030

31-
[Maximum Mean Discrepancy (MMD)](../api_reference/metrics/mmd.md) is the most commonly used approach for comparing graph distributions.
31+
[Maximum Mean Discrepancy (MMD)](../api_reference/metrics/mmd.md) is the predominant method for comparing graph distributions.
3232
The two distributions are embedded in a reproducing kernel Hilbert space (RKHS) and their distance is then computed in this space.
3333

34-
To construct an MMD metric, one must choose two components:
34+
In `polygraph`, we bundle the most commonly used MMD metrics in two benchmark classes: [`MMD2CollectionGaussianTV`][polygraph.metrics.MMD2CollectionGaussianTV] and [`MMD2CollectionRBF`][polygraph.metrics.MMD2CollectionRBF]. These benchmarks may be evaluated in the following fashion:
35+
36+
```python
37+
from polygraph.datasets import PlanarGraphDataset, SBMGraphDataset
38+
from polygraph.metrics import MMD2CollectionGaussianTV, MMD2IntervalCollectionGaussianTV
39+
40+
reference = PlanarGraphDataset("val").to_nx()
41+
generated = SBMGraphDataset("val").to_nx()
42+
43+
# Evaluate the benchmark with point estimates
44+
benchmark = MMD2CollectionGaussianTV(reference)
45+
print(benchmark.compute(generated)) # {'orbit': 1.067700488335175, 'clustering': 0.32549637224264394, 'degree': 0.3375409762261701, 'spectral': 0.0830197437100697}
46+
```
47+
48+
For more details on these collections we refer to the documentation on the [Gaussian TV metrics](../metrics/gaussian_tv_mmd.md) and [RBF metrics](../metrics/rbf_mmd.md).
49+
50+
Polygraph also allows you to construct custom MMD metrics. To construct an MMD metric, one must choose two components:
3551

3652
- [Descriptor](../api_reference/utils/graph_descriptors.md) - A function that transforms graphs into vectorial descriptions
37-
- [Kernel](../api_reference/utils/graph_kernels.md) - A kernel function operating on these vectors produced by the descriptor
53+
- [Kernel](../api_reference/utils/graph_kernels.md) - A kernel function operating on the vectors produced by the descriptor
3854

3955
We implement a large number of different descriptors and kernels in `polygraph`.
40-
For convenience, we provide commonly used combinations of kernels, descriptors, and estimators, based on [classical descriptors](../metrics/gran.md) or [gnn features](../metrics/gin.md).
41-
We recommend using these standardized implementations to ensure fair and comparable evaluations.
42-
43-
However, you may also construct custom MMD metrics, combining kernels and descriptors as you like.
4456
An MMD metric operating on orbit counts with a linear kernel may thus be constructed in the following fashion:
4557

4658
```python
@@ -58,20 +70,33 @@ metric = DescriptorMMD2(
5870

5971
The MMD may be computed via a biased estimator (`"biased"`) or via an unbiased one (`"umve"`).
6072
In the large sample size limit, the two should converge to the same value. However, at low sample sizes the differences may be substantial.
61-
In practice the biased estimator is oftentimes used.
73+
In practice the biased estimator is oftentimes used. We refer to the documentation of the [base MMD classes](../api_reference/metrics/mmd.md).
6274

6375

6476
!!! warning
6577
MMD metrics that are computed with different estimators, metrics, or kernels lie on different scales and are not comparable to each other.
6678

6779
## PolyGraphScore
6880

69-
The [PolyGraphScore metric](../api_reference/metrics/polygraphscore.md) operates in a similar fashion as MMD metrics. However, it aims to make metrics comparable across graph descriptors and produces interpretable values between 0 and 1.
70-
The PolyGraphScore is typically computed for several graph descriptors and produces a summary metric for these descriptors.
81+
The [PolyGraphScore metric](../api_reference/metrics/polygraphscore.md) compares two graph distributions by determining how well they can be distinguished by a binary classifier.
82+
It aims to make metrics comparable across graph descriptors and produces interpretable values between 0 and 1.
83+
The PolyGraphScore is computed for several graph descriptors and produces a summary metric for these descriptors.
7184
This summary metric is an estimated lower bound on a probability metric that is intrinsic to the graph distributions and independent of the descriptors
7285

86+
We provide [`PGS5`][polygraph.metrics.PGS5], a standardized version of the PolyGraphScore that combines 5 different graph descriptors:
87+
7388
```python
7489
from polygraph.datasets import PlanarGraphDataset, SBMGraphDataset
90+
from polygraph.metrics import PGS5
91+
92+
metric = PGS5(reference_graphs=PlanarGraphDataset("test").to_nx())
93+
metric.compute(SBMGraphDataset("test").to_nx()) # {'polygraphscore': 0.999301797449604, 'polygraphscore_descriptor': 'degree', 'subscores': {'orbit': 0.9986018004713674, 'clustering': 0.9933180272388359, 'degree': 0.999301797449604, 'spectral': 0.9690467491487502, 'gin': 0.9984711185804029}}
94+
```
95+
96+
As with MMD metrics, you may also construct custom PolyGraphScore variants using other graph descriptors, evaluation metrics, or binary classification approaches.
97+
E.g., you may construct the following metric
98+
99+
```python
75100
from polygraph.utils.graph_descriptors import OrbitCounts, SparseDegreeHistogram
76101
from polygraph.metrics.base import PolyGraphScore
77102

@@ -81,12 +106,13 @@ metric = PolyGraphScore(
81106
"orbit": OrbitCounts(),
82107
"degree": SparseDegreeHistogram(),
83108
},
84-
classifier="tabpfn",
85-
variant="jsd"
109+
classifier="logistic",
110+
variant="informedness",
86111
)
87-
metric.compute(SBMGraphDataset("test").to_nx())
112+
metric.compute(SBMGraphDataset("test").to_nx()) # {'polygraphscore': 0.9, 'polygraphscore_descriptor': 'orbit', 'subscores': {'orbit': 0.9, 'degree': 0.9}}
88113
```
89114

115+
We refer to the [API reference](../api_reference/metrics/polygraphscore.md) for further details.
90116

91117
## Validity, Uniqueness, Novelty
92118

@@ -100,7 +126,6 @@ To determine novelty, this metric must be passed the training set on which the g
100126

101127
```python
102128
from polygraph.metrics import VUN
103-
from polygraph.datasets import PlanarGraphDataset, SBMGraphDataset
104129

105130
train = PlanarGraphDataset("train").to_nx()
106131
generated = SBMGraphDataset("val").to_nx()
@@ -109,11 +134,8 @@ metric = VUN(
109134
train_graphs=train, # Pass the training set to determine novelty
110135
validity_fn=PlanarGraphDataset.is_valid
111136
)
112-
print(metric.compute(generated)) # Dictionary containing fraction of unique/novel/valid graphs (all combinations)
137+
print(metric.compute(generated)) # {'unique': 1.0, 'novel': 1.0, 'unique_novel': 1.0, 'valid': 0.0, 'valid_unique_novel': 0.0, 'valid_novel': 0.0, 'valid_unique': 0.0}
113138
```
114139

115140
All synthetic datasets in the `polygraph` package provide a static `is_valid` function.
116141
If no validity function is available for your dataset, `validity_fn` may be set to `None`. In this case, only the fraction of unique and novel graphs is computed.
117-
118-
119-
## Uncertaingy Quantification
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Uncertainty Quantification

mkdocs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ nav:
1111
- Tutorials:
1212
- Basic Usage: tutorials/basic_usage.md
1313
- Metrics Overview: tutorials/metrics_overview.md
14-
- Evaluating Models: tutorials/evaluating_models.md
14+
- Uncertainty Quantification: tutorials/uncertainty_quantification.md
1515
- Defining Custom Metrics: tutorials/custom_metrics.md
1616
- Base API Reference:
1717
- polygraph.metrics:

0 commit comments

Comments
 (0)