Search in sources :

Example 1 with CounterfactualEntity

use of org.kie.kogito.explainability.local.counterfactual.entities.CounterfactualEntity in project kogito-apps by kiegroup.

the class CounterfactualEntityFactoryTest method testCreateFixedEntities.

@Test
void testCreateFixedEntities() {
    List<Feature> features = new LinkedList<>();
    features.add(FeatureFactory.newNumericalFeature("f-num1", 100.1));
    features.add(FeatureFactory.newNumericalFeature("f-num2", 100.2, NumericalFeatureDomain.create(0.0, 1000.0)));
    features.add(FeatureFactory.newNumericalFeature("f-num3", 100.3));
    features.add(FeatureFactory.newNumericalFeature("f-num4", 100.4, NumericalFeatureDomain.create(0.0, 1000.0)));
    PredictionInput input = new PredictionInput(features);
    List<CounterfactualEntity> entities = CounterfactualEntityFactory.createEntities(input);
    // Check types
    assertTrue(entities.get(0) instanceof FixedDoubleEntity);
    assertTrue(entities.get(1) instanceof DoubleEntity);
    assertTrue(entities.get(2) instanceof FixedDoubleEntity);
    assertTrue(entities.get(3) instanceof DoubleEntity);
    // Check values
    assertEquals(100.1, entities.get(0).asFeature().getValue().asNumber());
    assertEquals(100.2, entities.get(1).asFeature().getValue().asNumber());
    assertEquals(100.3, entities.get(2).asFeature().getValue().asNumber());
    assertEquals(100.4, entities.get(3).asFeature().getValue().asNumber());
    // Check constraints
    assertTrue(entities.get(0).isConstrained());
    assertFalse(entities.get(1).isConstrained());
    assertTrue(entities.get(2).isConstrained());
    assertFalse(entities.get(3).isConstrained());
}
Also used : CounterfactualEntity(org.kie.kogito.explainability.local.counterfactual.entities.CounterfactualEntity) PredictionInput(org.kie.kogito.explainability.model.PredictionInput) FixedDoubleEntity(org.kie.kogito.explainability.local.counterfactual.entities.fixed.FixedDoubleEntity) DoubleEntity(org.kie.kogito.explainability.local.counterfactual.entities.DoubleEntity) FixedDoubleEntity(org.kie.kogito.explainability.local.counterfactual.entities.fixed.FixedDoubleEntity) Feature(org.kie.kogito.explainability.model.Feature) LinkedList(java.util.LinkedList) Test(org.junit.jupiter.api.Test)

Example 2 with CounterfactualEntity

use of org.kie.kogito.explainability.local.counterfactual.entities.CounterfactualEntity in project kogito-apps by kiegroup.

the class CounterfactualEntityFactoryTest method testURIFactory.

