Search in sources :

Example 26 with Output

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

the class CounterfactualScoreCalculatorTest method timeDistanceNull.

@Test
void timeDistanceNull() {
    final LocalTime value = LocalTime.of(17, 17);
    // Null as a goal
    Feature predictionFeature = FeatureFactory.newTimeFeature("x", value);
    Feature goalFeature = FeatureFactory.newTimeFeature("y", null);
    Output predictionOutput = outputFromFeature(predictionFeature);
    Output goalOutput = outputFromFeature(goalFeature);
    double distance = CounterFactualScoreCalculator.outputDistance(predictionOutput, goalOutput);
    assertEquals(Type.TIME, goalOutput.getType());
    assertEquals(1.0, distance);
    // Null as a prediction
    predictionFeature = FeatureFactory.newTimeFeature("x", null);
    goalFeature = FeatureFactory.newTimeFeature("y", value);
    predictionOutput = outputFromFeature(predictionFeature);
    goalOutput = outputFromFeature(goalFeature);
    distance = CounterFactualScoreCalculator.outputDistance(predictionOutput, goalOutput);
    assertEquals(Type.TIME, predictionOutput.getType());
    assertEquals(1.0, distance);
    // Null as both prediction and goal
    predictionFeature = FeatureFactory.newTimeFeature("x", null);
    goalFeature = FeatureFactory.newTimeFeature("y", null);
    predictionOutput = outputFromFeature(predictionFeature);
    goalOutput = outputFromFeature(goalFeature);
    distance = CounterFactualScoreCalculator.outputDistance(predictionOutput, goalOutput);
    assertEquals(Type.TIME, predictionOutput.getType());
}
Also used : LocalTime(java.time.LocalTime) PredictionOutput(org.kie.kogito.explainability.model.PredictionOutput) Output(org.kie.kogito.explainability.model.Output) Feature(org.kie.kogito.explainability.model.Feature) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 27 with Output

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

the class CounterfactualScoreCalculatorTest method currencyDistanceNull.

@ParameterizedTest
@ValueSource(ints = { 0, 1, 2, 3, 4 })
void currencyDistanceNull(int seed) {
    final Random random = new Random(seed);
    final Currency value = Currency.getInstance(Locale.UK);
    // Null as a goal
    Feature predictionFeature = FeatureFactory.newCurrencyFeature("x", value);
    Feature goalFeature = FeatureFactory.newCurrencyFeature("y", null);
    Output predictionOutput = outputFromFeature(predictionFeature);
    Output goalOutput = outputFromFeature(goalFeature);
    double distance = CounterFactualScoreCalculator.outputDistance(predictionOutput, goalOutput);
    assertEquals(Type.CURRENCY, goalOutput.getType());
    assertEquals(1.0, distance);
    // Null as a prediction
    predictionFeature = FeatureFactory.newCurrencyFeature("x", null);
    goalFeature = FeatureFactory.newCurrencyFeature("y", value);
    predictionOutput = outputFromFeature(predictionFeature);
    goalOutput = outputFromFeature(goalFeature);
    distance = CounterFactualScoreCalculator.outputDistance(predictionOutput, goalOutput);
    assertEquals(Type.CURRENCY, predictionOutput.getType());
    assertEquals(1.0, distance);
    // Null as both prediction and goal
    predictionFeature = FeatureFactory.newCurrencyFeature("x", null);
    goalFeature = FeatureFactory.newCurrencyFeature("y", null);
    predictionOutput = outputFromFeature(predictionFeature);
    goalOutput = outputFromFeature(goalFeature);
    distance = CounterFactualScoreCalculator.outputDistance(predictionOutput, goalOutput);
    assertEquals(Type.CURRENCY, predictionOutput.getType());
}
Also used : Random(java.util.Random) Currency(java.util.Currency) PredictionOutput(org.kie.kogito.explainability.model.PredictionOutput) Output(org.kie.kogito.explainability.model.Output) Feature(org.kie.kogito.explainability.model.Feature) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 28 with Output

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

the class CounterfactualScoreCalculatorTest method TextDistanceDifferentValue.

