-
Notifications
You must be signed in to change notification settings - Fork 2
/
run_secret_sharing_vertically_linear_regression.py
70 lines (59 loc) · 2.09 KB
/
run_secret_sharing_vertically_linear_regression.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
from processes_of_clients import *
from utils_ import *
from multiprocessing import Pool
from time import gmtime, strftime
import os
def vertical_secret_sharing_linear_regression(X, y, X_test, y_test, config):
"""
Start the processes of the three clients: A, B and C.
:param X: features of the training dataset
:param y: labels of the training dataset
:param X_test: features of the test dataset
:param y_test: labels of the test dataset
:param config: the config dict
:return: True
"""
XA, XB, XA_test, XB_test = vertically_partition_data(X, X_test, config['A_idx'], config['B_idx'])
print(XA.shape, XB.shape)
p = Pool(3) # Init a pool that can run 3 processes concurrently.
p.apply_async(process_A, args=("A", XA, config))
p.apply_async(process_B, args=("B", XB, y, config))
p.apply_async(process_C, args=("C", XA.shape, XB.shape, config))
print("All process initialized")
p.close()
p.join()
print("All process done.")
return True
if __name__ == '__main__':
# Network address config
HOST = "localhost"
ADDR_A = (HOST, 4501)
ADDR_B = (HOST, 4502)
ADDR_C = (HOST, 4503)
tm = strftime("_weight_%d_%b_%H_%M_%S.txt", gmtime())
A_log_file_name = "log_file/A" + tm
B_log_file_name = "log_file/B" + tm
if not os.path.exists("log_file"):
os.makedirs("log_file")
# Do configuration
config = {
'n_clients': 1,
'key_length': 512,
'n_iter': 10000,
'lambda': 0.01,
'lr': 0.05,
# 'eta': 0.1,
'pause_time': 0.001,
'A_idx': [3, 4, 5, 6, 7, 8],
'B_idx': [0, 1, 2],
'A_log_file': A_log_file_name,
'B_log_file': B_log_file_name,
'ADDR_A': ADDR_A,
'ADDR_B': ADDR_B,
'ADDR_C': ADDR_C,
}
# Process data.
X, y, X_test, y_test = split_train_test()
print(X.shape, y.shape, X_test.shape, y_test.shape)
# perform protocol iva secret sharing only.
vertical_secret_sharing_linear_regression(X, y, X_test, y_test, config)