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

Discrepancy in Assortativity Coefficient Values between Networkit and Networkx #1161

Open
Fabio-Giacomelli opened this issue Jan 10, 2024 · 1 comment

Comments

@Fabio-Giacomelli
Copy link

Hello,

I've encountered an issue with the Assortativity class in Networkit. When comparing the assortativity coefficient calculated by Networkit and Networkx for the same graph, I noticed a discrepancy in the values.

Here's the code snippet I used for testing:

import networkx as nx 
import networkit as nk
from networkit.correlation import Assortativity
from networkit.generators import BarabasiAlbertGenerator
from networkit.centrality import DegreeCentrality

generator = BarabasiAlbertGenerator(1, 100)
nkG = generator.generate()
r_nk = Assortativity(nkG, DegreeCentrality(nkG).run().scores()).run().getCoefficient()
nxG = nk.nxadapter.nk2nx(nkG)
r_nx = nx.degree_assortativity_coefficient(nxG)

print(r_nk, r_nx)

The assortativity coefficient computed with Networkit returns positive values, while the one computed with Networkx returns negative values. I believe the usage of the Assortativity class is correct, or am I wrong?

Could you please look into this issue? Any guidance or clarification would be greatly appreciated.

Thank you, Fabio

@fabratu
Copy link
Member

fabratu commented Jan 16, 2024

Hi Fabio,

thanks for bringing this up. Your code does correctly use Assortativity from NetworKit and NetworkX. Our documentation is a bit imprecise, since it computes something related to what NetworkX is doing - but not the same thing.

Our function computes a sample pearson correlation coefficient, which is for example described here: https://en.wikipedia.org/wiki/Pearson_correlation_coefficient#For_a_sample

In NetworkX, the standard pearson correlation coefficient (scalar mixing) is computed. Information about the formula can be seen here: https://journals.aps.org/pre/pdf/10.1103/PhysRevE.67.026126 (formula [21])

While both numbers are between -1 and 1, the difference is, that the sample approach considers (only) the correlation between numbers. If we relate this to degrees, a node with a higher degree should therefore connect to another node with a higher degree. The standard pearson correlation coefficient considers the mixing of the degree of both endpoints. That means, that the difference between degrees should also be minimized.

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

No branches or pull requests

2 participants