Search in sources :

Example 6 with CounterfactualDomainRange

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

the class AbstractTrustyServiceIT method testCounterfactuals_StoreSingleAndRetrieveSingleWithSearchDomainRange.

@Test
public void testCounterfactuals_StoreSingleAndRetrieveSingleWithSearchDomainRange() {
    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.
    CounterfactualSearchDomain searchDomain = buildSearchDomainUnit("test", "number", new CounterfactualDomainRange(new IntNode(1), new IntNode(2)));
    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());
    assertCounterfactualSearchDomainRange(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());
    assertCounterfactualSearchDomainRange(searchDomain, resultSearchDomains.get(0));
}
Also used : CounterfactualExplainabilityRequest(org.kie.kogito.explainability.api.CounterfactualExplainabilityRequest) IntNode(com.fasterxml.jackson.databind.node.IntNode) CounterfactualDomainRange(org.kie.kogito.explainability.api.CounterfactualDomainRange) ArrayList(java.util.ArrayList) CounterfactualSearchDomain(org.kie.kogito.explainability.api.CounterfactualSearchDomain) Test(org.junit.jupiter.api.Test)

Example 7 with CounterfactualDomainRange

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

the class AbstractTrustyServiceIT method assertCounterfactualDomainRange.

private void assertCounterfactualDomainRange(CounterfactualDomain expectedDomain, CounterfactualDomain actualDomain) {
    assertTrue(expectedDomain instanceof CounterfactualDomainRange);
    assertTrue(actualDomain instanceof CounterfactualDomainRange);
    CounterfactualDomainRange expectedDomainRange = (CounterfactualDomainRange) expectedDomain;
    CounterfactualDomainRange actualDomainRange = (CounterfactualDomainRange) actualDomain;
    assertEquals(expectedDomainRange.getLowerBound(), actualDomainRange.getLowerBound());
    assertEquals(expectedDomainRange.getUpperBound(), actualDomainRange.getUpperBound());
}
Also used : CounterfactualDomainRange(org.kie.kogito.explainability.api.CounterfactualDomainRange)

Example 8 with CounterfactualDomainRange

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

the class AbstractTrustyServiceIT method testCounterfactuals_StoreMultipleAndRetrieveAllWithEmptyDefinition.

