# Katz centrality

**URL:** <https://igraph.discourse.group/t/katz-centrality/2163>\
**Category:** Usage\
**Tags:** Python\
**Created:** [8 June 2025 09:19 UTC](https://igraph.discourse.group/t/katz-centrality/2163 "2025-06-08T09:19:53Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![logion2000](https://avatars.discourse-cdn.com/v4/letter/l/ba8739/32.png) [@logion2000](https://igraph.discourse.group/u/logion2000)\
**Post date:** [8 June 2025 09:19 UTC](https://igraph.discourse.group/t/katz-centrality/2163/1 "2025-06-08T09:19:53Z")

</div>

Eigenvector centrality cannot be calculated for a disconnected graph. Even though it can be calculated for each connected subgraph, the values cannot be compared across subgraphs. It is said that Katz centrality overcomes this problem. I did not find any function for Katz centrality in Python igraph. Is it possible to calculate Katz centrality using Python igraph?

---

<div class="post-metadata">

**Author:** ![szhorvat](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/szhorvat/32/3_2.png) [@szhorvat](https://igraph.discourse.group/u/szhorvat)\
**Post date:** [8 June 2025 10:33 UTC](https://igraph.discourse.group/t/katz-centrality/2163/2 "2025-06-08T10:33:53Z")

</div>

> [@logion2000](#):
>
> Eigenvector centrality cannot be calculated for a disconnected graph.

I would phrase this as: _is it not meaningful for disconnected graphs_.

> [@logion2000](#):
>
> Is it possible to calculate Katz centrality using Python igraph?

Currently, there is no function for this. The feature request is here:

> <https://github.com/igraph/igraph/issues/1977>
>
> \*\*What is the feature or improvement you would like to see?\*\*
> 
> Implement Katz …centrality. This requires some linear algebra, ideally done with sparse matrices for good performance. The implementation will likely need to use CXSparse.
> 
> \*\*Use cases for the feature\*\*
> 
> This may be the most popular centrality measure not yet implemented in igraph.
> 
> \*\*References\*\*
> 
> - https://en.wikipedia.org/wiki/Katz\_centrality
> - Katz, Leo (Mar. 1953). “A new status index derived from sociometric analysis”. en. In: Psychometrika 18.1, pp. 39–43. ISSN: 1860-0980. DOI: 10.1007/BF02289026. URL: https://doi.org/10.1007/BF02289026
> - Bonacich, Phillip and Paulette Lloyd (July 2001). “Eigenvector-like measures of centrality for asymmetric relations”. en. In: Social Networks 23.3, pp. 191–201. ISSN: 03788733. DOI: 10.1016/S0378-8733(01)00038-7. URL: https://linkinghub.elsevier.com/retrieve/pii/S0378873301000387
> 
> \*\*Related\*\*
> 
> - \`alpha\_centrality()\` in the R interface is related

That said, calculating it is relatively easy with any linear algebra package. You simply need to solve

(I - \alpha A) x = \beta

One issue with Katz centrality is the finicky choice of \alpha. I recommend reading up on this topic in a textbook, for example Newman’s book [https://academic.oup.com/book/27884](https://academic.oup.com/book/27884) I do not recommend relying on Wikipedia—the article on this topic is quite bad.

\alpha should be less than 1/\lambda, where \lambda is the principal eigenvalue of the adjacency matrix. As \alpha approaches 1/\lambda, the Katz centrality approaches the eigenvector centrality. In this sense, Katz centrality doesn’t truly resolve the issues with eigenvector centrality. If \alpha is close to 1/\lambda, all but the scores in the largest component will be close to zeros.

Given the need to do all these linear algebra calculations, you might actually be better off using a linear algebra package than a network analysis package.

---

<div class="post-metadata">

**Author:** ![logion2000](https://avatars.discourse-cdn.com/v4/letter/l/ba8739/32.png) [@logion2000](https://igraph.discourse.group/u/logion2000)\
**Post date:** [8 June 2025 13:00 UTC](https://igraph.discourse.group/t/katz-centrality/2163/3 "2025-06-08T13:00:38Z")

</div>

Thank you very much for the reply. I hope the wish will come true. It has been there for more than 3 years.

---

<div class="post-metadata">

**Author:** ![szhorvat](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/szhorvat/32/3_2.png) [@szhorvat](https://igraph.discourse.group/u/szhorvat)\
**Post date:** [8 June 2025 16:55 UTC](https://igraph.discourse.group/t/katz-centrality/2163/4 "2025-06-08T16:55:03Z")

</div>

Here’s a simple solution using igraph and scipy:

```python
def katz(graph, alpha, beta = 1.0):
    A = graph.get_adjacency_sparse().transpose();
    A = scipy.sparse.identity(graph.vcount()) - alpha * A
    if numpy.isscalar(beta):
        beta = numpy.full(graph.vcount(), beta)
    return scipy.sparse.linalg.spsolve(A, beta)

```

(Sorry about my bad Python.)

This is straightforward when having access to an advanced linear algebra library. It’s more complicated to program it from scratch, unless using a naive power iteration. This is one reason why it’s not yet in igraph.
