本文整理汇总了Java中org.apache.mahout.math.Vector.minus方法的典型用法代码示例。如果您正苦于以下问题:Java Vector.minus方法的具体用法?Java Vector.minus怎么用?Java Vector.minus使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.mahout.math.Vector
的用法示例。
在下文中一共展示了Vector.minus方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: observe
import org.apache.mahout.math.Vector; //导入方法依赖的package包/类
@Override
public void observe(Vector x, double weight) {
double temp = weight + sumWeight;
Vector q;
if (mean == null) {
mean = x.like();
q = x.clone();
} else {
q = x.minus(mean);
}
Vector r = q.times(weight).divide(temp);
if (s == null) {
s = q.times(sumWeight).times(r);
} else {
s = s.plus(q.times(sumWeight).times(r));
}
mean = mean.plus(r);
sumWeight = temp;
variance = s.divide(sumWeight - 1); // # if sample is the population, omit -1
}
示例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 result = 0.0;
Vector vector = v1.minus(v2);
Iterator<Vector.Element> iter = vector.iterateNonZero();
while (iter.hasNext()) {
Vector.Element e = iter.next();
double d = Math.abs(e.get());
if (d > result) {
result = d;
}
}
return result;
}
示例3: 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 result = 0;
Vector vector = v1.minus(v2);
Iterator<Vector.Element> iter = vector.iterateNonZero();
// this contains all non zero elements between the two
while (iter.hasNext()) {
Vector.Element e = iter.next();
result += Math.abs(e.get());
}
return result;
}
示例4: distance
import org.apache.mahout.math.Vector; //导入方法依赖的package包/类
/**
* Math.pow is clever about integer-valued doubles
*/
@Override
public double distance(Vector v1, Vector v2) {
Vector distVector = v1.minus(v2);
double sum = 0.0;
Iterator<Element> it = distVector.iterateNonZero();
while (it.hasNext()) {
Element e = it.next();
sum += Math.pow(Math.abs(e.get()), exponent);
}
return Math.pow(sum, 1.0 / exponent);
}