Search in sources :

Example 6 with NumericFeatureDistribution

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

the class IntegerEntityTest method distanceScaled.

@ParameterizedTest
@ValueSource(ints = { 0, 1, 2, 3, 4 })
void distanceScaled(int seed) {
    Random random = new Random();
    random.setSeed(seed);
    final FeatureDomain featureDomain = NumericalFeatureDomain.create(0, 100);
    final Feature integerFeature = FeatureFactory.newNumericalFeature("feature-integer", 20, featureDomain);
    final FeatureDistribution featureDistribution = new NumericFeatureDistribution(integerFeature, random.ints(5000, 10, 40).mapToDouble(x -> x).toArray());
    IntegerEntity entity = (IntegerEntity) CounterfactualEntityFactory.from(integerFeature, featureDistribution);
    entity.proposedValue = 40;
    final double distance = entity.distance();
    assertTrue(distance > 0.2 && distance < 0.3);
}
Also used : NumericFeatureDistribution(org.kie.kogito.explainability.model.NumericFeatureDistribution) FeatureDistribution(org.kie.kogito.explainability.model.FeatureDistribution) Random(java.util.Random) NumericalFeatureDomain(org.kie.kogito.explainability.model.domain.NumericalFeatureDomain) FeatureDomain(org.kie.kogito.explainability.model.domain.FeatureDomain) Feature(org.kie.kogito.explainability.model.Feature) NumericFeatureDistribution(org.kie.kogito.explainability.model.NumericFeatureDistribution) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 7 with NumericFeatureDistribution

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

the class LongEntityTest method distanceScaled.

@ParameterizedTest
@ValueSource(ints = { 0, 1, 2, 3, 4 })
void distanceScaled(int seed) {
    Random random = new Random();
    random.setSeed(seed);
    final FeatureDomain featureDomain = NumericalFeatureDomain.create(0, 100);
    final Feature feature = FeatureFactory.newNumericalFeature("feature-long", 20L, featureDomain);
    final FeatureDistribution featureDistribution = new NumericFeatureDistribution(feature, random.longs(5000, 10, 40).mapToDouble(x -> x).toArray());
    LongEntity entity = (LongEntity) CounterfactualEntityFactory.from(feature, featureDistribution);
    entity.proposedValue = 40L;
    final double distance = entity.distance();
    assertTrue(distance > 0.2 && distance < 0.3);
}
Also used : NumericFeatureDistribution(org.kie.kogito.explainability.model.NumericFeatureDistribution) FeatureDistribution(org.kie.kogito.explainability.model.FeatureDistribution) Random(java.util.Random) NumericalFeatureDomain(org.kie.kogito.explainability.model.domain.NumericalFeatureDomain) FeatureDomain(org.kie.kogito.explainability.model.domain.FeatureDomain) Feature(org.kie.kogito.explainability.model.Feature) NumericFeatureDistribution(org.kie.kogito.explainability.model.NumericFeatureDistribution) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 8 with NumericFeatureDistribution

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

the class DataUtils method generateRandomDataDistribution.

/**
 * Generate a random data distribution.
 *
 * @param noOfFeatures number of features
 * @param distributionSize number of samples for each feature
 * @return a data distribution
 */
public static DataDistribution generateRandomDataDistribution(int noOfFeatures, int distributionSize, Random random) {
    List<FeatureDistribution> featureDistributions = new LinkedList<>();
    for (int i = 0; i < noOfFeatures; i++) {
        double[] doubles = generateData(random.nextDouble(), random.nextDouble(), distributionSize, random);
        Feature feature = FeatureFactory.newNumericalFeature("f_" + i, Double.NaN);
        FeatureDistribution featureDistribution = new NumericFeatureDistribution(feature, doubles);
        featureDistributions.add(featureDistribution);
    }
    return new IndependentFeaturesDataDistribution(featureDistributions);
}
Also used : NumericFeatureDistribution(org.kie.kogito.explainability.model.NumericFeatureDistribution) FeatureDistribution(org.kie.kogito.explainability.model.FeatureDistribution) IndependentFeaturesDataDistribution(org.kie.kogito.explainability.model.IndependentFeaturesDataDistribution) Feature(org.kie.kogito.explainability.model.Feature) NumericFeatureDistribution(org.kie.kogito.explainability.model.NumericFeatureDistribution) LinkedList(java.util.LinkedList)

Aggregations

Feature (org.kie.kogito.explainability.model.Feature)8 FeatureDistribution (org.kie.kogito.explainability.model.FeatureDistribution)8 NumericFeatureDistribution (org.kie.kogito.explainability.model.NumericFeatureDistribution)8 Random (java.util.Random)7 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)5 ValueSource (org.junit.jupiter.params.provider.ValueSource)5 LinkedList (java.util.LinkedList)3 FeatureDomain (org.kie.kogito.explainability.model.domain.FeatureDomain)3 NumericalFeatureDomain (org.kie.kogito.explainability.model.domain.NumericalFeatureDomain)3 CounterfactualEntity (org.kie.kogito.explainability.local.counterfactual.entities.CounterfactualEntity)2 Output (org.kie.kogito.explainability.model.Output)2 PredictionOutput (org.kie.kogito.explainability.model.PredictionOutput)2 Value (org.kie.kogito.explainability.model.Value)2 BufferedReader (java.io.BufferedReader)1 IOException (java.io.IOException)1 Writer (java.io.Writer)1 MalformedInputException (java.nio.charset.MalformedInputException)1 Files (java.nio.file.Files)1 Path (java.nio.file.Path)1 Duration (java.time.Duration)1