Package statechum.analysis.learning.experiments.PairSelection.PairQualityLearner

Examples of statechum.analysis.learning.experiments.PairSelection.PairQualityLearner.LearnerThatCanClassifyPairs


      try {
      Transform.augmentFromIfThenAutomaton(initPTA, null, ifthenAutomata,learnerInitConfiguration.config.getHowManyStatesToAddFromIFTHEN());
    } catch (AugmentFromIfThenAutomatonException e) {
      Helper.throwUnchecked("failed to augment using if-then", e);
    }// we only need  to augment our PTA once (refer to the explanation above).
      LearnerThatCanClassifyPairs learner =  c != null? new PairQualityLearner.LearnerThatUsesWekaResults(ifDepth,learnerInitConfiguration,referenceGraph,c,initPTA):
          new PairQualityLearner.ReferenceLearner(learnerInitConfiguration,referenceGraph,initPTA);
      learner.setLabelsLeadingToStatesToBeMerged(labelsToMergeTo);learner.setLabelsLeadingFromStatesToBeMerged(labelsToMergeFrom);learner.setAlphabetUsedForIfThen(referenceGraph.pathroutines.computeAlphabet());
        LearnerGraph actualAutomaton = learner.learnMachine(new LinkedList<List<Label>>(),new LinkedList<List<Label>>());
       
        // Now merge everything that we need to merge
        LinkedList<AMEquivalenceClass<CmpVertex,LearnerGraphCachedData>> verticesToMerge = new LinkedList<AMEquivalenceClass<CmpVertex,LearnerGraphCachedData>>();
    List<StatePair> pairsList = LearnerThatCanClassifyPairs.buildVerticesToMerge(actualAutomaton,learner.getLabelsLeadingToStatesToBeMerged(),learner.getLabelsLeadingFromStatesToBeMerged());
    if (!pairsList.isEmpty())
    {
      int score = actualAutomaton.pairscores.computePairCompatibilityScore_general(null, pairsList, verticesToMerge);
      if (score < 0) throw new RuntimeException("last merge in the learning process was not possible");
      actualAutomaton = MergeStates.mergeCollectionOfVertices(actualAutomaton, null, verticesToMerge);
View Full Code Here


    System.out.println(new Date().toString()+" Graph loaded: "+initialPTA.getStateNumber()+" states, adding at most "+ initConfiguration.config.getHowManyStatesToAddFromIFTHEN()+" if-then states");
    Transform.augmentFromIfThenAutomaton(initialPTA, null, ifthenAutomata, initConfiguration.config.getHowManyStatesToAddFromIFTHEN());// we only need  to augment our PTA once (refer to the explanation above).
    System.out.println(new Date().toString()+" if-then states added, now "+initialPTA.getStateNumber()+" states");
    WekaDataCollector dataCollector = PairQualityLearner.createDataCollector(ifDepth);
    // Run the learner that will find out how to select the correct pairs.
    LearnerThatCanClassifyPairs learnerOfPairs = new PairQualityLearner.LearnerThatUpdatesWekaResults(initConfiguration,referenceGraph,dataCollector,initialPTA);
    LearnerGraph actualAutomaton = learnerOfPairs.learnMachine(new LinkedList<List<Label>>(),new LinkedList<List<Label>>());
   
    // final weka.classifiers.trees.J48 classifier = new weka.classifiers.trees.J48();
    FileWriter wekaInstances= null;
    try
    {
View Full Code Here

       
       final InitialConfigurationAndData initialConfigAndData = PairQualityLearner.loadInitialAndPopulateInitialConfiguration(PairQualityLearner.largePTAFileName, learnerConfig, new Transform.InternStringLabel());

    LearnerGraph referenceGraph = new LearnerGraph(initialConfigAndData.initial.graph.config);AbstractPersistence.loadGraph("resources/largePTA/outcome_correct", referenceGraph, initialConfigAndData.learnerInitConfiguration.getLabelConverter());
      WekaDataCollector dataCollector = PairQualityLearner.createDataCollector(ifDepth);
      LearnerThatCanClassifyPairs learnerOfPairs = new PairQualityLearner.LearnerThatUpdatesWekaResults(initialConfigAndData.learnerInitConfiguration,referenceGraph,dataCollector,initialConfigAndData.initial.graph);
    learnerOfPairs.learnMachine(new LinkedList<List<Label>>(),new LinkedList<List<Label>>());
   
    FileWriter wekaInstances=new FileWriter("resources/largePTA/pairsEncountered3.arff");
    wekaInstances.write(dataCollector.trainingData.toString());
    wekaInstances.close();
  }
View Full Code Here

        Transform.augmentFromIfThenAutomaton(pta, null, ifthenAutomata, statesToAdd);// we only need  to augment our PTA once (refer to the explanation above).
        //System.out.println(new Date().toString()+" Graph augmented: "+pta.getStateNumber()+" states ("+pta.getAcceptStateNumber()+" accept states)");
      }
      else assert pta.getStateNumber() == pta.getAcceptStateNumber() : "graph with negatives but onlyUsePositives is set";
     
      LearnerThatCanClassifyPairs learnerOfPairs = null;
      LearnerGraph actualAutomaton = null;
     
      //Visualiser.updateFrame(pta, referenceGraph);Visualiser.waitForKey();
     
      for(Entry<CmpVertex,List<Label>> path: pta.pathroutines.computeShortPathsToAllStates().entrySet())
      {
        boolean accept = path.getKey().isAccept();
        CmpVertex vert = referenceGraph.getVertex(path.getValue());
        boolean shouldBe = vert==null?false:vert.isAccept();
        assert accept == shouldBe: "state "+vert+" is incorrectly annotated as "+accept+" in path "+path;
      }
     
      {
       
        LearnerGraph reducedPTA = PairQualityLearner.mergeStatesForUnique(pta,uniqueFromInitial);
        learnerOfPairs = new PairQualityLearner.ReferenceLearner(learnerEval, referenceGraph, reducedPTA);
        //learnerOfPairs.setLabelsLeadingFromStatesToBeMerged(Arrays.asList(new Label[]{uniqueFromInitial}));
       
        synchronized (AbstractLearnerGraph.syncObj) {
          PaperUAS.computePTASize(selectionID+" with unique "+uniqueFromInitial+" : ", reducedPTA, referenceGraph);
        }

        actualAutomaton = learnerOfPairs.learnMachine(new LinkedList<List<Label>>(),new LinkedList<List<Label>>());

        LinkedList<AMEquivalenceClass<CmpVertex,LearnerGraphCachedData>> verticesToMerge = new LinkedList<AMEquivalenceClass<CmpVertex,LearnerGraphCachedData>>();
        List<StatePair> pairsList = LearnerThatCanClassifyPairs.buildVerticesToMerge(actualAutomaton,learnerOfPairs.getLabelsLeadingToStatesToBeMerged(),learnerOfPairs.getLabelsLeadingFromStatesToBeMerged());
        if (!pairsList.isEmpty())
        {
          int score = actualAutomaton.pairscores.computePairCompatibilityScore_general(null, pairsList, verticesToMerge);
          if (score < 0)
          {
            learnerOfPairs = new PairQualityLearner.ReferenceLearner(learnerEval, referenceGraph, reducedPTA);
            learnerOfPairs.setLabelsLeadingFromStatesToBeMerged(Arrays.asList(new Label[]{uniqueFromInitial}));
            actualAutomaton = learnerOfPairs.learnMachine(new LinkedList<List<Label>>(),new LinkedList<List<Label>>());
            score = actualAutomaton.pairscores.computePairCompatibilityScore_general(null, pairsList, verticesToMerge);
            throw new RuntimeException("last merge in the learning process was not possible");
          }
          actualAutomaton = MergeStates.mergeCollectionOfVertices(actualAutomaton, null, verticesToMerge);
        }
       
        DifferenceToReference similarityMeasure = getMeasure(actualAutomaton,referenceGraph,testSet);
        System.out.println("similarity = "+similarityMeasure);
      }

      {// not merging based on a unique transition from an initial state
        learnerOfPairs = new PairQualityLearner.ReferenceLearner(learnerEval, referenceGraph, pta);
        synchronized (AbstractLearnerGraph.syncObj) {
          PaperUAS.computePTASize(selectionID+" no unique: ", pta, referenceGraph);
        }
        actualAutomaton = learnerOfPairs.learnMachine(new LinkedList<List<Label>>(),new LinkedList<List<Label>>());
        DifferenceToReference similarityMeasure = getMeasure(actualAutomaton,referenceGraph,testSet);
        System.out.println("similarity = "+similarityMeasure);
        System.out.println();
        /*
        LearnerGraph reducedPTA = PairQualityLearner.mergeStatesForUnique(pta,uniqueFromInitial);
View Full Code Here

        Transform.augmentFromIfThenAutomaton(pta, null, ifthenAutomata, statesToAdd);// we only need  to augment our PTA once (refer to the explanation above).
        //System.out.println(new Date().toString()+" Graph augmented: "+pta.getStateNumber()+" states ("+pta.getAcceptStateNumber()+" accept states)");
      }
      else assert pta.getStateNumber() == pta.getAcceptStateNumber() : "graph with negatives but onlyUsePositives is set";
     
      LearnerThatCanClassifyPairs learnerOfPairs = null;
      LearnerGraph actualAutomaton = null;
     
      //Visualiser.updateFrame(pta, referenceGraph);Visualiser.waitForKey();
     
      for(Entry<CmpVertex,List<Label>> path: pta.pathroutines.computeShortPathsToAllStates().entrySet())
      {
        boolean accept = path.getKey().isAccept();
        CmpVertex vert = referenceGraph.getVertex(path.getValue());
        boolean shouldBe = vert==null?false:vert.isAccept();
        assert accept == shouldBe: "state "+vert+" is incorrectly annotated as "+accept+" in path "+path;
      }
     
      {
       
        LearnerGraph reducedPTA = PairQualityLearner.mergeStatesForUnique(pta,uniqueFromInitial);
        learnerOfPairs = new PairQualityLearner.ReferenceLearner(learnerEval, referenceGraph, reducedPTA,false);
        //learnerOfPairs.setLabelsLeadingFromStatesToBeMerged(Arrays.asList(new Label[]{uniqueFromInitial}));
       
        synchronized (AbstractLearnerGraph.syncObj) {
          PaperUAS.computePTASize(selectionID+" with unique "+uniqueFromInitial+" : ", reducedPTA, referenceGraph);
        }

        actualAutomaton = learnerOfPairs.learnMachine(new LinkedList<List<Label>>(),new LinkedList<List<Label>>());

        LinkedList<AMEquivalenceClass<CmpVertex,LearnerGraphCachedData>> verticesToMerge = new LinkedList<AMEquivalenceClass<CmpVertex,LearnerGraphCachedData>>();
        List<StatePair> pairsList = LearnerThatCanClassifyPairs.buildVerticesToMerge(actualAutomaton,learnerOfPairs.getLabelsLeadingToStatesToBeMerged(),learnerOfPairs.getLabelsLeadingFromStatesToBeMerged());
        if (!pairsList.isEmpty())
        {
          int score = actualAutomaton.pairscores.computePairCompatibilityScore_general(null, pairsList, verticesToMerge);
          if (score < 0)
          {
            learnerOfPairs = new PairQualityLearner.ReferenceLearner(learnerEval, referenceGraph, reducedPTA,false);
            learnerOfPairs.setLabelsLeadingFromStatesToBeMerged(Arrays.asList(new Label[]{uniqueFromInitial}));
            actualAutomaton = learnerOfPairs.learnMachine(new LinkedList<List<Label>>(),new LinkedList<List<Label>>());
            score = actualAutomaton.pairscores.computePairCompatibilityScore_general(null, pairsList, verticesToMerge);
            throw new RuntimeException("last merge in the learning process was not possible");
          }
          actualAutomaton = MergeStates.mergeCollectionOfVertices(actualAutomaton, null, verticesToMerge);
        }
       
        DifferenceToReference similarityMeasure = getMeasure(actualAutomaton,referenceGraph,testSet);
        System.out.println("similarity = "+similarityMeasure);
      }

      {// not merging based on a unique transition from an initial state
        learnerOfPairs = new PairQualityLearner.ReferenceLearner(learnerEval, referenceGraph, pta,false);
        synchronized (AbstractLearnerGraph.syncObj) {
          PaperUAS.computePTASize(selectionID+" no unique: ", pta, referenceGraph);
        }
        actualAutomaton = learnerOfPairs.learnMachine(new LinkedList<List<Label>>(),new LinkedList<List<Label>>());
        DifferenceToReference similarityMeasure = getMeasure(actualAutomaton,referenceGraph,testSet);
        System.out.println("similarity = "+similarityMeasure);
        System.out.println();
        /*
        LearnerGraph reducedPTA = PairQualityLearner.mergeStatesForUnique(pta,uniqueFromInitial);
View Full Code Here

      try {
      Transform.augmentFromIfThenAutomaton(initPTA, null, ifthenAutomata,learnerInitConfiguration.config.getHowManyStatesToAddFromIFTHEN());
    } catch (AugmentFromIfThenAutomatonException e) {
      Helper.throwUnchecked("failed to augment using if-then", e);
    }// we only need  to augment our PTA once (refer to the explanation above).
      LearnerThatCanClassifyPairs learner =  c != null? new PairQualityLearner.LearnerThatUsesWekaResults(ifDepth,learnerInitConfiguration,referenceGraph,c,initPTA):
          new PairQualityLearner.ReferenceLearner(learnerInitConfiguration,referenceGraph,initPTA);
      learner.setLabelsLeadingToStatesToBeMerged(labelsToMergeTo);learner.setLabelsLeadingFromStatesToBeMerged(labelsToMergeFrom);learner.setAlphabetUsedForIfThen(referenceGraph.pathroutines.computeAlphabet());
        LearnerGraph actualAutomaton = learner.learnMachine(new LinkedList<List<Label>>(),new LinkedList<List<Label>>());
       
        // Now merge everything that we need to merge
        LinkedList<AMEquivalenceClass<CmpVertex,LearnerGraphCachedData>> verticesToMerge = new LinkedList<AMEquivalenceClass<CmpVertex,LearnerGraphCachedData>>();
    List<StatePair> pairsList = LearnerThatCanClassifyPairs.buildVerticesToMerge(actualAutomaton,learner.getLabelsLeadingToStatesToBeMerged(),learner.getLabelsLeadingFromStatesToBeMerged());
    if (!pairsList.isEmpty())
    {
      int score = actualAutomaton.pairscores.computePairCompatibilityScore_general(null, pairsList, verticesToMerge);
      if (score < 0) throw new RuntimeException("last merge in the learning process was not possible");
      actualAutomaton = MergeStates.mergeCollectionOfVertices(actualAutomaton, null, verticesToMerge);
View Full Code Here

    System.out.println(new Date().toString()+" Graph loaded: "+initialPTA.getStateNumber()+" states, adding at most "+ initConfiguration.config.getHowManyStatesToAddFromIFTHEN()+" if-then states");
    Transform.augmentFromIfThenAutomaton(initialPTA, null, ifthenAutomata, initConfiguration.config.getHowManyStatesToAddFromIFTHEN());// we only need  to augment our PTA once (refer to the explanation above).
    System.out.println(new Date().toString()+" if-then states added, now "+initialPTA.getStateNumber()+" states");
    WekaDataCollector dataCollector = PairQualityLearner.createDataCollector(ifDepth);
    // Run the learner that will find out how to select the correct pairs.
    LearnerThatCanClassifyPairs learnerOfPairs = new PairQualityLearner.LearnerThatUpdatesWekaResults(initConfiguration,referenceGraph,dataCollector,initialPTA);
    LearnerGraph actualAutomaton = learnerOfPairs.learnMachine(new LinkedList<List<Label>>(),new LinkedList<List<Label>>());
   
    // final weka.classifiers.trees.J48 classifier = new weka.classifiers.trees.J48();
    FileWriter wekaInstances= null;
    try
    {
View Full Code Here

       
       final InitialConfigurationAndData initialConfigAndData = PairQualityLearner.loadInitialAndPopulateInitialConfiguration(PairQualityLearner.largePTAFileName, learnerConfig, new Transform.InternStringLabel());

    LearnerGraph referenceGraph = new LearnerGraph(initialConfigAndData.initial.graph.config);AbstractPersistence.loadGraph("resources/largePTA/outcome_correct", referenceGraph, initialConfigAndData.learnerInitConfiguration.getLabelConverter());
      WekaDataCollector dataCollector = PairQualityLearner.createDataCollector(ifDepth);
      LearnerThatCanClassifyPairs learnerOfPairs = new PairQualityLearner.LearnerThatUpdatesWekaResults(initialConfigAndData.learnerInitConfiguration,referenceGraph,dataCollector,initialConfigAndData.initial.graph);
    learnerOfPairs.learnMachine(new LinkedList<List<Label>>(),new LinkedList<List<Label>>());
   
    FileWriter wekaInstances=new FileWriter("resources/largePTA/pairsEncountered3.arff");
    wekaInstances.write(dataCollector.trainingData.toString());
    wekaInstances.close();
  }
View Full Code Here

      try {
      Transform.augmentFromIfThenAutomaton(initPTA, null, ifthenAutomata,learnerInitConfiguration.config.getHowManyStatesToAddFromIFTHEN());
    } catch (AugmentFromIfThenAutomatonException e) {
      Helper.throwUnchecked("failed to augment using if-then", e);
    }// we only need  to augment our PTA once (refer to the explanation above).
      LearnerThatCanClassifyPairs learner =  c != null? new PairQualityLearner.LearnerThatUsesWekaResults(ifDepth,learnerInitConfiguration,referenceGraph,c,initPTA):
          new PairQualityLearner.ReferenceLearner(learnerInitConfiguration,referenceGraph,initPTA,false);
      learner.setLabelsLeadingToStatesToBeMerged(labelsToMergeTo);learner.setLabelsLeadingFromStatesToBeMerged(labelsToMergeFrom);learner.setAlphabetUsedForIfThen(referenceGraph.pathroutines.computeAlphabet());
        LearnerGraph actualAutomaton = learner.learnMachine(new LinkedList<List<Label>>(),new LinkedList<List<Label>>());
       
        // Now merge everything that we need to merge
        LinkedList<AMEquivalenceClass<CmpVertex,LearnerGraphCachedData>> verticesToMerge = new LinkedList<AMEquivalenceClass<CmpVertex,LearnerGraphCachedData>>();
    List<StatePair> pairsList = LearnerThatCanClassifyPairs.buildVerticesToMerge(actualAutomaton,learner.getLabelsLeadingToStatesToBeMerged(),learner.getLabelsLeadingFromStatesToBeMerged());
    if (!pairsList.isEmpty())
    {
      int score = actualAutomaton.pairscores.computePairCompatibilityScore_general(null, pairsList, verticesToMerge);
      if (score < 0) throw new RuntimeException("last merge in the learning process was not possible");
      actualAutomaton = MergeStates.mergeCollectionOfVertices(actualAutomaton, null, verticesToMerge);
View Full Code Here

    System.out.println(new Date().toString()+" Graph loaded: "+initialPTA.getStateNumber()+" states, adding at most "+ initConfiguration.config.getHowManyStatesToAddFromIFTHEN()+" if-then states");
    Transform.augmentFromIfThenAutomaton(initialPTA, null, ifthenAutomata, initConfiguration.config.getHowManyStatesToAddFromIFTHEN());// we only need  to augment our PTA once (refer to the explanation above).
    System.out.println(new Date().toString()+" if-then states added, now "+initialPTA.getStateNumber()+" states");
    WekaDataCollector dataCollector = PairQualityLearner.createDataCollector(ifDepth);
    // Run the learner that will find out how to select the correct pairs.
    LearnerThatCanClassifyPairs learnerOfPairs = new PairQualityLearner.LearnerThatUpdatesWekaResults(initConfiguration,referenceGraph,dataCollector,initialPTA);
    LearnerGraph actualAutomaton = learnerOfPairs.learnMachine(new LinkedList<List<Label>>(),new LinkedList<List<Label>>());
   
    // final weka.classifiers.trees.J48 classifier = new weka.classifiers.trees.J48();
    FileWriter wekaInstances= null;
    try
    {
View Full Code Here

TOP

Related Classes of statechum.analysis.learning.experiments.PairSelection.PairQualityLearner.LearnerThatCanClassifyPairs

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.