Search in sources :

Example 46 with FeatureVector

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

the class NearestTransformTest method makeFeatureVector.

public FeatureVector makeFeatureVector() {
    Map<String, Set<String>> stringFeatures = new HashMap<>();
    Map<String, Map<String, Double>> floatFeatures = new HashMap<>();
    Set list = new HashSet<String>();
    list.add("aaa");
    list.add("bbb");
    stringFeatures.put("strFeature1", list);
    Map<String, Double> map = new HashMap<>();
    map.put("lat", 37.7);
    map.put("long", 40.0);
    floatFeatures.put("loc", map);
    Map<String, Double> map2 = new HashMap<>();
    map2.put("foo", 41.0);
    floatFeatures.put("f2", map2);
    FeatureVector featureVector = new FeatureVector();
    featureVector.setStringFeatures(stringFeatures);
    featureVector.setFloatFeatures(floatFeatures);
    return featureVector;
}
Also used : FeatureVector(com.airbnb.aerosolve.core.FeatureVector)

Example 47 with FeatureVector

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

the class NearestTransformTest method testTransform.

@Test
public void testTransform() {
    Config config = ConfigFactory.parseString(makeConfig());
    Transform transform = TransformFactory.createTransform(config, "test_nearest");
    FeatureVector featureVector = makeFeatureVector();
    transform.doTransform(featureVector);
    Map<String, Set<String>> stringFeatures = featureVector.getStringFeatures();
    assertTrue(stringFeatures.size() == 2);
    Set<String> out = stringFeatures.get("nearest");
    log.info("nearest output");
    for (String string : out) {
        log.info(string);
    }
    assertTrue(out.size() == 1);
    assertTrue(out.contains("foo~=long"));
}
Also used : FeatureVector(com.airbnb.aerosolve.core.FeatureVector) Config(com.typesafe.config.Config) Test(org.junit.Test)

Example 48 with FeatureVector

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

the class NgramTransformTest method makeFeatureVector.

public FeatureVector makeFeatureVector() {
    Map<String, Set<String>> stringFeatures = new HashMap<>();
    Map<String, Map<String, Double>> floatFeatures = new HashMap<>();
    Set<String> list = new HashSet<>();
    list.add("I like blueberry pie, apple pie; and I also like blue!");
    list.add("I'm so  excited: I   like blue!?!!");
    stringFeatures.put("strFeature1", list);
    FeatureVector featureVector = new FeatureVector();
    featureVector.setStringFeatures(stringFeatures);
    featureVector.setFloatFeatures(floatFeatures);
    return featureVector;
}
Also used : FeatureVector(com.airbnb.aerosolve.core.FeatureVector) HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) Map(java.util.Map) HashMap(java.util.HashMap) HashSet(java.util.HashSet)

Example 49 with FeatureVector

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

the class NgramTransformTest method testTransform1gram.

@Test
public void testTransform1gram() {
    Config config = ConfigFactory.parseString(makeConfig("\"\"\"[\\s\\p{Punct}]\"\"\"", 1, false));
    Transform transform = TransformFactory.createTransform(config, "test_ngram");
    FeatureVector featureVector = makeFeatureVector();
    transform.doTransform(featureVector);
    Map<String, Set<String>> stringFeatures = featureVector.getStringFeatures();
    Map<String, Map<String, Double>> floatFeatures = featureVector.getFloatFeatures();
    assertEquals(1, stringFeatures.size());
    assertEquals(1, floatFeatures.size());
    Map<String, Double> output = floatFeatures.get("bar");
    assertEquals(11, output.size());
    assertEquals(1.0, output.get("apple"), 0.0);
    assertEquals(1.0, output.get("blueberry"), 0.0);
    assertEquals(2.0, output.get("blue"), 0.0);
    assertEquals(3.0, output.get("like"), 0.0);
    assertEquals(1.0, output.get("excited"), 0.0);
    assertEquals(1.0, output.get("and"), 0.0);
    assertEquals(4.0, output.get("I"), 0.0);
    assertEquals(1.0, output.get("also"), 0.0);
    assertEquals(1.0, output.get("so"), 0.0);
    assertEquals(2.0, output.get("pie"), 0.0);
    assertEquals(1.0, output.get("m"), 0.0);
}
Also used : FeatureVector(com.airbnb.aerosolve.core.FeatureVector) HashSet(java.util.HashSet) Set(java.util.Set) Config(com.typesafe.config.Config) Map(java.util.Map) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 50 with FeatureVector

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