@Test
void testURIFactory() throws URISyntaxException {
    final URI value = URI.create("./");
    Feature feature = FeatureFactory.newURIFeature("uri-feature", value);
    CounterfactualEntity counterfactualEntity = CounterfactualEntityFactory.from(feature);
    assertTrue(counterfactualEntity instanceof FixedURIEntity);
    assertEquals(Type.URI, counterfactualEntity.asFeature().getType());
    FeatureDomain domain = URIFeatureDomain.create(new URI("./"), new URI("../"), new URI("https://example.com"));
    feature = FeatureFactory.newURIFeature("uri-feature", value, domain);
    counterfactualEntity = CounterfactualEntityFactory.from(feature);
    assertTrue(counterfactualEntity instanceof URIEntity);
    assertEquals(value, counterfactualEntity.asFeature().getValue().getUnderlyingObject());
    domain = URIFeatureDomain.create(List.of(new URI("./"), new URI("../"), new URI("https://example.com")));
    feature = FeatureFactory.newURIFeature("uri-feature", value, domain);
    counterfactualEntity = CounterfactualEntityFactory.from(feature);
    assertTrue(counterfactualEntity instanceof URIEntity);
    assertEquals(value, counterfactualEntity.asFeature().getValue().getUnderlyingObject());
    domain = URIFeatureDomain.create(Set.of(new URI("./"), new URI("../"), new URI("https://example.com")));
    feature = FeatureFactory.newURIFeature("uri-feature", value, domain);
    counterfactualEntity = CounterfactualEntityFactory.from(feature);
    assertTrue(counterfactualEntity instanceof URIEntity);
    assertEquals(value, counterfactualEntity.asFeature().getValue().getUnderlyingObject());
}
Also used : CounterfactualEntity(org.kie.kogito.explainability.local.counterfactual.entities.CounterfactualEntity) ObjectFeatureDomain(org.kie.kogito.explainability.model.domain.ObjectFeatureDomain) EmptyFeatureDomain(org.kie.kogito.explainability.model.domain.EmptyFeatureDomain) CategoricalFeatureDomain(org.kie.kogito.explainability.model.domain.CategoricalFeatureDomain) CurrencyFeatureDomain(org.kie.kogito.explainability.model.domain.CurrencyFeatureDomain) URIFeatureDomain(org.kie.kogito.explainability.model.domain.URIFeatureDomain) DurationFeatureDomain(org.kie.kogito.explainability.model.domain.DurationFeatureDomain) TimeFeatureDomain(org.kie.kogito.explainability.model.domain.TimeFeatureDomain) NumericalFeatureDomain(org.kie.kogito.explainability.model.domain.NumericalFeatureDomain) BinaryFeatureDomain(org.kie.kogito.explainability.model.domain.BinaryFeatureDomain) FeatureDomain(org.kie.kogito.explainability.model.domain.FeatureDomain) URI(java.net.URI) Feature(org.kie.kogito.explainability.model.Feature) URIEntity(org.kie.kogito.explainability.local.counterfactual.entities.URIEntity) FixedURIEntity(org.kie.kogito.explainability.local.counterfactual.entities.fixed.FixedURIEntity) FixedURIEntity(org.kie.kogito.explainability.local.counterfactual.entities.fixed.FixedURIEntity) Test(org.junit.jupiter.api.Test)

Example 3 with CounterfactualEntity

use of org.kie.kogito.explainability.local.counterfactual.entities.CounterfactualEntity in project kogito-apps by kiegroup.

the class CounterfactualEntityFactoryTest method testFixedIntegerFactory.

@Test
void testFixedIntegerFactory() {
    final int value = 5;
    final Feature feature = FeatureFactory.newNumericalFeature("int-feature", value);
    final CounterfactualEntity counterfactualEntity = CounterfactualEntityFactory.from(feature);
    assertTrue(counterfactualEntity instanceof FixedIntegerEntity);
    assertEquals(value, counterfactualEntity.asFeature().getValue().asNumber());
}
Also used : CounterfactualEntity(org.kie.kogito.explainability.local.counterfactual.entities.CounterfactualEntity) FixedIntegerEntity(org.kie.kogito.explainability.local.counterfactual.entities.fixed.FixedIntegerEntity) Feature(org.kie.kogito.explainability.model.Feature) Test(org.junit.jupiter.api.Test)

Example 4 with CounterfactualEntity

use of org.kie.kogito.explainability.local.counterfactual.entities.CounterfactualEntity in project kogito-apps by kiegroup.

the class CounterfactualEntityFactoryTest method testFixedDoubleFactory.

@Test
void testFixedDoubleFactory() {
    final double value = 5.5;
    final Feature feature = FeatureFactory.newNumericalFeature("double-feature", value);
    final CounterfactualEntity counterfactualEntity = CounterfactualEntityFactory.from(feature);
    assertTrue(counterfactualEntity instanceof FixedDoubleEntity);
    assertEquals(value, counterfactualEntity.asFeature().getValue().asNumber());
}
Also used : CounterfactualEntity(org.kie.kogito.explainability.local.counterfactual.entities.CounterfactualEntity) FixedDoubleEntity(org.kie.kogito.explainability.local.counterfactual.entities.fixed.FixedDoubleEntity) Feature(org.kie.kogito.explainability.model.Feature) Test(org.junit.jupiter.api.Test)

