use of org.kie.kogito.explainability.api.HasNameValue in project kogito-apps by kiegroup.
the class ConversionUtils method toFeatureList.
// //////////////////////////
// TO EXPLAINABILITY MODEL
// //////////////////////////
/*
* ---------------------------------------
* Feature conversion
* ---------------------------------------
*/
public static List<Feature> toFeatureList(Collection<? extends HasNameValue<TypedValue>> values, Collection<CounterfactualSearchDomain> searchDomains) {
if (searchDomains.isEmpty()) {
return toFeatureList(values);
} else {
AtomicInteger index = new AtomicInteger();
final List<FeatureDomain> featureDomains = toFeatureDomainList(searchDomains);
final List<Boolean> featureConstraints = toFeatureConstraintList(searchDomains);
return values.stream().map(hnv -> {
final String name = hnv.getName();
final TypedValue value = hnv.getValue();
final int i = index.getAndIncrement();
return toFeature(name, value, featureDomains.get(i), featureConstraints.get(i));
}).collect(Collectors.toList());
}
}
use of org.kie.kogito.explainability.api.HasNameValue in project kogito-apps by kiegroup.
the class RemotePredictionProvider method toPredictionOutput.
protected PredictionOutput toPredictionOutput(JsonObject mainObj) {
if (mainObj == null || !mainObj.containsKey("result")) {
LOG.error("Malformed json {}", mainObj);
return null;
}
List<Output> resultOutputs = toOutputList(mainObj.getJsonObject("result"));
List<String> resultOutputNames = resultOutputs.stream().map(Output::getName).collect(toList());
Map<String, TypedValue> mappedOutputs = predictionOutputs.stream().collect(Collectors.toMap(HasNameValue::getName, HasNameValue::getValue));
// It's possible that some outputs are missing in the response from the prediction service
// (e.g. when the generated perturbed inputs don't make sense and a decision is skipped).
// The explainer, however, may throw exceptions if it can't find all the inputs that were
// specified in the execution request.
// Here we take the outputs received from the prediction service and we fill (only if needed)
// the missing ones with Output objects containing "null" values of type UNDEFINED, to make
// the explainer happy.
List<Output> outputs = Stream.concat(resultOutputs.stream().filter(output -> mappedOutputs.containsKey(output.getName())), mappedOutputs.keySet().stream().filter(key -> !resultOutputNames.contains(key)).map(key -> new Output(key, Type.UNDEFINED, new Value(null), 1d))).collect(toList());
return new PredictionOutput(outputs);
}
Aggregations