the class NgramTransformTest method testTransformUseMinN.

@Test
public void testTransformUseMinN() {
    Config config = ConfigFactory.parseString(makeConfig("\"\"\"[\\s\\p{Punct}]\"\"\"", 2, true));
    Transform transform = TransformFactory.createTransform(config, "test_ngram");
    FeatureVector featureVector = makeFeatureVector();
    transform.doTransform(featureVector);
    Map<String, Set<String>> stringFeatures = featureVector.getStringFeatures();
    Map<String, Map<String, Double>> floatFeatures = featureVector.getFloatFeatures();
    assertEquals(1, stringFeatures.size());
    assertEquals(1, floatFeatures.size());
    Map<String, Double> output = floatFeatures.get("bar");
    assertEquals(25, output.size());
    assertEquals(1.0, output.get("apple"), 0.0);
    assertEquals(1.0, output.get("blueberry"), 0.0);
    assertEquals(2.0, output.get("blue"), 0.0);
    assertEquals(3.0, output.get("like"), 0.0);
    assertEquals(1.0, output.get("excited"), 0.0);
    assertEquals(1.0, output.get("and"), 0.0);
    assertEquals(4.0, output.get("I"), 0.0);
    assertEquals(1.0, output.get("also"), 0.0);
    assertEquals(1.0, output.get("so"), 0.0);
    assertEquals(2.0, output.get("pie"), 0.0);
    assertEquals(1.0, output.get("m"), 0.0);
    assertEquals(2.0, output.get("I" + NgramTransform.BIGRAM_SEPARATOR + "like"), 0.0);
    assertEquals(1.0, output.get("like" + NgramTransform.BIGRAM_SEPARATOR + "blueberry"), 0.0);
    assertEquals(1.0, output.get("blueberry" + NgramTransform.BIGRAM_SEPARATOR + "pie"), 0.0);
    assertEquals(1.0, output.get("pie" + NgramTransform.BIGRAM_SEPARATOR + "apple"), 0.0);
    assertEquals(1.0, output.get("apple" + NgramTransform.BIGRAM_SEPARATOR + "pie"), 0.0);
    assertEquals(1.0, output.get("pie" + NgramTransform.BIGRAM_SEPARATOR + "and"), 0.0);
    assertEquals(1.0, output.get("and" + NgramTransform.BIGRAM_SEPARATOR + "I"), 0.0);
    assertEquals(1.0, output.get("I" + NgramTransform.BIGRAM_SEPARATOR + "also"), 0.0);
    assertEquals(1.0, output.get("also" + NgramTransform.BIGRAM_SEPARATOR + "like"), 0.0);
    assertEquals(2.0, output.get("like" + NgramTransform.BIGRAM_SEPARATOR + "blue"), 0.0);
    assertEquals(1.0, output.get("I" + NgramTransform.BIGRAM_SEPARATOR + "m"), 0.0);
    assertEquals(1.0, output.get("m" + NgramTransform.BIGRAM_SEPARATOR + "so"), 0.0);
    assertEquals(1.0, output.get("so" + NgramTransform.BIGRAM_SEPARATOR + "excited"), 0.0);
    assertEquals(1.0, output.get("excited" + NgramTransform.BIGRAM_SEPARATOR + "I"), 0.0);
}
Also used : FeatureVector(com.airbnb.aerosolve.core.FeatureVector) HashSet(java.util.HashSet) Set(java.util.Set) Config(com.typesafe.config.Config) Map(java.util.Map) HashMap(java.util.HashMap) 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