@ParameterizedTest
@ValueSource(ints = { 0, 1, 2, 3, 4 })
void TextDistanceDifferentValue(int seed) {
    final Random random = new Random(seed);
    Feature x = FeatureFactory.newTextFeature("x", UUID.randomUUID().toString());
    Feature y = FeatureFactory.newTextFeature("y", UUID.randomUUID().toString());
    Output ox = outputFromFeature(x);
    Output oy = outputFromFeature(y);
    double distance = CounterFactualScoreCalculator.outputDistance(ox, oy);
    assertEquals(Type.TEXT, ox.getType());
    assertEquals(Type.TEXT, oy.getType());
    assertEquals(1.0, distance);
}
Also used : Random(java.util.Random) PredictionOutput(org.kie.kogito.explainability.model.PredictionOutput) Output(org.kie.kogito.explainability.model.Output) Feature(org.kie.kogito.explainability.model.Feature) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 29 with Output

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

the class CounterfactualScoreCalculatorTest method differentFeatureTypes.

@Test
void differentFeatureTypes() {
    Feature x = FeatureFactory.newCategoricalFeature("x", UUID.randomUUID().toString());
    Feature y = FeatureFactory.newNumericalFeature("y", 0.0);
    Output ox = outputFromFeature(x);
    Output oy = outputFromFeature(y);
    IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> {
        CounterFactualScoreCalculator.outputDistance(ox, oy);
    });
    assertEquals("Features must have the same type. Feature 'x', has type 'categorical' and 'number'", exception.getMessage());
}
Also used : PredictionOutput(org.kie.kogito.explainability.model.PredictionOutput) Output(org.kie.kogito.explainability.model.Output) Feature(org.kie.kogito.explainability.model.Feature) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 30 with Output

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

the class CounterfactualScoreCalculatorTest method currencyDistanceDifferentValue.

@ParameterizedTest
@ValueSource(ints = { 0, 1, 2, 3, 4 })
void currencyDistanceDifferentValue(int seed) {
    final Random random = new Random(seed);
    Feature x = FeatureFactory.newCurrencyFeature("x", Currency.getInstance("GBP"));
    Feature y = FeatureFactory.newCurrencyFeature("y", Currency.getInstance("EUR"));
    Output ox = outputFromFeature(x);
    Output oy = outputFromFeature(y);
    double distance = CounterFactualScoreCalculator.outputDistance(ox, oy);
    assertEquals(Type.CURRENCY, ox.getType());
    assertEquals(Type.CURRENCY, oy.getType());
    assertEquals(1.0, distance);
    // Use a random threshold, mustn't make a difference
    distance = CounterFactualScoreCalculator.outputDistance(ox, oy, random.nextDouble());
    assertEquals(1.0, distance);
}
Also used : Random(java.util.Random) PredictionOutput(org.kie.kogito.explainability.model.PredictionOutput) Output(org.kie.kogito.explainability.model.Output) Feature(org.kie.kogito.explainability.model.Feature) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

Output (org.kie.kogito.explainability.model.Output)120 PredictionOutput (org.kie.kogito.explainability.model.PredictionOutput)109 Feature (org.kie.kogito.explainability.model.Feature)102 Value (org.kie.kogito.explainability.model.Value)63 Random (java.util.Random)61 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)59 PredictionInput (org.kie.kogito.explainability.model.PredictionInput)57 PredictionProvider (org.kie.kogito.explainability.model.PredictionProvider)52 ArrayList (java.util.ArrayList)47 ValueSource (org.junit.jupiter.params.provider.ValueSource)47 Prediction (org.kie.kogito.explainability.model.Prediction)46 Test (org.junit.jupiter.api.Test)42 List (java.util.List)39 Type (org.kie.kogito.explainability.model.Type)36 LinkedList (java.util.LinkedList)35 CounterfactualEntity (org.kie.kogito.explainability.local.counterfactual.entities.CounterfactualEntity)23 Mockito.mock (org.mockito.Mockito.mock)20 Optional (java.util.Optional)19 ExecutionException (java.util.concurrent.ExecutionException)19 Collectors (java.util.stream.Collectors)18