use of org.kie.kogito.explainability.model.Output in project kogito-apps by kiegroup.
the class CounterfactualScoreCalculatorTest method IntegerDistanceDifferentValue.
@ParameterizedTest
@ValueSource(ints = { 0, 1, 2, 3, 4 })
void IntegerDistanceDifferentValue(int seed) {
final Random random = new Random(seed);
int value = random.nextInt(1000);
Feature x = FeatureFactory.newNumericalFeature("x", value);
Feature y = FeatureFactory.newNumericalFeature("y", value + 100);
Output ox = outputFromFeature(x);
Output oy = outputFromFeature(y);
double distance = CounterFactualScoreCalculator.outputDistance(ox, oy);
assertEquals(Type.NUMBER, ox.getType());
assertEquals(Type.NUMBER, oy.getType());
assertTrue(distance * distance > 0);
y = FeatureFactory.newNumericalFeature("y", value - 100);
oy = outputFromFeature(y);
distance = CounterFactualScoreCalculator.outputDistance(ox, oy);
assertTrue(distance * distance > 0);
}
use of org.kie.kogito.explainability.model.Output in project kogito-apps by kiegroup.
the class CounterfactualScoreCalculatorTest method IntegerDistanceNull.
@ParameterizedTest
@ValueSource(ints = { 0, 1, 2, 3, 4 })
void IntegerDistanceNull(int seed) {
final Random random = new Random(seed);
final int value = random.nextInt(1000);
// Null as a goal
IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> {
Feature predictionFeature = FeatureFactory.newNumericalFeature("x", value);
Feature goalFeature = FeatureFactory.newNumericalFeature("x", null);
Output predictionOutput = outputFromFeature(predictionFeature);
Output goalOutput = outputFromFeature(goalFeature);
CounterFactualScoreCalculator.outputDistance(predictionOutput, goalOutput);
});
assertEquals("Unsupported NaN or NULL for numeric feature 'x'", exception.getMessage());
// Null as a prediction
exception = assertThrows(IllegalArgumentException.class, () -> {
Feature predictionFeature = FeatureFactory.newNumericalFeature("x", null);
Feature goalFeature = FeatureFactory.newNumericalFeature("x", value);
Output predictionOutput = outputFromFeature(predictionFeature);
Output goalOutput = outputFromFeature(goalFeature);
CounterFactualScoreCalculator.outputDistance(predictionOutput, goalOutput);
});
assertEquals("Unsupported NaN or NULL for numeric feature 'x'", exception.getMessage());
// Null as both prediction and goal
exception = assertThrows(IllegalArgumentException.class, () -> {
Feature predictionFeature = FeatureFactory.newNumericalFeature("x", null);
Feature goalFeature = FeatureFactory.newNumericalFeature("x", null);
Output predictionOutput = outputFromFeature(predictionFeature);
Output goalOutput = outputFromFeature(goalFeature);
CounterFactualScoreCalculator.outputDistance(predictionOutput, goalOutput);
});
assertEquals("Unsupported NaN or NULL for numeric feature 'x'", exception.getMessage());
}
use of org.kie.kogito.explainability.model.Output in project kogito-apps by kiegroup.
the class CounterfactualScoreCalculatorTest method DoubleDistanceDifferentValueThresholdMet.
@ParameterizedTest
@ValueSource(ints = { 0, 1, 2, 3, 4 })
void DoubleDistanceDifferentValueThresholdMet(int seed) {
final double value = 100.0;
Feature x = FeatureFactory.newNumericalFeature("x", value);
Feature y = FeatureFactory.newNumericalFeature("y", value - 20.0);
Output ox = outputFromFeature(x);
Output oy = outputFromFeature(y);
double distance = CounterFactualScoreCalculator.outputDistance(ox, oy);
assertEquals(Type.NUMBER, ox.getType());
assertEquals(Type.NUMBER, oy.getType());
assertTrue(distance * distance > 0);
distance = CounterFactualScoreCalculator.outputDistance(ox, oy, 0.1);
assertTrue(distance * distance > 0);
distance = CounterFactualScoreCalculator.outputDistance(ox, oy, 0.2);
assertTrue(distance * distance > 0);
distance = CounterFactualScoreCalculator.outputDistance(ox, oy, 0.3);
assertFalse(distance * distance > 0);
}
use of org.kie.kogito.explainability.model.Output 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);
}
use of org.kie.kogito.explainability.model.Output 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);
}
Aggregations