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;
}
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;
}
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));
}
}
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();
}
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;
}
Aggregations