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);
}
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);
}
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);
}
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);
}
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);
}
}
Aggregations