use of org.kie.kogito.explainability.local.lime.LimeConfig in project kogito-apps by kiegroup.
the class PmmlRegressionCategoricalLimeExplainerTest method testExplanationStabilityWithOptimization.
@Disabled("See KOGITO-6154")
@Test
void testExplanationStabilityWithOptimization() throws ExecutionException, InterruptedException, TimeoutException {
PredictionProvider model = getModel();
List<PredictionInput> samples = getSamples();
List<PredictionOutput> predictionOutputs = model.predictAsync(samples.subList(0, 5)).get();
List<Prediction> predictions = DataUtils.getPredictions(samples, predictionOutputs);
long seed = 0;
LimeConfigOptimizer limeConfigOptimizer = new LimeConfigOptimizer().withDeterministicExecution(true);
Random random = new Random();
PerturbationContext perturbationContext = new PerturbationContext(seed, random, 1);
LimeConfig initialConfig = new LimeConfig().withSamples(10).withPerturbationContext(perturbationContext);
LimeConfig optimizedConfig = limeConfigOptimizer.optimize(initialConfig, predictions, model);
assertThat(optimizedConfig).isNotSameAs(initialConfig);
LimeExplainer limeExplainer = new LimeExplainer(optimizedConfig);
PredictionInput testPredictionInput = getTestInput();
List<PredictionOutput> testPredictionOutputs = model.predictAsync(List.of(testPredictionInput)).get(Config.INSTANCE.getAsyncTimeout(), Config.INSTANCE.getAsyncTimeUnit());
Prediction instance = new SimplePrediction(testPredictionInput, testPredictionOutputs.get(0));
assertDoesNotThrow(() -> ValidationUtils.validateLocalSaliencyStability(model, instance, limeExplainer, 1, 0.6, 0.6));
}
use of org.kie.kogito.explainability.local.lime.LimeConfig in project kogito-apps by kiegroup.
the class LimeConfigEntityFactoryTest method testProximityEntities.
@Test
void testProximityEntities() {
List<? extends LimeConfigEntity> entities = LimeConfigEntityFactory.createProximityEntities(new LimeConfig());
assertThat(entities).isNotNull().hasSize(4);
}
use of org.kie.kogito.explainability.local.lime.LimeConfig in project kogito-apps by kiegroup.
the class LimeConfigEntityFactoryTest method testEncodingEntities.
@Test
void testEncodingEntities() {
List<? extends LimeConfigEntity> entities = LimeConfigEntityFactory.createEncodingEntities(new LimeConfig());
assertThat(entities).isNotNull().hasSize(2);
}
use of org.kie.kogito.explainability.local.lime.LimeConfig in project kogito-apps by kiegroup.
the class LimeConfigOptimizerTest method assertConfigOptimized.
private void assertConfigOptimized(LimeConfigOptimizer limeConfigOptimizer) throws InterruptedException, java.util.concurrent.ExecutionException {
LimeConfig initialConfig = new LimeConfig().withSamples(10);
PredictionProvider model = TestUtils.getSumSkipModel(1);
Random random = new Random();
random.setSeed(4);
DataDistribution dataDistribution = DataUtils.generateRandomDataDistribution(5, 100, random);
List<PredictionInput> samples = dataDistribution.sample(10);
List<PredictionOutput> predictionOutputs = model.predictAsync(samples).get();
List<Prediction> predictions = DataUtils.getPredictions(samples, predictionOutputs);
LimeConfig optimizedConfig = limeConfigOptimizer.optimize(initialConfig, predictions, model);
assertThat(optimizedConfig).isNotNull();
Assertions.assertThat(optimizedConfig).isNotSameAs(initialConfig);
}
use of org.kie.kogito.explainability.local.lime.LimeConfig in project kogito-apps by kiegroup.
the class LimeImpactScoreCalculatorTest method testNonZeroScore.
@Test
void testNonZeroScore() throws ExecutionException, InterruptedException, TimeoutException {
PredictionProvider model = TestUtils.getDummyTextClassifier();
LimeImpactScoreCalculator scoreCalculator = new LimeImpactScoreCalculator();
LimeConfig config = new LimeConfig();
List<Feature> features = List.of(FeatureFactory.newFulltextFeature("text", "money so they say is the root of all evil today"));
PredictionInput input = new PredictionInput(features);
List<PredictionOutput> predictionOutputs = model.predictAsync(List.of(input)).get(Config.DEFAULT_ASYNC_TIMEOUT, Config.DEFAULT_ASYNC_TIMEUNIT);
assertThat(predictionOutputs).isNotNull();
assertThat(predictionOutputs.size()).isEqualTo(1);
PredictionOutput output = predictionOutputs.get(0);
Prediction prediction = new SimplePrediction(input, output);
List<Prediction> predictions = List.of(prediction);
List<LimeConfigEntity> entities = LimeConfigEntityFactory.createEncodingEntities(config);
LimeConfigSolution solution = new LimeConfigSolution(config, predictions, entities, model);
SimpleBigDecimalScore score = scoreCalculator.calculateScore(solution);
assertThat(score).isNotNull();
assertThat(score.getScore()).isNotNull().isNotEqualTo(BigDecimal.valueOf(0));
}
Aggregations