def normalize_confusion_matrix(confusion_matrix_dict: dict, normalize_index: int = 0) -> dict:
    """
    normalize a confusion matrix;

    :param confusion_matrix_dict: dict, a confusion matrix, e.g.,
        {('a', 'a'): 1, ('a', 'b'): 2, ('b', 'a'): 3, ('b', 'b'): 4};
    :param normalize_index: int, [0, 1], the position index of the confusion matrix dict key (tuple) where normalization
    is performed along;
    :return: a normalized confusion matrix;
    """
    labels = set([key[0] for key in confusion_matrix_dict.keys()])
    normalized_confusion_matrix_dict = dict()

    sum_dict = {label: 0 for label in labels}
    for condition, condition_count in confusion_matrix_dict.items():
        sum_dict[condition[normalize_index]] += condition_count

    for condition, condition_count in confusion_matrix_dict.items():
        normalized_confusion_matrix_dict[condition] = \
            condition_count / sum_dict[condition[normalize_index]] if sum_dict[condition[normalize_index]] else 0

    return normalized_confusion_matrix_dict