Search in sources :

Example 6 with LIMEExplainabilityResult

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

the class TrustyServiceTest method givenAnExplainabilityResultWhenStoreModelIsCalledThenNoExceptionsAreThrown.

@Test
@SuppressWarnings("unchecked")
void givenAnExplainabilityResultWhenStoreModelIsCalledThenNoExceptionsAreThrown() {
    LIMEExplainabilityResult result = new LIMEExplainabilityResult(TEST_EXECUTION_ID, ExplainabilityStatus.SUCCEEDED, null, Collections.emptyList());
    Storage<String, LIMEExplainabilityResult> storageMock = mock(Storage.class);
    when(storageMock.put(eq(TEST_EXECUTION_ID), any(LIMEExplainabilityResult.class))).thenReturn(result);
    when(trustyStorageServiceMock.getLIMEResultStorage()).thenReturn(storageMock);
    Assertions.assertDoesNotThrow(() -> trustyService.storeExplainabilityResult(TEST_EXECUTION_ID, result));
}
Also used : LIMEExplainabilityResult(org.kie.kogito.explainability.api.LIMEExplainabilityResult) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.jupiter.api.Test)

Example 7 with LIMEExplainabilityResult

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

the class AbstractTrustyServiceIT method testStoreExplainabilityResult_LIME.

@Test
public void testStoreExplainabilityResult_LIME() {
    String executionId = "myLIMEExecution1Store";
    trustyService.storeExplainabilityResult(executionId, new LIMEExplainabilityResult(executionId, ExplainabilityStatus.SUCCEEDED, "status", List.of(new SaliencyModel("outcomeName", List.of(new FeatureImportanceModel("feature", 1.0))))));
    LIMEExplainabilityResult result = trustyService.getExplainabilityResultById(executionId, LIMEExplainabilityResult.class);
    assertNotNull(result);
}
Also used : LIMEExplainabilityResult(org.kie.kogito.explainability.api.LIMEExplainabilityResult) SaliencyModel(org.kie.kogito.explainability.api.SaliencyModel) FeatureImportanceModel(org.kie.kogito.explainability.api.FeatureImportanceModel) Test(org.junit.jupiter.api.Test)

Example 8 with LIMEExplainabilityResult

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

the class LIMEExplainabilityResultMarshallerTest method testWriteAndRead.

@Test
public void testWriteAndRead() throws IOException {
    List<FeatureImportanceModel> featureImportanceModels = Collections.singletonList(new FeatureImportanceModel("aFeature", 0d));
    List<SaliencyModel> saliencyModels = Collections.singletonList(new SaliencyModel("outcomeName", featureImportanceModels));
    LIMEExplainabilityResult limeExplainabilityResult = new LIMEExplainabilityResult("executionId", ExplainabilityStatus.SUCCEEDED, "statusDetail", saliencyModels);
    LIMEExplainabilityResultMarshaller marshaller = new LIMEExplainabilityResultMarshaller(new ObjectMapper());
    marshaller.writeTo(writer, limeExplainabilityResult);
    LIMEExplainabilityResult retrieved = marshaller.readFrom(reader);
    Assertions.assertEquals(limeExplainabilityResult.getExecutionId(), retrieved.getExecutionId());
    Assertions.assertEquals(limeExplainabilityResult.getStatus(), retrieved.getStatus());
    Assertions.assertEquals(limeExplainabilityResult.getStatusDetails(), retrieved.getStatusDetails());
    Assertions.assertEquals(saliencyModels.get(0).getOutcomeName(), retrieved.getSaliencies().get(0).getOutcomeName());
    Assertions.assertEquals(featureImportanceModels.get(0).getFeatureName(), retrieved.getSaliencies().get(0).getFeatureImportance().get(0).getFeatureName());
    Assertions.assertEquals(featureImportanceModels.get(0).getFeatureScore(), retrieved.getSaliencies().get(0).getFeatureImportance().get(0).getFeatureScore());
}
Also used : LIMEExplainabilityResult(org.kie.kogito.explainability.api.LIMEExplainabilityResult) SaliencyModel(org.kie.kogito.explainability.api.SaliencyModel) FeatureImportanceModel(org.kie.kogito.explainability.api.FeatureImportanceModel) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.jupiter.api.Test)

