def calculate_distance(a,b,data):
    """ Calculates the distance between two instances in the dataset.  Handles discrete and continuous attributes. Continuous attributes are accomodated
    by scaling the distance difference within the context of the observed attribute range. If a respective data point is missing from either instance, it is left out 
    of the distance calculation. """
    d=0 #distance
    for i in range(data.numAttributes):
        if a[i]!=data.labelMissingData and b[i]!=data.labelMissingData: 
            if not data.attributeInfo[i][0]: #Discrete Attribute
                if a[i] != b[i]:
                    d+=1
            else: #Continuous Attribute
                min_bound=float(data.attributeInfo[i][1][0])
                max_bound=float(data.attributeInfo[i][1][1])
                d+=abs(float(a[i])-float(b[i]))/float(max_bound-min_bound) #Kira & Rendell, 1992 -handling continiuous attributes
    return d