Search in sources :

Example 6 with LIMEExplainabilityRequest

use of org.kie.kogito.explainability.api.LIMEExplainabilityRequest in project kogito-apps by kiegroup.

the class LimeExplainerServiceHandlerTest method testGetPredictionWithEmptyDefinition.

@Test
public void testGetPredictionWithEmptyDefinition() {
    LIMEExplainabilityRequest request = new LIMEExplainabilityRequest(EXECUTION_ID, SERVICE_URL, MODEL_IDENTIFIER, Collections.emptyList(), Collections.emptyList());
    Prediction prediction = handler.getPrediction(request);
    assertTrue(prediction instanceof SimplePrediction);
    SimplePrediction simplePrediction = (SimplePrediction) prediction;
    assertTrue(simplePrediction.getInput().getFeatures().isEmpty());
    assertTrue(simplePrediction.getOutput().getOutputs().isEmpty());
}
Also used : LIMEExplainabilityRequest(org.kie.kogito.explainability.api.LIMEExplainabilityRequest) SimplePrediction(org.kie.kogito.explainability.model.SimplePrediction) Prediction(org.kie.kogito.explainability.model.Prediction) SimplePrediction(org.kie.kogito.explainability.model.SimplePrediction) Test(org.junit.jupiter.api.Test)

Example 7 with LIMEExplainabilityRequest

use of org.kie.kogito.explainability.api.LIMEExplainabilityRequest in project kogito-apps by kiegroup.

the class LocalExplainerServiceHandlerRegistryTest method testLIME_explainAsyncWithResults.

@Test
public void testLIME_explainAsyncWithResults() {
    LIMEExplainabilityRequest request = new LIMEExplainabilityRequest(EXECUTION_ID, SERVICE_URL, MODEL_IDENTIFIER, Collections.emptyList(), Collections.emptyList());
    registry.explainAsyncWithResults(request, callback);
    verify(limeExplainerServiceHandler).explainAsyncWithResults(eq(request), eq(callback));
}
Also used : LIMEExplainabilityRequest(org.kie.kogito.explainability.api.LIMEExplainabilityRequest) Test(org.junit.jupiter.api.Test)

Example 8 with LIMEExplainabilityRequest

use of org.kie.kogito.explainability.api.LIMEExplainabilityRequest in project kogito-apps by kiegroup.

the class ExplainabilityApiV1IT method testEndpointWithRequest.

@Test
void testEndpointWithRequest() throws JsonProcessingException {
    ModelIdentifier modelIdentifier = new ModelIdentifier("dmn", "namespace:name");
    String body = MAPPER.writeValueAsString(new LIMEExplainabilityRequest(executionId, serviceUrl, modelIdentifier, Collections.emptyList(), Collections.emptyList()));
    BaseExplainabilityResult result = given().contentType(ContentType.JSON).body(body).when().post("/v1/explain").as(BaseExplainabilityResult.class);
    assertEquals(executionId, result.getExecutionId());
}
Also used : LIMEExplainabilityRequest(org.kie.kogito.explainability.api.LIMEExplainabilityRequest) BaseExplainabilityResult(org.kie.kogito.explainability.api.BaseExplainabilityResult) ModelIdentifier(org.kie.kogito.explainability.api.ModelIdentifier) Test(org.junit.jupiter.api.Test) QuarkusTest(io.quarkus.test.junit.QuarkusTest)

Example 9 with LIMEExplainabilityRequest

use of org.kie.kogito.explainability.api.LIMEExplainabilityRequest in project kogito-apps by kiegroup.

the class TrustyServiceImpl method processDecision.

@Override
public void processDecision(String executionId, Decision decision) {
    storeDecision(executionId, decision);
    if (isExplainabilityEnabled) {
        List<NamedTypedValue> inputs = decision.getInputs() != null ? decision.getInputs().stream().map(input -> new NamedTypedValue(input.getName(), input.getValue())).collect(Collectors.toList()) : Collections.emptyList();
        List<NamedTypedValue> outputs = decision.getOutcomes() != null ? decision.getOutcomes().stream().map(output -> new NamedTypedValue(output.getOutcomeName(), output.getOutcomeResult())).collect(Collectors.toList()) : Collections.emptyList();
        explainabilityRequestProducer.sendEvent(new LIMEExplainabilityRequest(executionId, decision.getServiceUrl(), createDecisionModelIdentifier(decision), inputs, outputs));
    }
}
Also used : LIMEExplainabilityRequest(org.kie.kogito.explainability.api.LIMEExplainabilityRequest) NamedTypedValue(org.kie.kogito.explainability.api.NamedTypedValue)

Example 10 with LIMEExplainabilityRequest

use of org.kie.kogito.explainability.api.LIMEExplainabilityRequest in project kogito-apps by kiegroup.

the class ExplainabilityRequestProducerTest method test.

@Test
void test() {
    AssertSubscriber<String> subscriber = AssertSubscriber.create(1);
    ExplainabilityRequestProducer producer = new ExplainabilityRequestProducer();
    producer.getEventPublisher().subscribe(subscriber);
    producer.sendEvent(new LIMEExplainabilityRequest("executionId", "http://localhost:8080/model", new ModelIdentifier("dmn", "modelNamespace:model"), Collections.emptyList(), Collections.emptyList()));
    assertEquals(1, subscriber.getItems().size());
}
Also used : LIMEExplainabilityRequest(org.kie.kogito.explainability.api.LIMEExplainabilityRequest) ModelIdentifier(org.kie.kogito.explainability.api.ModelIdentifier) Test(org.junit.jupiter.api.Test)

Aggregations

LIMEExplainabilityRequest (org.kie.kogito.explainability.api.LIMEExplainabilityRequest)10 Test (org.junit.jupiter.api.Test)9 BaseExplainabilityResult (org.kie.kogito.explainability.api.BaseExplainabilityResult)4 ModelIdentifier (org.kie.kogito.explainability.api.ModelIdentifier)4 LIMEExplainabilityResult (org.kie.kogito.explainability.api.LIMEExplainabilityResult)3 NamedTypedValue (org.kie.kogito.explainability.api.NamedTypedValue)3 QuarkusTest (io.quarkus.test.junit.QuarkusTest)2 SaliencyModel (org.kie.kogito.explainability.api.SaliencyModel)2 Feature (org.kie.kogito.explainability.model.Feature)2 FeatureImportance (org.kie.kogito.explainability.model.FeatureImportance)2 Output (org.kie.kogito.explainability.model.Output)2 Prediction (org.kie.kogito.explainability.model.Prediction)2 Saliency (org.kie.kogito.explainability.model.Saliency)2 SimplePrediction (org.kie.kogito.explainability.model.SimplePrediction)2 Value (org.kie.kogito.explainability.model.Value)2 CollectionValue (org.kie.kogito.tracing.typedvalue.CollectionValue)2 StructureValue (org.kie.kogito.tracing.typedvalue.StructureValue)2 UnitValue (org.kie.kogito.tracing.typedvalue.UnitValue)2 IntNode (com.fasterxml.jackson.databind.node.IntNode)1 Collections (java.util.Collections)1