Skip to content

Commit

Permalink
feat: entropy profile
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrugman committed Jul 7, 2022
1 parent 7760047 commit 96dd7d1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
4 changes: 1 addition & 3 deletions popmon/analysis/profiling/hist_profiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ def _profile_1d_histogram(self, name, hist):

# difference between htype=None and htype="all" are arguments (bin labels vs hist)
profile.update(Profiles.run([hist], dim=1, htype=None))
profile.update(Profiles.run([hist], dim=-1, htype=None))

# postprocessing TS
if is_ts:
Expand All @@ -110,9 +111,6 @@ def _profile_1d_histogram(self, name, hist):
for k, v in profile.items()
}

# postprocessing sum
profile["count"] = profile["filled"] + profile["nan"]

return profile

def _profile_nd_histogram(self, name, hist, dim):
Expand Down
12 changes: 12 additions & 0 deletions popmon/analysis/profiling/profiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,18 @@ def profile_count(hist):
return int(sum_entries(hist))


@Profiles.register(
key="entropy",
description="Entropy in nats",
dim=-1,
htype=None,
)
def profile_entropy(hist):
h = hist.bin_entries()
h = h / h.sum()
return -(h * np.ma.log(h)).sum()


@Profiles.register(
key="filled",
description="Number of non-missing entries (non-NaN)",
Expand Down

0 comments on commit 96dd7d1

Please sign in to comment.