Search in sources :

Example 81 with Feature

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

the class DoubleEntityTest method distanceUnscaled.

@Test
void distanceUnscaled() {
    final FeatureDomain featureDomain = NumericalFeatureDomain.create(0.0, 40.0);
    final Feature doubleFeature = FeatureFactory.newNumericalFeature("feature-double", 20.0, featureDomain);
    DoubleEntity entity = (DoubleEntity) CounterfactualEntityFactory.from(doubleFeature);
    entity.proposedValue = 30.0;
    assertEquals(10.0, entity.distance());
}
Also used : NumericalFeatureDomain(org.kie.kogito.explainability.model.domain.NumericalFeatureDomain) FeatureDomain(org.kie.kogito.explainability.model.domain.FeatureDomain) Feature(org.kie.kogito.explainability.model.Feature) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 82 with Feature

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

the class IntegerEntityTest method distanceUnscaled.

@Test
void distanceUnscaled() {
    final FeatureDomain featureDomain = NumericalFeatureDomain.create(0, 100);
    final Feature integerFeature = FeatureFactory.newNumericalFeature("feature-integer", 20, featureDomain);
    IntegerEntity entity = (IntegerEntity) CounterfactualEntityFactory.from(integerFeature);
    entity.proposedValue = 40;
    assertEquals(20.0, entity.distance());
}
Also used : NumericalFeatureDomain(org.kie.kogito.explainability.model.domain.NumericalFeatureDomain) FeatureDomain(org.kie.kogito.explainability.model.domain.FeatureDomain) Feature(org.kie.kogito.explainability.model.Feature) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 83 with Feature

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

the class LongEntityTest method distanceUnscaled.

@Test
void distanceUnscaled() {
    final FeatureDomain featureDomain = NumericalFeatureDomain.create(0, 100);
    final Feature feature = FeatureFactory.newNumericalFeature("feature-long", 20L, featureDomain);
    LongEntity entity = (LongEntity) CounterfactualEntityFactory.from(feature);
    entity.proposedValue = 40L;
    assertEquals(20.0, entity.distance());
}
Also used : NumericalFeatureDomain(org.kie.kogito.explainability.model.domain.NumericalFeatureDomain) FeatureDomain(org.kie.kogito.explainability.model.domain.FeatureDomain) Feature(org.kie.kogito.explainability.model.Feature) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 84 with Feature

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

the class DatasetEncoderTest method testDatasetEncodingWithBooleanData.

@Test
void testDatasetEncodingWithBooleanData() {
    List<PredictionInput> perturbedInputs = new LinkedList<>();
    for (int i = 0; i < 10; i++) {
        List<Feature> inputFeatures = new LinkedList<>();
        for (int j = 0; j < 3; j++) {
            inputFeatures.add(TestUtils.getMockedFeature(Type.BOOLEAN, new Value(j % 2 == 0)));
        }
        perturbedInputs.add(new PredictionInput(inputFeatures));
    }
    List<Feature> features = new LinkedList<>();
    for (int i = 0; i < 3; i++) {
        features.add(TestUtils.getMockedFeature(Type.BOOLEAN, new Value(i % 2 == 0)));
    }
    PredictionInput originalInput = new PredictionInput(features);
    assertEncode(perturbedInputs, originalInput);
}
Also used : PredictionInput(org.kie.kogito.explainability.model.PredictionInput) Value(org.kie.kogito.explainability.model.Value) Feature(org.kie.kogito.explainability.model.Feature) LinkedList(java.util.LinkedList) Test(org.junit.jupiter.api.Test)

Example 85 with Feature

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

the class DatasetEncoderTest method testEmptyDatasetEncoding.

@Test
void testEmptyDatasetEncoding() {
    List<PredictionInput> inputs = new LinkedList<>();
    List<Output> outputs = new LinkedList<>();
    List<Feature> features = new LinkedList<>();
    Output originalOutput = new Output("foo", Type.NUMBER, new Value(1), 1d);
    EncodingParams params = new EncodingParams(1, 0.1);
    DatasetEncoder datasetEncoder = new DatasetEncoder(inputs, outputs, features, originalOutput, params);
    Collection<Pair<double[], Double>> trainingSet = datasetEncoder.getEncodedTrainingSet();
    assertNotNull(trainingSet);
    assertTrue(trainingSet.isEmpty());
}
Also used : PredictionInput(org.kie.kogito.explainability.model.PredictionInput) Output(org.kie.kogito.explainability.model.Output) Value(org.kie.kogito.explainability.model.Value) EncodingParams(org.kie.kogito.explainability.model.EncodingParams) Feature(org.kie.kogito.explainability.model.Feature) LinkedList(java.util.LinkedList) Pair(org.apache.commons.lang3.tuple.Pair) Test(org.junit.jupiter.api.Test)

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