示例#1
0
文件: metric.cpp 项目: haradh1/madlib
double
squaredAngle(
    const MappedColumnVector& inX,
    const MappedColumnVector& inY) {

    double cosine = dot(inX, inY) / (inX.norm() * inY.norm());
    if (cosine > 1)
        cosine = 1;
    else if (cosine < -1)
        cosine = -1;
    double angle = std::acos(cosine);
    return angle * angle;
}
示例#2
0
文件: metric.cpp 项目: 0x0all/madlib
double
distAngle(
    const MappedColumnVector& inX,
    const MappedColumnVector& inY) {

	// Deal with the undefined case where one of the norm is zero
	// Angle is not defined. Just return \pi.
	double xnorm = inX.norm(), ynorm = inY.norm();
	if (xnorm < std::numeric_limits<double>::denorm_min()
		|| ynorm < std::numeric_limits<double>::denorm_min())
		return std::acos(-1);
	
    double cosine = dot(inX, inY) / (xnorm * ynorm);
    if (cosine > 1)
        cosine = 1;
    else if (cosine < -1)
        cosine = -1;
    return std::acos(cosine);
}