-
Notifications
You must be signed in to change notification settings - Fork 3
/
test_distributed.py
128 lines (101 loc) · 4.55 KB
/
test_distributed.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# coding: utf-8
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import unittest
from utils_const import FIXED_SEED
import numpy as np
from data_distributed import (distributed_last_criterion,
distributed_single_pruning,
distributed_pruning_methods)
def generate_data(nb_clas, nb_inst, nb_cls):
prng = np.random.RandomState(FIXED_SEED + 3)
y = prng.randint(nb_clas, size=nb_inst)
yt = prng.randint(nb_clas, size=(nb_cls, nb_inst))
return y, yt
class TestDistributed(unittest.TestCase):
def test_prelim(self):
y = np.random.randint(4, size=50)
yt = np.random.randint(4, size=(17, 50))
accsg = distributed_last_criterion(y, yt)
# assert 0. <= accsg <= 1.
self.assertTrue(0. <= accsg <= 1.)
def check_centralized_distributed(self, name_pru, y, yt, nb_pru):
nb_cls = len(yt)
rho = nb_pru / nb_cls
Pc = distributed_single_pruning(
name_pru, y, yt, nb_cls, nb_pru, rho=rho)
Pd = distributed_pruning_methods(
y, yt, nb_pru, 2, name_pru, rho=rho)
# assert Pc and Pd
self.assertTrue(Pc and Pd)
def test_centralized_distributed(self):
y = np.random.randint(4, size=50)
yt = np.random.randint(4, size=(11, 50))
nb_pru = 5
self.check_centralized_distributed('ES', y, yt, nb_pru)
self.check_centralized_distributed('KP', y, yt, nb_pru)
self.check_centralized_distributed('KL', y, yt, nb_pru)
self.check_centralized_distributed('RE', y, yt, nb_pru)
self.check_centralized_distributed('OO', y, yt, nb_pru)
## check_centralized_distributed('GMA', y, yt, nb_pru)
## check_centralized_distributed('LCS', y, yt, nb_pru)
# check_centralized_distributed('OEP', y, yt, nb_pru)
# check_centralized_distributed('SEP', y, yt, nb_pru)
# check_centralized_distributed('PEP', y, yt, nb_pru)
def test_binary_situation(self):
y = np.random.randint(2, size=50)
yt = np.random.randint(2, size=(11, 50))
nb_pru = 5
self.check_centralized_distributed('ES', y, yt, nb_pru)
self.check_centralized_distributed('KP', y, yt, nb_pru)
self.check_centralized_distributed('KL', y, yt, nb_pru)
self.check_centralized_distributed('RE', y, yt, nb_pru)
self.check_centralized_distributed('OO', y, yt, nb_pru)
## check_centralized_distributed('GMA', y, yt, nb_pru)
## check_centralized_distributed('LCS', y, yt, nb_pru)
## check_centralized_distributed('DREP', y, yt, nb_pru)
# check_centralized_distributed('OEP', y, yt, nb_pru)
# check_centralized_distributed('SEP', y, yt, nb_pru)
# check_centralized_distributed('PEP', y, yt, nb_pru)
def test_OEP(self):
nb_pru = 9
y, yt = generate_data(4, 50, 17)
self.check_centralized_distributed('OEP', y, yt, nb_pru)
y, yt = generate_data(2, 50, 17)
self.check_centralized_distributed('OEP', y, yt, nb_pru)
def test_SEP(self):
nb_pru = 9
y, yt = generate_data(4, 50, 17)
self.check_centralized_distributed('SEP', y, yt, nb_pru)
y, yt = generate_data(2, 50, 17)
self.check_centralized_distributed('SEP', y, yt, nb_pru)
def test_PEP(self):
nb_pru = 9
y, yt = generate_data(4, 50, 17)
self.check_centralized_distributed('PEP', y, yt, nb_pru)
y, yt = generate_data(2, 50, 17)
self.check_centralized_distributed('PEP', y, yt, nb_pru)
def test_composable(self):
nb_pru = 9
y, yt = generate_data(2, 50, 17)
self.check_centralized_distributed('DREP', y, yt, nb_pru)
#
# check_centralized_distributed('GMA', y, yt, nb_pru)
# check_centralized_distributed('LCS', y, yt, nb_pru)
#
# y, yt = generate_data(4, 50, 17)
# check_centralized_distributed('GMA', y, yt, nb_pru)
# check_centralized_distributed('LCS', y, yt, nb_pru)
def test_GMA(self):
nb_pru = 5
y, yt = generate_data(2, 50, 11)
self.check_centralized_distributed('GMA', y, yt, nb_pru)
y, yt = generate_data(4, 50, 11)
self.check_centralized_distributed('GMA', y, yt, nb_pru)
def test_LCS(self):
nb_pru = 5
y, yt = generate_data(2, 50, 11)
self.check_centralized_distributed('LCS', y, yt, nb_pru)
y, yt = generate_data(4, 50, 11)
self.check_centralized_distributed('LCS', y, yt, nb_pru)