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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations