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