PolyGraphDiscrepancy
PolyGraph discrepancy metrics compare generated graphs to reference graphs by fitting a binary classifier to discriminate between the two. Performance metrics of this classifier lower-bound intrinsic probability metrics. Multiple graph descriptors may be combined within the metric to yield a theoretically grounded summary metric.
Any binary classifier implementing the standard scikit-learn interface (as defined in ClassifierProtocol)
may be used for classification. By default, we use TabPFN.
The classifiers may be then be evaluated by either:
- Data log-likelihood (default) - Provides a lower bound on the Jensen-Shannon distance, or
- Informedness - Provides a lower bound on the total variation distance.
The PolyGraphDiscrepancy class combines metrics across multiple graph descriptors,
providing the tightest lower-bound on the probability metrics.
The ClassifierMetric class, on the other hand, computes a lower bound
for a single graph descriptor.
The PolyGraphDiscrepancyInterval class implements a variant of the PolyGraphDiscrepancy
with uncertainty quantification.
Example
from polygraph.datasets import PlanarGraphDataset, SBMGraphDataset
from polygraph.metrics.base import PolyGraphDiscrepancy
from polygraph.utils.descriptors import OrbitCounts, SparseDegreeHistogram
reference = PlanarGraphDataset("val").to_nx()
generated = SBMGraphDataset("val").to_nx()
benchmark = PolyGraphDiscrepancy(
reference,
descriptors={
"orbit": OrbitCounts(),
"degree": SparseDegreeHistogram(),
},
)
print(benchmark.compute(generated)) # {'pgd': 0.9975117559449073, 'pgd_descriptor': 'degree', 'subscores': {'orbit': 0.9962500491652303, 'degree': 0.9975117559449073}}
PolyGraphDiscrepancy
polygraph.metrics.base.PolyGraphDiscrepancy
Bases: GenerationMetric[GraphType], Generic[GraphType]
PolyGraphDiscrepancy to compare graph distributions, combining multiple graph descriptors.
| Parameters: |
|
|---|
compute(generated_graphs)
Compute the PolyGraphDiscrepancy.
| Parameters: |
|
|---|
| Returns: |
|
|---|
polygraph.metrics.base.PolyGraphDiscrepancyInterval
Bases: GenerationMetric[GraphType], Generic[GraphType]
Uncertainty quantification for PolyGraphDiscrepancy.
| Parameters: |
|
|---|
compute(generated_graphs)
Compute the PolyGraphDiscrepancyInterval.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Estimating Distances with a Single Descriptor
polygraph.metrics.base.ClassifierMetric
Bases: GenerationMetric[GraphType], Generic[GraphType]
Classifier-based metric using a single graph descriptor.
| Parameters: |
|
|---|
compute(generated_graphs)
Compute the classifier metric.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Classifier Interface
polygraph.metrics.base.polygraphdiscrepancy.ClassifierProtocol
Bases: Protocol
Protocol for binary classifiers used in the PolyGraph discrepancy metric.
fit(X, y)
Fit the classifier to the data.
| Parameters: |
|
|---|
| Returns: |
|
|---|
predict_proba(X)
Predict the probability of the positive class.
| Parameters: |
|
|---|
| Returns: |
|
|---|