Skip to content

Commit e6a429e

Browse files
author
Anton Eriksson
committed
fix: Avoid nan values for relative codelength savings
1 parent 0dfe43c commit e6a429e

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/core/InfomapBase.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,11 @@ class InfomapBase : public InfomapConfig<InfomapBase> {
151151

152152
double getOneLevelCodelength() const { return m_oneLevelCodelength; }
153153

154-
double getRelativeCodelengthSavings() const { return 1.0 - codelength() / getOneLevelCodelength(); }
154+
double getRelativeCodelengthSavings() const
155+
{
156+
auto oneLevelCodelength = getOneLevelCodelength();
157+
return oneLevelCodelength < 1e-16 ? 0 : 1.0 - codelength() / oneLevelCodelength;
158+
}
155159

156160
bool isFullNetwork() const { return m_isMain && m_aggregationLevel == 0; }
157161
bool isFirstLoop() { return m_tuneIterationIndex == 0 && isFullNetwork(); }

0 commit comments

Comments
 (0)