Search in sources :

Example 16 with DecisionModel

use of org.kie.kogito.decision.DecisionModel in project kogito-apps by kiegroup.

the class TrafficViolationDmnLimeExplainerTest method getModel.

private PredictionProvider getModel() {
    DMNRuntime dmnRuntime = DMNKogito.createGenericDMNRuntime(new InputStreamReader(getClass().getResourceAsStream("/dmn/TrafficViolation.dmn")));
    assertEquals(1, dmnRuntime.getModels().size());
    final String TRAFFIC_VIOLATION_NS = "https://github.com/kiegroup/drools/kie-dmn/_A4BCA8B8-CF08-433F-93B2-A2598F19ECFF";
    final String TRAFFIC_VIOLATION_NAME = "Traffic Violation";
    DecisionModel decisionModel = new DmnDecisionModel(dmnRuntime, TRAFFIC_VIOLATION_NS, TRAFFIC_VIOLATION_NAME);
    return new DecisionModelWrapper(decisionModel);
}
Also used : InputStreamReader(java.io.InputStreamReader) DmnDecisionModel(org.kie.kogito.dmn.DmnDecisionModel) DecisionModel(org.kie.kogito.decision.DecisionModel) DmnDecisionModel(org.kie.kogito.dmn.DmnDecisionModel) DMNRuntime(org.kie.dmn.api.core.DMNRuntime)

Example 17 with DecisionModel

use of org.kie.kogito.decision.DecisionModel in project kogito-apps by kiegroup.

the class TrafficViolationDmnPDPExplainerTest method testTrafficViolationDMNExplanation.

@Test
void testTrafficViolationDMNExplanation() throws ExecutionException, InterruptedException, TimeoutException {
    DMNRuntime dmnRuntime = DMNKogito.createGenericDMNRuntime(new InputStreamReader(getClass().getResourceAsStream("/dmn/TrafficViolation.dmn")));
    assertEquals(1, dmnRuntime.getModels().size());
    final String TRAFFIC_VIOLATION_NS = "https://github.com/kiegroup/drools/kie-dmn/_A4BCA8B8-CF08-433F-93B2-A2598F19ECFF";
    final String TRAFFIC_VIOLATION_NAME = "Traffic Violation";
    DecisionModel decisionModel = new DmnDecisionModel(dmnRuntime, TRAFFIC_VIOLATION_NS, TRAFFIC_VIOLATION_NAME);
    PredictionProvider model = new DecisionModelWrapper(decisionModel);
    List<PredictionInput> inputs = DmnTestUtils.randomTrafficViolationInputs();
    List<PredictionOutput> predictionOutputs = model.predictAsync(inputs).get(Config.INSTANCE.getAsyncTimeout(), Config.INSTANCE.getAsyncTimeUnit());
    List<Prediction> predictions = new ArrayList<>();
    for (int i = 0; i < predictionOutputs.size(); i++) {
        predictions.add(new SimplePrediction(inputs.get(i), predictionOutputs.get(i)));
    }
    PartialDependencePlotExplainer partialDependencePlotExplainer = new PartialDependencePlotExplainer();
    List<PartialDependenceGraph> pdps = partialDependencePlotExplainer.explainFromPredictions(model, predictions);
    AssertionsForClassTypes.assertThat(pdps).isNotNull();
    Assertions.assertThat(pdps).hasSize(8);
}
Also used : SimplePrediction(org.kie.kogito.explainability.model.SimplePrediction) InputStreamReader(java.io.InputStreamReader) PredictionInput(org.kie.kogito.explainability.model.PredictionInput) SimplePrediction(org.kie.kogito.explainability.model.SimplePrediction) Prediction(org.kie.kogito.explainability.model.Prediction) ArrayList(java.util.ArrayList) DecisionModel(org.kie.kogito.decision.DecisionModel) DmnDecisionModel(org.kie.kogito.dmn.DmnDecisionModel) PredictionProvider(org.kie.kogito.explainability.model.PredictionProvider) DMNRuntime(org.kie.dmn.api.core.DMNRuntime) PartialDependencePlotExplainer(org.kie.kogito.explainability.global.pdp.PartialDependencePlotExplainer) PredictionOutput(org.kie.kogito.explainability.model.PredictionOutput) DmnDecisionModel(org.kie.kogito.dmn.DmnDecisionModel) PartialDependenceGraph(org.kie.kogito.explainability.model.PartialDependenceGraph) Test(org.junit.jupiter.api.Test)

Example 18 with DecisionModel

use of org.kie.kogito.decision.DecisionModel in project kogito-apps by kiegroup.

the class LoanEligibilityDmnCounterfactualExplainerTest method getModel.

private PredictionProvider getModel() {
    DMNRuntime dmnRuntime = DMNKogito.createGenericDMNRuntime(new InputStreamReader(Objects.requireNonNull(getClass().getResourceAsStream("/dmn/LoanEligibility.dmn"))));
    assertEquals(1, dmnRuntime.getModels().size());
    final String FRAUD_NS = "https://github.com/kiegroup/kogito-examples/dmn-quarkus-listener-example";
    final String FRAUD_NAME = "LoanEligibility";
    DecisionModel decisionModel = new DmnDecisionModel(dmnRuntime, FRAUD_NS, FRAUD_NAME);
    return new DecisionModelWrapper(decisionModel, List.of("Judgement"));
}
Also used : InputStreamReader(java.io.InputStreamReader) DmnDecisionModel(org.kie.kogito.dmn.DmnDecisionModel) DecisionModel(org.kie.kogito.decision.DecisionModel) DmnDecisionModel(org.kie.kogito.dmn.DmnDecisionModel) DMNRuntime(org.kie.dmn.api.core.DMNRuntime)

