Search in sources :

Example 1 with BinaryEntity

use of org.kie.kogito.explainability.local.counterfactual.entities.BinaryEntity 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)

Aggregations

ByteBuffer (java.nio.ByteBuffer)1 HashSet (java.util.HashSet)1 Test (org.junit.jupiter.api.Test)1 BinaryEntity (org.kie.kogito.explainability.local.counterfactual.entities.BinaryEntity)1 CounterfactualEntity (org.kie.kogito.explainability.local.counterfactual.entities.CounterfactualEntity)1 FixedBinaryEntity (org.kie.kogito.explainability.local.counterfactual.entities.fixed.FixedBinaryEntity)1 Feature (org.kie.kogito.explainability.model.Feature)1 BinaryFeatureDomain (org.kie.kogito.explainability.model.domain.BinaryFeatureDomain)1 CategoricalFeatureDomain (org.kie.kogito.explainability.model.domain.CategoricalFeatureDomain)1 CurrencyFeatureDomain (org.kie.kogito.explainability.model.domain.CurrencyFeatureDomain)1 DurationFeatureDomain (org.kie.kogito.explainability.model.domain.DurationFeatureDomain)1 EmptyFeatureDomain (org.kie.kogito.explainability.model.domain.EmptyFeatureDomain)1 FeatureDomain (org.kie.kogito.explainability.model.domain.FeatureDomain)1 NumericalFeatureDomain (org.kie.kogito.explainability.model.domain.NumericalFeatureDomain)1 ObjectFeatureDomain (org.kie.kogito.explainability.model.domain.ObjectFeatureDomain)1 TimeFeatureDomain (org.kie.kogito.explainability.model.domain.TimeFeatureDomain)1 URIFeatureDomain (org.kie.kogito.explainability.model.domain.URIFeatureDomain)1