Exemplo n.º 1
0
 def on_epoch_end(self, epoch, logs={}):
     self.sum += time.time() - self.epoch_time_start
     if epoch < 30:
         recorder_step = 5
     elif epoch < 300:
         recorder_step = 50
     else:
         recorder_step = 150
     if epoch % recorder_step == 0:
         self.intervals.append(self.sum)
         self.sum = 0
         y_true = y_test
         y_pred = autoencoder.predict(x_test)
         pred_index, true_index = dblp_eval.find_indices(y_pred, y_true)
         self.ndcg.append(ndcg_metric(pred_index, true_index))
         self.map.append(map_metric(pred_index, true_index))
Exemplo n.º 2
0
    true_indices = []
    pred_indices = []
    x_test = np.asarray([
        x_test_record[0].todense() for x_test_record in x_test
    ]).reshape(x_test.__len__(), -1)
    y_test = np.asarray([
        y_test_record[0].todense() for y_test_record in y_test
    ]).reshape(y_test.__len__(), -1)
    with open(result_output_name, 'a+') as file:
        writer = csv.writer(file)
        for sample_x, sample_y in zip(x_test, y_test):
            start_time = time.time()
            sample_prediction = autoencoder.predict(np.asmatrix(sample_x))
            end_time = time.time()
            elapsed_time = (end_time - start_time) * 1000
            pred_index, true_index = dblp_eval.find_indices(
                sample_prediction, [sample_y])
            true_indices.append(true_index[0])
            pred_indices.append(pred_index[0])
            writer.writerow([
                method_name, k_fold, fold_counter,
                len(pred_index[0][:k_max]),
                len(true_index[0]), elapsed_time
            ] + pred_index[0][:k_max] + true_index[0])

    # print("eval on test data.")
    # prediction_test = autoencoder.predict(
    #         np.asarray([x_test_record[0].todense() for x_test_record in x_test]).reshape(x_test.__len__(), -1))
    # y_test = np.asarray([y_test_record[0].todense() for y_test_record in y_test]).reshape(y_test.__len__(), -1)
    # pred_indices, true_indices = dblp_eval.find_indices(prediction_test, y_test)
    # for k in evaluation_k_set:
    #     # r@k evaluation