use of org.kie.kogito.explainability.api.LIMEExplainabilityResult in project kogito-apps by kiegroup.
the class LIMESaliencyConverterTest method testFromResult_DecisionNotExists.
@Test
public void testFromResult_DecisionNotExists() {
LIMEExplainabilityResult result = LIMEExplainabilityResult.buildSucceeded(EXECUTION_ID, List.of(new SaliencyModel("outcomeName1", List.of(new FeatureImportanceModel("feature1a", 1.0), new FeatureImportanceModel("feature1b", 2.0))), new SaliencyModel("outcomeName2", List.of(new FeatureImportanceModel("feature2", 3.0)))));
when(trustyService.getDecisionById(eq(EXECUTION_ID))).thenThrow(new IllegalArgumentException());
assertThrows(IllegalArgumentException.class, () -> converter.fromResult(EXECUTION_ID, result));
}
use of org.kie.kogito.explainability.api.LIMEExplainabilityResult in project kogito-apps by kiegroup.
the class LIMESaliencyConverterTest method testFromResult_DecisionExists_WhenOutcomeNameNotFound.
@Test
public void testFromResult_DecisionExists_WhenOutcomeNameNotFound() {
LIMEExplainabilityResult result = LIMEExplainabilityResult.buildSucceeded(EXECUTION_ID, List.of(new SaliencyModel("outcomeName1", List.of(new FeatureImportanceModel("feature1", 1.0))), new SaliencyModel("outcomeName2", List.of(new FeatureImportanceModel("feature2", 2.0)))));
Decision decision = new Decision(EXECUTION_ID, "sourceUrl", "serviceUrl", 0L, true, "executorName", "executorModelName", "executorModelNamespace", new ArrayList<>(), new ArrayList<>());
decision.getOutcomes().add(new DecisionOutcome("outcomeId1", "outcomeName1", ExplainabilityStatus.SUCCEEDED.name(), new UnitValue("type", new IntNode(1)), Collections.emptyList(), Collections.emptyList()));
decision.getOutcomes().add(new DecisionOutcome("outcomeId2", "outcomeNameX", ExplainabilityStatus.SUCCEEDED.name(), new UnitValue("type2", new IntNode(2)), Collections.emptyList(), Collections.emptyList()));
when(trustyService.getDecisionById(eq(EXECUTION_ID))).thenReturn(decision);
SalienciesResponse response = converter.fromResult(EXECUTION_ID, result);
assertNotNull(response);
assertEquals(ExplainabilityStatus.SUCCEEDED.name(), response.getStatus());
assertEquals(1, response.getSaliencies().size());
List<SaliencyResponse> saliencyResponses = new ArrayList<>(response.getSaliencies());
SaliencyResponse saliencyResponse1 = saliencyResponses.get(0);
assertEquals("outcomeId1", saliencyResponse1.getOutcomeId());
assertEquals("outcomeName1", saliencyResponse1.getOutcomeName());
assertEquals(1, saliencyResponse1.getFeatureImportance().size());
Optional<FeatureImportanceModel> oFeatureImportance1Model1 = saliencyResponse1.getFeatureImportance().stream().filter(fim -> fim.getFeatureName().equals("feature1")).findFirst();
assertTrue(oFeatureImportance1Model1.isPresent());
assertEquals(1.0, oFeatureImportance1Model1.get().getFeatureScore());
}
use of org.kie.kogito.explainability.api.LIMEExplainabilityResult in project kogito-apps by kiegroup.
the class TrustyServiceTest method givenAnExplainabilityResultWhenAnExplainabilityResultIsStoredAndRetrievedByIdThenTheOriginalObjectIsReturned.
@Test
void givenAnExplainabilityResultWhenAnExplainabilityResultIsStoredAndRetrievedByIdThenTheOriginalObjectIsReturned() {
LIMEExplainabilityResult result = new LIMEExplainabilityResult(TEST_EXECUTION_ID, ExplainabilityStatus.SUCCEEDED, null, Collections.emptyList());
Storage<String, LIMEExplainabilityResult> storageMock = new StorageImplMock<>(String.class);
when(trustyStorageServiceMock.getLIMEResultStorage()).thenReturn(storageMock);
trustyService.storeExplainabilityResult(TEST_EXECUTION_ID, result);
// The mocked stream needs to be recreated for subsequent invocations
when(explanationHandlers.stream()).thenReturn(Stream.of(limeExplainerServiceHandler, counterfactualExplainerServiceHandler));
assertEquals(result, trustyService.getExplainabilityResultById(TEST_EXECUTION_ID, LIMEExplainabilityResult.class));
}
use of org.kie.kogito.explainability.api.LIMEExplainabilityResult in project kogito-apps by kiegroup.
the class TrustyServiceTest method givenAnExplainabilityResultWhenStoreModelIsCalledMoreThanOnceForSameModelThenExceptionIsThrown.
@Test
@SuppressWarnings("unchecked")
void givenAnExplainabilityResultWhenStoreModelIsCalledMoreThanOnceForSameModelThenExceptionIsThrown() {
LIMEExplainabilityResult result = new LIMEExplainabilityResult(TEST_EXECUTION_ID, ExplainabilityStatus.SUCCEEDED, null, Collections.emptyList());
Storage<String, LIMEExplainabilityResult> storageMock = mock(Storage.class);
when(storageMock.containsKey(eq(TEST_EXECUTION_ID))).thenReturn(true);
when(storageMock.put(eq(TEST_EXECUTION_ID), any(LIMEExplainabilityResult.class))).thenReturn(result);
when(trustyStorageServiceMock.getLIMEResultStorage()).thenReturn(storageMock);
assertThrows(IllegalArgumentException.class, () -> trustyService.storeExplainabilityResult(TEST_EXECUTION_ID, result));
}
Aggregations