use of org.kie.kogito.explainability.model.Output in project kogito-apps by kiegroup.
the class CounterfactualScoreCalculatorTest method timeDistanceSameValue.
@ParameterizedTest
@ValueSource(ints = { 0, 1, 2, 3, 4 })
void timeDistanceSameValue(int seed) {
final Random random = new Random(seed);
final LocalTime value = LocalTime.of(random.nextInt(24), random.nextInt(60));
Feature x = FeatureFactory.newTimeFeature("x", value);
Feature y = FeatureFactory.newTimeFeature("y", value);
Output ox = outputFromFeature(x);
Output oy = outputFromFeature(y);
double distance = CounterFactualScoreCalculator.outputDistance(ox, oy);
assertEquals(Type.TIME, ox.getType());
assertEquals(0.0, Math.abs(distance));
// Use a random threshold, mustn't make a difference
distance = CounterFactualScoreCalculator.outputDistance(ox, oy, random.nextDouble());
assertEquals(0.0, Math.abs(distance));
}
use of org.kie.kogito.explainability.model.Output in project kogito-apps by kiegroup.
the class CounterfactualScoreCalculatorTest method DoubleDistanceNull.
@ParameterizedTest
@ValueSource(ints = { 0, 1, 2, 3, 4 })
void DoubleDistanceNull(int seed) {
final Random random = new Random(seed);
final double value = random.nextDouble() * 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 objectDistanceNull.
@ParameterizedTest
@ValueSource(ints = { 0, 1, 2, 3, 4 })
void objectDistanceNull(int seed) {
final Random random = new Random(seed);
final ByteBuffer value = ByteBuffer.wrap("foo".getBytes());
// Null as a goal
Feature predictionFeature = FeatureFactory.newObjectFeature("x", value);
Feature goalFeature = FeatureFactory.newObjectFeature("y", null);
Output predictionOutput = outputFromFeature(predictionFeature);
Output goalOutput = outputFromFeature(goalFeature);
double distance = CounterFactualScoreCalculator.outputDistance(predictionOutput, goalOutput);
assertEquals(Type.UNDEFINED, goalOutput.getType());
assertEquals(1.0, distance);
// Null as a prediction
predictionFeature = FeatureFactory.newObjectFeature("x", null);
goalFeature = FeatureFactory.newObjectFeature("y", value);
predictionOutput = outputFromFeature(predictionFeature);
goalOutput = outputFromFeature(goalFeature);
distance = CounterFactualScoreCalculator.outputDistance(predictionOutput, goalOutput);
assertEquals(Type.UNDEFINED, predictionOutput.getType());
assertEquals(1.0, distance);
// Null as both prediction and goal
predictionFeature = FeatureFactory.newObjectFeature("x", null);
goalFeature = FeatureFactory.newObjectFeature("y", null);
predictionOutput = outputFromFeature(predictionFeature);
goalOutput = outputFromFeature(goalFeature);
distance = CounterFactualScoreCalculator.outputDistance(predictionOutput, goalOutput);
assertEquals(Type.UNDEFINED, predictionOutput.getType());
}
use of org.kie.kogito.explainability.model.Output in project kogito-apps by kiegroup.
the class CounterfactualScoreCalculatorTest method BooleanDistanceSameValue.
@ParameterizedTest
@ValueSource(ints = { 0, 1, 2, 3, 4 })
void BooleanDistanceSameValue(int seed) {
final Random random = new Random(seed);
final boolean value = random.nextBoolean();
Feature x = FeatureFactory.newBooleanFeature("x", value);
Feature y = FeatureFactory.newBooleanFeature("y", value);
Output ox = outputFromFeature(x);
Output oy = outputFromFeature(y);
double distance = CounterFactualScoreCalculator.outputDistance(ox, oy);
assertEquals(Type.BOOLEAN, 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);
}
use of org.kie.kogito.explainability.model.Output in project kogito-apps by kiegroup.
the class CounterfactualScoreCalculatorTest method binaryDistanceNull.
@ParameterizedTest
@ValueSource(ints = { 0, 1, 2, 3, 4 })
void binaryDistanceNull(int seed) {
final Random random = new Random(seed);
final ByteBuffer value = ByteBuffer.wrap("foo".getBytes());
// Null as a goal
Feature predictionFeature = FeatureFactory.newBinaryFeature("x", value);
Feature goalFeature = FeatureFactory.newBinaryFeature("y", null);
Output predictionOutput = outputFromFeature(predictionFeature);
Output goalOutput = outputFromFeature(goalFeature);
double distance = CounterFactualScoreCalculator.outputDistance(predictionOutput, goalOutput);
assertEquals(Type.BINARY, goalOutput.getType());
assertEquals(1.0, distance);
// Null as a prediction
predictionFeature = FeatureFactory.newBinaryFeature("x", null);
goalFeature = FeatureFactory.newBinaryFeature("y", value);
predictionOutput = outputFromFeature(predictionFeature);
goalOutput = outputFromFeature(goalFeature);
distance = CounterFactualScoreCalculator.outputDistance(predictionOutput, goalOutput);
assertEquals(Type.BINARY, predictionOutput.getType());
assertEquals(1.0, distance);
// Null as both prediction and goal
predictionFeature = FeatureFactory.newBinaryFeature("x", null);
goalFeature = FeatureFactory.newBinaryFeature("y", null);
predictionOutput = outputFromFeature(predictionFeature);
goalOutput = outputFromFeature(goalFeature);
distance = CounterFactualScoreCalculator.outputDistance(predictionOutput, goalOutput);
assertEquals(Type.BINARY, predictionOutput.getType());
}
Aggregations