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

fixed math that was not represented properly. #381

Merged
merged 1 commit into from
Jun 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 23 additions & 12 deletions xgi/algorithms/centrality.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ def line_vector_centrality(H):


def katz_centrality(H, index=False, cutoff=100):
"""Returns the Katz-centrality vector of a non-empty hypergraph H.
r"""Returns the Katz-centrality vector of a non-empty hypergraph H.

The Katz-centrality measures the relative importance of a node by counting
how many distinct walks start from it. The longer the walk is the smaller
Expand All @@ -330,7 +330,7 @@ def katz_centrality(H, index=False, cutoff=100):
If set to `True`, will return a dictionary mapping each vector index to a
node. Default value is `False`.
cutoff : int
Power at which to stop the series A + alpha * A**2 + alpha**2 * A**3 + ..
Power at which to stop the series :math:`A + \alpha A^2 + \alpha^2 A^3 + \dots`
Default value is 100.

Returns
Expand All @@ -349,16 +349,27 @@ def katz_centrality(H, index=False, cutoff=100):

Notes
-----
[1] The Katz-centrality is defined as :
$$c = [(I - \alpha A^{t})^{-1} - I]{\bf 1},$$
where $A$ is the adjency matrix of the the (hyper)graph.
Since $A^{t} = A$ for undirected graphs (our case), we have :
$$(I + A + \alpha A^2 + \alpha^2 A^3 + ...)(I - \alpha A^{t})$$
$$= (I + A + \alpha A^2 + \alpha^2 A^3 + ...) * (I - \alpha A)$$
$$= (I + A + \alpha A^2 + \alpha^2 A^3 + ...) - A - \alpha A^2$$
$$- \alpha^2 A^3 - alpha^3 A^4 - \dots$$
$$= I$$
And $(I - \alpha A^{t})^{-1} = I + A + \alpha A^2 + \alpha^2 A^3 + \dots$
[1] The Katz-centrality is defined as

.. math::
c = [(I - \alpha A^{t})^{-1} - I]{\bf 1},

where :math:`A` is the adjency matrix of the the (hyper)graph.
Since :math:`A^{t} = A` for undirected graphs (our case), we have:


.. math::
&[I + A + \alpha A^2 + \alpha^2 A^3 + \dots](I - \alpha A^{t})

& = [I + A + \alpha A^2 + \alpha^2 A^3 + \dots](I - \alpha A)

& = (I + A + \alpha A^2 + \alpha^2 A^3 + \dots) - A - \alpha A^2

& - \alpha^2 A^3 - \alpha^3 A^4 - \dots

& = I

And :math:`(I - \alpha A^{t})^{-1} = I + A + \alpha A^2 + \alpha^2 A^3 + \dots`
Thus we can use the power serie to compute the Katz-centrality.
[2] The Katz-centrality of isolated nodes (no hyperedges contains them) is
zero. The Katz-centrality of an empty hypergraph is not defined.
Expand Down
10 changes: 5 additions & 5 deletions xgi/classes/dihypergraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ class DiHypergraph:
More formally, a directed hypergraph (dihypergraph) is a pair :math:`(V, E)`,
where :math:`V` is a set of elements called *nodes* or *vertices*,
and :math:`E` is the set of directed hyperedges.
A directed hyperedge is an ordered pair, $(e^+, e^-)$,
where $e^+ \subset V$, the set of senders, is known as the "tail" and
$e^-\subset V$, the set of receivers, is known as the "head".
The equivalent undirected edge, is $e = e^+ \cap e^-$ and
the edge size is defined as $|e|$.
A directed hyperedge is an ordered pair, :math:`(e^+, e^-)`,
where :math:`e^+ \subset V`, the set of senders, is known as the "tail" and
:math:`e^-\subset V`, the set of receivers, is known as the "head".
The equivalent undirected edge, is :math:`e = e^+ \cap e^-` and
the edge size is defined as :math:`|e|`.

The DiHypergraph class allows any hashable object as a node and can associate
attributes to each node, edge, or the hypergraph itself, in the form of key/value
Expand Down