Skip to content

Commit

Permalink
tests yay (negentropy)
Browse files Browse the repository at this point in the history
  • Loading branch information
tjlane committed Aug 11, 2024
1 parent 687ce86 commit 0ed4a34
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion meteor/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from scipy.stats import differential_entropy


def negentropy(samples: np.ndarray, tolerance: float = 1e-4) -> float:
def negentropy(samples: np.ndarray, tolerance: float = 0.01) -> float:
"""
Return negentropy (float) of X (numpy array)
Expand Down
15 changes: 12 additions & 3 deletions test/unit/test_validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,18 @@
from meteor import validate

def test_negentropy_gaussian() -> None:
n_samples = 100
n_samples = 10000
samples = np.random.normal(size=n_samples)
negentropy = validate.negentropy(samples)

# negentropy should be small for a Gaussian sample
assert np.abs(negentropy) < 1e-5
# negentropy should be zero for a Gaussian sample
assert np.abs(negentropy) < 1e-2


def test_negentropy_uniform() -> None:
n_samples = 1000000
samples = np.random.uniform(size=n_samples)
negentropy = validate.negentropy(samples)

uniform_negentropy = (1./2.) * np.log(np.pi * np.exp(1) / 6.0)
assert np.abs(negentropy - uniform_negentropy) < 1e-2

0 comments on commit 0ed4a34

Please sign in to comment.