use of org.kie.kogito.explainability.model.Feature 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());
}
use of org.kie.kogito.explainability.model.Feature 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());
}
use of org.kie.kogito.explainability.model.Feature 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());
}
use of org.kie.kogito.explainability.model.Feature 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());
}
use of org.kie.kogito.explainability.model.Feature in project kogito-apps by kiegroup.
the class CounterfactualEntityFactoryTest method testDoubleFactory.
@Test
void testDoubleFactory() {
final double value = 5.5;
final FeatureDomain domain = NumericalFeatureDomain.create(0.0, 10.0);
final Feature feature = FeatureFactory.newNumericalFeature("double-feature", value, domain);
final CounterfactualEntity counterfactualEntity = CounterfactualEntityFactory.from(feature);
assertTrue(counterfactualEntity instanceof DoubleEntity);
assertEquals(value, counterfactualEntity.asFeature().getValue().asNumber());
}
Aggregations