Search in sources :

Example 21 with CounterfactualExplainabilityResult

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

the class CounterfactualExplainabilityResultsManagerDuplicatesTest method testPurgeWhenResultSetSizeIsGreaterThanMinimum_WithoutDuplicateOutputs.

@Test
public void testPurgeWhenResultSetSizeIsGreaterThanMinimum_WithoutDuplicateOutputs() {
    CounterfactualExplainabilityResult result0 = makeResult(0, Collections.emptyList(), List.of(makeCounterfactualOutput("0")));
    CounterfactualExplainabilityResult result1 = makeResult(1, Collections.emptyList(), List.of(makeCounterfactualOutput("1")));
    CounterfactualExplainabilityResult result2 = makeResult(2, Collections.emptyList(), List.of(makeCounterfactualOutput("2")));
    CounterfactualExplainabilityResult result3 = makeResult(3, Collections.emptyList(), List.of(makeCounterfactualOutput("3")));
    when(query.execute()).thenReturn(List.of(result0, result1, result2, result3));
    manager.purge(COUNTERFACTUAL_ID, storage);
    verify(storage, never()).remove(anyString());
}
Also used : CounterfactualExplainabilityResult(org.kie.kogito.explainability.api.CounterfactualExplainabilityResult) Test(org.junit.jupiter.api.Test)

Example 22 with CounterfactualExplainabilityResult

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

the class CounterfactualExplainabilityResultsManagerDuplicatesTest method testPurgeWhenResultSetSizeIsGreaterThanMinimum_WithDuplicateOutputs.

@Test
public void testPurgeWhenResultSetSizeIsGreaterThanMinimum_WithDuplicateOutputs() {
    CounterfactualExplainabilityResult result0 = makeResult(0, Collections.emptyList(), Collections.emptyList());
    CounterfactualExplainabilityResult result1 = makeResult(1, Collections.emptyList(), Collections.emptyList());
    CounterfactualExplainabilityResult result2 = makeResult(2, Collections.emptyList(), List.of(makeCounterfactualOutput("a")));
    CounterfactualExplainabilityResult result3 = makeResult(3, Collections.emptyList(), List.of(makeCounterfactualOutput("a")));
    when(query.execute()).thenReturn(List.of(result0, result1, result2, result3));
    manager.purge(COUNTERFACTUAL_ID, storage);
    verify(storage).remove(anyString());
    verify(storage).remove(result3.getSolutionId());
}
Also used : CounterfactualExplainabilityResult(org.kie.kogito.explainability.api.CounterfactualExplainabilityResult) Test(org.junit.jupiter.api.Test)

Example 23 with CounterfactualExplainabilityResult

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

the class CounterfactualExplainabilityResultsManagerSlidingWindowTest method testPurgeWhenResultSetSizeIsGreaterThanWindowSize.

@Test
public void testPurgeWhenResultSetSizeIsGreaterThanWindowSize() {
    CounterfactualExplainabilityResult result0 = makeResult(0);
    CounterfactualExplainabilityResult result1 = makeResult(1);
    CounterfactualExplainabilityResult result2 = makeResult(2);
    CounterfactualExplainabilityResult result3 = makeResult(3);
    when(query.execute()).thenReturn(List.of(result0, result1, result2, result3));
    manager.purge(COUNTERFACTUAL_ID, storage);
    verify(storage, times(2)).remove(anyString());
    verify(storage).remove(result0.getSolutionId());
    verify(storage).remove(result1.getSolutionId());
}
Also used : CounterfactualExplainabilityResult(org.kie.kogito.explainability.api.CounterfactualExplainabilityResult) Test(org.junit.jupiter.api.Test)

Example 24 with CounterfactualExplainabilityResult

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

the class CounterfactualExplainerServiceHandlerTest method testGetExplainabilityResultById_WhenMultipleStored.

@Test
public void testGetExplainabilityResultById_WhenMultipleStored() {
    CounterfactualExplainabilityResult intermediate = mock(CounterfactualExplainabilityResult.class);
    when(intermediate.getExecutionId()).thenReturn(EXECUTION_ID);
    when(intermediate.getSolutionId()).thenReturn(SOLUTION_ID);
    when(intermediate.getStage()).thenReturn(CounterfactualExplainabilityResult.Stage.INTERMEDIATE);
    when(query.execute()).thenReturn(List.of(intermediate, result));
    assertEquals(result, handler.getExplainabilityResultById(EXECUTION_ID));
}
Also used : CounterfactualExplainabilityResult(org.kie.kogito.explainability.api.CounterfactualExplainabilityResult) Test(org.junit.jupiter.api.Test)

Example 25 with CounterfactualExplainabilityResult

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

the class CounterfactualExplainerServiceHandlerTest method testGetExplainabilityResultById_WhenOnlyIntermediateStored.

@Test
public void testGetExplainabilityResultById_WhenOnlyIntermediateStored() {
    CounterfactualExplainabilityResult intermediate = mock(CounterfactualExplainabilityResult.class);
    when(intermediate.getExecutionId()).thenReturn(EXECUTION_ID);
    when(intermediate.getSolutionId()).thenReturn(SOLUTION_ID);
    when(intermediate.getStage()).thenReturn(CounterfactualExplainabilityResult.Stage.INTERMEDIATE);
    when(query.execute()).thenReturn(List.of(intermediate));
    assertThrows(IllegalArgumentException.class, () -> handler.getExplainabilityResultById(EXECUTION_ID));
}
Also used : CounterfactualExplainabilityResult(org.kie.kogito.explainability.api.CounterfactualExplainabilityResult) Test(org.junit.jupiter.api.Test)

Aggregations

CounterfactualExplainabilityResult (org.kie.kogito.explainability.api.CounterfactualExplainabilityResult)29 Test (org.junit.jupiter.api.Test)26 NamedTypedValue (org.kie.kogito.explainability.api.NamedTypedValue)8 BaseExplainabilityResult (org.kie.kogito.explainability.api.BaseExplainabilityResult)6 UnitValue (org.kie.kogito.tracing.typedvalue.UnitValue)6 IntNode (com.fasterxml.jackson.databind.node.IntNode)5 ArrayList (java.util.ArrayList)4 List (java.util.List)4 Consumer (java.util.function.Consumer)4 CounterfactualExplainabilityRequest (org.kie.kogito.explainability.api.CounterfactualExplainabilityRequest)4 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)3 Assertions.assertThrows (org.junit.jupiter.api.Assertions.assertThrows)3 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)3 BeforeEach (org.junit.jupiter.api.BeforeEach)3 CounterfactualSearchDomain (org.kie.kogito.explainability.api.CounterfactualSearchDomain)3 ExplainabilityStatus (org.kie.kogito.explainability.api.ExplainabilityStatus)3 ModelIdentifier (org.kie.kogito.explainability.api.ModelIdentifier)3 Prediction (org.kie.kogito.explainability.model.Prediction)3 Query (org.kie.kogito.persistence.api.query.Query)3 BooleanNode (com.fasterxml.jackson.databind.node.BooleanNode)2