@Test public void testPerturbedExecution() { DecisionModels decisionModels = (namespace, name) -> { if (MODEL_NAMESPACE.equals(namespace) && MODEL_NAME.equals(name)) { return decisionModel; } throw new RuntimeException("Model " + namespace + ":" + name + " not found."); }; Map<String, Object> perturbedRequest = createRequest(); PredictInput predictInput = new PredictInput( new ModelIdentifier("dmn", String.format("%s%s%s", MODEL_NAMESPACE, RESOURCE_ID_SEPARATOR, MODEL_NAME)), perturbedRequest); StaticApplication application = new StaticApplication(null, null, null, decisionModels, null); ExplainabilityService explainabilityService = ExplainabilityService.INSTANCE; List<PredictOutput> predictOutputs = explainabilityService.processRequest(application, singletonList(predictInput)); Assertions.assertEquals(1, predictOutputs.size()); PredictOutput predictOutput = predictOutputs.get(0); Assertions.assertNotNull(predictOutput); Assertions.assertNotNull(predictOutput.getResult()); Map<String, Object> perturbedResult = predictOutput.getResult(); Assertions.assertTrue(perturbedResult.containsKey("Should the driver be suspended?")); Assertions.assertEquals("No", perturbedResult.get("Should the driver be suspended?")); Assertions.assertTrue(perturbedResult.containsKey("Fine")); Assertions.assertNull(perturbedResult.get("Fine")); }
public List<PredictOutput> processRequest(Application application, List<PredictInput> predictInputs) { return predictInputs.stream().map(predictInput -> executors.stream() .filter(r -> r.acceptRequest(predictInput)) .map(r -> r.processRequest(application, predictInput)) .findFirst() .orElseThrow(() -> new IllegalArgumentException("Malformed resourceType " + predictInput.getModelIdentifier().getResourceType()))) .collect(toList()); }
ExplainabilityService { public List<PredictOutput> processRequest(Application application, List<PredictInput> predictInputs) { return predictInputs.stream().map(predictInput -> executors.stream() .filter(r -> r.acceptRequest(predictInput)) .map(r -> r.processRequest(application, predictInput)) .findFirst() .orElseThrow(() -> new IllegalArgumentException("Malformed resourceType " + predictInput.getModelIdentifier().getResourceType()))) .collect(toList()); } }
ExplainabilityService { public List<PredictOutput> processRequest(Application application, List<PredictInput> predictInputs) { return predictInputs.stream().map(predictInput -> executors.stream() .filter(r -> r.acceptRequest(predictInput)) .map(r -> r.processRequest(application, predictInput)) .findFirst() .orElseThrow(() -> new IllegalArgumentException("Malformed resourceType " + predictInput.getModelIdentifier().getResourceType()))) .collect(toList()); } ExplainabilityService(Collection<ExplainabilityResourceExecutor> executors); }
ExplainabilityService { public List<PredictOutput> processRequest(Application application, List<PredictInput> predictInputs) { return predictInputs.stream().map(predictInput -> executors.stream() .filter(r -> r.acceptRequest(predictInput)) .map(r -> r.processRequest(application, predictInput)) .findFirst() .orElseThrow(() -> new IllegalArgumentException("Malformed resourceType " + predictInput.getModelIdentifier().getResourceType()))) .collect(toList()); } ExplainabilityService(Collection<ExplainabilityResourceExecutor> executors); List<PredictOutput> processRequest(Application application, List<PredictInput> predictInputs); }
ExplainabilityService { public List<PredictOutput> processRequest(Application application, List<PredictInput> predictInputs) { return predictInputs.stream().map(predictInput -> executors.stream() .filter(r -> r.acceptRequest(predictInput)) .map(r -> r.processRequest(application, predictInput)) .findFirst() .orElseThrow(() -> new IllegalArgumentException("Malformed resourceType " + predictInput.getModelIdentifier().getResourceType()))) .collect(toList()); } ExplainabilityService(Collection<ExplainabilityResourceExecutor> executors); List<PredictOutput> processRequest(Application application, List<PredictInput> predictInputs); static final ExplainabilityService INSTANCE; }