use of org.kie.kogito.explainability.model.EncodingParams 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());
}
use of org.kie.kogito.explainability.model.EncodingParams in project kogito-apps by kiegroup.
the class DatasetEncoderTest method assertEncode.
private void assertEncode(List<PredictionInput> perturbedInputs, PredictionInput originalInput) {
List<Output> outputs = new LinkedList<>();
for (int i = 0; i < 10; i++) {
outputs.add(new Output("o", Type.NUMBER, new Value(i % 2 == 0 ? 1d : 0d), 1d));
}
Output originalOutput = new Output("o", Type.BOOLEAN, new Value(1d), 1d);
EncodingParams params = new EncodingParams(1, 0.1);
DatasetEncoder datasetEncoder = new DatasetEncoder(perturbedInputs, outputs, originalInput.getFeatures(), originalOutput, params);
Collection<Pair<double[], Double>> trainingSet = datasetEncoder.getEncodedTrainingSet();
assertNotNull(trainingSet);
assertEquals(10, trainingSet.size());
for (Pair<double[], Double> pair : trainingSet) {
assertNotNull(pair.getKey());
assertNotNull(pair.getValue());
assertThat(pair.getValue()).isBetween(0d, 1d);
}
}
use of org.kie.kogito.explainability.model.EncodingParams in project kogito-apps by kiegroup.
the class LimeConfigTest method testNumericEncodingParams.
@Test
void testNumericEncodingParams() {
LimeConfig config = new LimeConfig().withEncodingParams(new EncodingParams(0.01, 2));
assertThat(config.getEncodingParams().getNumericTypeClusterGaussianFilterWidth()).isEqualTo(0.01);
assertThat(config.getEncodingParams().getNumericTypeClusterThreshold()).isEqualTo(2);
}
use of org.kie.kogito.explainability.model.EncodingParams in project kogito-apps by kiegroup.
the class LimeConfigEntityFactory method initProcessors.
private static Map<String, BiFunction<LimeConfig, LimeConfigEntity, LimeConfig>> initProcessors() {
Map<String, BiFunction<LimeConfig, LimeConfigEntity, LimeConfig>> processors = new HashMap<>();
processors.put(PROXIMITY_KERNEL_WIDTH, (limeConfig, limeConfigEntity) -> limeConfig.withProximityKernelWidth(limeConfigEntity.asDouble()));
processors.put(PROXIMITY_THRESHOLD, (limeConfig, limeConfigEntity) -> limeConfig.withProximityThreshold(limeConfigEntity.asDouble()));
processors.put(PROXIMITY_FILTERED_DATASET_MINIMUM, (limeConfig, limeConfigEntity) -> limeConfig.withProximityFilteredDatasetMinimum(limeConfigEntity.asDouble()));
processors.put(EP_NUMERIC_CLUSTER_FILTER_WIDTH, (limeConfig, limeConfigEntity) -> limeConfig.withEncodingParams(new EncodingParams(limeConfigEntity.asDouble(), limeConfig.getEncodingParams().getNumericTypeClusterThreshold())));
processors.put(EP_NUMERIC_CLUSTER_THRESHOLD, (limeConfig, limeConfigEntity) -> limeConfig.withEncodingParams(new EncodingParams(limeConfig.getEncodingParams().getNumericTypeClusterGaussianFilterWidth(), limeConfigEntity.asDouble())));
processors.put(SAMPLING_SEPARABLE_DATASET_RATIO, (limeConfig, limeConfigEntity) -> limeConfig.withSeparableDatasetRatio(limeConfigEntity.asDouble()));
processors.put(SAMPLING_SIZE, (limeConfig, limeConfigEntity) -> limeConfig.withSamples((int) limeConfigEntity.asDouble()));
processors.put(SAMPLING_PERTURBATIONS, (limeConfig, limeConfigEntity) -> limeConfig.withPerturbationContext(limeConfig.getPerturbationContext().getSeed().isPresent() ? new PerturbationContext(limeConfig.getPerturbationContext().getSeed().get(), limeConfig.getPerturbationContext().getRandom(), (int) limeConfigEntity.asDouble()) : new PerturbationContext(limeConfig.getPerturbationContext().getRandom(), (int) limeConfigEntity.asDouble())));
processors.put(PROXIMITY_FILTER_ENABLED, (limeConfig, limeConfigEntity) -> limeConfig.withProximityFilter(limeConfigEntity.asBoolean()));
processors.put(WEIGHTING_PENALIZE_BALANCE_SPARSE, (limeConfig, limeConfigEntity) -> limeConfig.withPenalizeBalanceSparse(limeConfigEntity.asBoolean()));
processors.put(SAMPLING_ADAPT_DATASET_VARIANCE, (limeConfig, limeConfigEntity) -> limeConfig.withAdaptiveVariance(limeConfigEntity.asBoolean()));
return processors;
}
Aggregations