@Test public void testNonSquareMatrix() { int[][] testInput = { {6, 0, 5}, {0, 1, 1}, {1, 5, 0}, {0, 1, 0}, {1, 5, 7}, {1, 1, 1} }; double[][] testOutput = {{}}; double error = .00001; Matrix inputMatrix = new YaleSparseMatrix(6, 3); for (int row = 0; row < 6; ++row) for (int col = 0; col < 3; ++col) inputMatrix.set(row, col, testInput[row][col]); Transform transform = new TfIdfTransform(); Matrix outputMatrix = transform.transform(inputMatrix); for (int row = 0; row < 6; ++row) { for (int col = 0; col < 3; ++col) System.out.println(outputMatrix.get(row, col)); // assertEquals(testOutput[row][col], // outputMatrix.get(row, col), error); } }
@Test public void testMatrixTransformSize() { int[][] testInput = { {0, 0, 0, 0, 1, 1, 2, 4, 5, 0}, {0, 1, 1, 2, 0, 1, 5, 2, 8, 10}, {1, 5, 0, 0, 1, 0, 6, 3, 7, 9}, {0, 1, 0, 1, 0, 1, 2, 0, 3, 0}, {1, 5, 7, 0, 0, 1, 6, 10, 2, 45}, {1, 1, 1, 1, 1, 1, 1, 1, 1, 1} }; double[][] testOutput = { { 0.00000, 0.00000, 0.00000, 0.00000, 0.17028, 0.10217, 0.04644, 0.10217, 0.09824, 0.00000, }, { 0.00000, 0.00810, 0.01171, 0.05268, 0.00000, 0.02107, 0.02395, 0.01054, 0.03242, 0.01621, }, { 0.07438, 0.08582, 0.00000, 0.00000, 0.07438, 0.00000, 0.06086, 0.03347, 0.06008, 0.03090, }, { 0.00000, 0.03929, 0.00000, 0.12771, 0.00000, 0.10217, 0.04644, 0.00000, 0.05894, 0.00000, }, { 0.03512, 0.04052, 0.08195, 0.00000, 0.00000, 0.02107, 0.02873, 0.05268, 0.00810, 0.07294, }, { -0.03177, -0.00733, -0.01059, -0.02383, -0.03177, -0.01906, -0.00433, -0.00477, -0.00367, -0.00147, } }; double error = .00001; Matrix inputMatrix = new YaleSparseMatrix(6, 10); for (int row = 0; row < 6; ++row) for (int col = 0; col < 10; ++col) inputMatrix.set(row, col, testInput[row][col]); Transform transform = new TfIdfTransform(); Matrix outputMatrix = transform.transform(inputMatrix); for (int row = 0; row < 6; ++row) { for (int col = 0; col < 10; ++col) assertEquals(testOutput[row][col], outputMatrix.get(row, col), error); } }