@Test
public void testCounterfactuals_StoreMultipleAndRetrieveAllWithEmptyDefinition() {
    String executionId = "myCFExecution2";
    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.
    CounterfactualSearchDomain searchDomain = buildSearchDomainUnit("test", "number", new CounterfactualDomainRange(new IntNode(1), new IntNode(2)));
    CounterfactualExplainabilityRequest request1 = trustyService.requestCounterfactuals(executionId, Collections.emptyList(), Collections.singletonList(searchDomain));
    CounterfactualExplainabilityRequest request2 = trustyService.requestCounterfactuals(executionId, Collections.emptyList(), Collections.singletonList(searchDomain));
    List<CounterfactualExplainabilityRequest> result = trustyService.getCounterfactualRequests(executionId);
    assertNotNull(result);
    assertEquals(2, result.size());
    assertTrue(result.stream().anyMatch(c -> c.getCounterfactualId().equals(request1.getCounterfactualId())));
    assertTrue(result.stream().anyMatch(c -> c.getCounterfactualId().equals(request2.getCounterfactualId())));
}
Also used : CounterfactualExplainabilityRequest(org.kie.kogito.explainability.api.CounterfactualExplainabilityRequest) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) BeforeEach(org.junit.jupiter.api.BeforeEach) LIMEExplainabilityResult(org.kie.kogito.explainability.api.LIMEExplainabilityResult) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) FeatureImportanceModel(org.kie.kogito.explainability.api.FeatureImportanceModel) Decision(org.kie.kogito.trusty.storage.api.model.decision.Decision) DecisionInput(org.kie.kogito.trusty.storage.api.model.decision.DecisionInput) IntNode(com.fasterxml.jackson.databind.node.IntNode) CounterfactualDomainRange(org.kie.kogito.explainability.api.CounterfactualDomainRange) ArrayList(java.util.ArrayList) MatchedExecutionHeaders(org.kie.kogito.trusty.service.common.models.MatchedExecutionHeaders) Inject(javax.inject.Inject) JsonNode(com.fasterxml.jackson.databind.JsonNode) TypedValueTestUtils.buildSearchDomainUnit(org.kie.kogito.trusty.service.common.TypedValueTestUtils.buildSearchDomainUnit) ZoneOffset(java.time.ZoneOffset) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) CounterfactualDomainCategorical(org.kie.kogito.explainability.api.CounterfactualDomainCategorical) TypedValueTestUtils.buildGoalUnit(org.kie.kogito.trusty.service.common.TypedValueTestUtils.buildGoalUnit) CounterfactualExplainabilityRequest(org.kie.kogito.explainability.api.CounterfactualExplainabilityRequest) NamedTypedValue(org.kie.kogito.explainability.api.NamedTypedValue) TrustyStorageService(org.kie.kogito.trusty.storage.common.TrustyStorageService) Collection(java.util.Collection) ExplainabilityStatus(org.kie.kogito.explainability.api.ExplainabilityStatus) Instant(java.time.Instant) TextNode(com.fasterxml.jackson.databind.node.TextNode) UnitValue(org.kie.kogito.tracing.typedvalue.UnitValue) Test(org.junit.jupiter.api.Test) DMNModelMetadata(org.kie.kogito.trusty.storage.api.model.decision.DMNModelMetadata) List(java.util.List) OffsetDateTime(java.time.OffsetDateTime) CounterfactualDomain(org.kie.kogito.explainability.api.CounterfactualDomain) JsonNodeFactory(com.fasterxml.jackson.databind.node.JsonNodeFactory) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Assertions(org.junit.jupiter.api.Assertions) CounterfactualExplainabilityResult(org.kie.kogito.explainability.api.CounterfactualExplainabilityResult) CounterfactualSearchDomain(org.kie.kogito.explainability.api.CounterfactualSearchDomain) SaliencyModel(org.kie.kogito.explainability.api.SaliencyModel) Collections(java.util.Collections) DMNModelWithMetadata(org.kie.kogito.trusty.storage.api.model.decision.DMNModelWithMetadata) DecisionOutcome(org.kie.kogito.trusty.storage.api.model.decision.DecisionOutcome) IntNode(com.fasterxml.jackson.databind.node.IntNode) CounterfactualDomainRange(org.kie.kogito.explainability.api.CounterfactualDomainRange) CounterfactualSearchDomain(org.kie.kogito.explainability.api.CounterfactualSearchDomain) Test(org.junit.jupiter.api.Test)

Example 9 with CounterfactualDomainRange

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

the class CounterfactualExplainerServiceHandlerTest method testGetPredictionWithCollectionSearchDomains.

@Test
public void testGetPredictionWithCollectionSearchDomains() {
    CounterfactualExplainabilityRequest request = new CounterfactualExplainabilityRequest(EXECUTION_ID, SERVICE_URL, MODEL_IDENTIFIER, COUNTERFACTUAL_ID, Collections.emptyList(), Collections.emptyList(), List.of(new CounterfactualSearchDomain("input1", new CounterfactualSearchDomainCollectionValue("number", List.of(new CounterfactualSearchDomainUnitValue("number", "number", true, new CounterfactualDomainRange(new IntNode(10), new IntNode(20))))))), MAX_RUNNING_TIME_SECONDS);
    assertThrows(IllegalArgumentException.class, () -> handler.getPrediction(request));
}
Also used : CounterfactualExplainabilityRequest(org.kie.kogito.explainability.api.CounterfactualExplainabilityRequest) IntNode(com.fasterxml.jackson.databind.node.IntNode) CounterfactualDomainRange(org.kie.kogito.explainability.api.CounterfactualDomainRange) CounterfactualSearchDomainUnitValue(org.kie.kogito.explainability.api.CounterfactualSearchDomainUnitValue) CounterfactualSearchDomainCollectionValue(org.kie.kogito.explainability.api.CounterfactualSearchDomainCollectionValue) CounterfactualSearchDomain(org.kie.kogito.explainability.api.CounterfactualSearchDomain) Test(org.junit.jupiter.api.Test)

Example 10 with CounterfactualDomainRange

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

the class CounterfactualExplainerServiceHandlerTest method testGetPredictionWithFlatSearchDomainsNotFixed.

