Search in sources :

Example 41 with CounterfactualExplainabilityRequest

use of org.kie.kogito.explainability.api.CounterfactualExplainabilityRequest 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));
}
Also used : CounterfactualExplainabilityRequest(org.kie.kogito.explainability.api.CounterfactualExplainabilityRequest) ArrayList(java.util.ArrayList) JsonNode(com.fasterxml.jackson.databind.JsonNode) TextNode(com.fasterxml.jackson.databind.node.TextNode) CounterfactualDomainCategorical(org.kie.kogito.explainability.api.CounterfactualDomainCategorical) CounterfactualSearchDomain(org.kie.kogito.explainability.api.CounterfactualSearchDomain) Test(org.junit.jupiter.api.Test)

Aggregations

CounterfactualExplainabilityRequest (org.kie.kogito.explainability.api.CounterfactualExplainabilityRequest)41 Test (org.junit.jupiter.api.Test)37 CounterfactualSearchDomain (org.kie.kogito.explainability.api.CounterfactualSearchDomain)23 IntNode (com.fasterxml.jackson.databind.node.IntNode)22 NamedTypedValue (org.kie.kogito.explainability.api.NamedTypedValue)21 CounterfactualSearchDomainUnitValue (org.kie.kogito.explainability.api.CounterfactualSearchDomainUnitValue)18 CounterfactualDomainRange (org.kie.kogito.explainability.api.CounterfactualDomainRange)17 UnitValue (org.kie.kogito.tracing.typedvalue.UnitValue)17 List (java.util.List)11 CounterfactualSearchDomainStructureValue (org.kie.kogito.explainability.api.CounterfactualSearchDomainStructureValue)11 StructureValue (org.kie.kogito.tracing.typedvalue.StructureValue)10 ArrayList (java.util.ArrayList)9 ModelIdentifier (org.kie.kogito.explainability.api.ModelIdentifier)9 TextNode (com.fasterxml.jackson.databind.node.TextNode)8 CounterfactualExplainabilityResult (org.kie.kogito.explainability.api.CounterfactualExplainabilityResult)8 CounterfactualSearchDomainCollectionValue (org.kie.kogito.explainability.api.CounterfactualSearchDomainCollectionValue)8 CounterfactualPrediction (org.kie.kogito.explainability.model.CounterfactualPrediction)8 Prediction (org.kie.kogito.explainability.model.Prediction)8 CollectionValue (org.kie.kogito.tracing.typedvalue.CollectionValue)8 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)7