Example usage for org.apache.commons.lang3.tuple Pair getKey

List of usage examples for org.apache.commons.lang3.tuple Pair getKey

Introduction

In this page you can find the example usage for org.apache.commons.lang3.tuple Pair getKey.

Prototype

@Override
public final L getKey() 

Source Link

Document

Gets the key from this pair.

This method implements the Map.Entry interface returning the left element as the key.

Usage

From source file:sadl.detectors.ButlaTest.java

@Test
public void testThresholdOriginalKDE() throws IOException, URISyntaxException {

    logger.info("Starting Threshold Original KDE test...");
    final ButlaPdtaLearner learner = new ButlaPdtaLearner(10000, 0.05, TransitionsType.Incoming, 0.01, 0.05,
            PTAOrdering.TopDown, EventsCreationStrategy.SplitEvents, KDEFormelVariant.OriginalKDE,
            IntervalCreationStrategy.extendInterval);
    final AnomalyDetector detector = new VectorDetector(ProbabilityAggregationMethod.NORMALIZED_MULTIPLY,
            new AggregatedSingleFeatureCreator(), new ThresholdClassifier(Math.exp(-1)));

    final AnomalyDetection detection = new AnomalyDetection(detector, learner);
    ExperimentResult expected = new ExperimentResult(467, 1382, 3151, 0);
    Path p = Paths.get(this.getClass().getResource("/pdtta/smac_mix_type1.txt").toURI());
    Pair<TimedInput, TimedInput> trainTest = IoUtils.readTrainTestFile(p);
    TimedInput trainSet = trainTest.getKey();
    trainSet.decreaseSamples(0.1);/*from w  ww.jav a 2  s .com*/
    ExperimentResult actual = detection.trainTest(trainSet, trainTest.getValue());
    assertEquals(expected, actual);

    expected = new ExperimentResult(381, 1440, 3065, 114);
    p = Paths.get(this.getClass().getResource("/pdtta/smac_mix_type2.txt").toURI());
    trainTest = IoUtils.readTrainTestFile(p);
    trainSet = trainTest.getKey();
    trainSet.decreaseSamples(0.1);
    actual = detection.trainTest(trainSet, trainTest.getValue());
    assertEquals(expected, actual);

    expected = new ExperimentResult(486, 1640, 2874, 0);
    p = Paths.get(this.getClass().getResource("/pdtta/smac_mix_type3.txt").toURI());
    trainTest = IoUtils.readTrainTestFile(p);
    trainSet = trainTest.getKey();
    trainSet.decreaseSamples(0.1);
    actual = detection.trainTest(trainSet, trainTest.getValue());
    assertEquals(expected, actual);

    expected = new ExperimentResult(523, 1388, 3089, 0);
    p = Paths.get(this.getClass().getResource("/pdtta/smac_mix_type4.txt").toURI());
    trainTest = IoUtils.readTrainTestFile(p);
    trainSet = trainTest.getKey();
    trainSet.decreaseSamples(0.1);
    actual = detection.trainTest(trainSet, trainTest.getValue());
    assertEquals(expected, actual);

    expected = new ExperimentResult(462, 1379, 3159, 0);
    p = Paths.get(this.getClass().getResource("/pdtta/smac_mix_type5.txt").toURI());
    trainTest = IoUtils.readTrainTestFile(p);
    trainSet = trainTest.getKey();
    trainSet.decreaseSamples(0.1);
    actual = detection.trainTest(trainSet, trainTest.getValue());
    assertEquals(expected, actual);

    logger.info("Finished Threshold Original KDE test.");
}

From source file:sadl.detectors.PdttaDeterminismTest.java

@Test
public void svmDeterminismTest() throws IOException, URISyntaxException {
    double fMeasure = -1;
    final boolean firstRun = true;
    for (int i = 1; i <= 10; i++) {
        final Pair<TimedInput, TimedInput> trainTest = IoUtils
                .readTrainTestFile(Paths.get(this.getClass().getResource("/pdtta/smac_mix_type1.txt").toURI()));
        Settings.setDebug(false);//from   ww  w.jav a  2  s .  c o m
        final PdttaLearner learner = new PdttaLearner(new AlergiaRedBlue(0.05, true));
        final AnomalyDetector detector = new VectorDetector(ProbabilityAggregationMethod.NORMALIZED_MULTIPLY,
                new UberFeatureCreator(),
                new LibSvmClassifier(1, 0.2, 0.1, 1, 0.001, 3, ScalingMethod.NORMALIZE));

        final AnomalyDetection detection = new AnomalyDetection(detector, learner);

        final ExperimentResult result = detection.trainTest(trainTest.getKey(), trainTest.getValue());

        if (firstRun) {
            fMeasure = result.getFMeasure();
        } else {
            if (!Precision.equals(fMeasure, result.getFMeasure())) {
                fail("Failed for run " + i + " because in previous runs fMeasure=" + fMeasure
                        + "; now fMeasure=" + result.getFMeasure());
            }
        }

    }
}

From source file:sadl.detectors.PdttaDeterminismTest.java

