Search in sources :

Example 1 with DebugScoreRecord

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

the class FullRankLinearModel method debugScoreComponents.

@Override
public List<DebugScoreRecord> debugScoreComponents(FeatureVector combinedItem) {
    Map<String, Map<String, Double>> flatFeatures = Util.flattenFeature(combinedItem);
    List<DebugScoreRecord> scoreRecordsList = new ArrayList<>();
    int dim = labelDictionary.size();
    for (Map.Entry<String, Map<String, Double>> entry : flatFeatures.entrySet()) {
        String familyKey = entry.getKey();
        Map<String, FloatVector> family = weightVector.get(familyKey);
        if (family != null) {
            for (Map.Entry<String, Double> feature : entry.getValue().entrySet()) {
                String featureKey = feature.getKey();
                FloatVector featureWeights = family.get(featureKey);
                float val = feature.getValue().floatValue();
                if (featureWeights != null) {
                    for (int i = 0; i < dim; i++) {
                        DebugScoreRecord record = new DebugScoreRecord();
                        record.setFeatureFamily(familyKey);
                        record.setFeatureName(featureKey);
                        record.setFeatureValue(val);
                        record.setFeatureWeight(featureWeights.get(i));
                        record.setLabel(labelDictionary.get(i).label);
                        scoreRecordsList.add(record);
                    }
                }
            }
        }
    }
    return scoreRecordsList;
}
Also used : DebugScoreRecord(com.airbnb.aerosolve.core.DebugScoreRecord) FloatVector(com.airbnb.aerosolve.core.util.FloatVector)

Example 2 with DebugScoreRecord

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

the class SplineModel method debugScoreComponents.

@Override
public List<DebugScoreRecord> debugScoreComponents(FeatureVector combinedItem) {
    Map<String, Map<String, Double>> flatFeatures = Util.flattenFeature(combinedItem);
    List<DebugScoreRecord> scoreRecordsList = new ArrayList<>();
    for (Map.Entry<String, Map<String, Double>> featureFamily : flatFeatures.entrySet()) {
        Map<String, WeightSpline> familyWeightMap = weightSpline.get(featureFamily.getKey());
        if (familyWeightMap == null)
            continue;
        for (Map.Entry<String, Double> feature : featureFamily.getValue().entrySet()) {
            WeightSpline ws = familyWeightMap.get(feature.getKey());
            if (ws == null)
                continue;
            float val = feature.getValue().floatValue();
            float weight = ws.spline.evaluate(val);
            DebugScoreRecord record = new DebugScoreRecord();
            record.setFeatureFamily(featureFamily.getKey());
            record.setFeatureName(feature.getKey());
            record.setFeatureValue(val);
            record.setFeatureWeight(weight);
            scoreRecordsList.add(record);
        }
    }
    return scoreRecordsList;
}
Also used : DebugScoreRecord(com.airbnb.aerosolve.core.DebugScoreRecord)

Example 3 with DebugScoreRecord

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

the class AdditiveModel method debugScoreComponents.

@Override
public List<DebugScoreRecord> debugScoreComponents(FeatureVector combinedItem) {
    Map<String, Map<String, Double>> flatFeatures = Util.flattenFeature(combinedItem);
    List<DebugScoreRecord> scoreRecordsList = new ArrayList<>();
    for (Map.Entry<String, Map<String, Double>> featureFamily : flatFeatures.entrySet()) {
        Map<String, Function> familyWeightMap = weights.get(featureFamily.getKey());
        if (familyWeightMap == null)
            continue;
        for (Map.Entry<String, Double> feature : featureFamily.getValue().entrySet()) {
            Function func = familyWeightMap.get(feature.getKey());
            if (func == null)
                continue;
            float val = feature.getValue().floatValue();
            float weight = func.evaluate(val);
            DebugScoreRecord record = new DebugScoreRecord();
            record.setFeatureFamily(featureFamily.getKey());
            record.setFeatureName(feature.getKey());
            record.setFeatureValue(val);
            record.setFeatureWeight(weight);
            scoreRecordsList.add(record);
        }
    }
    Map<String, List<Double>> denseFeatures = combinedItem.getDenseFeatures();
    if (denseFeatures != null) {
        Map<String, Function> denseWeights = getOrCreateDenseWeights();
        for (Map.Entry<String, List<Double>> feature : denseFeatures.entrySet()) {
            String featureName = feature.getKey();
            Function fun = denseWeights.get(featureName);
            float[] val = toFloat(feature.getValue());
            float weight = fun.evaluate(val);
            DebugScoreRecord record = new DebugScoreRecord();
            record.setFeatureFamily(DENSE_FAMILY);
            record.setFeatureName(feature.getKey());
            record.setDenseFeatureValue(feature.getValue());
            record.setFeatureWeight(weight);
            scoreRecordsList.add(record);
        }
    }
    return scoreRecordsList;
}
Also used : DebugScoreRecord(com.airbnb.aerosolve.core.DebugScoreRecord) ArrayList(java.util.ArrayList) AbstractFunction(com.airbnb.aerosolve.core.function.AbstractFunction) Function(com.airbnb.aerosolve.core.function.Function) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) AbstractMap(java.util.AbstractMap) Map(java.util.Map)

Example 4 with DebugScoreRecord

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

the class BoostedStumpsModel method debugScoreComponents.

@Override
public List<DebugScoreRecord> debugScoreComponents(FeatureVector combinedItem) {
    List<DebugScoreRecord> scoreRecordsList = new ArrayList<>();
    Map<String, Map<String, Double>> floatFeatures = Util.flattenFeature(combinedItem);
    for (ModelRecord stump : stumps) {
        boolean response = getStumpResponse(stump, floatFeatures);
        if (response) {
            DebugScoreRecord record = new DebugScoreRecord();
            record.setFeatureFamily(stump.featureFamily);
            record.setFeatureName(stump.featureName);
            record.setFeatureValue(floatFeatures.get(stump.featureFamily).get(stump.featureName));
            record.setFeatureWeight(stump.featureWeight);
            scoreRecordsList.add(record);
        }
    }
    return scoreRecordsList;
}
Also used : DebugScoreRecord(com.airbnb.aerosolve.core.DebugScoreRecord) ArrayList(java.util.ArrayList) ModelRecord(com.airbnb.aerosolve.core.ModelRecord) Map(java.util.Map)

Example 5 with DebugScoreRecord

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

the class LinearModel method debugScoreComponents.

@Override
public List<DebugScoreRecord> debugScoreComponents(FeatureVector combinedItem) {
    // linear model takes only string features
    Map<String, Set<String>> stringFeatures = combinedItem.getStringFeatures();
    List<DebugScoreRecord> scoreRecordsList = new ArrayList<>();
    if (stringFeatures == null || weights == null) {
        return scoreRecordsList;
    }
    for (Entry<String, Set<String>> entry : stringFeatures.entrySet()) {
        String family = entry.getKey();
        Map<String, Float> inner = weights.get(family);
        if (inner == null)
            continue;
        for (String value : entry.getValue()) {
            DebugScoreRecord record = new DebugScoreRecord();
            Float weight = inner.get(value);
            if (weight != null) {
                record.setFeatureFamily(family);
                record.setFeatureName(value);
                // 1.0 if the string feature exists, 0.0 otherwise
                record.setFeatureValue(1.0);
                record.setFeatureWeight(weight);
                scoreRecordsList.add(record);
            }
        }
    }
    return scoreRecordsList;
}
Also used : DebugScoreRecord(com.airbnb.aerosolve.core.DebugScoreRecord)

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