Search in sources :

Example 36 with FeatureDomain

use of org.kie.kogito.explainability.model.domain.FeatureDomain in project kogito-apps by kiegroup.

the class ConversionUtilsTest method testToFeatureDomain_UnitCategoricalString.

@Test
void testToFeatureDomain_UnitCategoricalString() {
    FeatureDomain featureDomain = ConversionUtils.toFeatureDomain(new CounterfactualSearchDomainUnitValue("string", "string", true, new CounterfactualDomainCategorical(List.of(TextNode.valueOf("Black"), TextNode.valueOf("White")))));
    assertTrue(featureDomain instanceof CategoricalFeatureDomain);
    CategoricalFeatureDomain categoricalFeatureDomain = (CategoricalFeatureDomain) featureDomain;
    assertEquals(2, categoricalFeatureDomain.getCategories().size());
    assertTrue(categoricalFeatureDomain.getCategories().containsAll(List.of("White", "Black")));
    assertNull(categoricalFeatureDomain.getLowerBound());
    assertNull(categoricalFeatureDomain.getUpperBound());
}
Also used : EmptyFeatureDomain(org.kie.kogito.explainability.model.domain.EmptyFeatureDomain) CategoricalFeatureDomain(org.kie.kogito.explainability.model.domain.CategoricalFeatureDomain) NumericalFeatureDomain(org.kie.kogito.explainability.model.domain.NumericalFeatureDomain) FeatureDomain(org.kie.kogito.explainability.model.domain.FeatureDomain) CounterfactualSearchDomainUnitValue(org.kie.kogito.explainability.api.CounterfactualSearchDomainUnitValue) CounterfactualDomainCategorical(org.kie.kogito.explainability.api.CounterfactualDomainCategorical) CategoricalFeatureDomain(org.kie.kogito.explainability.model.domain.CategoricalFeatureDomain) Test(org.junit.jupiter.api.Test)

Example 37 with FeatureDomain

use of org.kie.kogito.explainability.model.domain.FeatureDomain in project kogito-apps by kiegroup.

the class ConversionUtilsTest method toFeatureDomainsConstraintsMultiElement.

@Test
void toFeatureDomainsConstraintsMultiElement() {
    final Random random = new Random();
    List<NamedTypedValue> values = IntStream.range(0, 10).mapToObj(i -> getDoubleUnit("f-" + i, random.nextDouble())).collect(Collectors.toList());
    List<CounterfactualSearchDomain> domains = IntStream.range(0, 10).mapToObj(i -> getDoubleSearchDomain("f-" + i, -1, 1)).collect(Collectors.toList());
    final List<Feature> features = ConversionUtils.toFeatureList(values, domains);
    assertEquals(10, features.size());
    assertTrue(features.stream().allMatch(f -> f.getType() == Type.NUMBER));
    assertTrue(features.stream().noneMatch(Feature::isConstrained));
    assertTrue(features.stream().map(Feature::getDomain).noneMatch(FeatureDomain::isEmpty));
    assertTrue(features.stream().map(Feature::getDomain).map(FeatureDomain::getLowerBound).allMatch(lb -> lb == -1.0));
    assertTrue(features.stream().map(Feature::getDomain).map(FeatureDomain::getUpperBound).allMatch(ub -> ub == 1.0));
}
Also used : IntStream(java.util.stream.IntStream) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) IntNode(com.fasterxml.jackson.databind.node.IntNode) Feature(org.kie.kogito.explainability.model.Feature) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) Random(java.util.Random) CounterfactualDomainRange(org.kie.kogito.explainability.api.CounterfactualDomainRange) Value(org.kie.kogito.explainability.model.Value) StructureValue(org.kie.kogito.tracing.typedvalue.StructureValue) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayList(java.util.ArrayList) Pair(org.apache.commons.lang3.tuple.Pair) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) Map(java.util.Map) EmptyFeatureDomain(org.kie.kogito.explainability.model.domain.EmptyFeatureDomain) JsonNode(com.fasterxml.jackson.databind.JsonNode) JsonObject(io.vertx.core.json.JsonObject) Collections.singletonMap(java.util.Collections.singletonMap) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) CounterfactualDomainCategorical(org.kie.kogito.explainability.api.CounterfactualDomainCategorical) NamedTypedValue(org.kie.kogito.explainability.api.NamedTypedValue) CategoricalFeatureDomain(org.kie.kogito.explainability.model.domain.CategoricalFeatureDomain) Collections.emptyList(java.util.Collections.emptyList) Collection(java.util.Collection) Collectors(java.util.stream.Collectors) Type(org.kie.kogito.explainability.model.Type) TextNode(com.fasterxml.jackson.databind.node.TextNode) TypedValue(org.kie.kogito.tracing.typedvalue.TypedValue) UnitValue(org.kie.kogito.tracing.typedvalue.UnitValue) Test(org.junit.jupiter.api.Test) List(java.util.List) CounterfactualDomain(org.kie.kogito.explainability.api.CounterfactualDomain) CollectionValue(org.kie.kogito.tracing.typedvalue.CollectionValue) CounterfactualSearchDomainUnitValue(org.kie.kogito.explainability.api.CounterfactualSearchDomainUnitValue) DoubleNode(com.fasterxml.jackson.databind.node.DoubleNode) NumericalFeatureDomain(org.kie.kogito.explainability.model.domain.NumericalFeatureDomain) JsonNodeFactory(com.fasterxml.jackson.databind.node.JsonNodeFactory) Output(org.kie.kogito.explainability.model.Output) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Optional(java.util.Optional) BooleanNode(com.fasterxml.jackson.databind.node.BooleanNode) CounterfactualSearchDomain(org.kie.kogito.explainability.api.CounterfactualSearchDomain) FeatureDomain(org.kie.kogito.explainability.model.domain.FeatureDomain) NamedTypedValue(org.kie.kogito.explainability.api.NamedTypedValue) Random(java.util.Random) EmptyFeatureDomain(org.kie.kogito.explainability.model.domain.EmptyFeatureDomain) CategoricalFeatureDomain(org.kie.kogito.explainability.model.domain.CategoricalFeatureDomain) NumericalFeatureDomain(org.kie.kogito.explainability.model.domain.NumericalFeatureDomain) FeatureDomain(org.kie.kogito.explainability.model.domain.FeatureDomain) Feature(org.kie.kogito.explainability.model.Feature) CounterfactualSearchDomain(org.kie.kogito.explainability.api.CounterfactualSearchDomain) Test(org.junit.jupiter.api.Test)

