Search in sources :

Example 26 with CounterfactualEntity

use of org.kie.kogito.explainability.local.counterfactual.entities.CounterfactualEntity in project kogito-apps by kiegroup.

the class CounterfactualEntityFactoryTest method testIntegerFactory.

@Test
void testIntegerFactory() {
    final int value = 5;
    final FeatureDomain domain = NumericalFeatureDomain.create(0.0, 10.0);
    final Feature feature = FeatureFactory.newNumericalFeature("int-feature", value, domain);
    final CounterfactualEntity counterfactualEntity = CounterfactualEntityFactory.from(feature);
    assertTrue(counterfactualEntity instanceof IntegerEntity);
    assertEquals(value, counterfactualEntity.asFeature().getValue().asNumber());
}
Also used : CounterfactualEntity(org.kie.kogito.explainability.local.counterfactual.entities.CounterfactualEntity) IntegerEntity(org.kie.kogito.explainability.local.counterfactual.entities.IntegerEntity) FixedIntegerEntity(org.kie.kogito.explainability.local.counterfactual.entities.fixed.FixedIntegerEntity) ObjectFeatureDomain(org.kie.kogito.explainability.model.domain.ObjectFeatureDomain) EmptyFeatureDomain(org.kie.kogito.explainability.model.domain.EmptyFeatureDomain) CategoricalFeatureDomain(org.kie.kogito.explainability.model.domain.CategoricalFeatureDomain) CurrencyFeatureDomain(org.kie.kogito.explainability.model.domain.CurrencyFeatureDomain) URIFeatureDomain(org.kie.kogito.explainability.model.domain.URIFeatureDomain) DurationFeatureDomain(org.kie.kogito.explainability.model.domain.DurationFeatureDomain) TimeFeatureDomain(org.kie.kogito.explainability.model.domain.TimeFeatureDomain) NumericalFeatureDomain(org.kie.kogito.explainability.model.domain.NumericalFeatureDomain) BinaryFeatureDomain(org.kie.kogito.explainability.model.domain.BinaryFeatureDomain) FeatureDomain(org.kie.kogito.explainability.model.domain.FeatureDomain) Feature(org.kie.kogito.explainability.model.Feature) Test(org.junit.jupiter.api.Test)

Example 27 with CounterfactualEntity

use of org.kie.kogito.explainability.local.counterfactual.entities.CounterfactualEntity in project kogito-apps by kiegroup.

the class CounterfactualEntityFactoryTest method testVectorFactory.

@Test
void testVectorFactory() {
    final double[] value = new double[10];
    Arrays.fill(value, 1d);
    final Feature feature = FeatureFactory.newVectorFeature("uri-feature", value);
    CounterfactualEntity counterfactualEntity = CounterfactualEntityFactory.from(feature);
    assertTrue(counterfactualEntity instanceof FixedVectorEntity);
    assertEquals(Type.VECTOR, counterfactualEntity.asFeature().getType());
}
Also used : CounterfactualEntity(org.kie.kogito.explainability.local.counterfactual.entities.CounterfactualEntity) FixedVectorEntity(org.kie.kogito.explainability.local.counterfactual.entities.fixed.FixedVectorEntity) Feature(org.kie.kogito.explainability.model.Feature) Test(org.junit.jupiter.api.Test)

Example 28 with CounterfactualEntity

use of org.kie.kogito.explainability.local.counterfactual.entities.CounterfactualEntity in project kogito-apps by kiegroup.

the class CounterfactualEntityFactoryTest method testFixedLongFactory.

@Test
void testFixedLongFactory() {
    final long value = 5;
    final Feature feature = FeatureFactory.newNumericalFeature("long-feature", value);
    final CounterfactualEntity counterfactualEntity = CounterfactualEntityFactory.from(feature);
    assertNotNull(counterfactualEntity);
    assertTrue(counterfactualEntity instanceof FixedLongEntity);
    assertEquals(value, counterfactualEntity.asFeature().getValue().asNumber());
}
Also used : CounterfactualEntity(org.kie.kogito.explainability.local.counterfactual.entities.CounterfactualEntity) Feature(org.kie.kogito.explainability.model.Feature) FixedLongEntity(org.kie.kogito.explainability.local.counterfactual.entities.fixed.FixedLongEntity) Test(org.junit.jupiter.api.Test)

Example 29 with CounterfactualEntity

use of org.kie.kogito.explainability.local.counterfactual.entities.CounterfactualEntity in project kogito-apps by kiegroup.

