org.apache.mahout.math.Vector.times()方法的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(6.1k)|赞(0)|评价(0)|浏览(113)

本文整理了Java中org.apache.mahout.math.Vector.times()方法的一些代码示例,展示了Vector.times()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Vector.times()方法的具体详情如下:
包路径:org.apache.mahout.math.Vector
类名称:Vector
方法名:times

Vector.times介绍

[英]Return a new vector containing the product of each value of the recipient and the argument
[中]返回一个新向量,该向量包含接收者的每个值与参数的乘积

代码示例

代码示例来源:origin: apache/mahout

@Override
public Vector precondition(Vector v) {
 return v.times(inverseDiagonal);
}

代码示例来源:origin: apache/mahout

@Override
public Vector times(double x) {
 return delegate.times(x);
}

代码示例来源:origin: apache/mahout

@Override
public Vector times(Vector x) {
 return delegate.times(x);
}

代码示例来源:origin: apache/mahout

@Override
public Vector times(Vector x) {
 return delegate.times(x);
}

代码示例来源:origin: apache/mahout

@Override
public Vector times(double x) {
 return delegate.times(x);
}

代码示例来源:origin: apache/mahout

private Vector localVOrtho(Vector v) {
 for (Vector old : localV) {
  if (old != null) {
   double x = v.dot(old);
   v = v.minus(old.times(x));
  }
 }
 return v;
}

代码示例来源:origin: apache/mahout

@Override
public Matrix cross(Vector other) {
 Matrix result = matrixLike(size, other.size());
 Iterator<Vector.Element> it = iterateNonZero();
 while (it.hasNext()) {
  Vector.Element e = it.next();
  int row = e.index();
  result.assignRow(row, other.times(getQuick(row)));
 }
 return result;
}

代码示例来源:origin: apache/mahout

@Override
public Matrix timesRight(Matrix that) {
 if (that.numRows() != diagonal.size()) {
  throw new IllegalArgumentException("Incompatible number of rows in the right operand of matrix multiplication.");
 }
 Matrix m = that.like();
 for (int row = 0; row < diagonal.size(); row++) {
  m.assignRow(row, that.viewRow(row).times(diagonal.getQuick(row)));
 }
 return m;
}

代码示例来源:origin: apache/mahout

@Override
public Matrix timesLeft(Matrix that) {
 if (that.numCols() != diagonal.size()) {
  throw new IllegalArgumentException(
   "Incompatible number of rows in the left operand of matrix-matrix multiplication.");
 }
 Matrix m = that.like();
 for (int col = 0; col < diagonal.size(); col++) {
  m.assignColumn(col, that.viewColumn(col).times(diagonal.getQuick(col)));
 }
 return m;
}

代码示例来源:origin: apache/mahout

/** Y' Cu p(u) */
private Matrix getYtransponseCuPu(Vector userRatings) {
 Preconditions.checkArgument(userRatings.isSequentialAccess(), "need sequential access to ratings!");
 Vector YtransponseCuPu = new DenseVector(numFeatures);
 for (Element e : userRatings.nonZeroes()) {
  YtransponseCuPu.assign(Y.get(e.index()).times(confidence(e.get())), Functions.PLUS);
 }
 return columnVectorAsMatrix(YtransponseCuPu);
}

代码示例来源:origin: apache/mahout

