Search in sources :

Example 1 with ModelRecord

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

the class BoostedStumpsModel method debugScoreItem.

@Override
public float debugScoreItem(FeatureVector combinedItem, StringBuilder builder) {
    float sum = 0.0f;
    Map<String, Map<String, Double>> floatFeatures = Util.flattenFeature(combinedItem);
    for (ModelRecord stump : stumps) {
        boolean response = getStumpResponse(stump, floatFeatures);
        String output = stump.featureFamily + ':' + stump.getFeatureName();
        Double threshold = stump.threshold;
        Double weight = stump.featureWeight;
        if (response) {
            builder.append(output);
            builder.append(" >= " + threshold.toString() + " ==> " + weight.toString());
            sum += stump.featureWeight;
        }
    }
    return sum;
}
Also used : ModelRecord(com.airbnb.aerosolve.core.ModelRecord) Map(java.util.Map)

Example 2 with ModelRecord

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

the class BoostedStumpsModel method save.

public void save(BufferedWriter writer) throws IOException {
    ModelHeader header = new ModelHeader();
    header.setModelType("boosted_stumps");
    long count = stumps.size();
    header.setNumRecords(count);
    ModelRecord headerRec = new ModelRecord();
    headerRec.setModelHeader(header);
    writer.write(Util.encode(headerRec));
    writer.newLine();
    for (ModelRecord rec : stumps) {
        writer.write(Util.encode(rec));
        writer.newLine();
    }
    writer.flush();
}
Also used : ModelHeader(com.airbnb.aerosolve.core.ModelHeader) ModelRecord(com.airbnb.aerosolve.core.ModelRecord)

Example 3 with ModelRecord

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

the class FullRankLinearModel method save.

public void save(BufferedWriter writer) throws IOException {
    ModelHeader header = new ModelHeader();
    header.setModelType("full_rank_linear");
    long count = 0;
    for (Map.Entry<String, Map<String, FloatVector>> familyMap : weightVector.entrySet()) {
        count += familyMap.getValue().entrySet().size();
    }
    header.setNumRecords(count);
    header.setLabelDictionary(labelDictionary);
    ModelRecord headerRec = new ModelRecord();
    headerRec.setModelHeader(header);
    writer.write(Util.encode(headerRec));
    writer.newLine();
    for (Map.Entry<String, Map<String, FloatVector>> familyMap : weightVector.entrySet()) {
        for (Map.Entry<String, FloatVector> feature : familyMap.getValue().entrySet()) {
            ModelRecord record = new ModelRecord();
            record.setFeatureFamily(familyMap.getKey());
            record.setFeatureName(feature.getKey());
            ArrayList<Double> arrayList = new ArrayList<Double>();
            for (int i = 0; i < feature.getValue().values.length; i++) {
                arrayList.add((double) feature.getValue().values[i]);
            }
            record.setWeightVector(arrayList);
            writer.write(Util.encode(record));
            writer.newLine();
        }
    }
    writer.flush();
}
Also used : ModelHeader(com.airbnb.aerosolve.core.ModelHeader) ModelRecord(com.airbnb.aerosolve.core.ModelRecord) FloatVector(com.airbnb.aerosolve.core.util.FloatVector)

Example 4 with ModelRecord

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

the class BoostedStumpsModel method scoreItem.

@Override
public float scoreItem(FeatureVector combinedItem) {
    float sum = 0.0f;
    Map<String, Map<String, Double>> floatFeatures = Util.flattenFeature(combinedItem);
    for (ModelRecord stump : stumps) {
        if (getStumpResponse(stump, floatFeatures)) {
            sum += stump.featureWeight;
        }
    }
    return sum;
}
Also used : ModelRecord(com.airbnb.aerosolve.core.ModelRecord) Map(java.util.Map)

Example 5 with ModelRecord

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

the class MultiDimensionSpline method toModelRecord.

@Override
public ModelRecord toModelRecord(String featureFamily, String featureName) {
    ModelRecord record = new ModelRecord();
    record.setFunctionForm(FunctionForm.MultiDimensionSpline);
    record.setFeatureFamily(featureFamily);
    record.setFeatureName(featureName);
    record.setWeightVector(getWeightsFromList());
    record.setNdtreeModel(Arrays.asList(ndTreeModel.getNodes()));
    // Use first coordinates as x for now
    record.setMinVal(points.get(0).getCoordinates().get(0));
    record.setMaxVal(points.get(points.size() - 1).getCoordinates().get(0));
    return record;
}
Also used : ModelRecord(com.airbnb.aerosolve.core.ModelRecord)

Aggregations

ModelRecord (com.airbnb.aerosolve.core.ModelRecord)40 ModelHeader (com.airbnb.aerosolve.core.ModelHeader)14 Test (org.junit.Test)11 ArrayList (java.util.ArrayList)10 FloatVector (com.airbnb.aerosolve.core.util.FloatVector)8 Map (java.util.Map)5 FeatureVector (com.airbnb.aerosolve.core.FeatureVector)4 BufferedReader (java.io.BufferedReader)3 BufferedWriter (java.io.BufferedWriter)3 CharArrayWriter (java.io.CharArrayWriter)3 IOException (java.io.IOException)3 StringReader (java.io.StringReader)3 LabelDictionaryEntry (com.airbnb.aerosolve.core.LabelDictionaryEntry)2 AbstractFunction (com.airbnb.aerosolve.core.function.AbstractFunction)2 Function (com.airbnb.aerosolve.core.function.Function)2 NDTreeModelTest (com.airbnb.aerosolve.core.models.NDTreeModelTest)2 SupportVector (com.airbnb.aerosolve.core.util.SupportVector)2 HashMap (java.util.HashMap)2 DebugScoreRecord (com.airbnb.aerosolve.core.DebugScoreRecord)1 MulticlassScoringResult (com.airbnb.aerosolve.core.MulticlassScoringResult)1