@Test
public void thresholdDeterminismTest() throws IOException, URISyntaxException {
    double fMeasure = -1;
    final boolean firstRun = true;
    for (int i = 1; i <= 10; i++) {
        final Pair<TimedInput, TimedInput> trainTest = IoUtils
                .readTrainTestFile(Paths.get(this.getClass().getResource("/pdtta/smac_mix_type1.txt").toURI()));
        Settings.setDebug(false);/*from  ww  w .j  a va  2 s .  co  m*/
        final PdttaLearner learner = new PdttaLearner(new AlergiaRedBlue(0.05, true));

        final SmallFeatureCreator featureCreator = new SmallFeatureCreator();
        final ThresholdClassifier classifier = new ThresholdClassifier(Math.exp(-5), Math.exp(-8), 0.01, 0.001);

        final VectorDetector detector = new VectorDetector(ProbabilityAggregationMethod.NORMALIZED_MULTIPLY,
                featureCreator, classifier);

        final AnomalyDetection detection = new AnomalyDetection(detector, learner);

        final ExperimentResult result = detection.trainTest(trainTest.getKey(), trainTest.getValue());

        if (firstRun) {
            fMeasure = result.getFMeasure();
        } else {
            if (!Precision.equals(fMeasure, result.getFMeasure())) {
                fail("Failed for run " + i + " because in previous runs fMeasure=" + fMeasure
                        + "; now fMeasure=" + result.getFMeasure());
            }
        }

    }
}

From source file:sadl.detectors.PdttaWithPreprocessingTest.java

@Test
public void test() throws URISyntaxException, IOException {
    final PdttaLearner learner = new PdttaLearner(new AlergiaRedBlue(0.05, true));
    // final AggregatedThresholdDetector detector = new AggregatedThresholdDetector(ProbabilityAggregationMethod.NORMALIZED_MULTIPLY, -5, -8,
    // false);// w  w w . ja v  a  2s  . c  o m
    final AnomalyDetector detector = new VectorDetector(ProbabilityAggregationMethod.NORMALIZED_MULTIPLY,
            new AggregatedSingleFeatureCreator(), new ThresholdClassifier(Math.exp(-5)));

    final Path p = Paths.get(this.getClass().getResource("/pdtta/smac_mix_type1.txt").toURI());
    final Pair<TimedInput, TimedInput> trainTest = IoUtils.readTrainTestFile(p);

    final ButlaPdtaLearner butla = new ButlaPdtaLearner(20000, EventsCreationStrategy.SplitEvents,
            KDEFormelVariant.OriginalKDE);
    // final ButlaPdtaLearner butla = new ButlaPdtaLearner(EventsCreationStrategy.SplitEvents, KDEFormelVariant.OriginalKDE);

    final Pair<TimedInput, Map<String, Event>> pair = butla.splitEventsInTimedSequences(trainTest.getKey());
    final TimedInput splittedTrainSet = pair.getKey();
    final Map<String, Event> eventMapping = pair.getValue();
    final PDTTA model = learner.train(splittedTrainSet);
    detector.setModel(model);
    final AnomalyDetection detection = new AnomalyDetection(detector, model);
    final TimedInput testSet = butla.getSplitInputForMapping(trainTest.getValue(), eventMapping);
    final ExperimentResult result = detection.test(testSet);
    final ExperimentResult expected = new ExperimentResult(467, 4421, 112, 0);
    assertEquals(expected, result);
}

From source file:sadl.modellearner.AlergiaTest.java

@Test
public void testLoopBigNonRecPaperMerge() throws URISyntaxException, IOException {
    final Alergia alergia = new Alergia(0.05, false, MergeMethod.ALERGIA_PAPER);
    final Pair<TimedInput, TimedInput> trainTest = IoUtils
            .readTrainTestFile(Paths.get(this.getClass().getResource("/pdtta/smac_mix_type1.txt").toURI()));
    final PDFA pdfa = alergia.train(trainTest.getKey());
    final AnomalyDetector detector = new VectorDetector(ProbabilityAggregationMethod.NORMALIZED_MULTIPLY,
            new AggregatedSingleFeatureCreator(), new ThresholdClassifier(Math.exp(-5)));
    final AnomalyDetection detection = new AnomalyDetection(detector, pdfa);
    final ExperimentResult expected = new ExperimentResult(467, 4531, 2, 0);
    final ExperimentResult actual = detection.test(trainTest.getValue());
    assertEquals(expected, actual);//from  w  w w.j a v  a 2s .co  m
    assertEquals(808, pdfa.getStateCount());
}

From source file:sadl.modellearner.AlergiaTest.java

@Test
public void testLoopBigNonRecTrebaMerge() throws URISyntaxException, IOException {
    final Alergia alergia = new Alergia(0.05, false, MergeMethod.TREBA);
    final Pair<TimedInput, TimedInput> trainTest = IoUtils
            .readTrainTestFile(Paths.get(this.getClass().getResource("/pdtta/smac_mix_type1.txt").toURI()));
    final PDFA pdfa = alergia.train(trainTest.getKey());
    final AnomalyDetector detector = new VectorDetector(ProbabilityAggregationMethod.NORMALIZED_MULTIPLY,
            new AggregatedSingleFeatureCreator(), new ThresholdClassifier(Math.exp(-5)));
    final AnomalyDetection detection = new AnomalyDetection(detector, pdfa);
    final ExperimentResult expected = new ExperimentResult(467, 4531, 2, 0);
    final ExperimentResult actual = detection.test(trainTest.getValue());
    assertEquals(expected, actual);//from  w w  w  .  j a  v  a  2  s . c om
    assertEquals(808, pdfa.getStateCount());
}

