forked from ioanabica/HTCE-learners
-
Notifications
You must be signed in to change notification settings - Fork 0
/
learners.py
124 lines (118 loc) · 3.58 KB
/
learners.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
import contrib.catenets.models as cate_models
from htce_learners.htce_one_step_learners import (
HTCE_SLearner,
HTCE_TARNet,
HTCE_TLearner,
)
from htce_learners.htce_two_step_learners import HTCE_DRLearner
def get_flex_transfer_learner(name, X_shared_size, X_source_specific_size, X_target_specific_size, binary_Y, n_iter):
transfer_learner = {
"TLearner": HTCE_TLearner(
"TLearner",
n_unit_in_shared=X_shared_size,
n_unit_in_source_specific=X_source_specific_size,
n_unit_in_target_specific=X_target_specific_size,
binary_y=binary_Y,
batch_size=128,
n_iter=n_iter,
nonlin="relu",
),
"SLearner": HTCE_SLearner(
"SLearner",
n_unit_in_shared=X_shared_size,
n_unit_in_source_specific=X_source_specific_size,
n_unit_in_target_specific=X_target_specific_size,
binary_y=binary_Y,
batch_size=128,
n_iter=n_iter,
nonlin="relu",
),
"TARNet": HTCE_TARNet(
"TARNet",
n_unit_in_shared=X_shared_size,
n_unit_in_source_specific=X_source_specific_size,
n_unit_in_target_specific=X_target_specific_size,
binary_y=binary_Y,
n_units_r=100,
batch_size=128,
n_iter=n_iter,
nonlin="relu",
),
"DRLearner": HTCE_DRLearner(
"DRLearner",
n_unit_in_shared=X_shared_size,
n_unit_in_source_specific=X_source_specific_size,
n_unit_in_target_specific=X_target_specific_size,
binary_y=binary_Y,
batch_size=128,
n_iter=n_iter,
nonlin="relu",
),
}
return transfer_learner[name]
def get_learner(name, X_size, binary_Y, n_iter):
learners = {
"TLearner": cate_models.torch.TLearner(
X_size,
binary_y=binary_Y,
n_layers_out=5,
n_units_out=100,
batch_size=128,
n_iter=n_iter,
batch_norm=False,
nonlin="relu",
),
"SLearner": cate_models.torch.SLearner(
X_size,
binary_y=binary_Y,
n_layers_out=5,
n_units_out=100,
n_iter=n_iter,
batch_size=128,
batch_norm=False,
nonlin="relu",
),
"TARNet": cate_models.torch.TARNet(
X_size,
binary_y=binary_Y,
n_layers_r=2,
n_layers_out=3,
n_units_out=100,
n_units_r=100,
batch_size=128,
n_iter=n_iter,
batch_norm=False,
nonlin="relu",
),
"DRLearner": cate_models.torch.DRLearner(
X_size,
binary_y=binary_Y,
n_layers_out=5,
n_units_out=100,
batch_size=128,
n_iter=n_iter,
batch_norm=False,
nonlin="relu",
),
"PWLearner": cate_models.torch.PWLearner(
X_size,
binary_y=binary_Y,
n_layers_out=5,
n_units_out=100,
batch_size=128,
n_iter=n_iter,
batch_norm=False,
nonlin="relu",
),
"RALearner": cate_models.torch.RALearner(
X_size,
binary_y=binary_Y,
n_layers_out=5,
n_units_out=100,
batch_size=128,
n_iter=n_iter,
batch_norm=False,
nonlin="relu",
),
}
return learners[name]