use of org.kie.kogito.explainability.model.FeatureDistribution in project kogito-apps by kiegroup.
the class CompositeEntityTest method distanceScaled.
@ParameterizedTest
@ValueSource(ints = { 0, 1, 2, 3, 4 })
void distanceScaled(int seed) {
Random random = new Random();
random.setSeed(seed);
final Feature doubleFeature = FeatureFactory.newNumericalFeature("feature-double", 20.0, NumericalFeatureDomain.create(0.0, 40.0));
final FeatureDistribution featureDistribution = new NumericFeatureDistribution(doubleFeature, random.doubles(5000, 10.0, 40.0).toArray());
DoubleEntity entity = (DoubleEntity) CounterfactualEntityFactory.from(doubleFeature, featureDistribution);
entity.proposedValue = 30.0;
final double distance = entity.distance();
assertTrue(distance > 0.1 && distance < 0.2);
}
use of org.kie.kogito.explainability.model.FeatureDistribution in project kogito-apps by kiegroup.
the class DoubleEntityTest method distanceScaled.
@ParameterizedTest
@ValueSource(ints = { 0, 1, 2, 3, 4 })
void distanceScaled(int seed) {
Random random = new Random();
random.setSeed(seed);
final FeatureDomain featureDomain = NumericalFeatureDomain.create(0.0, 40.0);
final Feature doubleFeature = FeatureFactory.newNumericalFeature("feature-double", 20.0, featureDomain);
final FeatureDistribution featureDistribution = new NumericFeatureDistribution(doubleFeature, random.doubles(5000, 10.0, 40.0).toArray());
DoubleEntity entity = (DoubleEntity) CounterfactualEntityFactory.from(doubleFeature, featureDistribution);
entity.proposedValue = 30.0;
final double distance = entity.distance();
assertTrue(distance > 0.1 && distance < 0.2);
}
use of org.kie.kogito.explainability.model.FeatureDistribution in project kogito-apps by kiegroup.
the class IntegerEntityTest method distanceScaled.
@ParameterizedTest
@ValueSource(ints = { 0, 1, 2, 3, 4 })
void distanceScaled(int seed) {
Random random = new Random();
random.setSeed(seed);
final FeatureDomain featureDomain = NumericalFeatureDomain.create(0, 100);
final Feature integerFeature = FeatureFactory.newNumericalFeature("feature-integer", 20, featureDomain);
final FeatureDistribution featureDistribution = new NumericFeatureDistribution(integerFeature, random.ints(5000, 10, 40).mapToDouble(x -> x).toArray());
IntegerEntity entity = (IntegerEntity) CounterfactualEntityFactory.from(integerFeature, featureDistribution);
entity.proposedValue = 40;
final double distance = entity.distance();
assertTrue(distance > 0.2 && distance < 0.3);
}
use of org.kie.kogito.explainability.model.FeatureDistribution in project kogito-apps by kiegroup.
the class LongEntityTest method distanceScaled.
@ParameterizedTest
@ValueSource(ints = { 0, 1, 2, 3, 4 })
void distanceScaled(int seed) {
Random random = new Random();
random.setSeed(seed);
final FeatureDomain featureDomain = NumericalFeatureDomain.create(0, 100);
final Feature feature = FeatureFactory.newNumericalFeature("feature-long", 20L, featureDomain);
final FeatureDistribution featureDistribution = new NumericFeatureDistribution(feature, random.longs(5000, 10, 40).mapToDouble(x -> x).toArray());
LongEntity entity = (LongEntity) CounterfactualEntityFactory.from(feature, featureDistribution);
entity.proposedValue = 40L;
final double distance = entity.distance();
assertTrue(distance > 0.2 && distance < 0.3);
}
use of org.kie.kogito.explainability.model.FeatureDistribution in project kogito-apps by kiegroup.
the class HighScoreNumericFeatureZonesProviderTest method testNonEmptyData.
@Test
void testNonEmptyData() {
Random random = new Random();
random.setSeed(0);
PerturbationContext perturbationContext = new PerturbationContext(random, 1);
List<Feature> features = new ArrayList<>();
PredictionProvider predictionProvider = TestUtils.getSumThresholdModel(0.1, 0.1);
List<FeatureDistribution> featureDistributions = new ArrayList<>();
int nf = 4;
for (int i = 0; i < nf; i++) {
Feature numericalFeature = FeatureFactory.newNumericalFeature("f-" + i, Double.NaN);
features.add(numericalFeature);
List<Value> values = new ArrayList<>();
for (int r = 0; r < 4; r++) {
values.add(Type.NUMBER.randomValue(perturbationContext));
}
featureDistributions.add(new GenericFeatureDistribution(numericalFeature, values));
}
DataDistribution dataDistribution = new IndependentFeaturesDataDistribution(featureDistributions);
Map<String, HighScoreNumericFeatureZones> highScoreFeatureZones = HighScoreNumericFeatureZonesProvider.getHighScoreFeatureZones(dataDistribution, predictionProvider, features, 10);
assertThat(highScoreFeatureZones).isNotNull();
assertThat(highScoreFeatureZones.size()).isEqualTo(4);
}
Aggregations