from sklearn.metrics import mean_absolute_error import sys sys.path.append('../') from train import * from args import Args from GraphCompletion.graph_completion_with_training import graph_show from GraphCompletion.graph_show import graph_save def test_completion(x_batch, y_len_unsorted, args, rnn, output, test_batch_size=32, sample_time=1): rnn.hidden = rnn.init_hidden(1) rnn.eval() output.eval() # generate graphs max_num_node = int(args.max_num_node) y_pred = Variable( torch.zeros(test_batch_size, max_num_node, args.max_prev_node)).cuda() # normalized prediction score y_pred_long = Variable(torch.zeros(test_batch_size, max_num_node, args.max_prev_node)).cuda() # discrete prediction x_step = Variable(torch.ones(1, 1, args.max_prev_node)).cuda() # number_of_missing_nodes = args.number_of_missing_nodes number_of_missing_nodes = 2 for j in range(test_batch_size): incomplete_graph_size = y_len_unsorted.data[j] - number_of_missing_nodes for i in range(y_len_unsorted.data[j]-1): h = rnn(x_step) y_pred_step = output(h) y_pred[j:j+1, i:i + 1, :] = F.sigmoid(y_pred_step) if(i