@Test
public void testGetPredictionWithFlatSearchDomainsNotFixed() {
    CounterfactualExplainabilityRequest request = new CounterfactualExplainabilityRequest(EXECUTION_ID, SERVICE_URL, MODEL_IDENTIFIER, COUNTERFACTUAL_ID, List.of(new NamedTypedValue("output1", new UnitValue("number", new IntNode(25)))), Collections.emptyList(), List.of(new CounterfactualSearchDomain("output1", new CounterfactualSearchDomainUnitValue("number", "number", false, new CounterfactualDomainRange(new IntNode(10), new IntNode(20))))), MAX_RUNNING_TIME_SECONDS);
    Prediction prediction = handler.getPrediction(request);
    assertTrue(prediction instanceof CounterfactualPrediction);
    CounterfactualPrediction counterfactualPrediction = (CounterfactualPrediction) prediction;
    assertEquals(1, counterfactualPrediction.getInput().getFeatures().size());
    Feature feature1 = counterfactualPrediction.getInput().getFeatures().get(0);
    assertTrue(feature1.getDomain() instanceof NumericalFeatureDomain);
    final NumericalFeatureDomain domain = (NumericalFeatureDomain) feature1.getDomain();
    assertEquals(10, domain.getLowerBound());
    assertEquals(20, domain.getUpperBound());
    assertEquals(counterfactualPrediction.getMaxRunningTimeSeconds(), request.getMaxRunningTimeSeconds());
}
Also used : CounterfactualExplainabilityRequest(org.kie.kogito.explainability.api.CounterfactualExplainabilityRequest) NamedTypedValue(org.kie.kogito.explainability.api.NamedTypedValue) IntNode(com.fasterxml.jackson.databind.node.IntNode) CounterfactualDomainRange(org.kie.kogito.explainability.api.CounterfactualDomainRange) Prediction(org.kie.kogito.explainability.model.Prediction) CounterfactualPrediction(org.kie.kogito.explainability.model.CounterfactualPrediction) UnitValue(org.kie.kogito.tracing.typedvalue.UnitValue) CounterfactualSearchDomainUnitValue(org.kie.kogito.explainability.api.CounterfactualSearchDomainUnitValue) NumericalFeatureDomain(org.kie.kogito.explainability.model.domain.NumericalFeatureDomain) CounterfactualSearchDomainUnitValue(org.kie.kogito.explainability.api.CounterfactualSearchDomainUnitValue) Feature(org.kie.kogito.explainability.model.Feature) CounterfactualSearchDomain(org.kie.kogito.explainability.api.CounterfactualSearchDomain) CounterfactualPrediction(org.kie.kogito.explainability.model.CounterfactualPrediction) Test(org.junit.jupiter.api.Test)

Aggregations

CounterfactualDomainRange (org.kie.kogito.explainability.api.CounterfactualDomainRange)21 Test (org.junit.jupiter.api.Test)18 CounterfactualSearchDomain (org.kie.kogito.explainability.api.CounterfactualSearchDomain)17 IntNode (com.fasterxml.jackson.databind.node.IntNode)13 CounterfactualExplainabilityRequest (org.kie.kogito.explainability.api.CounterfactualExplainabilityRequest)13 CounterfactualSearchDomainUnitValue (org.kie.kogito.explainability.api.CounterfactualSearchDomainUnitValue)10 NamedTypedValue (org.kie.kogito.explainability.api.NamedTypedValue)8 ArrayList (java.util.ArrayList)6 UnitValue (org.kie.kogito.tracing.typedvalue.UnitValue)5 List (java.util.List)4 CounterfactualDomainCategorical (org.kie.kogito.explainability.api.CounterfactualDomainCategorical)4 JsonNode (com.fasterxml.jackson.databind.JsonNode)3 TextNode (com.fasterxml.jackson.databind.node.TextNode)3 EmptyFeatureDomain (org.kie.kogito.explainability.model.domain.EmptyFeatureDomain)3 NumericalFeatureDomain (org.kie.kogito.explainability.model.domain.NumericalFeatureDomain)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 QuarkusTest (io.quarkus.test.junit.QuarkusTest)2 RequestLoggingFilter (io.restassured.filter.log.RequestLoggingFilter)2 ResponseLoggingFilter (io.restassured.filter.log.ResponseLoggingFilter)2 OffsetDateTime (java.time.OffsetDateTime)2