-
Notifications
You must be signed in to change notification settings - Fork 4
/
test_fuzzy_layer_inference.py
executable file
·83 lines (65 loc) · 2.66 KB
/
test_fuzzy_layer_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
72
73
74
75
76
77
78
79
80
81
82
import pytest
from torchfuzzy import FuzzyLayer
import torch
def test_case_1():
model = FuzzyLayer.from_centers([[1,1], [10,10], [1,10], [10,1]])
x = torch.FloatTensor([[1,1]])
y = model(x)
assert y.shape == (1,4)
assert y.detach().numpy()[0] == pytest.approx([1,0,0,0], abs=0.1)
def test_case_2():
model = FuzzyLayer.from_centers([[1,1], [10,10], [1,10], [10,1]])
x = torch.FloatTensor([[10,10]])
y = model(x)
assert y.detach().numpy()[0] == pytest.approx([0,1,0,0], abs=0.1)
def test_case_3():
model = FuzzyLayer.from_centers([[1,1], [10,10], [1,10], [10,1]])
x = torch.FloatTensor([[1,10]])
y = model(x)
assert y.detach().numpy()[0] == pytest.approx([0,0,1,0], abs=0.1)
def test_case_4():
model = FuzzyLayer.from_centers([[1,1], [10,10], [1,10], [10,1]])
x = torch.FloatTensor([[10,1]])
y = model(x)
assert y.detach().numpy()[0] == pytest.approx([0,0,0,1], abs=0.1)
def test_case_5():
model = FuzzyLayer.from_centers([[1,1], [2,2], [1,2], [2,1]])
x = torch.FloatTensor([[1.5,1.5]])
y = model(x)
assert y.detach().numpy()[0] == pytest.approx([0.5,0.5,0.5,0.5], abs=1e-2)
def test_case_5_inputs_shape():
model = FuzzyLayer.from_centers([[1,1], [2,2], [1,2], [2,1]])
x = torch.FloatTensor([[1,1], [2,2], [1,2], [2,1], [1.5,1.5]])
y = model(x)
ny = y.detach().numpy()
assert ny.shape == (5,4)
def test_case_5_inputs_p0():
model = FuzzyLayer.from_centers([[1,1], [20,20], [1,20], [20,1]])
x = torch.FloatTensor([[1,1], [20,20], [1,20], [20,1]])
y = model(x)
ny = y.detach().numpy()
assert ny[0] == pytest.approx([1,0,0,0], abs=1e-2)
def test_case_5_inputs_p1():
model = FuzzyLayer.from_centers([[1,1], [20,20], [1,20], [20,1]])
x = torch.FloatTensor([[1,1], [20,20], [1,20], [20,1]])
y = model(x)
ny = y.detach().numpy()
assert ny[1] == pytest.approx([0,1,0,0], abs=1e-2)
def test_case_5_inputs_p2():
model = FuzzyLayer.from_centers([[1,1], [20,20], [1,20], [20,1]])
x = torch.FloatTensor([[1,1], [20,20], [1,20], [20,1]])
y = model(x)
ny = y.detach().numpy()
assert ny[2] == pytest.approx([0,0,1,0], abs=1e-2)
def test_case_5_inputs_p3():
model = FuzzyLayer.from_centers([[1,1], [20,20], [1,20], [20,1]])
x = torch.FloatTensor([[1,1], [20,20], [1,20], [20,1]])
y = model(x)
ny = y.detach().numpy()
assert ny[3] == pytest.approx([0,0,0,1], abs=1e-2)
def test_case_5_inputs_p4():
model = FuzzyLayer.from_centers([[1,1], [2,2], [1,2], [2,1]])
x = torch.FloatTensor([[1,1], [2,2], [1,2], [2,1], [1.5,1.5]])
y = model(x)
ny = y.detach().numpy()
assert ny[4] == pytest.approx([0.5,0.5,0.5,0.5], abs=1e-2)