Search in sources :

Example 1 with FeatureDomain

use of org.kie.kogito.explainability.model.domain.FeatureDomain 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 2 with FeatureDomain

use of org.kie.kogito.explainability.model.domain.FeatureDomain 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)

Example 3 with FeatureDomain

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

the class CounterfactualEntityFactoryTest method testBinaryFactory.

@Test
void testBinaryFactory() {
    final ByteBuffer value = ByteBuffer.allocate(256);
    Feature feature = FeatureFactory.newBinaryFeature("binary-feature", value);
    CounterfactualEntity counterfactualEntity = CounterfactualEntityFactory.from(feature);
    assertTrue(counterfactualEntity instanceof FixedBinaryEntity);
    assertEquals(Type.BINARY, counterfactualEntity.asFeature().getType());
    final List<ByteBuffer> categories = Stream.of("bar".getBytes(), "baz".getBytes(), "fun".getBytes()).map(ByteBuffer::wrap).collect(Collectors.toList());
    FeatureDomain domain = BinaryFeatureDomain.create(categories);
    feature = FeatureFactory.newBinaryFeature("binary-feature", value, domain);
    counterfactualEntity = CounterfactualEntityFactory.from(feature);
    assertTrue(counterfactualEntity instanceof BinaryEntity);
    assertEquals(domain.getCategories(), ((BinaryEntity) counterfactualEntity).getValueRange());
    domain = BinaryFeatureDomain.create(new HashSet<>(categories));
    feature = FeatureFactory.newBinaryFeature("binary-feature", value, domain);
    counterfactualEntity = CounterfactualEntityFactory.from(feature);
    assertEquals(domain.getCategories(), ((BinaryEntity) counterfactualEntity).getValueRange());
    domain = BinaryFeatureDomain.create(ByteBuffer.wrap("bar".getBytes()), ByteBuffer.wrap("baz".getBytes()), ByteBuffer.wrap("fun".getBytes()));
    feature = FeatureFactory.newBinaryFeature("binary-feature", value, domain);
    counterfactualEntity = CounterfactualEntityFactory.from(feature);
    assertEquals(domain.getCategories(), ((BinaryEntity) counterfactualEntity).getValueRange());
    assertEquals(value, counterfactualEntity.asFeature().getValue().getUnderlyingObject());
}
Also used : CounterfactualEntity(org.kie.kogito.explainability.local.counterfactual.entities.CounterfactualEntity) BinaryEntity(org.kie.kogito.explainability.local.counterfactual.entities.BinaryEntity) FixedBinaryEntity(org.kie.kogito.explainability.local.counterfactual.entities.fixed.FixedBinaryEntity) FixedBinaryEntity(org.kie.kogito.explainability.local.counterfactual.entities.fixed.FixedBinaryEntity) 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) ByteBuffer(java.nio.ByteBuffer) Feature(org.kie.kogito.explainability.model.Feature) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 4 with FeatureDomain

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

the class CounterfactualEntityFactoryTest method testTimeFactory.

@Test
void testTimeFactory() {
    final LocalTime value = LocalTime.now();
    Feature feature = FeatureFactory.newTimeFeature("time-feature", value);
    CounterfactualEntity counterfactualEntity = CounterfactualEntityFactory.from(feature);
    assertTrue(counterfactualEntity instanceof FixedTimeEntity);
    assertEquals(Type.TIME, counterfactualEntity.asFeature().getType());
    FeatureDomain domain = TimeFeatureDomain.create(value.minusHours(10), value.plusHours(10));
    feature = FeatureFactory.newTimeFeature("time-feature", value, domain);
    counterfactualEntity = CounterfactualEntityFactory.from(feature);
    assertTrue(counterfactualEntity instanceof TimeEntity);
    assertEquals(Type.TIME, counterfactualEntity.asFeature().getType());
    assertEquals(value, ((TimeEntity) counterfactualEntity).getProposedValue());
}
Also used : CounterfactualEntity(org.kie.kogito.explainability.local.counterfactual.entities.CounterfactualEntity) FixedTimeEntity(org.kie.kogito.explainability.local.counterfactual.entities.fixed.FixedTimeEntity) TimeEntity(org.kie.kogito.explainability.local.counterfactual.entities.TimeEntity) LocalTime(java.time.LocalTime) FixedTimeEntity(org.kie.kogito.explainability.local.counterfactual.entities.fixed.FixedTimeEntity) 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) Feature(org.kie.kogito.explainability.model.Feature) Test(org.junit.jupiter.api.Test)

Example 5 with FeatureDomain

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

the class CounterfactualEntityFactoryTest method testDurationFactory.

@Test
void testDurationFactory() {
    final Duration value = Duration.ofDays(1);
    Feature feature = FeatureFactory.newDurationFeature("duration-feature", value);
    CounterfactualEntity counterfactualEntity = CounterfactualEntityFactory.from(feature);
    assertTrue(counterfactualEntity instanceof FixedDurationEntity);
    assertEquals(Type.DURATION, counterfactualEntity.asFeature().getType());
    FeatureDomain domain = DurationFeatureDomain.create(0, 60, ChronoUnit.SECONDS);
    feature = FeatureFactory.newDurationFeature("duration-feature", value, domain);
    counterfactualEntity = CounterfactualEntityFactory.from(feature);
    assertTrue(counterfactualEntity instanceof DurationEntity);
    assertEquals(Type.DURATION, counterfactualEntity.asFeature().getType());
    assertFalse(counterfactualEntity.isConstrained());
    CounterfactualEntity entity = DurationEntity.from(feature, Duration.ZERO, Duration.ofDays(2));
    assertEquals(0, entity.distance());
    assertTrue(((DurationEntity) entity).getValueRange().contains(1e5));
    assertFalse(((DurationEntity) entity).getValueRange().contains(2e5));
    assertFalse(entity.isConstrained());
    entity = DurationEntity.from(feature, Duration.ZERO, Duration.ofDays(2), false);
    assertEquals(0, entity.distance());
    assertFalse(entity.isConstrained());
    FeatureDistribution distribution = new NumericFeatureDistribution(feature, new Random().doubles(10).toArray());
    entity = DurationEntity.from(feature, Duration.ZERO, Duration.ofDays(2), distribution);
    assertEquals(0, entity.distance());
    assertFalse(entity.isConstrained());
}
Also used : CounterfactualEntity(org.kie.kogito.explainability.local.counterfactual.entities.CounterfactualEntity) FeatureDistribution(org.kie.kogito.explainability.model.FeatureDistribution) NumericFeatureDistribution(org.kie.kogito.explainability.model.NumericFeatureDistribution) FixedDurationEntity(org.kie.kogito.explainability.local.counterfactual.entities.fixed.FixedDurationEntity) Random(java.util.Random) 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) Duration(java.time.Duration) Feature(org.kie.kogito.explainability.model.Feature) FixedDurationEntity(org.kie.kogito.explainability.local.counterfactual.entities.fixed.FixedDurationEntity) DurationEntity(org.kie.kogito.explainability.local.counterfactual.entities.DurationEntity) NumericFeatureDistribution(org.kie.kogito.explainability.model.NumericFeatureDistribution) 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