Search in sources :

Example 1 with DataDomain

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

the class CounterfactualExplainerTest method testNoCounterfactualPossible.

@ParameterizedTest
@ValueSource(ints = { 0, 1, 2 })
void testNoCounterfactualPossible(long seed) throws ExecutionException, InterruptedException, TimeoutException {
    Random random = new Random();
    final PerturbationContext perturbationContext = new PerturbationContext(seed, random, 4);
    final List<Output> goal = List.of(new Output("inside", Type.BOOLEAN, new Value(true), 0.0));
    List<Feature> features = new LinkedList<>();
    List<FeatureDomain> featureBoundaries = new LinkedList<>();
    List<Boolean> constraints = new LinkedList<>();
    features.add(FeatureFactory.newNumericalFeature("f-num1", 1.0));
    constraints.add(true);
    featureBoundaries.add(EmptyFeatureDomain.create());
    features.add(FeatureFactory.newNumericalFeature("f-num2", 1.0));
    constraints.add(false);
    featureBoundaries.add(NumericalFeatureDomain.create(0.0, 2.0));
    features.add(FeatureFactory.newNumericalFeature("f-num3", 1.0));
    constraints.add(false);
    featureBoundaries.add(NumericalFeatureDomain.create(0.0, 2.0));
    features.add(FeatureFactory.newNumericalFeature("f-num4", 1.0));
    constraints.add(true);
    featureBoundaries.add(EmptyFeatureDomain.create());
    final DataDomain dataDomain = new DataDomain(featureBoundaries);
    final double center = 500.0;
    final double epsilon = 1.0;
    List<Feature> perturbedFeatures = DataUtils.perturbFeatures(features, perturbationContext);
    final CounterfactualResult result = runCounterfactualSearch((long) seed, goal, perturbedFeatures, TestUtils.getSumThresholdModel(center, epsilon), DEFAULT_GOAL_THRESHOLD);
    assertFalse(result.isValid());
}
Also used : PerturbationContext(org.kie.kogito.explainability.model.PerturbationContext) DataDomain(org.kie.kogito.explainability.model.DataDomain) EmptyFeatureDomain(org.kie.kogito.explainability.model.domain.EmptyFeatureDomain) CategoricalFeatureDomain(org.kie.kogito.explainability.model.domain.CategoricalFeatureDomain) NumericalFeatureDomain(org.kie.kogito.explainability.model.domain.NumericalFeatureDomain) FeatureDomain(org.kie.kogito.explainability.model.domain.FeatureDomain) Feature(org.kie.kogito.explainability.model.Feature) LinkedList(java.util.LinkedList) Random(java.util.Random) PredictionOutput(org.kie.kogito.explainability.model.PredictionOutput) Output(org.kie.kogito.explainability.model.Output) Value(org.kie.kogito.explainability.model.Value) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

LinkedList (java.util.LinkedList)1 Random (java.util.Random)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1 ValueSource (org.junit.jupiter.params.provider.ValueSource)1 DataDomain (org.kie.kogito.explainability.model.DataDomain)1 Feature (org.kie.kogito.explainability.model.Feature)1 Output (org.kie.kogito.explainability.model.Output)1 PerturbationContext (org.kie.kogito.explainability.model.PerturbationContext)1 PredictionOutput (org.kie.kogito.explainability.model.PredictionOutput)1 Value (org.kie.kogito.explainability.model.Value)1 CategoricalFeatureDomain (org.kie.kogito.explainability.model.domain.CategoricalFeatureDomain)1 EmptyFeatureDomain (org.kie.kogito.explainability.model.domain.EmptyFeatureDomain)1 FeatureDomain (org.kie.kogito.explainability.model.domain.FeatureDomain)1 NumericalFeatureDomain (org.kie.kogito.explainability.model.domain.NumericalFeatureDomain)1