use of org.kie.kogito.explainability.api.CounterfactualDomainCategorical in project kogito-apps by kiegroup.
the class ExplainabilityApiV1Test method testGetCounterfactualResultsWhenExecutionDoesExist.
@Test
public void testGetCounterfactualResultsWhenExecutionDoesExist() {
NamedTypedValue goal = buildGoalUnit("unit", "string", new TextNode("hello"));
CounterfactualSearchDomain searchDomain = buildSearchDomainUnit("unit", "string", new CounterfactualDomainCategorical(List.of(new TextNode("hello"), new TextNode("goodbye"))));
when(trustyService.getCounterfactualRequest(anyString(), anyString())).thenReturn(new CounterfactualExplainabilityRequest(EXECUTION_ID, SERVICE_URL, new ModelIdentifier("resourceType", "resourceIdentifier"), COUNTERFACTUAL_ID, Collections.emptyList(), List.of(goal), List.of(searchDomain), MAX_RUNNING_TIME_SECONDS));
Response response = explainabilityEndpoint.getCounterfactualDetails(EXECUTION_ID, COUNTERFACTUAL_ID);
assertNotNull(response);
assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
Object entity = response.getEntity();
assertNotNull(entity);
assertTrue(entity instanceof CounterfactualResultsResponse);
CounterfactualResultsResponse resultsResponse = (CounterfactualResultsResponse) entity;
assertEquals(EXECUTION_ID, resultsResponse.getExecutionId());
assertEquals(COUNTERFACTUAL_ID, resultsResponse.getCounterfactualId());
assertEquals(MAX_RUNNING_TIME_SECONDS, resultsResponse.getMaxRunningTimeSeconds());
assertEquals(1, resultsResponse.getGoals().size());
assertEquals(goal, resultsResponse.getGoals().iterator().next());
assertEquals(1, resultsResponse.getSearchDomains().size());
assertEquals(searchDomain, resultsResponse.getSearchDomains().iterator().next());
assertTrue(resultsResponse.getSolutions().isEmpty());
}
use of org.kie.kogito.explainability.api.CounterfactualDomainCategorical in project kogito-apps by kiegroup.
the class AbstractTrustyServiceIT method assertCounterfactualDomainCategorical.
private void assertCounterfactualDomainCategorical(CounterfactualDomain expectedDomain, CounterfactualDomain actualDomain) {
assertTrue(expectedDomain instanceof CounterfactualDomainCategorical);
assertTrue(actualDomain instanceof CounterfactualDomainCategorical);
CounterfactualDomainCategorical expectedDomainCategorical = (CounterfactualDomainCategorical) expectedDomain;
CounterfactualDomainCategorical actualDomainCategorical = (CounterfactualDomainCategorical) actualDomain;
assertEquals(expectedDomainCategorical.getCategories().size(), actualDomainCategorical.getCategories().size());
assertTrue(expectedDomainCategorical.getCategories().containsAll(actualDomainCategorical.getCategories()));
}
use of org.kie.kogito.explainability.api.CounterfactualDomainCategorical in project kogito-apps by kiegroup.
the class AbstractTrustyServiceIT method testCounterfactuals_StoreSingleAndRetrieveSingleWithSearchDomainCategorical.
@Test
public void testCounterfactuals_StoreSingleAndRetrieveSingleWithSearchDomainCategorical() {
String executionId = "myCFExecution1";
storeExecution(executionId, 0L);
// The Goals structures must be comparable to the original decisions outcomes.
// The Search Domain structures must be identical those of the original decision inputs.
Collection<JsonNode> categories = List.of(new TextNode("1"), new TextNode("2"));
CounterfactualSearchDomain searchDomain = buildSearchDomainUnit("test", "number", new CounterfactualDomainCategorical(categories));
CounterfactualExplainabilityRequest request = trustyService.requestCounterfactuals(executionId, Collections.emptyList(), Collections.singletonList(searchDomain));
assertNotNull(request);
assertEquals(request.getExecutionId(), executionId);
assertNotNull(request.getCounterfactualId());
assertEquals(1, request.getSearchDomains().size());
List<CounterfactualSearchDomain> requestSearchDomains = new ArrayList<>(request.getSearchDomains());
assertCounterfactualSearchDomainCategorical(searchDomain, requestSearchDomains.get(0));
CounterfactualExplainabilityRequest result = trustyService.getCounterfactualRequest(executionId, request.getCounterfactualId());
assertNotNull(result);
assertEquals(request.getExecutionId(), result.getExecutionId());
assertEquals(request.getCounterfactualId(), result.getCounterfactualId());
assertEquals(1, result.getSearchDomains().size());
List<CounterfactualSearchDomain> resultSearchDomains = new ArrayList<>(result.getSearchDomains());
assertCounterfactualSearchDomainCategorical(searchDomain, resultSearchDomains.get(0));
}
use of org.kie.kogito.explainability.api.CounterfactualDomainCategorical in project kogito-apps by kiegroup.
the class CounterfactualDomainSerialisationTest method testCounterfactualSearchDomain_Categorical_RoundTrip.
@Test
public void testCounterfactualSearchDomain_Categorical_RoundTrip() throws Exception {
CounterfactualDomainCategorical domainCategorical = new CounterfactualDomainCategorical(List.of(new TextNode("A"), new TextNode("B")));
CounterfactualSearchDomain searchDomain = new CounterfactualSearchDomain("age", new CounterfactualSearchDomainUnitValue("integer", "integer", Boolean.TRUE, domainCategorical));
mapper.writeValue(writer, searchDomain);
String searchDomainJson = writer.toString();
assertNotNull(searchDomainJson);
CounterfactualSearchDomain roundTrippedSearchDomain = mapper.readValue(searchDomainJson, CounterfactualSearchDomain.class);
assertTrue(roundTrippedSearchDomain.getValue() instanceof CounterfactualSearchDomainUnitValue);
assertEquals(searchDomain.getValue().getKind(), roundTrippedSearchDomain.getValue().getKind());
assertEquals(searchDomain.getName(), roundTrippedSearchDomain.getName());
assertEquals(searchDomain.getValue().getType(), roundTrippedSearchDomain.getValue().getType());
assertEquals(searchDomain.getValue().toUnit().getBaseType(), roundTrippedSearchDomain.getValue().toUnit().getBaseType());
assertEquals(searchDomain.getValue().toUnit().isFixed(), roundTrippedSearchDomain.getValue().toUnit().isFixed());
assertTrue(roundTrippedSearchDomain.getValue().toUnit().getDomain() instanceof CounterfactualDomainCategorical);
CounterfactualDomainCategorical roundTrippedDomainCategorical = (CounterfactualDomainCategorical) roundTrippedSearchDomain.getValue().toUnit().getDomain();
assertEquals(domainCategorical.getCategories().size(), roundTrippedDomainCategorical.getCategories().size());
assertTrue(roundTrippedDomainCategorical.getCategories().containsAll(domainCategorical.getCategories()));
}
Aggregations