the class CounterfactualEntityFactoryTest method testFixedBooleanFactory.

@Test
void testFixedBooleanFactory() {
    final boolean value = false;
    final Feature feature = FeatureFactory.newBooleanFeature("bool-feature", value);
    final CounterfactualEntity counterfactualEntity = CounterfactualEntityFactory.from(feature);
    assertTrue(counterfactualEntity instanceof FixedBooleanEntity);
    assertEquals(value, counterfactualEntity.asFeature().getValue().getUnderlyingObject());
}
Also used : CounterfactualEntity(org.kie.kogito.explainability.local.counterfactual.entities.CounterfactualEntity) Feature(org.kie.kogito.explainability.model.Feature) FixedBooleanEntity(org.kie.kogito.explainability.local.counterfactual.entities.fixed.FixedBooleanEntity) Test(org.junit.jupiter.api.Test)

Example 30 with CounterfactualEntity

use of org.kie.kogito.explainability.local.counterfactual.entities.CounterfactualEntity in project kogito-apps by kiegroup.

the class CounterfactualEntityFactoryTest method testCompositeFactory.

@Test
void testCompositeFactory() {
    Map<String, Object> map = new HashMap<>();
    List<Feature> features = new LinkedList<>();
    features.add(FeatureFactory.newObjectFeature("f1", new Object()));
    features.add(FeatureFactory.newTextFeature("f2", "hola"));
    features.add(FeatureFactory.newFulltextFeature("f3", "foo bar"));
    features.add(FeatureFactory.newNumericalFeature("f4", 131));
    features.add(FeatureFactory.newBooleanFeature("f5", false));
    features.add(FeatureFactory.newDurationFeature("f6", Duration.ofDays(2)));
    Map<String, Object> nestedMap = new HashMap<>();
    nestedMap.put("nf-1", "nested text");
    nestedMap.put("nf-2", ByteBuffer.allocate(1024));
    features.add(FeatureFactory.newCompositeFeature("f7", nestedMap));
    for (Feature f : features) {
        map.put(f.getName(), f.getValue().getUnderlyingObject());
    }
    final Feature feature = FeatureFactory.newCompositeFeature("composite-feature", map);
    CounterfactualEntity counterfactualEntity = CounterfactualEntityFactory.from(feature);
    assertTrue(counterfactualEntity instanceof FixedCompositeEntity);
    assertEquals(Type.COMPOSITE, counterfactualEntity.asFeature().getType());
}
Also used : CounterfactualEntity(org.kie.kogito.explainability.local.counterfactual.entities.CounterfactualEntity) FixedCompositeEntity(org.kie.kogito.explainability.local.counterfactual.entities.fixed.FixedCompositeEntity) HashMap(java.util.HashMap) Feature(org.kie.kogito.explainability.model.Feature) LinkedList(java.util.LinkedList) Test(org.junit.jupiter.api.Test)

Aggregations

CounterfactualEntity (org.kie.kogito.explainability.local.counterfactual.entities.CounterfactualEntity)45 Feature (org.kie.kogito.explainability.model.Feature)45 Test (org.junit.jupiter.api.Test)34 EmptyFeatureDomain (org.kie.kogito.explainability.model.domain.EmptyFeatureDomain)23 NumericalFeatureDomain (org.kie.kogito.explainability.model.domain.NumericalFeatureDomain)23 Output (org.kie.kogito.explainability.model.Output)22 PredictionOutput (org.kie.kogito.explainability.model.PredictionOutput)22 FeatureDomain (org.kie.kogito.explainability.model.domain.FeatureDomain)21 PredictionProvider (org.kie.kogito.explainability.model.PredictionProvider)18 Value (org.kie.kogito.explainability.model.Value)18 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)17 PredictionInput (org.kie.kogito.explainability.model.PredictionInput)17 LinkedList (java.util.LinkedList)16 CategoricalFeatureDomain (org.kie.kogito.explainability.model.domain.CategoricalFeatureDomain)16 Random (java.util.Random)14 ValueSource (org.junit.jupiter.params.provider.ValueSource)13 BinaryFeatureDomain (org.kie.kogito.explainability.model.domain.BinaryFeatureDomain)12 CurrencyFeatureDomain (org.kie.kogito.explainability.model.domain.CurrencyFeatureDomain)12 DurationFeatureDomain (org.kie.kogito.explainability.model.domain.DurationFeatureDomain)12 ObjectFeatureDomain (org.kie.kogito.explainability.model.domain.ObjectFeatureDomain)12