Testing Class Material

This commit is contained in:
Lisa Schwetlick 2024-08-26 13:54:13 +02:00
commit 05b1f6cdd5
85 changed files with 102796 additions and 0 deletions

View file

@ -0,0 +1,22 @@
from math import isclose
import numpy
def test_var_deterministic():
x = numpy.array([-2.0, 2.0])
expected = 4.0
assert isclose(numpy.var(x), expected)
def test_var_fuzzing():
rand_state = numpy.random.RandomState(8393)
N, D = 100000, 5
# Goal variances: [0.1 , 0.45, 0.8 , 1.15, 1.5]
expected = numpy.linspace(0.1, 1.5, D)
# Generate random, D-dimensional data
x = rand_state.randn(N, D) * numpy.sqrt(expected)
variance = numpy.var(x, axis=0)
numpy.testing.assert_allclose(variance, expected, rtol=1e-2)