Search in sources :

Example 1 with EncodingParams

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

Example 2 with EncodingParams

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);
    }
}
Also used : Output(org.kie.kogito.explainability.model.Output) Value(org.kie.kogito.explainability.model.Value) EncodingParams(org.kie.kogito.explainability.model.EncodingParams) LinkedList(java.util.LinkedList) Pair(org.apache.commons.lang3.tuple.Pair)

Example 3 with EncodingParams

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);
}
Also used : EncodingParams(org.kie.kogito.explainability.model.EncodingParams) Test(org.junit.jupiter.api.Test)

Example 4 with EncodingParams

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;
}
Also used : PerturbationContext(org.kie.kogito.explainability.model.PerturbationContext) BiFunction(java.util.function.BiFunction) HashMap(java.util.HashMap) EncodingParams(org.kie.kogito.explainability.model.EncodingParams)

Aggregations

EncodingParams (org.kie.kogito.explainability.model.EncodingParams)4 LinkedList (java.util.LinkedList)2 Pair (org.apache.commons.lang3.tuple.Pair)2 Test (org.junit.jupiter.api.Test)2 Output (org.kie.kogito.explainability.model.Output)2 Value (org.kie.kogito.explainability.model.Value)2 HashMap (java.util.HashMap)1 BiFunction (java.util.function.BiFunction)1 Feature (org.kie.kogito.explainability.model.Feature)1 PerturbationContext (org.kie.kogito.explainability.model.PerturbationContext)1 PredictionInput (org.kie.kogito.explainability.model.PredictionInput)1