Search in sources :

Example 81 with PredictionProvider

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

the class CountingOptimizationStrategyTest method testMaybeOptimize.

@Test
void testMaybeOptimize() {
    LimeOptimizationService optimizationService = mock(LimeOptimizationService.class);
    CountingOptimizationStrategy strategy = new CountingOptimizationStrategy(10, optimizationService);
    List<Prediction> recordedPredictions = Collections.emptyList();
    PredictionProvider model = mock(PredictionProvider.class);
    LimeExplainer explaier = new LimeExplainer();
    LimeConfig config = new LimeConfig();
    assertThatCode(() -> strategy.maybeOptimize(recordedPredictions, model, explaier, config)).doesNotThrowAnyException();
}
Also used : LimeExplainer(org.kie.kogito.explainability.local.lime.LimeExplainer) Prediction(org.kie.kogito.explainability.model.Prediction) PredictionProvider(org.kie.kogito.explainability.model.PredictionProvider) LimeConfig(org.kie.kogito.explainability.local.lime.LimeConfig) Test(org.junit.jupiter.api.Test)

Example 82 with PredictionProvider

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

the class TestUtils method getFixedOutputClassifier.

public static PredictionProvider getFixedOutputClassifier() {
    return inputs -> supplyAsync(() -> {
        List<PredictionOutput> outputs = new LinkedList<>();
        for (PredictionInput ignored : inputs) {
            Output output = new Output("class", Type.BOOLEAN, new Value(false), 1d);
            outputs.add(new PredictionOutput(List.of(output)));
        }
        return outputs;
    });
}
Also used : Arrays(java.util.Arrays) LimeExplainer(org.kie.kogito.explainability.local.lime.LimeExplainer) Feature(org.kie.kogito.explainability.model.Feature) Prediction(org.kie.kogito.explainability.model.Prediction) Random(java.util.Random) Mockito.when(org.mockito.Mockito.when) Value(org.kie.kogito.explainability.model.Value) Type(org.kie.kogito.explainability.model.Type) PredictionProvider(org.kie.kogito.explainability.model.PredictionProvider) ArrayList(java.util.ArrayList) PredictionInput(org.kie.kogito.explainability.model.PredictionInput) List(java.util.List) Pair(org.apache.commons.lang3.tuple.Pair) Output(org.kie.kogito.explainability.model.Output) CompletableFuture.supplyAsync(java.util.concurrent.CompletableFuture.supplyAsync) Optional(java.util.Optional) ValidationUtils(org.kie.kogito.explainability.utils.ValidationUtils) LinkedList(java.util.LinkedList) Assertions.assertDoesNotThrow(org.junit.jupiter.api.Assertions.assertDoesNotThrow) PredictionOutput(org.kie.kogito.explainability.model.PredictionOutput) Mockito.mock(org.mockito.Mockito.mock) PredictionInput(org.kie.kogito.explainability.model.PredictionInput) PredictionOutput(org.kie.kogito.explainability.model.PredictionOutput) Output(org.kie.kogito.explainability.model.Output) PredictionOutput(org.kie.kogito.explainability.model.PredictionOutput) Value(org.kie.kogito.explainability.model.Value) LinkedList(java.util.LinkedList)

Example 83 with PredictionProvider

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

the class TestUtils method getSumSkipModel.

