本文整理汇总了Java中cc.mallet.types.SparseVector.dotProduct方法的典型用法代码示例。如果您正苦于以下问题:Java SparseVector.dotProduct方法的具体用法?Java SparseVector.dotProduct怎么用?Java SparseVector.dotProduct使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cc.mallet.types.SparseVector
的用法示例。
在下文中一共展示了SparseVector.dotProduct方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: distance
import cc.mallet.types.SparseVector; //导入方法依赖的package包/类
public double distance( SparseVector a, int hashCodeA,
SparseVector b, int hashCodeB) {
Double cachedA = (Double) hash.get (new Integer (hashCodeA));
Double cachedB = (Double) hash.get (new Integer (hashCodeB));
if (a == null || b == null)
return 1.0;
if (cachedA == null) {
cachedA = new Double (a.dotProduct (a));
hash.put (new Integer (hashCodeA), cachedA);
}
if (cachedB == null) {
cachedB = new Double (b.dotProduct (b));
hash.put (new Integer (hashCodeB), cachedB);
}
double ab = a.dotProduct (b);
if (cachedA == null || cachedB == null) {
throw new IllegalStateException ("cachedValues null");
}
double ret = a.dotProduct (b) / Math.sqrt (cachedA.doubleValue()*cachedB.doubleValue());
return 1.0 - ret;
}
示例2: testDenseSparseVector
import cc.mallet.types.SparseVector; //导入方法依赖的package包/类
public void testDenseSparseVector ()
{
SparseVector svDense = new SparseVector (null, dbl3);
double sdot = svDense.dotProduct (svDense);
double ddot = d1.dotProduct (d1);
assertEquals (sdot, ddot, 0.0001);
svDense.plusEqualsSparse (s1);
checkAnswer (svDense, new double[] { 2.0, 2.5, 3.0, 5.7, 3.5,
5.6, 0, 3, 0, 0,
0, 0, 0, 4, 0,
5, });
svDense.plusEqualsSparse (s1, 2.0);
checkAnswer (svDense, new double[] { 2.0, 2.5, 3.0, 7.7, 3.5,
9.6, 0, 9, 0, 0,
0, 0, 0, 12, 0,
15, });
double[] dbl4 = new double [dbl3.length + 1];
for (int i = 0; i < dbl4.length; i++) dbl4[i] = 2.0;
SparseVector sv4 = new SparseVector (null, dbl4);
svDense.plusEqualsSparse (sv4);
checkAnswer (svDense, new double[] { 4.0, 4.5, 5.0, 9.7, 5.5,
11.6, 2.0, 11.0, 2.0, 2.0,
2, 2, 2, 14, 2.0,
17, });
}
示例3: testExtendedDotProduct
import cc.mallet.types.SparseVector; //导入方法依赖的package包/类
public void testExtendedDotProduct () {
SparseVector v1 = new SparseVector (null, dbl3);
SparseVector vInf = new SparseVector (null, dbl4);
double dp = v1.dotProduct (vInf);
assertTrue (!Double.isNaN(dp));
dp = vInf.dotProduct (v1);
assertTrue (!Double.isNaN(dp));
}