Example 19 with DecisionModel

use of org.kie.kogito.decision.DecisionModel in project kogito-apps by kiegroup.

the class PrequalificationDmnCounterfactualExplainerTest method getModel.

private PredictionProvider getModel() {
    DMNRuntime dmnRuntime = DMNKogito.createGenericDMNRuntime(new InputStreamReader(getClass().getResourceAsStream("/dmn/Prequalification-1.dmn")));
    assertEquals(1, dmnRuntime.getModels().size());
    final String NS = "http://www.trisotech.com/definitions/_f31e1f8e-d4ce-4a3a-ac3b-747efa6b3401";
    final String NAME = "Prequalification";
    DecisionModel decisionModel = new DmnDecisionModel(dmnRuntime, NS, NAME);
    return new DecisionModelWrapper(decisionModel, List.of("LTV", "LLPA", "DTI", "Loan Payment"));
}
Also used : InputStreamReader(java.io.InputStreamReader) DmnDecisionModel(org.kie.kogito.dmn.DmnDecisionModel) DecisionModel(org.kie.kogito.decision.DecisionModel) DmnDecisionModel(org.kie.kogito.dmn.DmnDecisionModel) DMNRuntime(org.kie.dmn.api.core.DMNRuntime)

Example 20 with DecisionModel

use of org.kie.kogito.decision.DecisionModel in project kogito-apps by kiegroup.

the class PrequalificationDmnPDPExplainerTest method testPrequalificationDMNExplanation.

@Test
void testPrequalificationDMNExplanation() throws ExecutionException, InterruptedException, TimeoutException {
    DMNRuntime dmnRuntime = DMNKogito.createGenericDMNRuntime(new InputStreamReader(getClass().getResourceAsStream("/dmn/Prequalification-1.dmn")));
    assertEquals(1, dmnRuntime.getModels().size());
    final String NS = "http://www.trisotech.com/definitions/_f31e1f8e-d4ce-4a3a-ac3b-747efa6b3401";
    final String NAME = "Prequalification";
    DecisionModel decisionModel = new DmnDecisionModel(dmnRuntime, NS, NAME);
    PredictionProvider model = new DecisionModelWrapper(decisionModel);
    List<PredictionInput> inputs = DmnTestUtils.randomPrequalificationInputs();
    List<PredictionOutput> predictionOutputs = model.predictAsync(inputs).get(Config.INSTANCE.getAsyncTimeout(), Config.INSTANCE.getAsyncTimeUnit());
    List<Prediction> predictions = new ArrayList<>();
    for (int i = 0; i < predictionOutputs.size(); i++) {
        predictions.add(new SimplePrediction(inputs.get(i), predictionOutputs.get(i)));
    }
    PartialDependencePlotExplainer partialDependencePlotExplainer = new PartialDependencePlotExplainer();
    List<PartialDependenceGraph> pdps = partialDependencePlotExplainer.explainFromPredictions(model, predictions);
    AssertionsForClassTypes.assertThat(pdps).isNotNull();
    Assertions.assertThat(pdps).hasSize(25);
}
Also used : SimplePrediction(org.kie.kogito.explainability.model.SimplePrediction) InputStreamReader(java.io.InputStreamReader) PredictionInput(org.kie.kogito.explainability.model.PredictionInput) SimplePrediction(org.kie.kogito.explainability.model.SimplePrediction) Prediction(org.kie.kogito.explainability.model.Prediction) ArrayList(java.util.ArrayList) DecisionModel(org.kie.kogito.decision.DecisionModel) DmnDecisionModel(org.kie.kogito.dmn.DmnDecisionModel) PredictionProvider(org.kie.kogito.explainability.model.PredictionProvider) DMNRuntime(org.kie.dmn.api.core.DMNRuntime) PartialDependencePlotExplainer(org.kie.kogito.explainability.global.pdp.PartialDependencePlotExplainer) PredictionOutput(org.kie.kogito.explainability.model.PredictionOutput) DmnDecisionModel(org.kie.kogito.dmn.DmnDecisionModel) PartialDependenceGraph(org.kie.kogito.explainability.model.PartialDependenceGraph) Test(org.junit.jupiter.api.Test)

Aggregations

DecisionModel (org.kie.kogito.decision.DecisionModel)28 DMNRuntime (org.kie.dmn.api.core.DMNRuntime)22 DmnDecisionModel (org.kie.kogito.dmn.DmnDecisionModel)22 InputStreamReader (java.io.InputStreamReader)15 Test (org.junit.jupiter.api.Test)14 ArrayList (java.util.ArrayList)7 Prediction (org.kie.kogito.explainability.model.Prediction)7 PredictionInput (org.kie.kogito.explainability.model.PredictionInput)7 PredictionOutput (org.kie.kogito.explainability.model.PredictionOutput)7 PredictionProvider (org.kie.kogito.explainability.model.PredictionProvider)7 SimplePrediction (org.kie.kogito.explainability.model.SimplePrediction)7 DMNContext (org.kie.dmn.api.core.DMNContext)6 EvaluateEvent (org.kie.kogito.tracing.decision.event.evaluate.EvaluateEvent)6 HashMap (java.util.HashMap)5 DMNResult (org.kie.dmn.api.core.DMNResult)5 PartialDependencePlotExplainer (org.kie.kogito.explainability.global.pdp.PartialDependencePlotExplainer)4 PartialDependenceGraph (org.kie.kogito.explainability.model.PartialDependenceGraph)4 Random (java.util.Random)3 LimeConfig (org.kie.kogito.explainability.local.lime.LimeConfig)3 LimeExplainer (org.kie.kogito.explainability.local.lime.LimeExplainer)3