public static PredictionProvider getSumSkipModel(int skipFeatureIndex) {
    return inputs -> supplyAsync(() -> {
        List<PredictionOutput> predictionOutputs = new LinkedList<>();
        for (PredictionInput predictionInput : inputs) {
            List<Feature> features = predictionInput.getFeatures();
            double result = 0;
            for (int i = 0; i < features.size(); i++) {
                if (skipFeatureIndex != i) {
                    result += features.get(i).getValue().asNumber();
                }
            }
            PredictionOutput predictionOutput = new PredictionOutput(List.of(new Output("sum-but" + skipFeatureIndex, Type.NUMBER, new Value(result), 1d)));
            predictionOutputs.add(predictionOutput);
        }
        return predictionOutputs;
    });
}
Also used : Arrays(java.util.Arrays) LimeExplainer(org.kie.kogito.explainability.local.lime.LimeExplainer) Feature(org.kie.kogito.explainability.model.Feature) Prediction(org.kie.kogito.explainability.model.Prediction) Random(java.util.Random) Mockito.when(org.mockito.Mockito.when) Value(org.kie.kogito.explainability.model.Value) Type(org.kie.kogito.explainability.model.Type) PredictionProvider(org.kie.kogito.explainability.model.PredictionProvider) ArrayList(java.util.ArrayList) PredictionInput(org.kie.kogito.explainability.model.PredictionInput) List(java.util.List) Pair(org.apache.commons.lang3.tuple.Pair) Output(org.kie.kogito.explainability.model.Output) CompletableFuture.supplyAsync(java.util.concurrent.CompletableFuture.supplyAsync) Optional(java.util.Optional) ValidationUtils(org.kie.kogito.explainability.utils.ValidationUtils) LinkedList(java.util.LinkedList) Assertions.assertDoesNotThrow(org.junit.jupiter.api.Assertions.assertDoesNotThrow) PredictionOutput(org.kie.kogito.explainability.model.PredictionOutput) Mockito.mock(org.mockito.Mockito.mock) PredictionInput(org.kie.kogito.explainability.model.PredictionInput) PredictionOutput(org.kie.kogito.explainability.model.PredictionOutput) Output(org.kie.kogito.explainability.model.Output) PredictionOutput(org.kie.kogito.explainability.model.PredictionOutput) Value(org.kie.kogito.explainability.model.Value) Feature(org.kie.kogito.explainability.model.Feature) LinkedList(java.util.LinkedList)

Example 84 with PredictionProvider

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

the class TestUtils method getSumSkipTwoOutputModel.

public static PredictionProvider getSumSkipTwoOutputModel(int skipFeatureIndex) {
    return inputs -> supplyAsync(() -> {
        List<PredictionOutput> predictionOutputs = new LinkedList<>();
        for (PredictionInput predictionInput : inputs) {
            List<Feature> features = predictionInput.getFeatures();
            double result = 0;
            for (int i = 0; i < features.size(); i++) {
                if (skipFeatureIndex != i) {
                    result += features.get(i).getValue().asNumber();
                }
            }
            Output output0 = new Output("sum-but" + skipFeatureIndex, Type.NUMBER, new Value(result), 1d);
            Output output1 = new Output("sum-but" + skipFeatureIndex + "*2", Type.NUMBER, new Value(result * 2), 1d);
            PredictionOutput predictionOutput = new PredictionOutput(List.of(output0, output1));
            predictionOutputs.add(predictionOutput);
        }
        return predictionOutputs;
    });
}
Also used : Arrays(java.util.Arrays) LimeExplainer(org.kie.kogito.explainability.local.lime.LimeExplainer) Feature(org.kie.kogito.explainability.model.Feature) Prediction(org.kie.kogito.explainability.model.Prediction) Random(java.util.Random) Mockito.when(org.mockito.Mockito.when) Value(org.kie.kogito.explainability.model.Value) Type(org.kie.kogito.explainability.model.Type) PredictionProvider(org.kie.kogito.explainability.model.PredictionProvider) ArrayList(java.util.ArrayList) PredictionInput(org.kie.kogito.explainability.model.PredictionInput) List(java.util.List) Pair(org.apache.commons.lang3.tuple.Pair) Output(org.kie.kogito.explainability.model.Output) CompletableFuture.supplyAsync(java.util.concurrent.CompletableFuture.supplyAsync) Optional(java.util.Optional) ValidationUtils(org.kie.kogito.explainability.utils.ValidationUtils) LinkedList(java.util.LinkedList) Assertions.assertDoesNotThrow(org.junit.jupiter.api.Assertions.assertDoesNotThrow) PredictionOutput(org.kie.kogito.explainability.model.PredictionOutput) Mockito.mock(org.mockito.Mockito.mock) PredictionInput(org.kie.kogito.explainability.model.PredictionInput) PredictionOutput(org.kie.kogito.explainability.model.PredictionOutput) Output(org.kie.kogito.explainability.model.Output) PredictionOutput(org.kie.kogito.explainability.model.PredictionOutput) Value(org.kie.kogito.explainability.model.Value) Feature(org.kie.kogito.explainability.model.Feature) LinkedList(java.util.LinkedList)

