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));
}
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);
}
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());
}
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());
}
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));
}
Aggregations