Search in sources :

Example 6 with FeatureDistribution

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);
}
Also used : NumericFeatureDistribution(org.kie.kogito.explainability.model.NumericFeatureDistribution) FeatureDistribution(org.kie.kogito.explainability.model.FeatureDistribution) Random(java.util.Random) Feature(org.kie.kogito.explainability.model.Feature) NumericFeatureDistribution(org.kie.kogito.explainability.model.NumericFeatureDistribution) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 7 with FeatureDistribution

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);
}
Also used : NumericFeatureDistribution(org.kie.kogito.explainability.model.NumericFeatureDistribution) FeatureDistribution(org.kie.kogito.explainability.model.FeatureDistribution) Random(java.util.Random) NumericalFeatureDomain(org.kie.kogito.explainability.model.domain.NumericalFeatureDomain) FeatureDomain(org.kie.kogito.explainability.model.domain.FeatureDomain) Feature(org.kie.kogito.explainability.model.Feature) NumericFeatureDistribution(org.kie.kogito.explainability.model.NumericFeatureDistribution) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 8 with FeatureDistribution

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);
}
Also used : NumericFeatureDistribution(org.kie.kogito.explainability.model.NumericFeatureDistribution) FeatureDistribution(org.kie.kogito.explainability.model.FeatureDistribution) Random(java.util.Random) NumericalFeatureDomain(org.kie.kogito.explainability.model.domain.NumericalFeatureDomain) FeatureDomain(org.kie.kogito.explainability.model.domain.FeatureDomain) Feature(org.kie.kogito.explainability.model.Feature) NumericFeatureDistribution(org.kie.kogito.explainability.model.NumericFeatureDistribution) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 9 with FeatureDistribution

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);
}
Also used : NumericFeatureDistribution(org.kie.kogito.explainability.model.NumericFeatureDistribution) FeatureDistribution(org.kie.kogito.explainability.model.FeatureDistribution) Random(java.util.Random) NumericalFeatureDomain(org.kie.kogito.explainability.model.domain.NumericalFeatureDomain) FeatureDomain(org.kie.kogito.explainability.model.domain.FeatureDomain) Feature(org.kie.kogito.explainability.model.Feature) NumericFeatureDistribution(org.kie.kogito.explainability.model.NumericFeatureDistribution) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 10 with FeatureDistribution

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);
}
Also used : PerturbationContext(org.kie.kogito.explainability.model.PerturbationContext) ArrayList(java.util.ArrayList) PredictionProvider(org.kie.kogito.explainability.model.PredictionProvider) Feature(org.kie.kogito.explainability.model.Feature) GenericFeatureDistribution(org.kie.kogito.explainability.model.GenericFeatureDistribution) FeatureDistribution(org.kie.kogito.explainability.model.FeatureDistribution) Random(java.util.Random) IndependentFeaturesDataDistribution(org.kie.kogito.explainability.model.IndependentFeaturesDataDistribution) DataDistribution(org.kie.kogito.explainability.model.DataDistribution) Value(org.kie.kogito.explainability.model.Value) IndependentFeaturesDataDistribution(org.kie.kogito.explainability.model.IndependentFeaturesDataDistribution) GenericFeatureDistribution(org.kie.kogito.explainability.model.GenericFeatureDistribution) Test(org.junit.jupiter.api.Test)

Aggregations

FeatureDistribution (org.kie.kogito.explainability.model.FeatureDistribution)15 Feature (org.kie.kogito.explainability.model.Feature)14 Random (java.util.Random)9 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)8 DataDistribution (org.kie.kogito.explainability.model.DataDistribution)8 NumericFeatureDistribution (org.kie.kogito.explainability.model.NumericFeatureDistribution)8 ArrayList (java.util.ArrayList)7 IndependentFeaturesDataDistribution (org.kie.kogito.explainability.model.IndependentFeaturesDataDistribution)7 Test (org.junit.jupiter.api.Test)6 Value (org.kie.kogito.explainability.model.Value)6 GenericFeatureDistribution (org.kie.kogito.explainability.model.GenericFeatureDistribution)5 PerturbationContext (org.kie.kogito.explainability.model.PerturbationContext)5 PredictionProvider (org.kie.kogito.explainability.model.PredictionProvider)5 ValueSource (org.junit.jupiter.params.provider.ValueSource)4 PredictionInput (org.kie.kogito.explainability.model.PredictionInput)4 PredictionOutput (org.kie.kogito.explainability.model.PredictionOutput)4 LinkedList (java.util.LinkedList)3 Output (org.kie.kogito.explainability.model.Output)3 Prediction (org.kie.kogito.explainability.model.Prediction)3 FeatureDomain (org.kie.kogito.explainability.model.domain.FeatureDomain)3