Search in sources :

Example 21 with ModelRecord

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

the class Point method toModelRecord.

@Override
public ModelRecord toModelRecord(String featureFamily, String featureName) {
    ModelRecord record = new ModelRecord();
    record.setFunctionForm(FunctionForm.Point);
    record.setFeatureFamily(featureFamily);
    record.setFeatureName(featureName);
    ArrayList<Double> arrayList = new ArrayList<Double>();
    arrayList.add((double) weight);
    record.setWeightVector(arrayList);
    return record;
}
Also used : ArrayList(java.util.ArrayList) ModelRecord(com.airbnb.aerosolve.core.ModelRecord)

Example 22 with ModelRecord

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

the class Spline method toModelRecord.

@Override
public ModelRecord toModelRecord(String featureFamily, String featureName) {
    ModelRecord record = new ModelRecord();
    record.setFunctionForm(FunctionForm.Spline);
    record.setFeatureFamily(featureFamily);
    record.setFeatureName(featureName);
    ArrayList<Double> arrayList = new ArrayList<Double>();
    for (int i = 0; i < weights.length; i++) {
        arrayList.add((double) weights[i]);
    }
    record.setWeightVector(arrayList);
    record.setMinVal(minVal);
    record.setMaxVal(maxVal);
    return record;
}
Also used : ArrayList(java.util.ArrayList) ModelRecord(com.airbnb.aerosolve.core.ModelRecord)

Example 23 with ModelRecord

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

the class AdditiveModel method loadInternal.

@Override
protected void loadInternal(ModelHeader header, BufferedReader reader) throws IOException {
    long rows = header.getNumRecords();
    slope = header.getSlope();
    offset = header.getOffset();
    weights = new HashMap<>();
    for (long i = 0; i < rows; i++) {
        String line = reader.readLine();
        ModelRecord record = Util.decodeModel(line);
        String family = record.getFeatureFamily();
        String name = record.getFeatureName();
        Map<String, Function> inner = weights.get(family);
        if (inner == null) {
            inner = new HashMap<>();
            weights.put(family, inner);
        }
        inner.put(name, AbstractFunction.buildFunction(record));
    }
}
Also used : AbstractFunction(com.airbnb.aerosolve.core.function.AbstractFunction) Function(com.airbnb.aerosolve.core.function.Function) ModelRecord(com.airbnb.aerosolve.core.ModelRecord)

Example 24 with ModelRecord

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

the class AdditiveModel method save.

@Override
public void save(BufferedWriter writer) throws IOException {
    ModelHeader header = new ModelHeader();
    header.setModelType("additive");
    header.setSlope(slope);
    header.setOffset(offset);
    long count = 0;
    for (Map.Entry<String, Map<String, Function>> familyMap : weights.entrySet()) {
        count += familyMap.getValue().size();
    }
    header.setNumRecords(count);
    ModelRecord headerRec = new ModelRecord();
    headerRec.setModelHeader(header);
    writer.write(Util.encode(headerRec));
    writer.newLine();
    for (Map.Entry<String, Map<String, Function>> familyMap : weights.entrySet()) {
        String featureFamily = familyMap.getKey();
        for (Map.Entry<String, Function> feature : familyMap.getValue().entrySet()) {
            Function func = feature.getValue();
            String featureName = feature.getKey();
            writer.write(Util.encode(func.toModelRecord(featureFamily, featureName)));
            writer.newLine();
        }
    }
    writer.flush();
}
Also used : AbstractFunction(com.airbnb.aerosolve.core.function.AbstractFunction) Function(com.airbnb.aerosolve.core.function.Function) ModelHeader(com.airbnb.aerosolve.core.ModelHeader) ModelRecord(com.airbnb.aerosolve.core.ModelRecord) HashMap(java.util.HashMap) AbstractMap(java.util.AbstractMap) Map(java.util.Map)

Example 25 with ModelRecord

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

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