Example 5 with CounterfactualEntity

use of org.kie.kogito.explainability.local.counterfactual.entities.CounterfactualEntity in project kogito-apps by kiegroup.

the class CounterfactualEntityFactoryTest method testCategoricalFactorySet.

@Test
void testCategoricalFactorySet() {
    final String value = "foo";
    final FeatureDomain domain = CategoricalFeatureDomain.create(Set.of("foo", "bar"));
    final Feature feature = FeatureFactory.newCategoricalFeature("categorical-feature", value, domain);
    final CounterfactualEntity counterfactualEntity = CounterfactualEntityFactory.from(feature);
    assertTrue(counterfactualEntity instanceof CategoricalEntity);
    assertEquals(domain.getCategories(), ((CategoricalEntity) counterfactualEntity).getValueRange());
    assertEquals(value, counterfactualEntity.asFeature().getValue().toString());
}
Also used : CounterfactualEntity(org.kie.kogito.explainability.local.counterfactual.entities.CounterfactualEntity) ObjectFeatureDomain(org.kie.kogito.explainability.model.domain.ObjectFeatureDomain) EmptyFeatureDomain(org.kie.kogito.explainability.model.domain.EmptyFeatureDomain) CategoricalFeatureDomain(org.kie.kogito.explainability.model.domain.CategoricalFeatureDomain) CurrencyFeatureDomain(org.kie.kogito.explainability.model.domain.CurrencyFeatureDomain) URIFeatureDomain(org.kie.kogito.explainability.model.domain.URIFeatureDomain) DurationFeatureDomain(org.kie.kogito.explainability.model.domain.DurationFeatureDomain) TimeFeatureDomain(org.kie.kogito.explainability.model.domain.TimeFeatureDomain) NumericalFeatureDomain(org.kie.kogito.explainability.model.domain.NumericalFeatureDomain) BinaryFeatureDomain(org.kie.kogito.explainability.model.domain.BinaryFeatureDomain) FeatureDomain(org.kie.kogito.explainability.model.domain.FeatureDomain) CategoricalEntity(org.kie.kogito.explainability.local.counterfactual.entities.CategoricalEntity) FixedCategoricalEntity(org.kie.kogito.explainability.local.counterfactual.entities.fixed.FixedCategoricalEntity) Feature(org.kie.kogito.explainability.model.Feature) Test(org.junit.jupiter.api.Test)

Aggregations

CounterfactualEntity (org.kie.kogito.explainability.local.counterfactual.entities.CounterfactualEntity)45 Feature (org.kie.kogito.explainability.model.Feature)45 Test (org.junit.jupiter.api.Test)34 EmptyFeatureDomain (org.kie.kogito.explainability.model.domain.EmptyFeatureDomain)23 NumericalFeatureDomain (org.kie.kogito.explainability.model.domain.NumericalFeatureDomain)23 Output (org.kie.kogito.explainability.model.Output)22 PredictionOutput (org.kie.kogito.explainability.model.PredictionOutput)22 FeatureDomain (org.kie.kogito.explainability.model.domain.FeatureDomain)21 PredictionProvider (org.kie.kogito.explainability.model.PredictionProvider)18 Value (org.kie.kogito.explainability.model.Value)18 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)17 PredictionInput (org.kie.kogito.explainability.model.PredictionInput)17 LinkedList (java.util.LinkedList)16 CategoricalFeatureDomain (org.kie.kogito.explainability.model.domain.CategoricalFeatureDomain)16 Random (java.util.Random)14 ValueSource (org.junit.jupiter.params.provider.ValueSource)13 BinaryFeatureDomain (org.kie.kogito.explainability.model.domain.BinaryFeatureDomain)12 CurrencyFeatureDomain (org.kie.kogito.explainability.model.domain.CurrencyFeatureDomain)12 DurationFeatureDomain (org.kie.kogito.explainability.model.domain.DurationFeatureDomain)12 ObjectFeatureDomain (org.kie.kogito.explainability.model.domain.ObjectFeatureDomain)12