Skip to content

Commit

Permalink
Merge pull request #118 from vitrivr/fix/cosineDistance
Browse files Browse the repository at this point in the history
Changed cosine similarity to cosine distance
  • Loading branch information
ppanopticon authored May 8, 2022
2 parents ce72ef8 + 96051c6 commit 83a6c47
Showing 1 changed file with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ sealed class CosineDistance<T : VectorValue<*>>(type: Types.Vector<T,*>): Vector
normq += query.data[i].pow(2)
normv += probing.data[i].pow(2)
}
return DoubleValue(dotp / (sqrt(normq) * sqrt(normv)))
return DoubleValue(1.0 - (dotp / (sqrt(normq) * sqrt(normv))))
}
override fun copy(d: Int) = DoubleVector(Types.DoubleVector(d))
}
Expand All @@ -92,7 +92,7 @@ sealed class CosineDistance<T : VectorValue<*>>(type: Types.Vector<T,*>): Vector
normq += query.data[i].pow(2)
normv += probing.data[i].pow(2)
}
return DoubleValue(dotp / (sqrt(normq) * sqrt(normv)))
return DoubleValue(1.0 - (dotp / (sqrt(normq) * sqrt(normv))))
}
override fun copy(d: Int) = FloatVector(Types.FloatVector(d))
}
Expand All @@ -113,7 +113,7 @@ sealed class CosineDistance<T : VectorValue<*>>(type: Types.Vector<T,*>): Vector
normq += query.data[i].toDouble().pow(2)
normv += probing.data[i].toDouble().pow(2)
}
return DoubleValue(dotp / (sqrt(normq) * sqrt(normv)))
return DoubleValue(1L - (dotp / (sqrt(normq) * sqrt(normv))))
}
override fun copy(d: Int) = LongVector(Types.LongVector(d))
}
Expand All @@ -134,7 +134,7 @@ sealed class CosineDistance<T : VectorValue<*>>(type: Types.Vector<T,*>): Vector
normq += query.data[i].toDouble().pow(2)
normv += probing.data[i].toDouble().pow(2)
}
return DoubleValue(dotp / (sqrt(normq) * sqrt(normv)))
return DoubleValue(1 - (dotp / (sqrt(normq) * sqrt(normv))))
}
override fun copy(d: Int) = IntVector(Types.IntVector(d))
}
Expand Down

0 comments on commit 83a6c47

Please sign in to comment.