예제 #1
0
파일: screen.py 프로젝트: ubccr/cockatoo
def distance(screen1, screen2, weights):
    """
    Compute the distance between two screens (from Newman et al. 2010).

    :param screen screen1: First screen
    :param screen screen2: Second screen
    :param array weights: weights

    :returns: The distance score between 0 and 1
        
    """
    sum1 = 0.0
    for c1 in screen1.cocktails:
        mini = 100000000
        for c2 in screen2.cocktails:
            distance = metric.distance(c1, c2, weights)
            if mini > distance:
                mini = distance
        sum1 += mini

    sum2 = 0.0
    for c1 in screen2.cocktails:
        mini = 100000000
        for c2 in screen1.cocktails:
            distance = metric.distance(c1, c2, weights)
            if mini > distance:
                mini = distance
        sum2 += mini

    score = ( (sum1/float(len(screen1))) + (sum2/float(len(screen2))) )/2.0
    return score
예제 #2
0
파일: screen.py 프로젝트: ubccr/cockatoo
def internal_similarity(s, weights):
    """
    Compute the internal diversity within a screen (from Newman et al. 2010).

    :param screen s: The screen
    :param array weights: weights

    :returns: The diversity score between 0 and 1
        
    """
    sum_avg = 0
    for c1 in s.cocktails:
        isum = 0
        n = 0
        for c2 in s.cocktails:
            isum += metric.distance(c1, c2, weights)
            n += 1

        sum_avg += isum / n

    return sum_avg / len(s)