Search in sources :

Example 31 with Feature

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

the class CounterfactualScoreCalculatorTest method DoubleDistanceSameValueZero.

@ParameterizedTest
@ValueSource(ints = { 0, 1, 2, 3, 4 })
void DoubleDistanceSameValueZero(int seed) {
    final Random random = new Random(seed);
    final double value = 0.0;
    Feature x = FeatureFactory.newNumericalFeature("x", value);
    Feature y = FeatureFactory.newNumericalFeature("y", value);
    Output ox = outputFromFeature(x);
    Output oy = outputFromFeature(y);
    // Use a random threshold, mustn't make a difference
    final double distance = CounterFactualScoreCalculator.outputDistance(ox, oy, random.nextDouble());
    assertEquals(Type.NUMBER, ox.getType());
    assertEquals(0.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 32 with Feature

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

the class CounterfactualScoreCalculatorTest method currencyDistanceSameValue.

@ParameterizedTest
@ValueSource(ints = { 0, 1, 2, 3, 4 })
void currencyDistanceSameValue(int seed) {
    final Random random = new Random(seed);
    final Currency value = Currency.getInstance(Locale.US);
    Feature x = FeatureFactory.newCurrencyFeature("x", value);
    Feature y = FeatureFactory.newCurrencyFeature("y", value);
    Output ox = outputFromFeature(x);
    Output oy = outputFromFeature(y);
    double distance = CounterFactualScoreCalculator.outputDistance(ox, oy);
    assertEquals(Type.CURRENCY, ox.getType());
    assertEquals(0.0, distance);
    // Use a random threshold, mustn't make a difference
    distance = CounterFactualScoreCalculator.outputDistance(ox, oy, random.nextDouble());
    assertEquals(0.0, distance);
}
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 33 with Feature

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

the class CounterfactualScoreCalculatorTest method objectDistanceSameValue.

@ParameterizedTest
@ValueSource(ints = { 0, 1, 2, 3, 4 })
void objectDistanceSameValue(int seed) {
    final Random random = new Random(seed);
    final ByteBuffer value = ByteBuffer.wrap("foo".getBytes());
    Feature x = FeatureFactory.newObjectFeature("x", value);
    Feature y = FeatureFactory.newObjectFeature("y", value);
    Output ox = outputFromFeature(x);
    Output oy = outputFromFeature(y);
    double distance = CounterFactualScoreCalculator.outputDistance(ox, oy);
    assertEquals(Type.UNDEFINED, ox.getType());
    assertEquals(0.0, distance);
    // Use a random threshold, mustn't make a difference
    distance = CounterFactualScoreCalculator.outputDistance(ox, oy, random.nextDouble());
    assertEquals(0.0, distance);
}
Also used : Random(java.util.Random) PredictionOutput(org.kie.kogito.explainability.model.PredictionOutput) Output(org.kie.kogito.explainability.model.Output) ByteBuffer(java.nio.ByteBuffer) Feature(org.kie.kogito.explainability.model.Feature) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 34 with Feature

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

the class CounterfactualScoreCalculatorTest method durationDistanceDifferentValue.

@Test
void durationDistanceDifferentValue() {
    final double SECONDS = 120L;
    Feature x = FeatureFactory.newDurationFeature("x", Duration.ZERO);
    Feature y = FeatureFactory.newDurationFeature("y", Duration.ofSeconds((long) SECONDS));
    Output ox = outputFromFeature(x);
    Output oy = outputFromFeature(y);
    double distance = CounterFactualScoreCalculator.outputDistance(ox, oy);
    assertEquals(Type.DURATION, ox.getType());
    assertEquals(Type.DURATION, oy.getType());
    assertEquals(SECONDS, distance);
    x = FeatureFactory.newDurationFeature("x", Duration.ofSeconds((long) SECONDS));
    y = FeatureFactory.newDurationFeature("y", Duration.ofDays(1L));
    ox = outputFromFeature(x);
    oy = outputFromFeature(y);
    distance = CounterFactualScoreCalculator.outputDistance(ox, oy);
    assertEquals(0.9986, distance, 0.01);
    x = FeatureFactory.newDurationFeature("x", Duration.ofDays(2L));
    y = FeatureFactory.newDurationFeature("y", Duration.ofDays(1L));
    ox = outputFromFeature(x);
    oy = outputFromFeature(y);
    distance = CounterFactualScoreCalculator.outputDistance(ox, oy);
    System.out.println(distance);
    assertEquals(0.5, distance, 1e-4);
}
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 35 with Feature

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

the class CounterfactualScoreCalculatorTest method CategoricalDistanceSameValue.

@ParameterizedTest
@ValueSource(ints = { 0, 1, 2, 3, 4 })
void CategoricalDistanceSameValue(int seed) {
    final Random random = new Random(seed);
    final String value = UUID.randomUUID().toString();
    Feature x = FeatureFactory.newCategoricalFeature("x", value);
    Feature y = FeatureFactory.newCategoricalFeature("y", value);
    Output ox = outputFromFeature(x);
    Output oy = outputFromFeature(y);
    double distance = CounterFactualScoreCalculator.outputDistance(ox, oy);
    assertEquals(Type.CATEGORICAL, ox.getType());
    assertEquals(0.0, distance);
    // Use a random threshold, mustn't make a difference
    distance = CounterFactualScoreCalculator.outputDistance(ox, oy, random.nextDouble());
    assertEquals(0.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

Feature (org.kie.kogito.explainability.model.Feature)233 PredictionOutput (org.kie.kogito.explainability.model.PredictionOutput)118 Test (org.junit.jupiter.api.Test)107 PredictionInput (org.kie.kogito.explainability.model.PredictionInput)107 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)104 Output (org.kie.kogito.explainability.model.Output)102 ArrayList (java.util.ArrayList)97 Random (java.util.Random)92 PredictionProvider (org.kie.kogito.explainability.model.PredictionProvider)78 Value (org.kie.kogito.explainability.model.Value)74 LinkedList (java.util.LinkedList)72 ValueSource (org.junit.jupiter.params.provider.ValueSource)71 Prediction (org.kie.kogito.explainability.model.Prediction)67 List (java.util.List)51 CounterfactualEntity (org.kie.kogito.explainability.local.counterfactual.entities.CounterfactualEntity)46 PerturbationContext (org.kie.kogito.explainability.model.PerturbationContext)42 Type (org.kie.kogito.explainability.model.Type)39 NumericalFeatureDomain (org.kie.kogito.explainability.model.domain.NumericalFeatureDomain)37 SimplePrediction (org.kie.kogito.explainability.model.SimplePrediction)35 FeatureDomain (org.kie.kogito.explainability.model.domain.FeatureDomain)33