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