use of org.kie.kogito.explainability.model.Feature 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());
}
use of org.kie.kogito.explainability.model.Feature in project kogito-apps by kiegroup.
the class CounterfactualEntityFactoryTest method testValidateNullNumericalFeature.
@Test
void testValidateNullNumericalFeature() {
final Feature feature = FeatureFactory.newNumericalFeature("double-feature", null);
IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> {
CounterfactualEntityFactory.from(feature);
});
assertEquals("Null numeric features are not supported in counterfactuals", exception.getMessage());
}
use of org.kie.kogito.explainability.model.Feature 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());
}
use of org.kie.kogito.explainability.model.Feature 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());
}
use of org.kie.kogito.explainability.model.Feature 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());
}
Aggregations