-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_inference.py
71 lines (49 loc) · 1.9 KB
/
test_inference.py
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import numpy as np
import random
import pytest
import inference
import network
import utils
# def make_random_array(length, limit_max=1000):
# a = np.random.random_integers(1, limit_max, length)
# #a = np.random.random((1, length))
# return a
# def make_random_coincidences(size, length, limit_max=1000):
# c = make_random_array(size, limit_max)
# for i in range(length - 1):
# c = np.vstack((c, make_random_array(size, limit_max)))
# return c
# def make_random_lambda(size, length):
# c = [make_random_array(size, size)]
# for i in range(length - 1):
# c.append(make_random_array(size, size))
# return c
# EPSILON = 0.00000001
# def test_dens_over_coinc():
# length = 16
# how_many_coinc = 200
# c = make_random_coincidences(length, how_many_coinc)
# i = make_random_array(length)
# ## test for network.ENTRY
# ##
# y = inference.dens_over_coinc(c, i, network.ENTRY)
# ## size of y equals the number of coinc
# assert y.shape[0] == how_many_coinc
# ## assert on each element of y
# for j in range(how_many_coinc):
# expected = np.linalg.norm(c[j,:] - i)
# expected = np.exp(- np.power(expected, 2) / 1.0)
# assert expected - y[j] < EPSILON
# ## test for network.INTERMEDIATE and network.OUTPUT
# ##
# c = make_random_coincidences(length, how_many_coinc, length - 1)
# i = make_random_lambda(length, how_many_coinc - 1)
# y = inference.dens_over_coinc(c, i, network.INTERMEDIATE)
# ## size of y equals the number of coinc
# assert y.shape[0] == how_many_coinc
# ## assert on each element of y
# for j in range(how_many_coinc):
# expected = np.array([])
# for k in range(length):
# expected = np.append(expected, i[k][c[j][k]])
# assert np.prod(expected) - y[j] < EPSILON