Skip to content

Commit a243dfc

Browse files
author
Anton Eriksson
committed
feat(python): Add entropy_rate property
1 parent 458a025 commit a243dfc

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

interfaces/python/infomap.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2569,6 +2569,35 @@ def relative_codelength_savings(self):
25692569
"""
25702570
return super().getRelativeCodelengthSavings()
25712571

2572+
@property
2573+
def entropy_rate(self):
2574+
"""Get the entropy rate of the network.
2575+
2576+
The entropy rate is an indication of the sparsity of a network.
2577+
A higher entropy rate corresponds to a densely connected network.
2578+
2579+
Notes
2580+
-----
2581+
This value is only accessable after running the optimizer (``im.run()``).
2582+
2583+
Examples
2584+
--------
2585+
2586+
>>> from infomap import Infomap
2587+
>>> im = Infomap(silent=True, no_infomap=True)
2588+
>>> im.read_file("twotriangles.net")
2589+
>>> im.run()
2590+
>>> f"{im.entropy_rate:.5f}"
2591+
'0.35714'
2592+
2593+
2594+
Returns
2595+
-------
2596+
float
2597+
The entropy rate
2598+
"""
2599+
return super().getEntropyRate()
2600+
25722601
@property
25732602
def meta_codelength(self):
25742603
"""Get the meta codelength.

src/Infomap.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ struct InfomapWrapper : public InfomapBase {
9191
}
9292

9393
using InfomapBase::codelength;
94+
using InfomapBase::getEntropyRate;
9495
using InfomapBase::getMultilevelModules;
9596
using InfomapBase::iterLeafNodes;
9697
using InfomapBase::iterTree;

src/core/InfomapBase.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,8 @@ class InfomapBase : public InfomapConfig<InfomapBase> {
135135
return oneLevelCodelength < 1e-16 ? 0 : 1.0 - codelength() / oneLevelCodelength;
136136
}
137137

138+
double getEntropyRate() { return calcEntropyRate(); }
139+
138140
const Date& getStartDate() const { return m_startDate; }
139141
const Stopwatch& getElapsedTime() const { return m_elapsedTime; }
140142

0 commit comments

Comments
 (0)