| 204 | } |
| 205 | |
| 206 | double |
| 207 | distAngle(const MappedColumnVector& inX, const MappedColumnVector& inY) { |
| 208 | if (inX.size() != inY.size()) { |
| 209 | throw std::runtime_error("Found input arrays of " |
| 210 | "different lengths unexpectedly."); |
| 211 | } |
| 212 | |
| 213 | // Deal with the undefined case where one of the norm is zero |
| 214 | // Angle is not defined. Just return \pi. |
| 215 | double xnorm = inX.norm(), ynorm = inY.norm(); |
| 216 | if (xnorm < std::numeric_limits<double>::denorm_min() |
| 217 | || ynorm < std::numeric_limits<double>::denorm_min()) |
| 218 | return std::acos(-1); |
| 219 | |
| 220 | double cosine = dot(inX, inY) / (xnorm * ynorm); |
| 221 | if (cosine > 1) |
| 222 | cosine = 1; |
| 223 | else if (cosine < -1) |
| 224 | cosine = -1; |
| 225 | return std::acos(cosine); |
| 226 | } |
| 227 | |
| 228 | double |
| 229 | distTanimoto(const MappedColumnVector& inX, const MappedColumnVector& inY) { |