Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FakeHeteroDataset generates graphs with higher mean node degrees than avg_degree #9988

Open
MatthijsdeJ opened this issue Jan 28, 2025 · 0 comments
Labels

Comments

@MatthijsdeJ
Copy link

🐛 Describe the bug

Graphs generated with FakeHeteroDataset have a higher mean node degree than specified with the avg_degree parameter. If averaged over sufficiently many graphs, I would expect the mean node degree to converge to the avg_degree parameter. However, this is not true, as inestigated with the MRE:

import torch_geometric as tg
import numpy as np
import matplotlib.pyplot as plt

MAX_AVR_DEGREE = 15
SAMPLES_PER_STEP = 100

mean_degrees = {}
for i in np.arange(1,MAX_AVR_DEGREE):
    mean_degrees[i] = []

    for _ in range(SAMPLES_PER_STEP):

        data = tg.datasets.FakeDataset(avg_num_nodes=32, avg_degree=i)
        mean_degree = tg.utils.degree(data.edge_index[0]).mean() # data.edge_index.shape[1] / data.x.shape[0]
        mean_degrees[i].append(mean_degree)
    
mean_degrees = {k:np.mean(v) for k, v in mean_degrees.items()}
plt.scatter(np.arange(1, MAX_AVR_DEGREE), mean_degrees.values())
plt.xlabel('avg_degree')
plt.ylabel('Mean (over samples) mean (over nodes) degree')

Resulting plot:

Image

As visible the specified avg_degree (x axis) and computed mean degree (y axis) diverge. This seems like unintended behavior.

Versions

Collecting environment information...
PyTorch version: 2.5.1
Is debug build: False
CUDA used to build PyTorch: None
ROCM used to build PyTorch: N/A

OS: macOS 14.4.1 (arm64)
GCC version: Could not collect
Clang version: 15.0.0 (clang-1500.3.9.4)
CMake version: Could not collect
Libc version: N/A

Python version: 3.11.0 | packaged by conda-forge | (main, Jan 14 2023, 12:26:40) [Clang 14.0.6 ] (64-bit runtime)
Python platform: macOS-14.4.1-arm64-arm-64bit
Is CUDA available: False
CUDA runtime version: No CUDA
CUDA_MODULE_LOADING set to: N/A
GPU models and configuration: No CUDA
Nvidia driver version: No CUDA
cuDNN version: No CUDA
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True

CPU:
Apple M1

Versions of relevant libraries:
[pip3] flake8==7.0.0
[pip3] mypy==1.8.0
[pip3] mypy-extensions==1.0.0
[pip3] numpy==1.26.4
[pip3] numpydoc==1.5.0
[pip3] torch==2.5.1
[pip3] torch-geometric==2.6.1
[conda] numpy 1.26.4 py311he598dae_0
[conda] numpy-base 1.26.4 py311hfbfe69c_0
[conda] numpydoc 1.5.0 py311hca03da5_0
[conda] torch 2.5.1 pypi_0 pypi
[conda] torch-geometric 2.6.1 pypi_0 pypi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant