@@ -24,7 +24,11 @@ def factory(cfg):
24
24
cfg .expr_out = tf .compat .v1 .placeholder (tf .float32 , [None , cfg .n_x ], name = 'expr_out' )
25
25
cfg .pert = pd .read_csv (os .path .join (cfg .root_dir , cfg .pert_file ), header = None , dtype = np .float32 )
26
26
cfg .expr = pd .read_csv (os .path .join (cfg .root_dir , cfg .expr_file ), header = None , dtype = np .float32 )
27
- cfg .loo = np .vstack (np .where (cfg .pert != 0 )).T + 1
27
+ group_df = pd .DataFrame (np .where (cfg .pert != 0 ), index = ['row_id' , 'pert_idx' ]).T .groupby ('row_id' )
28
+ max_combo_degree = group_df .pert_idx .count ().max ()
29
+ cfg .loo = pd .DataFrame (group_df .pert_idx .apply (
30
+ lambda x : pad_and_realign (x , max_combo_degree , cfg .n_activity_nodes - 1 )
31
+ ).tolist ())
28
32
29
33
# add noise
30
34
if cfg .add_noise_level > 0 :
@@ -68,6 +72,12 @@ def factory(cfg):
68
72
return cfg
69
73
70
74
75
+ def pad_and_realign (x , length , idx_shift = 0 ):
76
+ x -= idx_shift
77
+ padded = np .pad (x , (0 , length - len (x )), 'constant' )
78
+ return padded
79
+
80
+
71
81
def get_tensors (cfg ):
72
82
# prepare training placeholders
73
83
cfg .l1_lambda_placeholder = tf .compat .v1 .placeholder (tf .float32 , name = 'l1_lambda' )
0 commit comments