use of org.kie.kogito.explainability.model.domain.FeatureDomain in project kogito-apps by kiegroup.
the class ConversionUtilsTest method testToFeatureDomain_UnitCategoricalString.
@Test
void testToFeatureDomain_UnitCategoricalString() {
FeatureDomain featureDomain = ConversionUtils.toFeatureDomain(new CounterfactualSearchDomainUnitValue("string", "string", true, new CounterfactualDomainCategorical(List.of(TextNode.valueOf("Black"), TextNode.valueOf("White")))));
assertTrue(featureDomain instanceof CategoricalFeatureDomain);
CategoricalFeatureDomain categoricalFeatureDomain = (CategoricalFeatureDomain) featureDomain;
assertEquals(2, categoricalFeatureDomain.getCategories().size());
assertTrue(categoricalFeatureDomain.getCategories().containsAll(List.of("White", "Black")));
assertNull(categoricalFeatureDomain.getLowerBound());
assertNull(categoricalFeatureDomain.getUpperBound());
}
use of org.kie.kogito.explainability.model.domain.FeatureDomain in project kogito-apps by kiegroup.
the class ConversionUtilsTest method toFeatureDomainsConstraintsMultiElement.
@Test
void toFeatureDomainsConstraintsMultiElement() {
final Random random = new Random();
List<NamedTypedValue> values = IntStream.range(0, 10).mapToObj(i -> getDoubleUnit("f-" + i, random.nextDouble())).collect(Collectors.toList());
List<CounterfactualSearchDomain> domains = IntStream.range(0, 10).mapToObj(i -> getDoubleSearchDomain("f-" + i, -1, 1)).collect(Collectors.toList());
final List<Feature> features = ConversionUtils.toFeatureList(values, domains);
assertEquals(10, features.size());
assertTrue(features.stream().allMatch(f -> f.getType() == Type.NUMBER));
assertTrue(features.stream().noneMatch(Feature::isConstrained));
assertTrue(features.stream().map(Feature::getDomain).noneMatch(FeatureDomain::isEmpty));
assertTrue(features.stream().map(Feature::getDomain).map(FeatureDomain::getLowerBound).allMatch(lb -> lb == -1.0));
assertTrue(features.stream().map(Feature::getDomain).map(FeatureDomain::getUpperBound).allMatch(ub -> ub == 1.0));
}
use of org.kie.kogito.explainability.model.domain.FeatureDomain in project kogito-apps by kiegroup.
the class ConversionUtilsTest method testToFeatureDomain_UnitFixedString.
@Test
void testToFeatureDomain_UnitFixedString() {
FeatureDomain featureDomain = ConversionUtils.toFeatureDomain(new CounterfactualSearchDomainUnitValue("string", "string", true, null));
assertTrue(featureDomain instanceof EmptyFeatureDomain);
}
use of org.kie.kogito.explainability.model.domain.FeatureDomain in project kogito-apps by kiegroup.
the class ConversionUtilsTest method testToFeatureDomain_UnitRangeInteger.
@Test
void testToFeatureDomain_UnitRangeInteger() {
FeatureDomain featureDomain = ConversionUtils.toFeatureDomain(new CounterfactualSearchDomainUnitValue("int", "int", true, new CounterfactualDomainRange(IntNode.valueOf(18), IntNode.valueOf(65))));
assertTrue(featureDomain instanceof NumericalFeatureDomain);
NumericalFeatureDomain numericalFeatureDomain = (NumericalFeatureDomain) featureDomain;
assertEquals(18.0, numericalFeatureDomain.getLowerBound());
assertEquals(65.0, numericalFeatureDomain.getUpperBound());
assertNull(numericalFeatureDomain.getCategories());
}
Aggregations