Package statechum.analysis.learning.rpnicore.TestGD

Examples of statechum.analysis.learning.rpnicore.TestGD.ProgressIndicator


      int alphabet = states/2;
     
      MachineGenerator mg = new MachineGenerator(states, 40, states/10);
      int mutationsPerStage = (states/2) / 2;
      //System.out.print("\n"+states+": ");
      TestGD.ProgressIndicator progress = new ProgressIndicator(""+states, mutationStages*experimentsPerMutationCategory);
      for(int mutationStage = 0;mutationStage<mutationStages;mutationStage++)
      {
        for(int experiment=0;experiment<experimentsPerMutationCategory;experiment++)
        {
          ExperimentResult outcome = new ExperimentResult();
          while(!outcome.experimentValid)
          {
            int mutations = mutationsPerStage * (mutationStage+1);
            LearnerGraphND origGraph = mg.nextMachine(alphabet, experiment);
            GraphMutator<List<CmpVertex>,LearnerGraphNDCachedData> mutator = new GraphMutator<List<CmpVertex>,LearnerGraphNDCachedData>(origGraph,r);
            mutator.mutate(mutations);
            LearnerGraphND origAfterRenaming = new LearnerGraphND(origGraph.config);
            Map<CmpVertex,CmpVertex> origToNew = copyStatesAndTransitions(origGraph,origAfterRenaming);
            LearnerGraphND mutated = (LearnerGraphND)mutator.getMutated();
            Set<Transition> appliedMutations = new HashSet<Transition>();
            for(Transition tr:mutator.getDiff())
            {
              CmpVertex renamedFrom = origToNew.get(tr.getFrom());if (renamedFrom == null) renamedFrom = tr.getFrom();
              CmpVertex renamedTo = origToNew.get(tr.getTo());if (renamedTo == null) renamedTo = tr.getTo();
              appliedMutations.add(new Transition(renamedFrom,renamedTo,tr.getLabel()));
            }
           
            final double perfectLowToHigh=0.7,perfectThreshold=0.5;
           
            // These experiments are only run for the maximal number of states
            if (graphComplexity == graphComplexityMax-1)
            {
              for(double k:new double[]{0,.2,.4,.6,.8,.95})
              {
                config.setAttenuationK(k);
                config.setGdKeyPairThreshold(0.5);
                config.setGdLowToHighRatio(perfectLowToHigh);
                config.setGdPropagateDet(false);// this is to ensure that if we removed a transition 0 from to a state and then added one from that state to a different one, det-propagation will not force the two very different states into a key-pair relation.
                linearDiff(origAfterRenaming,mutated, appliedMutations,outcome);
               
                gr_Diff_k.add(k, outcome.getValue(DOUBLE_V.OBTAINED_TO_EXPECTED));
               
              }
             
              for(double threshold:new double[]{0.3,0.4,0.5,0.6,0.7,0.8,0.9,0.95})
              {
                config.setGdKeyPairThreshold(threshold);
                config.setGdLowToHighRatio(perfectLowToHigh);
                config.setGdPropagateDet(false);// this is to ensure that if we removed a transition 0 from to a state and then added one from that state to a different one, det-propagation will not force the two very different states into a key-pair relation.
                linearDiff(origAfterRenaming,mutated, appliedMutations,outcome);
               
                gr_Diff_threshold.add(threshold, outcome.getValue(DOUBLE_V.OBTAINED_TO_EXPECTED));
              }
             
             
             
              for(double lowtohigh:new double[]{0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,0.95})
              {
                config.setGdKeyPairThreshold(perfectThreshold);
                config.setGdLowToHighRatio(lowtohigh);
                config.setGdPropagateDet(false);// this is to ensure that if we removed a transition 0 from to a state and then added one from that state to a different one, det-propagation will not force the two very different states into a key-pair relation.
                linearDiff(origAfterRenaming,mutated, appliedMutations,outcome);
               
                gr_Diff_lowtohigh.add(lowtohigh, outcome.getValue(DOUBLE_V.OBTAINED_TO_EXPECTED));
              }
             
             
              for(int i=0;i<pairThreshold.length;++i)
                for(double ratio:lowToHigh)
                {
                  config.setGdKeyPairThreshold(pairThreshold[i]);
                  config.setGdLowToHighRatio(ratio);
                  config.setGdPropagateDet(false);// this is to ensure that if we removed a transition 0 from to a state and then added one from that state to a different one, det-propagation will not force the two very different states into a key-pair relation.
                  linearDiff(origAfterRenaming,mutated, appliedMutations,outcome);
                 
                  gr_Diff_thresholdslowhigh.add(new Pair<Double,Double>(ratio,pairThreshold[i]), outcome.getValue(DOUBLE_V.OBTAINED_TO_EXPECTED));
                }
            }
            config.setAttenuationK(0.5);
            config.setGdKeyPairThreshold(perfectThreshold);
            config.setGdLowToHighRatio(perfectLowToHigh);
            config.setGdPropagateDet(false);// this is to ensure that if we removed a transition 0 from to a state and then added one from that state to a different one, det-propagation will not force the two very different states into a key-pair relation.
            linearDiff(origAfterRenaming,mutated, appliedMutations,outcome);
           
            if (!skip)
            {
              LearnerGraph fromDet = null, toDet = null;
              try {
                fromDet = mergeAndDeterminize(origAfterRenaming);
                toDet = mergeAndDeterminize(mutated);
              } catch (IncompatibleStatesException e) {
                Helper.throwUnchecked("failed to build a deterministic graph from a nondet one", e);
              }
              languageDiff(fromDet,toDet,states, graphComplexity,outcome);
            }
            outcome.experimentValid = true;
            progress.next();
            gr_Diff_States.add(states, outcome.getValue(DOUBLE_V.OBTAINED_TO_EXPECTED));
            gr_W_States.add(states,outcome.getValue(DOUBLE_V.ACCURACY_W));
            Pair<Integer,Integer> mutations_states = new Pair<Integer,Integer>(mutationStage+1,states);
            Pair<Integer,Integer> states_mutations = new Pair<Integer,Integer>(states,mutationStage+1);
            gr_DiffGD_StatesLevel.add(mutations_states, outcome.getValue(DOUBLE_V.OBTAINED_TO_EXPECTED));
View Full Code Here


          int alphabet = states/2;
         
          MachineGenerator mg = new MachineGenerator(states, 40, states/10);
          int mutationsPerStage = (states/2) / 2;
          //System.out.print("\n"+states+": ");
          TestGD.ProgressIndicator progress = new ProgressIndicator(""+states, mutationStages*experimentsPerMutationCategory);
          for(int mutationStage = 0;mutationStage<mutationStages;mutationStage++)
          {
            for(int experiment=0;experiment<experimentsPerMutationCategory;experiment++)
            {
              ExperimentResult outcome = new ExperimentResult();
              final double perfectLowToHigh=0.7,perfectThreshold=0.5;
   
              config.setAttenuationK(0.5);
              config.setGdKeyPairThreshold(perfectThreshold);
              config.setGdLowToHighRatio(perfectLowToHigh);
              config.setGdPropagateDet(false);// this is to ensure that if we removed a transition 0 from to a state and then added one from that state to a different one, det-propagation will not force the two very different states into a key-pair relation.
   
              int mutations = mutationsPerStage * (mutationStage+1);
              LearnerGraphND origGraph = mg.nextMachine(alphabet, experiment);
              GraphMutator<List<CmpVertex>,LearnerGraphNDCachedData> mutator = new GraphMutator<List<CmpVertex>,LearnerGraphNDCachedData>(origGraph,new Random(mutationStage*experimentsPerMutationCategory+experiment));
              mutator.mutate(mutations);
              LearnerGraphND origAfterRenaming = new LearnerGraphND(origGraph.config);
              Map<CmpVertex,CmpVertex> origToNew = copyStatesAndTransitions(origGraph,origAfterRenaming);
              LearnerGraphND mutated = (LearnerGraphND)mutator.getMutated();
              Set<Transition> appliedMutations = new HashSet<Transition>();
              for(Transition tr:mutator.getDiff())
              {
                CmpVertex renamedFrom = origToNew.get(tr.getFrom());if (renamedFrom == null) renamedFrom = tr.getFrom();
                CmpVertex renamedTo = origToNew.get(tr.getTo());if (renamedTo == null) renamedTo = tr.getTo();
                appliedMutations.add(new Transition(renamedFrom,renamedTo,tr.getLabel()));
              }
             
              linearDiff(origAfterRenaming,mutated, appliedMutations,outcome);
             
              LearnerGraph fromDet = null, toDet = null;
              try {
                fromDet = mergeAndDeterminize(origAfterRenaming);
                toDet = mergeAndDeterminize(mutated);
              } catch (IncompatibleStatesException e) {
                Helper.throwUnchecked("failed to build a deterministic graph from a nondet one", e);
              }
              languageDiff(fromDet,toDet,states, graphComplexity,outcome);
             
              // zero the times.
              outcome.setValue(LONG_V.DURATION_GD, 0);
              outcome.setValue(LONG_V.DURATION_RAND, 0);
              outcome.setValue(LONG_V.DURATION_W, 0);
             
              outcome.experimentValid = true;
              processor.process(outcome);
              progress.next();
            }
          }
        }
      }
      finally
View Full Code Here

    {
      runners[i]=new ErlangRunner();processNames[i]=""+currentNumber++;runners[i].startErlang(processNames[i], 0);
    }
    Random rnd = new Random(0);
    final int testNumber = 1000;
    ProgressIndicator progress = new ProgressIndicator("Random erlang tests", testNumber);
    for(int cnt=0;cnt < testNumber;++cnt)
    {
      int runnerNumber = rnd.nextInt(runners.length);
      ErlangRunner r = runners[runnerNumber];
      if (rnd.nextInt(100) > 1)
      {
        int numA = rnd.nextInt(10000)-5000, numB=rnd.nextInt(10000)-5000;
        OtpErlangTuple response = (OtpErlangTuple)r.call(new OtpErlangObject[]{new OtpErlangAtom("echo"),
            new OtpErlangList(new OtpErlangObject[]{ new OtpErlangAtom(dataHead), new OtpErlangInt(numA), new OtpErlangInt(numB),new OtpErlangAtom(dataC)})},
            0);

        Assert.assertEquals(dataHead,((OtpErlangAtom)response.elementAt(0)).atomValue());
        Assert.assertEquals(processNames[runnerNumber],((OtpErlangAtom)response.elementAt(1)).atomValue());
        OtpErlangObject [] list = ((OtpErlangList)response.elementAt(2)).elements();
        Assert.assertEquals(3, list.length);
        Assert.assertEquals(numA,((OtpErlangLong)list[0]).intValue());
        Assert.assertEquals(numB,((OtpErlangLong)list[1]).intValue());
        Assert.assertEquals(dataC,((OtpErlangAtom)list[2]).atomValue());
      }
      else
      {
        r.killErlang();processNames[runnerNumber]=""+currentNumber++;runners[runnerNumber].startErlang(processNames[runnerNumber], 0);
      }
      progress.next();
    }
    for(int i=0;i<runners.length;++i) runners[i].killErlang();
    Assert.assertTrue(currentNumber > runners.length+10);
  }
View Full Code Here

TOP

Related Classes of statechum.analysis.learning.rpnicore.TestGD.ProgressIndicator

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.