File size: 1,696 Bytes
a7cd1c1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
"""Self-check for the simulator: shapes, seeding, label rates, realistic ranges. Run: python test_simulate.py"""
import numpy as np

from simulate import CLASSES, SIGNALS, simulate

a = simulate(n_cows=600, n_days=400, n_farms=4, seed=7)
b = simulate(n_cows=600, n_days=400, n_farms=4, seed=7)
c = simulate(n_cows=600, n_days=400, n_farms=4, seed=8)
X, y = a["X"], a["y"]
assert X.shape == (600, 400, len(SIGNALS)) and y.shape == (600, 400) and a["thi"].shape == (4, 400)
assert np.array_equal(X, b["X"], equal_nan=True) and np.array_equal(y, b["y"]), "same seed must reproduce"
assert not np.array_equal(y, c["y"]), "different seed must differ"
rates = np.bincount(y.ravel(), minlength=len(CLASSES)) / y.size
assert 0.90 < rates[0] < 0.99, rates                   # most cow-days are normal
assert all(r > 0 for r in rates[1:]), rates            # every event class occurs
assert 0.01 < np.isnan(X[:, :, 0]).mean() < 0.08       # missing data present but limited
temp = X[:, :, SIGNALS.index("thermal_drone")]
assert 20 <= np.nanmin(temp) and np.nanmax(temp) <= 38.5  # body SURFACE, not core (38.5-39.5)
assert 0.005 < np.isnan(temp).mean() < 0.2              # drone misses some cow-days
assert 25 < np.nanmedian(temp) < 36
for s in ["feeding_min", "rumination_min", "lying_min", "outside_fence_min"]:
    v = X[:, :, SIGNALS.index(s)]
    assert np.nanmin(v) >= 0 and np.nanmax(v) <= 1440, s
rum = X[:, :, SIGNALS.index("rumination_min")]
assert np.nanmean(rum[y == CLASSES.index("brd")]) < np.nanmean(rum[y == 0])
steps = X[:, :, SIGNALS.index("steps")]
assert np.nanmean(steps[y == CLASSES.index("estrus")]) > 1.3 * np.nanmean(steps[y == 0])
print("ok", dict(zip(CLASSES, rates.round(4))))