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

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

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

Vector.getQuick介绍

[英]Return the value at the given index, without checking bounds
[中]返回给定索引处的值,不检查边界

代码示例

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

/**
 * Return the value at the given index, without checking bounds
 *
 * @param index an int index
 * @return the double at the index
 */
@Override
public double getQuick(int index) {
 return vector.getQuick(pivot[index]);
}

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

static Matrix createMiIi(Iterable<Vector> featureVectors, int numFeatures) {
 double[][] MiIi =  new double[numFeatures][Iterables.size(featureVectors)];
 int n = 0;
 for (Vector featureVector : featureVectors) {
  for (int m = 0; m < numFeatures; m++) {
   MiIi[m][n] = featureVector.getQuick(m);
  }
  n++;
 }
 return new DenseMatrix(MiIi, true);
}

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

@Override
public double getQuick(int row, int column) {
 Vector r = rowVectors.get(row);
 return r == null ? 0.0 : r.getQuick(column);
}

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

@Override
 public Vector assign(Vector x, Vector y, DoubleDoubleFunction f) {
  for (int i = 0; i < x.size(); ++i) {
   x.setQuick(i, f.apply(x.getQuick(i), y.getQuick(i)));
  }
  return x;
 }
}

代码示例来源: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 Vector assign(Vector x, Vector y, DoubleDoubleFunction f) {
  for (Element xe : x.nonZeroes()) {
   xe.set(f.apply(xe.get(), y.getQuick(xe.index())));
  }
  return x;
 }
}

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

@Override
 public Vector assign(Vector x, Vector y, DoubleDoubleFunction f) {
  for (Element ye : y.nonZeroes()) {
   x.setQuick(ye.index(), f.apply(x.getQuick(ye.index()), ye.get()));
  }
  return x;
 }
}

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

@Override
 public Vector assign(Vector x, Vector y, DoubleDoubleFunction f) {
  for (Element xe : x.all()) {
   x.setQuick(xe.index(), f.apply(xe.get(), y.getQuick(xe.index())));
  }
  return x;
 }
}

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

@Override
 public Vector assign(Vector x, Vector y, DoubleDoubleFunction f) {
  for (Element ye : y.all()) {
   x.setQuick(ye.index(), f.apply(x.getQuick(ye.index()), ye.get()));
  }
  return x;
 }
}

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

@Override
 public Vector assign(Vector x, Vector y, DoubleDoubleFunction f) {
  OrderedIntDoubleMapping updates = new OrderedIntDoubleMapping(false);
  for (Element xe : x.all()) {
   updates.set(xe.index(), f.apply(xe.get(), y.getQuick(xe.index())));
  }
  x.mergeUpdates(updates);
  return x;
 }
}

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

@Override
 public Vector assign(Vector x, Vector y, DoubleDoubleFunction f) {
  OrderedIntDoubleMapping updates = new OrderedIntDoubleMapping(false);
  for (Element ye : y.all()) {
   updates.set(ye.index(), f.apply(x.getQuick(ye.index()), ye.get()));
  }
  x.mergeUpdates(updates);
  return x;
 }
}

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

@Override
 public Vector assign(Vector x, Vector y, DoubleDoubleFunction f) {
  OrderedIntDoubleMapping updates = new OrderedIntDoubleMapping(false);
  for (Element ye : y.nonZeroes()) {
   updates.set(ye.index(), f.apply(x.getQuick(ye.index()), ye.get()));
  }
  x.mergeUpdates(updates);
  return x;
 }
}

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

@Test
public void testAssignDoubleArray() {
 double[] array = new double[test.size()];
 test.assign(array);
 for (int i = 0; i < values.length; i++) {
  assertEquals("value[" + i + ']', 0.0, test.getQuick(i), EPSILON);
 }
}

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

@Test
public void testAssignDouble() {
 test.assign(0);
 for (int i = 0; i < test.size(); i++) {
  assertEquals("value[" + i + ']', 0.0, test.getQuick(i), EPSILON);
 }
}

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

@Test
public void testAssignBinaryFunction2() throws Exception {
 test.assign(Functions.PLUS, 4);
 for (int i = 0; i < test.size(); i++) {
  assertEquals("value[" + i + ']', values[i + 1] + 4, test.getQuick(i), EPSILON);
 }
}

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

@Test
public void testAssignBinaryFunction3() throws Exception {
 test.assign(new TimesFunction(), 4);
 for (int i = 0; i < test.size(); i++) {
  assertEquals("value[" + i + ']', values[i + 1] * 4, test.getQuick(i), EPSILON);
 }
}

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

@Test
public void testAssignBinaryFunction() {
 test.assign(test, Functions.PLUS);
 for (int i = 0; i < values.length; i++) {
  if (i % 2 == 0) {
   assertEquals("get [" + i + ']', 0.0, test.get(i), EPSILON);
  } else {
   assertEquals("value[" + i + ']', 2 * values[i - 1], test.getQuick(i), EPSILON);
  }
 }
}

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

@Test
public void testAssignBinaryFunction2() {
 test.assign(Functions.plus(4));
 for (int i = 0; i < values.length; i++) {
  if (i % 2 == 0) {
   assertEquals("get [" + i + ']', 4.0, test.get(i), EPSILON);
  } else {
   assertEquals("value[" + i + ']', values[i - 1] + 4, test.getQuick(i), EPSILON);
  }
 }
}

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

@Test
public void testCrossProduct() {
 Matrix result = test.cross(test);
 assertEquals("row size", test.size(), result.rowSize());
 assertEquals("col size", test.size(), result.columnSize());
 for (int row = 0; row < result.rowSize(); row++) {
  for (int col = 0; col < result.columnSize(); col++) {
   assertEquals("cross[" + row + "][" + col + ']', test.getQuick(row)
     * test.getQuick(col), result.getQuick(row, col), EPSILON);
  }
 }
}

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

@Test
public void testViewRow() {
 Vector row = test.viewRow(1);
 assertEquals("row size", 2, row.getNumNondefaultElements());
 //create a matrix with an unassigned row 0
 Matrix matrix = new SparseMatrix(1, 1);
 Vector view = matrix.viewRow(0);
 final double value = 1.23;
 view.assign(value);
 //test whether the update in the view is reflected in the matrix
 assertEquals("Matrix value", view.getQuick(0), matrix.getQuick(0, 0), EPSILON);
}

相关文章