Testing Class Material
This commit is contained in:
commit
05b1f6cdd5
85 changed files with 102796 additions and 0 deletions
22
hands_on_solutions/numerical_fuzzing/test_var.py
Normal file
22
hands_on_solutions/numerical_fuzzing/test_var.py
Normal 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)
|
Loading…
Add table
Add a link
Reference in a new issue