14 template <
typename Type>
15 static double dotProduct(
const std::vector<Type>& a,
const std::vector<Type>& b) {
18 for (std::size_t i = 0; i < a.size(); ++i) {
19 result += a[i] * b[i];
24 template <
typename Type>
25 static double magnitude(
const std::vector<Type>& v) {
27 for (
double value : v) {
28 result += value * value;
33 template <
typename Type>
34 static double cosineSimilarity(
const std::vector<Type>& a,
const std::vector<Type>& b) {
35 double dotProd = dotProduct(a, b);
36 double magA = magnitude(a);
37 double magB = magnitude(b);
38 if(magA == 0 && magB == 0) {
41 else if (magA == 0 || magB == 0) {
45 return dotProd / (magA * magB);
Definition: exceptions.hpp:15