Search in sources :

Example 6 with DebugScoreRecord

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

the class LinearModelTest method testDebugScoreComponents.

@Test
public void testDebugScoreComponents() {
    LinearModel model = makeLinearModel();
    FeatureVector fv = makeFeatureVector();
    List<DebugScoreRecord> scoreRecordsList = model.debugScoreComponents(fv);
    assertTrue(scoreRecordsList.size() == 2);
    for (DebugScoreRecord record : scoreRecordsList) {
        assertTrue(record.featureFamily == "string_feature");
        assertTrue(record.featureName == "aaa" || record.featureName == "bbb");
        assertTrue(record.featureValue == 1.0);
        if (record.featureName == "aaa") {
            assertTrue(record.featureWeight == 0.5f);
        } else {
            assertTrue(record.featureWeight == 0.25f);
        }
    }
}
Also used : FeatureVector(com.airbnb.aerosolve.core.FeatureVector) DebugScoreRecord(com.airbnb.aerosolve.core.DebugScoreRecord) Test(org.junit.Test)

Example 7 with DebugScoreRecord

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

the class UtilTest method testCompareDebugRecords.

@Test
public void testCompareDebugRecords() {
    List<DebugScoreRecord> record1 = new ArrayList<>();
    List<DebugScoreRecord> record2 = new ArrayList<>();
    DebugScoreRecord r11 = new DebugScoreRecord();
    r11.setFeatureFamily("a_family");
    r11.setFeatureName("a_name");
    r11.setFeatureValue(0.0);
    r11.setFeatureWeight(0.0);
    DebugScoreRecord r12 = new DebugScoreRecord();
    r12.setFeatureFamily("b_family");
    r12.setFeatureName("b_name");
    r12.setFeatureValue(0.1);
    r12.setFeatureWeight(1.0);
    DebugScoreRecord r13 = new DebugScoreRecord();
    r13.setFeatureFamily("c_family");
    r13.setFeatureName("c_name");
    r13.setFeatureValue(0.2);
    r13.setFeatureWeight(1.0);
    DebugScoreRecord r21 = new DebugScoreRecord();
    r21.setFeatureFamily("a_family");
    r21.setFeatureName("a_name");
    r21.setFeatureValue(0.0);
    // weight_diff = 0.0 - 1.0 = -1.0
    r21.setFeatureWeight(1.0);
    DebugScoreRecord r22 = new DebugScoreRecord();
    r22.setFeatureFamily("b_family");
    r22.setFeatureName("b_name");
    r22.setFeatureValue(0.1);
    // weight_diff = 1.0 - 0.5 = 0.5
    r22.setFeatureWeight(0.5);
    DebugScoreRecord r23 = new DebugScoreRecord();
    r23.setFeatureFamily("c_family");
    r23.setFeatureName("c_name");
    r23.setFeatureValue(0.2);
    // 1.0 - (-1.0) = 2.0
    r23.setFeatureWeight(-1.0);
    record1.add(r11);
    record2.add(r21);
    List<DebugScoreDiffRecord> result1 = Util.compareDebugRecords(record1, record2);
    assertEquals(1, result1.size());
    assertEquals(-1.0, result1.get(0).getFeatureWeightDiff(), 0.0001);
    // record2 has one more record
    record2.add(r22);
    List<DebugScoreDiffRecord> result2 = Util.compareDebugRecords(record1, record2);
    assertEquals(2, result2.size());
    assertEquals(-1.0, result2.get(0).getFeatureWeightDiff(), 0.0001);
    assertEquals(-0.5, result2.get(1).getFeatureWeightDiff(), 0.0001);
    record1.add(r12);
    record1.add(r13);
    record2.add(r23);
    List<DebugScoreDiffRecord> result3 = Util.compareDebugRecords(record1, record2);
    assertEquals(3, result3.size());
    assertEquals(2.0, result3.get(0).getFeatureWeightDiff(), 0.0001);
    assertEquals(-1.0, result3.get(1).getFeatureWeightDiff(), 0.0001);
    assertEquals(0.5, result3.get(2).getFeatureWeightDiff(), 0.0001);
}
Also used : DebugScoreRecord(com.airbnb.aerosolve.core.DebugScoreRecord) DebugScoreDiffRecord(com.airbnb.aerosolve.core.DebugScoreDiffRecord) Test(org.junit.Test)

Aggregations

DebugScoreRecord (com.airbnb.aerosolve.core.DebugScoreRecord)7 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 Test (org.junit.Test)2 DebugScoreDiffRecord (com.airbnb.aerosolve.core.DebugScoreDiffRecord)1 FeatureVector (com.airbnb.aerosolve.core.FeatureVector)1 ModelRecord (com.airbnb.aerosolve.core.ModelRecord)1 AbstractFunction (com.airbnb.aerosolve.core.function.AbstractFunction)1 Function (com.airbnb.aerosolve.core.function.Function)1 FloatVector (com.airbnb.aerosolve.core.util.FloatVector)1 AbstractMap (java.util.AbstractMap)1 HashMap (java.util.HashMap)1 List (java.util.List)1