def predict_single_input_multiclass()

in src/ppxgboost/PPBooster.py [0:0]


def predict_single_input_multiclass(trees, num_classes, vector):
    """
    return a prediction on a single input vector.
    The algorithm computes the sum of scores for all the corresponding classes (boosters in the xgboost model).
    For each class, it sum up all the leaves' values
    :param trees: a list of trees (model representation)
    :param num_classes: the total number classes to classify
    :param vector: a single input vector
    :return: the predicted score
    """
    num_trees = len(trees)

    # sum of score for each category: exp(score)
    result = []
    for i in range(num_classes):
        result.append(0)

    # this is to compute the softmax, however, server can only perform additvely homo operation,
    # so here we can compute scores seperately
    for i in range(num_trees):
        score = trees[i].eval(vector)

        result[i % num_classes] += score
    # return the result as a list (contains all of the scores for each labels).
    return result