本文整理汇总了Java中org.apache.mahout.math.Vector.dot方法的典型用法代码示例。如果您正苦于以下问题:Java Vector.dot方法的具体用法?Java Vector.dot怎么用?Java Vector.dot使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.mahout.math.Vector
的用法示例。
在下文中一共展示了Vector.dot方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: distance
import org.apache.mahout.math.Vector; //导入方法依赖的package包/类
/**
* Calculates the distance between two vectors.
*
* The coefficient (a measure of similarity) is: T(a, b) = a.b / (|a|^2 + |b|^2 - a.b)
*
* The distance d(a,b) = 1 - T(a,b)
*
* @return 0 for perfect match, > 0 for greater distance
*/
@Override
public double distance(Vector a, Vector b) {
double ab;
double denominator;
if (getWeights() != null) {
ab = dot(b, a); // b is SequentialAccess
denominator = dot(a, a) + dot(b, b) - ab;
} else {
ab = b.dot(a); // b is SequentialAccess
denominator = a.getLengthSquared() + b.getLengthSquared() - ab;
}
if (denominator < ab) { // correct for fp round-off: distance >= 0
denominator = ab;
}
if (denominator > 0) {
// denom == 0 only when dot(a,a) == dot(b,b) == dot(a,b) == 0
return 1.0 - ab / denominator;
} else {
return 0.0;
}
}
示例2: distance
import org.apache.mahout.math.Vector; //导入方法依赖的package包/类
@Override
public double distance(Vector v1, Vector v2) {
if (v1.size() != v2.size()) {
throw new CardinalityException(v1.size(), v2.size());
}
double lengthSquaredv1 = v1.getLengthSquared();
double lengthSquaredv2 = v2.getLengthSquared();
double dotProduct = v2.dot(v1);
double denominator = Math.sqrt(lengthSquaredv1) * Math.sqrt(lengthSquaredv2);
// correct for floating-point rounding errors
if (denominator < dotProduct) {
denominator = dotProduct;
}
// correct for zero-vector corner case
if (denominator == 0 && dotProduct == 0) {
return 1;
}
return 1.0 - dotProduct / denominator;
}
示例3: sparseVectorTimesMatrix
import org.apache.mahout.math.Vector; //导入方法依赖的package包/类
static Vector sparseVectorTimesMatrix(Vector vector, Matrix matrix,
DenseVector resVector) {
int nCols = matrix.numCols();
for (int c = 0; c < nCols; c++) {
Double resDouble = vector.dot(matrix.viewColumn(c));
resVector.set(c, resDouble);
}
return resVector;
}
示例4: distance
import org.apache.mahout.math.Vector; //导入方法依赖的package包/类
@Override
public double distance(double centroidLengthSquare, Vector centroid, Vector v) {
return centroidLengthSquare - 2 * v.dot(centroid) + v.getLengthSquared();
}