Search in sources :

Example 26 with LimeConfig

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));
}
Also used : SimplePrediction(org.kie.kogito.explainability.model.SimplePrediction) PerturbationContext(org.kie.kogito.explainability.model.PerturbationContext) PredictionInput(org.kie.kogito.explainability.model.PredictionInput) LimeExplainer(org.kie.kogito.explainability.local.lime.LimeExplainer) Prediction(org.kie.kogito.explainability.model.Prediction) SimplePrediction(org.kie.kogito.explainability.model.SimplePrediction) PredictionProvider(org.kie.kogito.explainability.model.PredictionProvider) LimeConfig(org.kie.kogito.explainability.local.lime.LimeConfig) Random(java.util.Random) PredictionOutput(org.kie.kogito.explainability.model.PredictionOutput) LimeConfigOptimizer(org.kie.kogito.explainability.local.lime.optim.LimeConfigOptimizer) Test(org.junit.jupiter.api.Test) Disabled(org.junit.jupiter.api.Disabled)

Example 27 with LimeConfig

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);
}
Also used : LimeConfig(org.kie.kogito.explainability.local.lime.LimeConfig) Test(org.junit.jupiter.api.Test)

Example 28 with LimeConfig

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);
}
Also used : LimeConfig(org.kie.kogito.explainability.local.lime.LimeConfig) Test(org.junit.jupiter.api.Test)

Example 29 with LimeConfig

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);
}
Also used : Random(java.util.Random) DataDistribution(org.kie.kogito.explainability.model.DataDistribution) PredictionInput(org.kie.kogito.explainability.model.PredictionInput) PredictionOutput(org.kie.kogito.explainability.model.PredictionOutput) Prediction(org.kie.kogito.explainability.model.Prediction) PredictionProvider(org.kie.kogito.explainability.model.PredictionProvider) LimeConfig(org.kie.kogito.explainability.local.lime.LimeConfig)

Example 30 with LimeConfig

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));
}
Also used : SimplePrediction(org.kie.kogito.explainability.model.SimplePrediction) PredictionInput(org.kie.kogito.explainability.model.PredictionInput) SimplePrediction(org.kie.kogito.explainability.model.SimplePrediction) Prediction(org.kie.kogito.explainability.model.Prediction) PredictionProvider(org.kie.kogito.explainability.model.PredictionProvider) Feature(org.kie.kogito.explainability.model.Feature) LimeConfig(org.kie.kogito.explainability.local.lime.LimeConfig) PredictionOutput(org.kie.kogito.explainability.model.PredictionOutput) SimpleBigDecimalScore(org.optaplanner.core.api.score.buildin.simplebigdecimal.SimpleBigDecimalScore) Test(org.junit.jupiter.api.Test)

Aggregations

LimeConfig (org.kie.kogito.explainability.local.lime.LimeConfig)65 Test (org.junit.jupiter.api.Test)56 Prediction (org.kie.kogito.explainability.model.Prediction)56 PredictionProvider (org.kie.kogito.explainability.model.PredictionProvider)53 SimplePrediction (org.kie.kogito.explainability.model.SimplePrediction)49 PredictionInput (org.kie.kogito.explainability.model.PredictionInput)48 PredictionOutput (org.kie.kogito.explainability.model.PredictionOutput)47 Random (java.util.Random)45 PerturbationContext (org.kie.kogito.explainability.model.PerturbationContext)45 LimeExplainer (org.kie.kogito.explainability.local.lime.LimeExplainer)36 LimeConfigOptimizer (org.kie.kogito.explainability.local.lime.optim.LimeConfigOptimizer)28 Saliency (org.kie.kogito.explainability.model.Saliency)16 DataDistribution (org.kie.kogito.explainability.model.DataDistribution)14 PredictionInputsDataDistribution (org.kie.kogito.explainability.model.PredictionInputsDataDistribution)13 ArrayList (java.util.ArrayList)11 Feature (org.kie.kogito.explainability.model.Feature)10 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)6 LinkedList (java.util.LinkedList)5 SimpleBigDecimalScore (org.optaplanner.core.api.score.buildin.simplebigdecimal.SimpleBigDecimalScore)5 InputStreamReader (java.io.InputStreamReader)4