From source file:sadl.modellearner.AlergiaTest.java

@Test
public void testLoopBigRecPaperMerge() throws URISyntaxException, IOException {
    final Alergia alergia = new Alergia(0.05, true, MergeMethod.ALERGIA_PAPER);
    final Pair<TimedInput, TimedInput> trainTest = IoUtils
            .readTrainTestFile(Paths.get(this.getClass().getResource("/pdtta/smac_mix_type1.txt").toURI()));
    final PDFA pdfa = alergia.train(trainTest.getKey());
    final AnomalyDetector detector = new VectorDetector(ProbabilityAggregationMethod.NORMALIZED_MULTIPLY,
            new AggregatedSingleFeatureCreator(), new ThresholdClassifier(Math.exp(-5)));
    final AnomalyDetection detection = new AnomalyDetection(detector, pdfa);
    final ExperimentResult expected = new ExperimentResult(467, 4525, 8, 0);
    final ExperimentResult actual = detection.test(trainTest.getValue());
    assertEquals(expected, actual);//from ww  w.j a  v  a 2s.c om
    assertEquals(882, pdfa.getStateCount());
}

From source file:sadl.modellearner.AlergiaTest.java

@Test
public void testLoopBigRecTrebaMerge() throws URISyntaxException, IOException {
    final Alergia alergia = new Alergia(0.05, true, MergeMethod.TREBA);
    final Pair<TimedInput, TimedInput> trainTest = IoUtils
            .readTrainTestFile(Paths.get(this.getClass().getResource("/pdtta/smac_mix_type1.txt").toURI()));
    final PDFA pdfa = alergia.train(trainTest.getKey());
    final AnomalyDetector detector = new VectorDetector(ProbabilityAggregationMethod.NORMALIZED_MULTIPLY,
            new AggregatedSingleFeatureCreator(), new ThresholdClassifier(Math.exp(-5)));
    final AnomalyDetection detection = new AnomalyDetection(detector, pdfa);
    final ExperimentResult expected = new ExperimentResult(467, 4528, 5, 0);
    final ExperimentResult actual = detection.test(trainTest.getValue());
    assertEquals(expected, actual);/*from  w  ww .  j a v  a2 s .co m*/
    assertEquals(808, pdfa.getStateCount());
}

From source file:sadl.modellearner.AlergiaTest.java

@Test
public void testRbBigNonRecPaperMerge() throws URISyntaxException, IOException {
    final AlergiaRedBlue alergia = new AlergiaRedBlue(0.05, false, MergeMethod.ALERGIA_PAPER);
    final Pair<TimedInput, TimedInput> trainTest = IoUtils
            .readTrainTestFile(Paths.get(this.getClass().getResource("/pdtta/smac_mix_type1.txt").toURI()));
    final PDFA pdfaAlergia = alergia.train(trainTest.getKey());
    final AnomalyDetector detector = new VectorDetector(ProbabilityAggregationMethod.NORMALIZED_MULTIPLY,
            new AggregatedSingleFeatureCreator(), new ThresholdClassifier(Math.exp(-5)));
    final AnomalyDetection detection = new AnomalyDetection(detector, pdfaAlergia);
    final ExperimentResult expected = new ExperimentResult(0, 4533, 0, 467);
    final ExperimentResult actual = detection.test(trainTest.getValue());
    assertEquals(expected, actual);//from w w  w . j a v  a 2 s.c  om
    assertEquals(2, pdfaAlergia.getStateCount());
}

From source file:sadl.modellearner.AlergiaTest.java

@Test
public void testRbBigNonRecTrebaMerge() throws URISyntaxException, IOException {
    final AlergiaRedBlue alergia = new AlergiaRedBlue(0.05, false, MergeMethod.TREBA);
    final Pair<TimedInput, TimedInput> trainTest = IoUtils
            .readTrainTestFile(Paths.get(this.getClass().getResource("/pdtta/smac_mix_type1.txt").toURI()));
    final PDFA pdfa = alergia.train(trainTest.getKey());
    final AnomalyDetector detector = new VectorDetector(ProbabilityAggregationMethod.NORMALIZED_MULTIPLY,
            new AggregatedSingleFeatureCreator(), new ThresholdClassifier(Math.exp(-5)));
    final AnomalyDetection detection = new AnomalyDetection(detector, pdfa);
    final ExperimentResult expected = new ExperimentResult(0, 4533, 0, 467);
    final ExperimentResult actual = detection.test(trainTest.getValue());
    assertEquals(expected, actual);/*w ww . j  a v  a  2s  .com*/
    assertEquals(2, pdfa.getStateCount());

}