Search in sources :

Example 16 with CounterfactualSearchDomainUnitValue

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

the class CounterfactualDomainSerialisationTest method testCounterfactualSearchDomain_Range_RoundTrip.

@Test
public void testCounterfactualSearchDomain_Range_RoundTrip() throws Exception {
    CounterfactualDomainRange domainRange = new CounterfactualDomainRange(new IntNode(18), new IntNode(65));
    CounterfactualSearchDomain searchDomain = new CounterfactualSearchDomain("age", new CounterfactualSearchDomainUnitValue("integer", "integer", Boolean.TRUE, domainRange));
    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 CounterfactualDomainRange);
    CounterfactualDomainRange roundTrippedDomainRange = (CounterfactualDomainRange) roundTrippedSearchDomain.getValue().toUnit().getDomain();
    assertEquals(domainRange.getLowerBound(), roundTrippedDomainRange.getLowerBound());
    assertEquals(domainRange.getUpperBound(), roundTrippedDomainRange.getUpperBound());
}
Also used : IntNode(com.fasterxml.jackson.databind.node.IntNode) CounterfactualDomainRange(org.kie.kogito.explainability.api.CounterfactualDomainRange) CounterfactualSearchDomainUnitValue(org.kie.kogito.explainability.api.CounterfactualSearchDomainUnitValue) CounterfactualSearchDomain(org.kie.kogito.explainability.api.CounterfactualSearchDomain) Test(org.junit.jupiter.api.Test)

Aggregations

CounterfactualSearchDomainUnitValue (org.kie.kogito.explainability.api.CounterfactualSearchDomainUnitValue)16 Test (org.junit.jupiter.api.Test)13 CounterfactualSearchDomain (org.kie.kogito.explainability.api.CounterfactualSearchDomain)11 CounterfactualDomainRange (org.kie.kogito.explainability.api.CounterfactualDomainRange)10 IntNode (com.fasterxml.jackson.databind.node.IntNode)8 CounterfactualExplainabilityRequest (org.kie.kogito.explainability.api.CounterfactualExplainabilityRequest)8 NamedTypedValue (org.kie.kogito.explainability.api.NamedTypedValue)6 EmptyFeatureDomain (org.kie.kogito.explainability.model.domain.EmptyFeatureDomain)6 NumericalFeatureDomain (org.kie.kogito.explainability.model.domain.NumericalFeatureDomain)6 UnitValue (org.kie.kogito.tracing.typedvalue.UnitValue)6 CategoricalFeatureDomain (org.kie.kogito.explainability.model.domain.CategoricalFeatureDomain)5 FeatureDomain (org.kie.kogito.explainability.model.domain.FeatureDomain)5 TextNode (com.fasterxml.jackson.databind.node.TextNode)4 CounterfactualSearchDomainStructureValue (org.kie.kogito.explainability.api.CounterfactualSearchDomainStructureValue)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 BaseExplainabilityRequest (org.kie.kogito.explainability.api.BaseExplainabilityRequest)2 CounterfactualDomainCategorical (org.kie.kogito.explainability.api.CounterfactualDomainCategorical)2 CounterfactualPrediction (org.kie.kogito.explainability.model.CounterfactualPrediction)2 Feature (org.kie.kogito.explainability.model.Feature)2 Prediction (org.kie.kogito.explainability.model.Prediction)2