u = A.times(v).minus(u.times(alpha));
beta = u.norm(2);
if (beta > 0) {
  localVEnqueue(v);
 v = transposedA.times(u).minus(v.times(beta));
hbar = h.minus(hbar.times(thetabar * rho / (rhoold * rhobarold)));
x.assign(hbar.times(zeta / (rho * rhobar)), Functions.PLUS);
h = v.minus(h.times(thetanew / rho));

代码示例来源:origin: apache/mahout

@Test(expected = CardinalityException.class)
public void testTimesVectorCardinality() {
 test.times(new DenseVector(test.size() + 1));
}

代码示例来源:origin: apache/mahout

@Test(expected = CardinalityException.class)
public void testTimesVectorCardinality() {
 test.times(new DenseVector(test.size() + 1));
}

代码示例来源:origin: apache/mahout

/** Y' (Cu - I) Y + λ I */
private Matrix getYtransponseCuMinusIYPlusLambdaI(Vector userRatings) {
 Preconditions.checkArgument(userRatings.isSequentialAccess(), "need sequential access to ratings!");
 /* (Cu -I) Y */
 OpenIntObjectHashMap<Vector> CuMinusIY = new OpenIntObjectHashMap<>(userRatings.getNumNondefaultElements());
 for (Element e : userRatings.nonZeroes()) {
  CuMinusIY.put(e.index(), Y.get(e.index()).times(confidence(e.get()) - 1));
 }
 Matrix YtransponseCuMinusIY = new DenseMatrix(numFeatures, numFeatures);
 /* Y' (Cu -I) Y by outer products */
 for (Element e : userRatings.nonZeroes()) {
  for (Vector.Element feature : Y.get(e.index()).all()) {
   Vector partial = CuMinusIY.get(e.index()).times(feature.get());
   YtransponseCuMinusIY.viewRow(feature.index()).assign(partial, Functions.PLUS);
  }
 }
 /* Y' (Cu - I) Y + λ I  add lambda on the diagonal */
 for (int feature = 0; feature < numFeatures; feature++) {
  YtransponseCuMinusIY.setQuick(feature, feature, YtransponseCuMinusIY.getQuick(feature, feature) + lambda);
 }
 return YtransponseCuMinusIY;
}

代码示例来源:origin: apache/mahout

@Test
public void testTimesVector() throws Exception {
 Vector val = test.times(test);
 assertEquals("size", 3, val.size());
 for (int i = 0; i < test.size(); i++) {
  assertEquals("get [" + i + ']', values[OFFSET + i] * values[OFFSET + i],
    val.get(i), EPSILON);
 }
}

代码示例来源:origin: apache/mahout

@Test
public void testTimesDouble() throws Exception {
 Vector val = test.times(3);
 assertEquals("size", 3, val.size());
 for (int i = 0; i < test.size(); i++) {
  assertEquals("get [" + i + ']', values[OFFSET + i] * 3, val.get(i), EPSILON);
 }
}

代码示例来源:origin: apache/mahout

@Test
public void testTimesVector() {
 Vector val = test.times(test);
 assertEquals("size", test.size(), val.size());
 for (int i = 0; i < test.size(); i++) {
  if (i % 2 == 0) {
   assertEquals("get [" + i + ']', 0.0, val.get(i), EPSILON);
  } else {
   assertEquals("get [" + i + ']', values[i/2] * values[i/2], val.get(i), EPSILON);
  }
 }
}

代码示例来源:origin: apache/mahout

@Test
public void testTimesDouble() {
 Vector val = test.times(3);
 assertEquals("size", test.size(), val.size());
 for (int i = 0; i < test.size(); i++) {
  if (i % 2 == 0) {
   assertEquals("get [" + i + ']', 0.0, val.get(i), EPSILON);
  } else {
   assertEquals("get [" + i + ']', values[i/2] * 3.0, val.get(i), EPSILON);
  }
 }
}

代码示例来源:origin: apache/mahout

assertEquals(0, dv1.plus(dv2).getDistanceSquared(sv1.plus(v2)), FUZZ);
assertEquals(0, dv1.times(dv2).getDistanceSquared(v1.times(v2)), FUZZ);
assertEquals(0, dv1.times(dv2).getDistanceSquared(v1.times(dv2)), FUZZ);
assertEquals(0, dv1.times(dv2).getDistanceSquared(v1.times(sv2)), FUZZ);
assertEquals(0, dv1.times(dv2).getDistanceSquared(sv1.times(v2)), FUZZ);
assertEquals(0, dv1.times(z).getDistanceSquared(v1.times(z)), 1.0e-12);
assertEquals(0, dv1.plus(z).getDistanceSquared(v1.plus(z)), 1.0e-12);

代码示例来源:origin: apache/mahout

assertEquals("mutation via normalize(double) fails to change lengthSquared", expected, v.getLengthSquared(), EPSILON);
v.times(2.0);
expected = lengthSquaredSlowly(v);
assertEquals("mutation via times(double) fails to change lengthSquared", expected, v.getLengthSquared(), EPSILON);
v.times(v);
expected = lengthSquaredSlowly(v);
assertEquals("mutation via times(vector) fails to change lengthSquared", expected, v.getLengthSquared(), EPSILON);

相关文章