def calc_cost(cl1_len, cl2_len, num_cl1, num_cl2):
    """
    Assign a cost to a pattern based on if the majority of its occurances are observed
    in regions of a time series that are annotated with the same binary label.
    The cost calculation takes into account a possible difference in the total lengths of the segments.


    Args:
        cl1_len: Total length of the time series that belong to the class 1.
        cl2_len: Total length of the time series that belong to the class 2.
        num_cl1: Number of occurances of the pattern in regions that belong to cl1.
        num_cl2: Number of occurances of the pattern in regions that belong to cl2.

    Return: The label name of the region that the pattern is contained in, as well as the normalized number of
            occurences.
    """

    if (num_cl1 + num_cl2 <= 2):
        return 1.0, None, None
    if (cl1_len == 0 or cl2_len == 0):
        return 1.0, None, None
    f = cl1_len / cl2_len
    norm_cl1 = num_cl1 / f
    norm_cl2 = num_cl2
    cost = 1 - (abs(norm_cl1 - norm_cl2) / (norm_cl1 + norm_cl2))
    return cost, norm_cl1, norm_cl2