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

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

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

Vector.set介绍

[英]Set the value at the given index
[中]在给定索引处设置值

代码示例

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

@Override
public void set(int index, double value) {
 delegate.set(index, value);
}

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

@Override
public void set(int index, double value) {
 delegate.set(index, value);
}

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

@Override
public void setQuick(int row, int column, double value) {
 if (row == column) {
  diagonal.set(row, value);
 } else {
  throw new UnsupportedOperationException("Can't set off-diagonal element");
 }
}

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

@Override
public void set(int index, double value) {
 if (index == this.index) {
  diagonal.set(index, value);
 } else {
  throw new IllegalArgumentException("Can't set off-diagonal element of diagonal matrix");
 }
}

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

@Override
public void setQuick(int index, double value) {
 if (index == this.index) {
  diagonal.set(this.index, value);
 } else {
  throw new IllegalArgumentException("Can't set off-diagonal element of DiagonalMatrix");
 }
}

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

private static void updateTrainingProjectionsVector(TrainingState state,
                          Vector trainingVector,
                          int previousEigenIndex) {
 Vector previousEigen = state.mostRecentEigen();
 Vector currentTrainingVectorProjection = state.currentTrainingProjection();
 double projection = previousEigen.dot(trainingVector);
 currentTrainingVectorProjection.set(previousEigenIndex, projection);
}

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

@Test
public void testDotSuperBig() {
 Vector w = new SequentialAccessSparseVector(Integer.MAX_VALUE, 12);
 w.set(1, 0.4);
 w.set(2, 0.4);
 w.set(3, -0.666666667);
 Vector v = new SequentialAccessSparseVector(Integer.MAX_VALUE, 12);
 v.set(3, 1);
 assertEquals("super-big", -0.666666667, v.dot(w), EPSILON);
}

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

public void testToString() {
  Vector w;

  w = generateTestVector(20);
  w.set(0, 1.1);
  w.set(13, 100500.);
  w.set(19, 3.141592);
  assertEquals("{0:1.1,13:100500.0,19:3.141592}", w.toString());

  w = generateTestVector(12);
  w.set(10, 0.1);
  assertEquals("{10:0.1}", w.toString());

  w = generateTestVector(12);
  assertEquals("{}", w.toString());
 }
}

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

@Test
public void testGetDistanceSquared() {
 Vector other = new RandomAccessSparseVector(test.size());
 other.set(1, -2);
 other.set(2, -5);
 other.set(3, -9);
 other.set(4, 1);
 double expected = test.minus(other).getLengthSquared();
 assertTrue("a.getDistanceSquared(b) != a.minus(b).getLengthSquared",
       Math.abs(expected - test.getDistanceSquared(other)) < 10.0E-7);
}

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

@Test
public void testDot2() {
 Vector test2 = test.clone();
 test2.set(1, 0.0);
 test2.set(3, 0.0);
 assertEquals(3.3 * 3.3, test2.dot(test), EPSILON);
}

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

/**
 * Collects the results of a function applied to each column of a matrix.
 *
 * @param f The function to be applied to each column.
 * @return The vector of results.
 */
@Override
public Vector aggregateColumns(VectorFunction f) {
 Vector r = new DenseVector(numCols());
 for (int col = 0; col < numCols(); col++) {
  r.set(col, f.apply(viewColumn(col)));
 }
 return r;
}

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

/**
 * Collects the results of a function applied to each row of a matrix.
 *
 * @param f The function to be applied to each row.
 * @return The vector of results.
 */
@Override
public Vector aggregateRows(VectorFunction f) {
 Vector r = new DenseVector(numRows());
 int n = numRows();
 for (int row = 0; row < n; row++) {
  r.set(row, f.apply(viewRow(row)));
 }
 return r;
}

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

@Override
@Before
public void setUp() throws Exception {
 super.setUp();
 test = generateTestVector(2 * values.length + 1);
 for (int i = 0; i < values.length; i++) {
  test.set(2 * i + 1, values[i]);
 }
}

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

@Test
public void testSet() throws Exception {
 test.set(2, 4.5);
 for (int i = 0; i < test.size(); i++) {
  assertEquals("set [" + i + ']', i == 2 ? 4.5 : values[OFFSET + i], test.get(i), EPSILON);
 }
}

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

public static Vector mult(Matrix m, Vector v) {
 if (m.numRows() != v.size()) {
  throw new CardinalityException(m.numRows(), v.size());
 }
 // Use a Dense Vector for the moment,
 Vector result = new DenseVector(m.numRows());
 
 for (int i = 0; i < m.numRows(); i++) {
  result.set(i, m.viewRow(i).dot(v));
 }
 
 return result;
}

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

public static Matrix randomHierarchicalMatrix(int numRows, int numCols, boolean symmetric) {
 Matrix matrix = new DenseMatrix(numRows, numCols);
 // TODO rejigger tests so that it doesn't expect this particular seed
 Random r = new Random(1234L);
 for (int row = 0; row < numRows; row++) {
  Vector v = new DenseVector(numCols);
  for (int col = 0; col < numCols; col++) {
   double val = r.nextGaussian();
   v.set(col, val);
  }
  v.assign(Functions.MULT, 1/((row + 1) * v.norm(2)));
  matrix.assignRow(row, v);
 }
 if (symmetric) {
  return matrix.times(matrix.transpose());
 }
 return matrix;
}

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

public void createRandom(Vector v) {
 int size = randomInt(v.size() - 1);
 for (int i = 0; i < size; ++i) {
  v.set(randomInt(v.size() - 1), randomDouble());
 }
 int zeros = Math.max(2, size / 4);
 for (Element e : v.nonZeroes()) {
  if (e.index() % zeros == 0) {
   e.set(0.0);
  }
 }
}

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

@Test
public void testViewBasics() {
 Vector v = randomVector();
 int[] pivot = pivot();
 Vector pvv = new PermutedVectorView(v, pivot);
 // verify the view has the same contents
 for (int i = 0; i < 20; i++) {
  assertEquals("Element " + i, v.get(pivot[i]), pvv.get(i), 0);
 }
 // change a view element or two on each side
 pvv.set(6, 321);
 v.set(9, 512);
 // verify again
 for (int i = 0; i < 20; i++) {
  assertEquals("Element " + i, v.get(pivot[i]), pvv.get(i), 0);
 }
}

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

@Test
public void testSet() {
 test.set(3, 4.5);
 for (int i = 0; i < test.size(); i++) {
  if (i % 2 == 0) {
   assertEquals("get [" + i + ']', 0.0, test.get(i), EPSILON);
  } else if (i == 3) {
   assertEquals("set [" + i + ']', 4.5, test.get(i), EPSILON);
  } else {
   assertEquals("set [" + i + ']', values[i/2], test.get(i), EPSILON);
  }
 }
}

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

@Test
public void testColumnView() {
 assertEquals(test.rowSize(), test.viewColumn(0).size());
 assertEquals(test.rowSize(), test.viewColumn(1).size());
 Random gen = RandomUtils.getRandom();
 for (int col = 0; col < test.columnSize(); col++) {
  int j = gen.nextInt(test.columnSize());
  double old = test.get(col, j);
  double v = gen.nextGaussian();
  test.viewColumn(col).set(j, v);
  assertEquals(v, test.get(j, col), 0);
  assertEquals(v, test.viewColumn(col).get(j), 0);
  test.set(j, col, old);
  assertEquals(old, test.get(j, col), 0);
  assertEquals(old, test.viewColumn(col).get(j), 0);
 }
}

相关文章