@staticmethod
def normalize_one(xi, learner_param, idf):
    """
        The maximum index of xi should be less
        or equal to the weight vector size.
        """
    norm = 0
    word_count = 0
    i = 0
    while xi[i].index != -1:
        idx = xi[i].index - 1
        if learner_param.binary_feature:
            xi[i].value = xi[i].value != 0
        word_count += abs(xi[i].value)
        if learner_param.inverse_document_frequency and idx < len(idf):
            xi[i].value *= idf[idx]
        norm += xi[i].value * xi[i].value
        i += 1
    norm **= 0.5
    if learner_param.term_frequency:
        i = 0
        while xi[i].index != -1:
            xi[i].value /= word_count
            i += 1
    if learner_param.inst_normalization:
        i = 0
        while xi[i].index != -1:
            xi[i].value /= norm
            i += 1