Example 38 with FeatureDomain

use of org.kie.kogito.explainability.model.domain.FeatureDomain in project kogito-apps by kiegroup.

the class ConversionUtilsTest method testToFeatureDomain_UnitFixedString.

@Test
void testToFeatureDomain_UnitFixedString() {
    FeatureDomain featureDomain = ConversionUtils.toFeatureDomain(new CounterfactualSearchDomainUnitValue("string", "string", true, null));
    assertTrue(featureDomain instanceof EmptyFeatureDomain);
}
Also used : EmptyFeatureDomain(org.kie.kogito.explainability.model.domain.EmptyFeatureDomain) EmptyFeatureDomain(org.kie.kogito.explainability.model.domain.EmptyFeatureDomain) CategoricalFeatureDomain(org.kie.kogito.explainability.model.domain.CategoricalFeatureDomain) NumericalFeatureDomain(org.kie.kogito.explainability.model.domain.NumericalFeatureDomain) FeatureDomain(org.kie.kogito.explainability.model.domain.FeatureDomain) CounterfactualSearchDomainUnitValue(org.kie.kogito.explainability.api.CounterfactualSearchDomainUnitValue) Test(org.junit.jupiter.api.Test)

Example 39 with FeatureDomain

use of org.kie.kogito.explainability.model.domain.FeatureDomain in project kogito-apps by kiegroup.

the class ConversionUtilsTest method testToFeatureDomain_UnitRangeInteger.

@Test
void testToFeatureDomain_UnitRangeInteger() {
    FeatureDomain featureDomain = ConversionUtils.toFeatureDomain(new CounterfactualSearchDomainUnitValue("int", "int", true, new CounterfactualDomainRange(IntNode.valueOf(18), IntNode.valueOf(65))));
    assertTrue(featureDomain instanceof NumericalFeatureDomain);
    NumericalFeatureDomain numericalFeatureDomain = (NumericalFeatureDomain) featureDomain;
    assertEquals(18.0, numericalFeatureDomain.getLowerBound());
    assertEquals(65.0, numericalFeatureDomain.getUpperBound());
    assertNull(numericalFeatureDomain.getCategories());
}
Also used : CounterfactualDomainRange(org.kie.kogito.explainability.api.CounterfactualDomainRange) EmptyFeatureDomain(org.kie.kogito.explainability.model.domain.EmptyFeatureDomain) CategoricalFeatureDomain(org.kie.kogito.explainability.model.domain.CategoricalFeatureDomain) NumericalFeatureDomain(org.kie.kogito.explainability.model.domain.NumericalFeatureDomain) FeatureDomain(org.kie.kogito.explainability.model.domain.FeatureDomain) NumericalFeatureDomain(org.kie.kogito.explainability.model.domain.NumericalFeatureDomain) CounterfactualSearchDomainUnitValue(org.kie.kogito.explainability.api.CounterfactualSearchDomainUnitValue) Test(org.junit.jupiter.api.Test)

Aggregations

FeatureDomain (org.kie.kogito.explainability.model.domain.FeatureDomain)39 NumericalFeatureDomain (org.kie.kogito.explainability.model.domain.NumericalFeatureDomain)38 Test (org.junit.jupiter.api.Test)32 EmptyFeatureDomain (org.kie.kogito.explainability.model.domain.EmptyFeatureDomain)31 Feature (org.kie.kogito.explainability.model.Feature)29 CategoricalFeatureDomain (org.kie.kogito.explainability.model.domain.CategoricalFeatureDomain)25 CounterfactualEntity (org.kie.kogito.explainability.local.counterfactual.entities.CounterfactualEntity)17 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)15 BinaryFeatureDomain (org.kie.kogito.explainability.model.domain.BinaryFeatureDomain)13 CurrencyFeatureDomain (org.kie.kogito.explainability.model.domain.CurrencyFeatureDomain)13 DurationFeatureDomain (org.kie.kogito.explainability.model.domain.DurationFeatureDomain)13 ObjectFeatureDomain (org.kie.kogito.explainability.model.domain.ObjectFeatureDomain)13 URIFeatureDomain (org.kie.kogito.explainability.model.domain.URIFeatureDomain)13 TimeFeatureDomain (org.kie.kogito.explainability.model.domain.TimeFeatureDomain)12 ArrayList (java.util.ArrayList)10 Output (org.kie.kogito.explainability.model.Output)8 Random (java.util.Random)7 PredictionFeatureDomain (org.kie.kogito.explainability.model.PredictionFeatureDomain)7 PredictionInput (org.kie.kogito.explainability.model.PredictionInput)7 Value (org.kie.kogito.explainability.model.Value)7