Example 9 with LIMEExplainabilityResult

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

the class ExplanationServiceImplTest method testLIMEExplainAsyncFailed.

@Test
@SuppressWarnings("unchecked")
void testLIMEExplainAsyncFailed() {
    String errorMessage = "Something bad happened";
    RuntimeException exception = new RuntimeException(errorMessage);
    when(instance.stream()).thenReturn(Stream.of(limeExplainerServiceHandlerMock));
    when(limeExplainerMock.explainAsync(any(Prediction.class), eq(predictionProviderMock), any(Consumer.class))).thenThrow(exception);
    BaseExplainabilityResult result = assertDoesNotThrow(() -> explanationService.explainAsync(LIME_REQUEST, callbackMock).toCompletableFuture().get(Config.INSTANCE.getAsyncTimeout(), Config.INSTANCE.getAsyncTimeUnit()));
    assertNotNull(result);
    assertTrue(result instanceof LIMEExplainabilityResult);
    LIMEExplainabilityResult exceptionResult = (LIMEExplainabilityResult) result;
    assertEquals(EXECUTION_ID, exceptionResult.getExecutionId());
    assertSame(ExplainabilityStatus.FAILED, exceptionResult.getStatus());
    assertEquals(errorMessage, exceptionResult.getStatusDetails());
}
Also used : LIMEExplainabilityResult(org.kie.kogito.explainability.api.LIMEExplainabilityResult) Consumer(java.util.function.Consumer) BaseExplainabilityResult(org.kie.kogito.explainability.api.BaseExplainabilityResult) Prediction(org.kie.kogito.explainability.model.Prediction) Test(org.junit.jupiter.api.Test)

Example 10 with LIMEExplainabilityResult

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

the class ExplainerServiceHandlerRegistryTest method testLIME_storeExplainabilityResult.

@Test
public void testLIME_storeExplainabilityResult() {
    when(storageLIME.containsKey(eq(EXECUTION_ID))).thenReturn(false);
    LIMEExplainabilityResult result = mock(LIMEExplainabilityResult.class);
    registry.storeExplainabilityResult(EXECUTION_ID, result);
    verify(limeExplainerServiceHandler).storeExplainabilityResult(eq(EXECUTION_ID), eq(result));
}
Also used : LIMEExplainabilityResult(org.kie.kogito.explainability.api.LIMEExplainabilityResult) Test(org.junit.jupiter.api.Test)

Aggregations

LIMEExplainabilityResult (org.kie.kogito.explainability.api.LIMEExplainabilityResult)14 Test (org.junit.jupiter.api.Test)13 SaliencyModel (org.kie.kogito.explainability.api.SaliencyModel)7 FeatureImportanceModel (org.kie.kogito.explainability.api.FeatureImportanceModel)6 BaseExplainabilityResult (org.kie.kogito.explainability.api.BaseExplainabilityResult)5 UnitValue (org.kie.kogito.tracing.typedvalue.UnitValue)3 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)3 IntNode (com.fasterxml.jackson.databind.node.IntNode)2 ArrayList (java.util.ArrayList)2 Collections (java.util.Collections)2 List (java.util.List)2 Optional (java.util.Optional)2 Consumer (java.util.function.Consumer)2 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)2 Assertions.assertNotNull (org.junit.jupiter.api.Assertions.assertNotNull)2 Assertions.assertThrows (org.junit.jupiter.api.Assertions.assertThrows)2 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)2 ExplainabilityStatus (org.kie.kogito.explainability.api.ExplainabilityStatus)2