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

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

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

Matrix.rowSize介绍

暂无

代码示例

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

@Test(expected = IndexException.class)
public void testSetOver() {
 for (int row = 0; row < test.rowSize() + 1; row++) {
  for (int col = 0; col < test.columnSize(); col++) {
   test.set(row, col, 1.23);
  }
 }
}

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

@Test(expected = IndexException.class)
public void testSetUnder() {
 for (int row = -1; row < test.rowSize(); row++) {
  for (int col = 0; col < test.columnSize(); col++) {
   test.set(row, col, 1.23);
  }
 }
}

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

@Override
public Matrix matrixFactory(double[][] values) {
 Matrix matrix = new SparseMatrix(values.length, values[0].length);
 for (int row = 0; row < matrix.rowSize(); row++) {
  for (int col = 0; col < matrix.columnSize(); col++) {
   matrix.setQuick(row, col, values[row][col]);
  }
 }
 return matrix;
}

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

@Override
public Matrix matrixFactory(double[][] values) {
 Matrix matrix = new SparseColumnMatrix(values.length, values[0].length);
 for (int row = 0; row < matrix.rowSize(); row++) {
  for (int col = 0; col < matrix.columnSize(); col++) {
   matrix.setQuick(row, col, values[row][col]);
  }
 }
 return matrix;
}

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

@Test(expected = IndexException.class)
public void testGetIndexOver() {
 for (int row = 0; row < test.rowSize() + 1; row++) {
  for (int col = 0; col < test.columnSize(); col++) {
   test.get(row, col);
  }
 }
}

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

@Test
public void testTranspose() {
 Matrix transpose = test.transpose();
 assertEquals("rows", test.columnSize(), transpose.rowSize());
 assertEquals("cols", test.rowSize(), transpose.columnSize());
 for (int row = 0; row < test.rowSize(); row++) {
  for (int col = 0; col < test.columnSize(); col++) {
   assertEquals("value[" + row + "][" + col + ']',
     test.getQuick(row, col), transpose.getQuick(col, row), EPSILON);
  }
 }
}

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

@Test
public void testGet() {
 for (int row = 0; row < test.rowSize(); row++) {
  for (int col = 0; col < test.columnSize(); col++) {
   assertEquals("value[" + row + "][" + col + ']', values[row][col], test
     .get(row, col), EPSILON);
  }
 }
}

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

@Test
public void testCardinality() {
 assertEquals("row cardinality", values.length, test.rowSize());
 assertEquals("col cardinality", values[0].length, test.columnSize());
}

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

@Test
public void testViewPart() {
 int[] offset = {1, 1};
 int[] size = {2, 1};
 Matrix view = test.viewPart(offset, size);
 for (int row = 0; row < view.rowSize(); row++) {
  for (int col = 0; col < view.columnSize(); col++) {
   assertEquals("value[" + row + "][" + col + ']',
     values[row + 2][col + 2], view.getQuick(row, col), EPSILON);
  }
 }
}

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

@Test
public void testAssignDouble() {
 test.assign(4.53);
 for (int row = 0; row < test.rowSize(); row++) {
  for (int col = 0; col < test.columnSize(); col++) {
   assertEquals("value[" + row + "][" + col + ']', 4.53, test.getQuick(
     row, col), EPSILON);
  }
 }
}

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

@Test
public void testPlusMatrix() {
 Matrix value = test.plus(test);
 for (int row = 0; row < test.rowSize(); row++) {
  for (int col = 0; col < test.columnSize(); col++) {
   assertEquals("value[" + row + "][" + col + ']', values[row][col] * 2,
     value.getQuick(row, col), EPSILON);
  }
 }
}

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

@Test
public void testAssignDouble() {
 test.assign(4.53);
 for (int row = 0; row < test.rowSize(); row++) {
  for (int col = 0; col < test.columnSize(); col++) {
   assertEquals("value[" + row + "][" + col + ']', 4.53, test.getQuick(
     row, col), EPSILON);
  }
 }
}

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

@Test
public void testAssignDoubleArrayArray() {
 test.assign(new double[3][2]);
 for (int row = 0; row < test.rowSize(); row++) {
  for (int col = 0; col < test.columnSize(); col++) {
   assertEquals("value[" + row + "][" + col + ']', 0.0, test.getQuick(row,
     col), EPSILON);
  }
 }
}

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

@Test
public void testAssignUnaryFunction() {
 test.assign(Functions.NEGATE);
 for (int row = 0; row < test.rowSize(); row++) {
  for (int col = 0; col < test.columnSize(); col++) {
   assertEquals("value[" + row + "][" + col + ']',
     -values[row + 1][col + 1], test.getQuick(row, col), EPSILON);
  }
 }
}

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

@Test
public void testAssignDoubleArrayArray() {
 test.assign(new double[3][2]);
 for (int row = 0; row < test.rowSize(); row++) {
  for (int col = 0; col < test.columnSize(); col++) {
   assertEquals("value[" + row + "][" + col + ']', 0.0, test.getQuick(row,
     col), EPSILON);
  }
 }
}

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

@Test
public void testMinus() {
 Matrix value = test.minus(test);
 for (int row = 0; row < test.rowSize(); row++) {
  for (int col = 0; col < test.columnSize(); col++) {
   assertEquals("value[" + row + "][" + col + ']', 0.0, value.getQuick(
     row, col), EPSILON);
  }
 }
}

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

@Test
public void testSetQuick() {
 for (int row = 0; row < test.rowSize(); row++) {
  for (int col = 0; col < test.columnSize(); col++) {
   test.setQuick(row, col, 1.23);
   assertEquals("value[" + row + "][" + col + ']', 1.23, test.getQuick(
     row, col), EPSILON);
  }
 }
}

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

@Test
public void testTimesDouble() {
 Matrix value = test.times(4.53);
 for (int row = 0; row < test.rowSize(); row++) {
  for (int col = 0; col < test.columnSize(); col++) {
   assertEquals("value[" + row + "][" + col + ']',
     values[row][col] * 4.53, value.getQuick(row, col), EPSILON);
  }
 }
}

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

@Test
public void testCopy() {
 Matrix copy = test.clone();
 assertTrue("wrong class", copy instanceof MatrixView);
 for (int row = 0; row < test.rowSize(); row++) {
  for (int col = 0; col < test.columnSize(); col++) {
   assertEquals("value[" + row + "][" + col + ']',
     test.getQuick(row, col), copy.getQuick(row, col), EPSILON);
  }
 }
}

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

private void validateYtY(Matrix matrixToTest, int numThreads) {
 OpenIntObjectHashMap<Vector> matrixToTestAsRowVectors = asRowVectors(matrixToTest);
 ImplicitFeedbackAlternatingLeastSquaresSolver solver = new ImplicitFeedbackAlternatingLeastSquaresSolver(
   matrixToTest.columnSize(), 1, 1, matrixToTestAsRowVectors, numThreads);
 Matrix yTy = matrixToTest.transpose().times(matrixToTest);
 Matrix shouldMatchyTy = solver.getYtransposeY(matrixToTestAsRowVectors);
 
 for (int row = 0; row < yTy.rowSize(); row++) {
  for (int column = 0; column < yTy.columnSize(); column++) {
   assertEquals(yTy.getQuick(row, column), shouldMatchyTy.getQuick(row, column), 0);
  }
 }
}

相关文章