Search in sources :

Example 1 with DebugScoreDiffRecord

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

the class Util method compareDebugRecords.

public static List<DebugScoreDiffRecord> compareDebugRecords(List<DebugScoreRecord> record1, List<DebugScoreRecord> record2) {
    List<DebugScoreDiffRecord> debugDiffRecord = new ArrayList<>();
    final String featureValue = "featureValue";
    final String featureWeight = "featureWeight";
    Set<String> keys = new HashSet();
    Map<String, Map<String, Double>> recordMap1 = debugScoreRecordListToMap(record1);
    Map<String, Map<String, Double>> recordMap2 = debugScoreRecordListToMap(record2);
    keys.addAll(recordMap1.keySet());
    keys.addAll(recordMap2.keySet());
    for (String key : keys) {
        DebugScoreDiffRecord diffRecord = new DebugScoreDiffRecord();
        double fv1 = 0.0;
        double fv2 = 0.0;
        double fw1 = 0.0;
        double fw2 = 0.0;
        if (recordMap1.get(key) != null) {
            fv1 = recordMap1.get(key).get(featureValue);
            fw1 = recordMap1.get(key).get(featureWeight);
        }
        if (recordMap2.get(key) != null) {
            fv2 = recordMap2.get(key).get(featureValue);
            fw2 = recordMap2.get(key).get(featureWeight);
        }
        String[] fvString = key.split("\t");
        diffRecord.setFeatureFamily(fvString[0]);
        diffRecord.setFeatureName(fvString[1]);
        diffRecord.setFeatureValue1(fv1);
        diffRecord.setFeatureValue2(fv2);
        diffRecord.setFeatureWeight1(fw1);
        diffRecord.setFeatureWeight2(fw2);
        diffRecord.setFeatureWeightDiff(fw1 - fw2);
        debugDiffRecord.add(diffRecord);
    }
    Collections.sort(debugDiffRecord, new DebugDiffRecordComparator());
    return debugDiffRecord;
}
Also used : DebugScoreDiffRecord(com.airbnb.aerosolve.core.DebugScoreDiffRecord) ArrayList(java.util.ArrayList) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Example 2 with DebugScoreDiffRecord

use of com.airbnb.aerosolve.core.DebugScoreDiffRecord 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

DebugScoreDiffRecord (com.airbnb.aerosolve.core.DebugScoreDiffRecord)2 DebugScoreRecord (com.airbnb.aerosolve.core.DebugScoreRecord)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Test (org.junit.Test)1