当前位置: 首页>>代码示例>>Java>>正文


Java Vector.dot方法代码示例

本文整理汇总了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;
  }
}
 
开发者ID:saradelrio,项目名称:Chi-FRBCS-BigDataCS,代码行数:32,代码来源:TanimotoDistanceMeasure.java

示例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;
}
 
开发者ID:saradelrio,项目名称:Chi-FRBCS-BigDataCS,代码行数:24,代码来源:CosineDistanceMeasure.java

示例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;
}
 
开发者ID:SiddharthMalhotra,项目名称:sPCA,代码行数:10,代码来源:PCACommon.java

示例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();
}
 
开发者ID:saradelrio,项目名称:Chi-FRBCS-BigDataCS,代码行数:5,代码来源:SquaredEuclideanDistanceMeasure.java


注:本文中的org.apache.mahout.math.Vector.dot方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。