Skip to content

Possible miscalc in OptimalCosineDistance #4

Closed
britg opened this Issue Feb 3, 2013 · 0 comments

1 participant

@britg
Owner
britg commented Feb 3, 2013

I am writing to you since we found a typo in the OptimalCosineDistance function. There is a minus instead of a plus sign (in the commented line):

float OptimalCosineDistance(FloatArrayContainer v1, FloatArrayContainer v2) {
    float a = 0.0;
    float b = 0.0;
    float angle;
    float score;

    int mincount = (v1.itemCount < v2.itemCount ? v1.itemCount : v2.itemCount);

    for (int ii = 0; ii < mincount; ii+=2) {
        a += v1.items[ii] * v2.items[ii] + v1.items[ii+1] * v2.items[ii+1];
//      b += v1.items[ii] * v2.items[ii+1] + v1.items[ii+1] * v2.items[ii];
        b += v1.items[ii] * v2.items[ii+1] - v1.items[ii+1] * v2.items[ii];
    }

    angle = atanf( b / a );
    score = acosf(a * cos(angle) + b * sin(angle));

    return score;
}

This made the predictions far more accurate. Thought I'd let you know =)

@britg britg was assigned Feb 3, 2013
@britg britg closed this in 00f0ba3 Feb 3, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.