import config, vector, util

V def WED(Vector *v, Vector *v2, V *weights):
    """
    Weighted Euclidean Distance.
    """
    V sdistance = 0
    int n = v->count
    for int i = 0; i < n; i++:
        V x = *(V *)vector_get(v, i)
        V xi = *(V *)vector_get(v2, i)
        V d = (x - xi) * (x - xi)

        if weights: d *= weights[i]
        sdistance += d

    sdistance /= n

    sdistance /= 1 + sdistance # Force into 0..1

    return sdistance