Search in sources :

Example 51 with FeatureVector

use of com.airbnb.aerosolve.core.FeatureVector in project aerosolve by airbnb.

the class NormalizeFloatTransformTest method testTransform.

@Test
public void testTransform() {
    Config config = ConfigFactory.parseString(makeConfig());
    Transform transform = TransformFactory.createTransform(config, "test_norm");
    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(3, feat1.size());
    double scale = 1.0 / Math.sqrt(37.7 * 37.7 + 40.0 * 40.0 + 20.0 * 20.0);
    assertEquals(scale * 37.7, feat1.get("lat"), 0.1);
    assertEquals(scale * 40.0, feat1.get("long"), 0.1);
    assertEquals(scale * -20.0, feat1.get("z"), 0.1);
}
Also used : FeatureVector(com.airbnb.aerosolve.core.FeatureVector) Config(com.typesafe.config.Config) Test(org.junit.Test)

Example 52 with FeatureVector

use of com.airbnb.aerosolve.core.FeatureVector in project aerosolve by airbnb.

the class NormalizeUtf8TransformTest method testEmptyFeatureVector.

@Test
public void testEmptyFeatureVector() {
    Config config = ConfigFactory.parseString(makeConfigWithoutNormalizationFormAndOutput());
    Transform transform = TransformFactory.createTransform(config, "test_normalize_utf_8");
    FeatureVector featureVector = new FeatureVector();
    transform.doTransform(featureVector);
    assertTrue(featureVector.getStringFeatures() == null);
}
Also used : FeatureVector(com.airbnb.aerosolve.core.FeatureVector) Config(com.typesafe.config.Config) Test(org.junit.Test)

Example 53 with FeatureVector

use of com.airbnb.aerosolve.core.FeatureVector in project aerosolve by airbnb.

the class NormalizeUtf8TransformTest method testTransformNfdNormalizationForm.

@Test
public void testTransformNfdNormalizationForm() {
    Config config = ConfigFactory.parseString(makeConfigWithNormalizationForm("NFD"));
    Transform transform = TransformFactory.createTransform(config, "test_normalize_utf_8");
    FeatureVector featureVector = makeFeatureVector();
    Map<String, Set<String>> stringFeatures = featureVector.getStringFeatures();
    transform.doTransform(featureVector);
    assertNotNull(stringFeatures);
    assertEquals(2, stringFeatures.size());
    Set<String> output = stringFeatures.get("bar");
    assertNotNull(output);
    assertEquals(1, output.size());
    assertTrue(output.contains("Funky string: ϓϔẛ"));
    assertTrue(Normalizer.isNormalized("Funky string: ϓϔẛ", Normalizer.Form.NFD));
}
Also used : FeatureVector(com.airbnb.aerosolve.core.FeatureVector) Set(java.util.Set) HashSet(java.util.HashSet) Config(com.typesafe.config.Config) Test(org.junit.Test)

Example 54 with FeatureVector

use of com.airbnb.aerosolve.core.FeatureVector in project aerosolve by airbnb.

the class NormalizeUtf8TransformTest method testTransformNfkdNormalizationForm.

@Test
public void testTransformNfkdNormalizationForm() {
    Config config = ConfigFactory.parseString(makeConfigWithNormalizationForm("NFKD"));
    Transform transform = TransformFactory.createTransform(config, "test_normalize_utf_8");
    FeatureVector featureVector = makeFeatureVector();
    Map<String, Set<String>> stringFeatures = featureVector.getStringFeatures();
    transform.doTransform(featureVector);
    assertNotNull(stringFeatures);
    assertEquals(2, stringFeatures.size());
    Set<String> output = stringFeatures.get("bar");
    assertNotNull(output);
    assertEquals(1, output.size());
    assertTrue(output.contains("Funky string: ΎΫṡ"));
    assertTrue(Normalizer.isNormalized("Funky string: ΎΫṡ", Normalizer.Form.NFKD));
}
Also used : FeatureVector(com.airbnb.aerosolve.core.FeatureVector) Set(java.util.Set) HashSet(java.util.HashSet) Config(com.typesafe.config.Config) Test(org.junit.Test)

Example 55 with FeatureVector

use of com.airbnb.aerosolve.core.FeatureVector in project aerosolve by airbnb.

the class CustomLinearLogQuantizeTransformTest method testTransform.

@Test
public void testTransform() {
    Config config = ConfigFactory.parseString(makeConfig());
    Transform transform = TransformFactory.createTransform(config, "test_quantize");
    FeatureVector featureVector = makeFeatureVector();
    transform.doTransform(featureVector);
    Map<String, Set<String>> stringFeatures = featureVector.getStringFeatures();
    assertTrue(stringFeatures.size() == 2);
    Set<String> out = stringFeatures.get("loc_quantized");
    log.info("quantize output");
    for (String string : out) {
        log.info(string);
    }
    assertTrue(out.size() == 10);
    log.info("quantize output");
    for (String string : out) {
        log.info(string);
    }
    assertTrue(out.contains("a=0.0"));
    assertTrue(out.contains("b=0.125"));
    assertTrue(out.contains("c=1.0"));
    assertTrue(out.contains("d=5.0"));
    assertTrue(out.contains("e=16.0"));
    assertTrue(out.contains("f=90.0"));
    assertTrue(out.contains("g=350.0"));
    assertTrue(out.contains("h=10000.0"));
    assertTrue(out.contains("i=-1.0"));
    assertTrue(out.contains("j=-22.0"));
}
Also used : FeatureVector(com.airbnb.aerosolve.core.FeatureVector) Config(com.typesafe.config.Config) Test(org.junit.Test)

Aggregations

FeatureVector (com.airbnb.aerosolve.core.FeatureVector)225 Test (org.junit.Test)154 Config (com.typesafe.config.Config)117 Set (java.util.Set)59 HashMap (java.util.HashMap)58 HashSet (java.util.HashSet)50 Map (java.util.Map)46 ArrayList (java.util.ArrayList)11 Example (com.airbnb.aerosolve.core.Example)9 List (java.util.List)9 ModelRecord (com.airbnb.aerosolve.core.ModelRecord)5 ModelHeader (com.airbnb.aerosolve.core.ModelHeader)4 BufferedReader (java.io.BufferedReader)4 IOException (java.io.IOException)4 MulticlassScoringResult (com.airbnb.aerosolve.core.MulticlassScoringResult)3 BufferedWriter (java.io.BufferedWriter)3 CharArrayWriter (java.io.CharArrayWriter)3 StringReader (java.io.StringReader)3 DebugScoreRecord (com.airbnb.aerosolve.core.DebugScoreRecord)2 SimpleEntry (java.util.AbstractMap.SimpleEntry)2