Search in sources :

Example 61 with Value

use of org.kie.kogito.explainability.model.Value in project kogito-apps by kiegroup.

the class DatasetEncoderTest method testDatasetEncodingWithVectorData.

@Test
void testDatasetEncodingWithVectorData() {
    List<PredictionInput> perturbedInputs = new LinkedList<>();
    for (int i = 0; i < 10; i++) {
        List<Feature> inputFeatures = new LinkedList<>();
        for (int j = 0; j < 3; j++) {
            double[] doubles = new double[2];
            doubles[0] = i;
            doubles[1] = j;
            inputFeatures.add(TestUtils.getMockedFeature(Type.VECTOR, new Value(doubles)));
        }
        perturbedInputs.add(new PredictionInput(inputFeatures));
    }
    List<Feature> features = new LinkedList<>();
    for (int i = 0; i < 3; i++) {
        double[] doubles = new double[2];
        doubles[0] = i;
        doubles[1] = i;
        features.add(TestUtils.getMockedFeature(Type.BINARY, new Value(doubles)));
    }
    PredictionInput originalInput = new PredictionInput(features);
    assertEncode(perturbedInputs, originalInput);
}
Also used : PredictionInput(org.kie.kogito.explainability.model.PredictionInput) Value(org.kie.kogito.explainability.model.Value) Feature(org.kie.kogito.explainability.model.Feature) LinkedList(java.util.LinkedList) Test(org.junit.jupiter.api.Test)

Example 62 with Value

use of org.kie.kogito.explainability.model.Value in project kogito-apps by kiegroup.

the class DatasetEncoderTest method testDatasetEncodingWithCategoricalData.

@Test
void testDatasetEncodingWithCategoricalData() {
    List<PredictionInput> perturbedInputs = new LinkedList<>();
    for (int i = 0; i < 10; i++) {
        List<Feature> inputFeatures = new LinkedList<>();
        for (int j = 0; j < 3; j++) {
            double[] doubles = new double[2];
            inputFeatures.add(TestUtils.getMockedFeature(Type.CATEGORICAL, new Value(i + "" + j)));
        }
        perturbedInputs.add(new PredictionInput(inputFeatures));
    }
    List<Feature> features = new LinkedList<>();
    for (int i = 0; i < 3; i++) {
        features.add(TestUtils.getMockedFeature(Type.CATEGORICAL, new Value(i + "" + i)));
    }
    PredictionInput originalInput = new PredictionInput(features);
    assertEncode(perturbedInputs, originalInput);
}
Also used : PredictionInput(org.kie.kogito.explainability.model.PredictionInput) Value(org.kie.kogito.explainability.model.Value) Feature(org.kie.kogito.explainability.model.Feature) LinkedList(java.util.LinkedList) Test(org.junit.jupiter.api.Test)

Example 63 with Value

use of org.kie.kogito.explainability.model.Value 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)

Example 64 with Value

use of org.kie.kogito.explainability.model.Value in project kogito-apps by kiegroup.

the class DataUtilsTest method testBootstrap.

@Test
void testBootstrap() {
    List<Value> values = new ArrayList<>();
    PerturbationContext perturbationContext = new PerturbationContext(random, 1);
    for (int i = 0; i < 4; i++) {
        values.add(Type.NUMBER.randomValue(perturbationContext));
    }
    Feature mockedNumericFeature = TestUtils.getMockedNumericFeature();
    DataDistribution dataDistribution = new IndependentFeaturesDataDistribution(List.of(new GenericFeatureDistribution(mockedNumericFeature, values)));
    Map<String, FeatureDistribution> featureDistributionMap = DataUtils.boostrapFeatureDistributions(dataDistribution, perturbationContext, 10, 1, 500, new HashMap<>());
    assertThat(featureDistributionMap).isNotNull();
    assertThat(featureDistributionMap).isNotEmpty();
    FeatureDistribution actual = featureDistributionMap.get(mockedNumericFeature.getName());
    assertThat(actual).isNotNull();
    List<Value> allSamples = actual.getAllSamples();
    assertThat(allSamples).isNotNull();
    assertThat(allSamples).hasSize(10);
}
Also used : PerturbationContext(org.kie.kogito.explainability.model.PerturbationContext) ArrayList(java.util.ArrayList) Feature(org.kie.kogito.explainability.model.Feature) GenericFeatureDistribution(org.kie.kogito.explainability.model.GenericFeatureDistribution) FeatureDistribution(org.kie.kogito.explainability.model.FeatureDistribution) DataDistribution(org.kie.kogito.explainability.model.DataDistribution) IndependentFeaturesDataDistribution(org.kie.kogito.explainability.model.IndependentFeaturesDataDistribution) 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) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 65 with Value

use of org.kie.kogito.explainability.model.Value in project kogito-apps by kiegroup.

the class DataUtilsTest method testDropFeature.

@Test
void testDropFeature() {
    for (Type t : Type.values()) {
        Feature target = TestUtils.getMockedFeature(t, new Value(1d));
        List<Feature> features = new LinkedList<>();
        features.add(TestUtils.getMockedNumericFeature());
        features.add(target);
        features.add(TestUtils.getMockedTextFeature("foo bar"));
        features.add(TestUtils.getMockedNumericFeature());
        List<Feature> newFeatures = DataUtils.dropFeature(features, target);
        assertNotEquals(features, newFeatures);
    }
}
Also used : Type(org.kie.kogito.explainability.model.Type) Value(org.kie.kogito.explainability.model.Value) Feature(org.kie.kogito.explainability.model.Feature) LinkedList(java.util.LinkedList) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

Value (org.kie.kogito.explainability.model.Value)80 Feature (org.kie.kogito.explainability.model.Feature)69 Output (org.kie.kogito.explainability.model.Output)59 PredictionOutput (org.kie.kogito.explainability.model.PredictionOutput)54 PredictionInput (org.kie.kogito.explainability.model.PredictionInput)49 ArrayList (java.util.ArrayList)42 PredictionProvider (org.kie.kogito.explainability.model.PredictionProvider)42 LinkedList (java.util.LinkedList)36 Type (org.kie.kogito.explainability.model.Type)36 Test (org.junit.jupiter.api.Test)35 List (java.util.List)33 Prediction (org.kie.kogito.explainability.model.Prediction)33 Random (java.util.Random)31 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)23 Arrays (java.util.Arrays)16 Map (java.util.Map)16 Optional (java.util.Optional)16 CounterfactualEntity (org.kie.kogito.explainability.local.counterfactual.entities.CounterfactualEntity)16 FeatureFactory (org.kie.kogito.explainability.model.FeatureFactory)16 Collectors (java.util.stream.Collectors)15