Search in sources :

Example 1 with FieldName

use of org.dmg.pmml.FieldName in project storm by apache.

the class JPmmlModelRunner method extractRawInputs.

/**
     * @return The raw inputs extracted from the tuple for all 'active fields'
     */
@Override
public Map<FieldName, Object> extractRawInputs(Tuple tuple) {
    LOG.debug("Extracting raw inputs from tuple: = [{}]", tuple);
    final Map<FieldName, Object> rawInputs = new LinkedHashMap<>();
    for (FieldName activeField : activeFields) {
        rawInputs.put(activeField, tuple.getValueByField(activeField.getValue()));
    }
    LOG.debug("Raw inputs = [{}]", rawInputs);
    return rawInputs;
}
Also used : FieldName(org.dmg.pmml.FieldName) LinkedHashMap(java.util.LinkedHashMap)

Example 2 with FieldName

use of org.dmg.pmml.FieldName in project storm by apache.

the class JPmmlModelRunner method toValuesMap.

// Sends the same tuple (list of scored/predicted values) to all the declared streams
private Map<String, List<Object>> toValuesMap(Map<FieldName, ?> predScores) {
    final List<Object> scoredVals = new ArrayList<>();
    for (FieldName predictedField : predictedFields) {
        Object targetValue = predScores.get(predictedField);
        scoredVals.add(EvaluatorUtil.decode(targetValue));
    }
    for (FieldName outputField : outputFields) {
        Object targetValue = predScores.get(outputField);
        scoredVals.add(EvaluatorUtil.decode(targetValue));
    }
    final Map<String, List<Object>> valuesMap = new HashMap<>();
    for (String stream : modelOutputs.streams()) {
        valuesMap.put(stream, scoredVals);
    }
    return valuesMap;
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) FieldName(org.dmg.pmml.FieldName)

Example 3 with FieldName

use of org.dmg.pmml.FieldName in project storm by apache.

the class JpmmlModelOutputs method create.

// ======
private static ModelOutputs create(PMML pmmlModel, List<String> streams) {
    final Set<String> fieldNames = new LinkedHashSet<>();
    final Evaluator evaluator = JpmmlFactory.newEvaluator(pmmlModel);
    for (FieldName predictedField : evaluator.getPredictedFields()) {
        fieldNames.add(predictedField.getValue());
    }
    for (FieldName outputField : evaluator.getOutputFields()) {
        fieldNames.add(outputField.getValue());
    }
    final Map<String, Fields> toDeclare = streams.stream().collect(Collectors.toMap(Function.identity(), (x) -> new Fields(new ArrayList<>(fieldNames))));
    return new JpmmlModelOutputs(toDeclare);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Evaluator(org.jpmml.evaluator.Evaluator) JpmmlFactory(org.apache.storm.pmml.runner.jpmml.JpmmlFactory) PMML(org.dmg.pmml.PMML) ModelOutputs(org.apache.storm.pmml.model.ModelOutputs) Set(java.util.Set) Fields(org.apache.storm.tuple.Fields) Utils(org.apache.storm.utils.Utils) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) File(java.io.File) ArrayList(java.util.ArrayList) FieldName(org.dmg.pmml.FieldName) Objects(java.util.Objects) List(java.util.List) Map(java.util.Map) Collections(java.util.Collections) LinkedHashSet(java.util.LinkedHashSet) InputStream(java.io.InputStream) Fields(org.apache.storm.tuple.Fields) Evaluator(org.jpmml.evaluator.Evaluator) FieldName(org.dmg.pmml.FieldName)

Aggregations

FieldName (org.dmg.pmml.FieldName)3 ArrayList (java.util.ArrayList)2 LinkedHashMap (java.util.LinkedHashMap)2 List (java.util.List)2 File (java.io.File)1 InputStream (java.io.InputStream)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 LinkedHashSet (java.util.LinkedHashSet)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Set (java.util.Set)1 Function (java.util.function.Function)1 Collectors (java.util.stream.Collectors)1 ModelOutputs (org.apache.storm.pmml.model.ModelOutputs)1 JpmmlFactory (org.apache.storm.pmml.runner.jpmml.JpmmlFactory)1 Fields (org.apache.storm.tuple.Fields)1 Utils (org.apache.storm.utils.Utils)1 PMML (org.dmg.pmml.PMML)1 Evaluator (org.jpmml.evaluator.Evaluator)1