@@ -43,28 +43,6 @@ def reward_nco(sample_solution, use_KT, use_cuda=False):
43
43
else :
44
44
return - reward_ddpg_C (solutions .permute (1 , 2 , 0 ), use_cuda , True )
45
45
46
- def reward_gcn (solution , use_cuda ):
47
- """
48
- solution is FloatTensor of dim [1,n]
49
- """
50
- sourceL = solution .size ()[1 ]
51
-
52
- longest = Variable (torch .ones (1 ), requires_grad = False )
53
- current = Variable (torch .ones (1 ), requires_grad = False )
54
- random_baseline = Variable (torch .FloatTensor ([0.3 ]))
55
- if use_cuda :
56
- longest = longest .cuda ()
57
- current = current .cuda ()
58
- random_baseline = random_baseline .cuda ()
59
- for i in range (1 , sourceL ):
60
- res = torch .lt (solution [0 , i - 1 ], solution [0 , i ])
61
- current += res .float ()
62
- current [torch .eq (res , 0 )] = 1
63
- mask = torch .gt (current , longest )
64
- longest [mask ] = current [mask ]
65
-
66
- return torch .div (longest , sourceL )
67
-
68
46
def reward_ddpg_A (solution , use_cuda ):
69
47
"""
70
48
Count number of consecutively correctly sorted for each sample in minibatch
@@ -143,6 +121,9 @@ def reward_ddpg_C(solution, use_cuda, nco=False):
143
121
return torch .div (longest , m )
144
122
145
123
def reward_ddpg_D (solution , use_cuda ):
124
+ """
125
+ Kendall-Tau correlation coefficient
126
+ """
146
127
(batch_size , n , m ) = solution .size ()
147
128
if use_cuda :
148
129
solution = solution .data .cpu ().numpy ()
@@ -279,42 +260,3 @@ def __len__(self):
279
260
280
261
def __getitem__ (self , idx ):
281
262
return self .data_set [idx ]
282
-
283
- if __name__ == '__main__' :
284
- if int (sys .argv [1 ]) == 0 :
285
- sample = Variable (torch .Tensor ([[3 , 2 , 1 , 4 , 5 ]]))
286
- #sample = [Variable(torch.Tensor([3,2])), Variable(torch.Tensor([2,3])), Variable(torch.Tensor([1,5])),
287
- # Variable(torch.Tensor([4, 1])), Variable(torch.Tensor([5, 4]))]
288
- answer = torch .Tensor ([3 / 5. ])
289
-
290
- res = reward_no_batch (sample , False )
291
-
292
- print ('Expected answer: {}, Actual answer: {}' .format (answer , res .data ))
293
- """
294
- sample = Variable(torch.Tensor([[1, 2, 3, 4, 5], [5, 4, 3, 2, 1]]))
295
- answer = torch.Tensor([1., 1/5])
296
-
297
- res = reward(sample)
298
-
299
- print('Expected answer: {}, Actual answer: {}'.format(answer, res.data))
300
-
301
- sample = Variable(torch.Tensor([[1, 2, 5, 4, 3], [4, 1, 2, 3, 5]]))
302
- answer = torch.Tensor([3/5., 4/5])
303
-
304
- res = reward(sample)
305
-
306
- print('Expected answer: {}, Actual answer: {}'.format(answer, res.data))
307
- """
308
- elif int (sys .argv [1 ]) == 1 :
309
- data_dir = '/home/pemami/Workspace/deep-assign/data/sort/icml2018'
310
- N = [10 , 15 , 20 , 25 ]
311
- for n in N :
312
- create_dataset (500000 , 10000 , data_dir , 666 , 0 , n - 1 , True , 3 )
313
-
314
- elif int (sys .argv [1 ]) == 2 :
315
-
316
- sorting_data = SortingDataset ('data' , 'sorting-size-1000-len-10-train.txt' ,
317
- 'sorting-size-100-len-10-val.txt' )
318
- for i in range (len (sorting_data )):
319
- print (sorting_data [i ])
320
-
0 commit comments