def evaluate_fold(self, test_tensor, test_needs, idx_test): self.logEvaluationLine() binary_pred = cosinus_link_prediciton(test_tensor, test_needs, self.threshold, self.transitive_threshold, self.weighted) self.report.add_evaluation_data(self.ground_truth.getArrayFromSliceMatrix( SparseTensor.CONNECTION_SLICE, idx_test), matrix_to_array(binary_pred, idx_test)) if self.args.statistics: self.evalDetails.add_statistic_details( self.ground_truth.getSliceMatrix(SparseTensor.CONNECTION_SLICE), binary_pred, idx_test)
def predict_intersect_cosine_rescal(self, input_tensor, test_needs, idx_test, rank, rescal_threshold, cosine_threshold, useNeedTypeSlice): wants = input_tensor.getWantIndices() offers = input_tensor.getOfferIndices() # execute the cosine algorithm binary_pred_cosine = cosinus_link_prediciton(input_tensor, test_needs, cosine_threshold, 0.0, False) # execute the rescal algorithm A,R = execute_rescal(input_tensor, rank) P_bin = predict_rescal_connections_by_threshold(A, R, rescal_threshold, offers, wants, test_needs) # return the intersection of the prediction of both algorithms binary_pred_cosine = matrix_to_array(binary_pred_cosine, idx_test) binary_pred_rescal = matrix_to_array(P_bin, idx_test) binary_pred = [min(binary_pred_cosine[i], binary_pred_rescal[i]) for i in range(len(binary_pred_cosine))] return binary_pred, binary_pred_cosine, binary_pred_rescal
def predict_combine_cosine_rescal(self, input_tensor, test_needs, idx_test, rank, rescal_threshold, cosine_threshold, useNeedTypeSlice): wants = input_tensor.getWantIndices() offers = input_tensor.getOfferIndices() # execute the cosine algorithm first binary_pred_cosine = cosinus_link_prediciton(input_tensor, test_needs, cosine_threshold, 0.0, False) # use the connection prediction of the cosine algorithm as input for rescal temp_tensor = input_tensor.copy() temp_tensor.addSliceMatrix(binary_pred_cosine, SparseTensor.CONNECTION_SLICE) A,R = execute_rescal(temp_tensor, rank) P_bin = predict_rescal_connections_by_threshold(A, R, rescal_threshold, offers, wants, test_needs) # return both predictions the earlier cosine and the combined rescal binary_pred_cosine = binary_pred_cosine[idx_test] binary_pred_rescal = matrix_to_array(P_bin, idx_test) return binary_pred_cosine, binary_pred_rescal