List of usage examples for org.apache.commons.lang3.tuple Pair getKey
@Override public final L getKey()
Gets the key from this pair.
This method implements the Map.Entry interface returning the left element as the key.
From source file:sadl.modellearner.AlergiaTest.java
@Test public void testRbBigRecPaperMerge() throws URISyntaxException, IOException { final AlergiaRedBlue alergia = new AlergiaRedBlue(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 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 alergiaEexpected = new ExperimentResult(467, 4532, 1, 0); final ExperimentResult alergiaActual = detection.test(trainTest.getValue()); assertEquals(alergiaEexpected, alergiaActual); assertEquals(108, pdfaAlergia.getStateCount()); }
From source file:sadl.modellearner.AlergiaTest.java
@Test public void testRbBigRecTrebaMerge() throws URISyntaxException, IOException { final AlergiaRedBlue alergia = new AlergiaRedBlue(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 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(467, 4532, 1, 0); final ExperimentResult actual = detection.test(trainTest.getValue()); assertEquals(expected, actual);//from w w w.j a va 2 s . c o m assertEquals(70, pdfaAlergia.getStateCount()); }
From source file:sadl.modellearner.AlergiaTest.java
@Test public void testTrebaBigNonRec() throws URISyntaxException, IOException { if (LibraryChecker.trebaDepsInstalled()) { final TrebaPdfaLearner treba = new TrebaPdfaLearner(0.05, false, MergeTest.ALERGIA, 0.0, 0); final Pair<TimedInput, TimedInput> trainTest = IoUtils .readTrainTestFile(Paths.get(this.getClass().getResource("/pdtta/smac_mix_type1.txt").toURI())); final AnomalyDetector detector = new VectorDetector(ProbabilityAggregationMethod.NORMALIZED_MULTIPLY, new AggregatedSingleFeatureCreator(), new ThresholdClassifier(Math.exp(-5))); final PDFA pdfaTreba = treba.train(trainTest.getKey()); final AnomalyDetection trebaDetection = new AnomalyDetection(detector, pdfaTreba); final ExperimentResult trebaExpected = new ExperimentResult(463, 4533, 0, 4); final ExperimentResult trebaActual = trebaDetection.test(trainTest.getValue()); logger.info("Treba PDFA has {} states.", pdfaTreba.getStateCount()); assertEquals(trebaExpected, trebaActual); assertEquals(42, pdfaTreba.getStateCount()); } else {/* ww w. jav a 2s . c o m*/ System.out.println("Did not do any test because OS is not linux and treba cannot be loaded."); } }
From source file:sadl.modellearner.AlergiaTest.java
@Test public void testTrebaBigRec() throws URISyntaxException, IOException { if (LibraryChecker.trebaDepsInstalled()) { final TrebaPdfaLearner treba = new TrebaPdfaLearner(0.05, true, MergeTest.ALERGIA, 0.0, 0); final Pair<TimedInput, TimedInput> trainTest = IoUtils .readTrainTestFile(Paths.get(this.getClass().getResource("/pdtta/smac_mix_type1.txt").toURI())); final AnomalyDetector detector = new VectorDetector(ProbabilityAggregationMethod.NORMALIZED_MULTIPLY, new AggregatedSingleFeatureCreator(), new ThresholdClassifier(Math.exp(-5))); final PDFA pdfaTreba = treba.train(trainTest.getKey()); final AnomalyDetection trebaDetection = new AnomalyDetection(detector, pdfaTreba); final ExperimentResult trebaExpected = new ExperimentResult(467, 4525, 8, 0); final ExperimentResult trebaActual = trebaDetection.test(trainTest.getValue()); logger.info("Treba PDFA has {} states.", pdfaTreba.getStateCount()); assertEquals(trebaExpected, trebaActual); assertEquals(356, pdfaTreba.getStateCount()); } else {//from ww w.j a v a 2s.co m System.out.println("Did not do any test because OS is not linux and treba cannot be loaded."); } }
From source file:sadl.modellearner.PdttaLearnerTest.java
@Test public void oldNewLeanerTest() throws IOException, URISyntaxException { if (LibraryChecker.trebaDepsInstalled()) { for (int i = 1; i <= 5; i++) { final Pair<TimedInput, TimedInput> trainTest = IoUtils.readTrainTestFile( Paths.get(this.getClass().getResource("/pdtta/smac_mix_type" + i + ".txt").toURI())); Settings.setDebug(false);/*from w w w . ja va 2s.c o m*/ final TimedInput ti1 = trainTest.getKey(); final TimedInput ti2 = SerializationUtils.clone(ti1); final PdttaLearner l1 = new PdttaLearner(new TrebaPdfaLearner(0.05, false)); final ProbabilisticModel p1 = l1.train(ti1); MasterSeed.reset(); final PdttaLeanerOld l2 = new PdttaLeanerOld(0.05, false); final ProbabilisticModel p2 = l2.train(ti2); assertEquals("PDTTAs for file " + i + " are not equal", p2, p1); // TODO Also compare with loaded model from file } } else { System.out.println("Did not do any test because OS is not linux and treba cannot be loaded."); } }
From source file:sadl.modellearner.RtiPlusTest.java
public void testDeterminismBig() throws URISyntaxException, IOException { // TODO fix this test for (int i = 1; i <= 5; i++) { final Pair<TimedInput, TimedInput> traintestSet = IoUtils.readTrainTestFile( Paths.get(this.getClass().getResource("/pdtta/smac_mix_type" + i + ".txt").toURI())); final TimedInput ti1 = traintestSet.getKey(); ti1.decreaseSamples(0.01);/*from ww w .j a v a2 s . co m*/ final TimedInput ti2 = SerializationUtils.clone(ti1); final SimplePDRTALearner l1 = new SimplePDRTALearner(0.05, "4", OperationTesterType.LRT, DistributionCheckType.STRICT, SplitPosition.MIDDLE, "AAO", null); final ProbabilisticModel p1 = l1.train(ti1); for (int j = 0; j < 10; j++) { final SimplePDRTALearner l2 = new SimplePDRTALearner(0.05, "4", OperationTesterType.LRT, DistributionCheckType.STRICT, SplitPosition.MIDDLE, "AAO", null); final ProbabilisticModel p2 = l2.train(ti2); assertEquals("PDRTAs for files " + i + " are not equal", p2, p1); } } }
From source file:sadl.modellearner.TrebaButlaLearnerTest.java
public void test() throws URISyntaxException { // TODO why do they give different results? final ButlaPdtaLearner butla = new ButlaPdtaLearner(100000000, 0.05, TransitionsType.Outgoing, 0.05, 0.05, PTAOrdering.TopDown, EventsCreationStrategy.DontSplitEvents, KDEFormelVariant.OriginalKDE, IntervalCreationStrategy.OriginalButla); final TrebaPdfaLearner treba = new TrebaPdfaLearner(0.05, true, MergeTest.ALERGIA, 0.0, 0); final Path p = Paths.get(this.getClass().getResource("/pdtta/smac_mix_type1.txt").toURI()); Pair<TimedInput, TimedInput> input = IoUtils.readTrainTestFile(p); final PDTA pdta = butla.train(input.getKey()); input = IoUtils.readTrainTestFile(p); final AutomatonModel pdfa = treba.train(input.getKey()); assertEquals(pdta.getStateCount(), pdfa.getStateCount()); assertEquals(pdta.getTransitionCount(), pdfa.getTransitionCount()); assertEquals(pdfa, pdta.toPDFA());/*from w w w . jav a2 s . c om*/ }
From source file:sadl.oneclassclassifier.NumericClassifierTest.java
@Test public void testLibSvmClassifier() throws URISyntaxException, IOException { final PdttaLearner learner = new PdttaLearner(new AlergiaRedBlue(0.05, true)); final FeatureCreator featureCreator = new UberFeatureCreator(); final LibSvmClassifier classifier = new LibSvmClassifier(1, 0.2, 0.1, 1, 0.001, 3, ScalingMethod.NONE); final VectorDetector detector = new VectorDetector(ProbabilityAggregationMethod.NORMALIZED_MULTIPLY, featureCreator, classifier, false); final AnomalyDetection detection = new AnomalyDetection(detector, learner); final Path p = Paths.get(this.getClass().getResource("/pdtta/smac_mix_type1.txt").toURI()); final Pair<TimedInput, TimedInput> inputSets = IoUtils.readTrainTestFile(p); final ExperimentResult actual = detection.trainTest(inputSets.getKey(), inputSets.getValue()); final ExperimentResult expected = new ExperimentResult(420, 4072, 461, 47); assertEquals(expected, actual);/* w w w. j a v a 2s . co m*/ }
From source file:sadl.oneclassclassifier.NumericClassifierTest.java
@Test public void testDBScanClassifier() throws URISyntaxException, IOException { final PdttaLearner learner = new PdttaLearner(new AlergiaRedBlue(0.05, true)); final FeatureCreator featureCreator = new UberFeatureCreator(); final NumericClassifier classifier = new DbScanClassifier(0.05, 5, DistanceMethod.EUCLIDIAN, ScalingMethod.NORMALIZE);//from www. j a v a 2s .co m final VectorDetector detector = new VectorDetector(ProbabilityAggregationMethod.NORMALIZED_MULTIPLY, featureCreator, classifier, false); final AnomalyDetection detection = new AnomalyDetection(detector, learner); final Path p = Paths.get(this.getClass().getResource("/pdtta/smac_mix_type1.txt").toURI()); final Pair<TimedInput, TimedInput> inputSets = IoUtils.readTrainTestFile(p); final ExperimentResult actual = detection.trainTest(inputSets.getKey(), inputSets.getValue()); final ExperimentResult expected = new ExperimentResult(467, 4356, 177, 0); assertEquals(expected, actual); }
From source file:sadl.oneclassclassifier.NumericClassifierTest.java
@Test public void testKMeansClassifier() throws URISyntaxException, IOException { final PdttaLearner learner = new PdttaLearner(new AlergiaRedBlue(0.05, true)); final FeatureCreator featureCreator = new UberFeatureCreator(); final NumericClassifier classifier = new KMeansClassifier(ScalingMethod.NORMALIZE, 10, 0.05, 0, DistanceMethod.EUCLIDIAN);//from ww w. jav a2s . com final VectorDetector detector = new VectorDetector(ProbabilityAggregationMethod.NORMALIZED_MULTIPLY, featureCreator, classifier, false); final AnomalyDetection detection = new AnomalyDetection(detector, learner); final Path p = Paths.get(this.getClass().getResource("/pdtta/smac_mix_type1.txt").toURI()); final Pair<TimedInput, TimedInput> inputSets = IoUtils.readTrainTestFile(p); final ExperimentResult actual = detection.trainTest(inputSets.getKey(), inputSets.getValue()); final ExperimentResult expected = new ExperimentResult(467, 445, 4088, 0); assertEquals(expected, actual); }