Пример #1
0
  @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 testEmptyFeatureVector() {
   Config config = ConfigFactory.parseString(makeConfig());
   Transform transform = TransformFactory.createTransform(config, "test_cut");
   FeatureVector featureVector = new FeatureVector();
   transform.doTransform(featureVector);
   assertTrue(featureVector.getStringFeatures() == null);
 }
  @Test
  public void testTransformLowerBoundOnly() {
    Config config = ConfigFactory.parseString(makeConfigWithLowerBoundOnly());
    Transform transform = TransformFactory.createTransform(config, "test_cut");
    FeatureVector featureVector = TransformTestingHelper.makeFeatureVector();
    transform.doTransform(featureVector);
    Map<String, Set<String>> stringFeatures = featureVector.getStringFeatures();
    assertTrue(stringFeatures.size() == 1);

    Map<String, Double> feat1 = featureVector.getFloatFeatures().get("loc");

    assertEquals(2, feat1.size());
    assertEquals(37.7, feat1.get("lat"), 0.1);
    assertEquals(40.0, feat1.get("long"), 0.1);
    assertNull(feat1.get("z"));
  }
Пример #4
0
  @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);
    }
  }
  @Test
  public void testTransformWithNewOutput() {
    Config config = ConfigFactory.parseString(makeConfigWithOutput());
    Transform transform = TransformFactory.createTransform(config, "test_cut");
    FeatureVector featureVector = TransformTestingHelper.makeFeatureVector();
    transform.doTransform(featureVector);
    Map<String, Set<String>> stringFeatures = featureVector.getStringFeatures();
    assertTrue(stringFeatures.size() == 1);
    // original feature should not change
    Map<String, Double> feat1 = featureVector.getFloatFeatures().get("loc");
    assertEquals(3, feat1.size());
    assertEquals(37.7, feat1.get("lat"), 0.1);
    assertEquals(40.0, feat1.get("long"), 0.1);
    assertEquals(-20, feat1.get("z"), 0.1);

    // capped features are in a new feature family
    assertTrue(featureVector.getFloatFeatures().containsKey("new_output"));
    Map<String, Double> feat2 = featureVector.getFloatFeatures().get("new_output");
    assertEquals(1, feat2.size());
    assertEquals(37.7, feat2.get("lat"), 0.1);
    assertNull(feat2.get("long"));
    assertNull(feat2.get("z"));
  }