import torch import torch.nn.functional as F from torch.autograd import Variable from sklearn.metrics import mean_absolute_error import sys sys.path.append('../') from data import * from train import * from args import Args def test_mlp(x_batch, y_len_unsorted, epoch, args, rnn, output, test_batch_size=32, save_histogram=False,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() incompleteness_ratio = 0.96 for j in range(test_batch_size): incomplete_graph_size = int(int(y_len_unsorted.data[j]) * incompleteness_ratio) # print(y_len_unsorted.data[j]) 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