Example 85 with PredictionProvider

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

the class TestUtils method getLinearModel.

public static PredictionProvider getLinearModel(double[] weights) {
    return inputs -> supplyAsync(() -> {
        List<PredictionOutput> predictionOutputs = new LinkedList<>();
        for (PredictionInput predictionInput : inputs) {
            List<Feature> features = predictionInput.getFeatures();
            double result = 0;
            for (int i = 0; i < features.size(); i++) {
                result += features.get(i).getValue().asNumber() * weights[i];
            }
            PredictionOutput predictionOutput = new PredictionOutput(List.of(new Output("linear-sum", Type.NUMBER, new Value(result), 1d)));
            predictionOutputs.add(predictionOutput);
        }
        return predictionOutputs;
    });
}
Also used : Arrays(java.util.Arrays) LimeExplainer(org.kie.kogito.explainability.local.lime.LimeExplainer) Feature(org.kie.kogito.explainability.model.Feature) Prediction(org.kie.kogito.explainability.model.Prediction) Random(java.util.Random) Mockito.when(org.mockito.Mockito.when) Value(org.kie.kogito.explainability.model.Value) Type(org.kie.kogito.explainability.model.Type) PredictionProvider(org.kie.kogito.explainability.model.PredictionProvider) ArrayList(java.util.ArrayList) PredictionInput(org.kie.kogito.explainability.model.PredictionInput) List(java.util.List) Pair(org.apache.commons.lang3.tuple.Pair) Output(org.kie.kogito.explainability.model.Output) CompletableFuture.supplyAsync(java.util.concurrent.CompletableFuture.supplyAsync) Optional(java.util.Optional) ValidationUtils(org.kie.kogito.explainability.utils.ValidationUtils) LinkedList(java.util.LinkedList) Assertions.assertDoesNotThrow(org.junit.jupiter.api.Assertions.assertDoesNotThrow) PredictionOutput(org.kie.kogito.explainability.model.PredictionOutput) Mockito.mock(org.mockito.Mockito.mock) PredictionInput(org.kie.kogito.explainability.model.PredictionInput) PredictionOutput(org.kie.kogito.explainability.model.PredictionOutput) Output(org.kie.kogito.explainability.model.Output) PredictionOutput(org.kie.kogito.explainability.model.PredictionOutput) Value(org.kie.kogito.explainability.model.Value) Feature(org.kie.kogito.explainability.model.Feature) LinkedList(java.util.LinkedList)

Aggregations

PredictionProvider (org.kie.kogito.explainability.model.PredictionProvider)158 Prediction (org.kie.kogito.explainability.model.Prediction)134 PredictionInput (org.kie.kogito.explainability.model.PredictionInput)134 PredictionOutput (org.kie.kogito.explainability.model.PredictionOutput)126 Test (org.junit.jupiter.api.Test)109 SimplePrediction (org.kie.kogito.explainability.model.SimplePrediction)99 Random (java.util.Random)91 Feature (org.kie.kogito.explainability.model.Feature)76 ArrayList (java.util.ArrayList)73 PerturbationContext (org.kie.kogito.explainability.model.PerturbationContext)69 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)64 LimeConfig (org.kie.kogito.explainability.local.lime.LimeConfig)59 LimeExplainer (org.kie.kogito.explainability.local.lime.LimeExplainer)54 Output (org.kie.kogito.explainability.model.Output)45 Saliency (org.kie.kogito.explainability.model.Saliency)45 LinkedList (java.util.LinkedList)41 Value (org.kie.kogito.explainability.model.Value)41 List (java.util.List)37 LimeConfigOptimizer (org.kie.kogito.explainability.local.lime.optim.LimeConfigOptimizer)33 ValueSource (org.junit.jupiter.params.provider.ValueSource)32