Package statechum.analysis.learning.rpnicore

Examples of statechum.analysis.learning.rpnicore.LSolver

MacOS X - specific instructions

It may be advisable to build gcc first (gmp web page suggests it will not work when built with XCode so using a recent gcc may be advisable), It is worth noting that the full path of the interface is encoded in the shared libraries hence moving this interface is only possible if libraries are rebuilt. For this reason, LSolver is stuck in the rpnicore rather than in learner/linear. Instructions for building OpenBLAS on Linux, Uncompress the .zip, then from the main directory run
 make PREFIX=/usr/local/soft/OpenBLAS-be853da DYNAMIC_ARCH=1 UTEST_CHECK=1 NO_LAPACK=1	NO_AFFINITY=1 
The first parameter is responsible for building in support for all CPU architectures, otherwise only the current one will This will attempt to download CUnit and then fail.
 cd utest;make 
should build and install CUnit into utest. Subsequently doing the following command from the main directory (the one just above utest)
  ln -s utest/CUnit-2.1-2/include/CUnit . 
would fix unit tests that ship with OpenBLAS and they will run when the above make command is run. After doing
  make PREFIX=/usr/local/soft/OpenBLAS-be853da DYNAMIC_ARCH=1 UTEST_CHECK=1 NO_LAPACK=1 install 
OpenBLAS is available. SuiteSparse_config.mk should have
 CC=x86_64-w64-mingw32-gcc AR=x86_64-w64-mingw32-ar RANLIB = x86_64-w64-mingw32-ranlib F77 = x86_64-w64-mingw32-gfortran BLAS = /usr/local/soft/OpenBLAS-be853da/lib/libopenblas.lib INSTALL_LIB=/usr/local/soft/umfpack-5.6.1-openblas/lib INSTALL_INCLUDE=/usr/local/soft/umfpack-5.6.1-openblas/include 
OpenBLAS on Windows7-x86_64 First, build OpenBLAS with both options for Unix (above) and those mentioned in quickbuild.64bit.

When building UMFPACK, most options are the same as for Unix but there are a few changes,

Finally, Makefile in the UMFPACK/Demo directory has the "run" target, where it runs demos and records the results. Every time it runs a demo, the output has to be piped through d2u to correct line endings on Windows and through sed 's/e\([+-]\)0\([0-9]\+\)/e\1\2/g' to convert the differences in which exponents are output on Windows. Hence the extra content is like
 ... _demo | d2u |  sed  's/e\([+-]\)0\([0-9]\+\)/e\1\2/g' > my_ ... .out 

    GDLearnerGraph ndGraph = new GDLearnerGraph(new LearnerGraph(buildGraph("A-a->B-a->B-b->A / B-c->C / E-a->F-a->F-d->F-b->E-c->F""dumpEquations"),config),LearnerGraphND.ignoreRejectStates, false);
    final int [] incompatiblePairs = new int[ndGraph.getPairNumber()];
    final int pairsNumber = incompatiblePairs.length;
    for(int i=0;i<incompatiblePairs.length;++i) incompatiblePairs[i]=i;// emulate the behaviour or non-public part for(int i=0;i<incompatiblePairs.length;++i) incompatiblePairs[i]=PAIR_OK;final int pairsNumber = ndGraph.findIncompatiblePairs(incompatiblePairs,1);

    LSolver solver = ndGraph.buildMatrix_internal(incompatiblePairs, pairsNumber, 1,null);

    System.out.println(ndGraph.dumpEquations(solver, incompatiblePairs, null).toString())}
View Full Code Here


      }
    });
    performRowTasks(handlerList, ThreadNumber, matrixForward.transitionMatrix,filter,
        GDLearnerGraph.partitionWorkLoadTriangular(ThreadNumber,matrixForward.transitionMatrix.size()));
    // At this point, we are finished building the matrices, it's time to populate the main arrays if needed - we do not have to do this if we only aim to compute the right-hand side.
    LSolver result = null;
    if (config.getGdScoreComputation() == GDScoreComputationEnum.GD_RH)
    {
      // First, we compute the number of non-zero elements.
      int size = 0;for(int thread=0;thread<ThreadNumber;++thread) size+=currentPosition[thread];
      // Second, allocate arrays.
      int Ai[]=new int[size];double Ax[]=new double[size];
 
      // In a number of cases we'll have more threads than rows to handle, hence threads will have nothing to do
      // and Ap_threadStart will be -1 for those threads. In order to ensure that Ap_threadStart contains
      // continuous values, we set those -1 elements to Ap_threadStart of the subsequent thread (or pairsNumber if there is none).
      int currentLastStatePair = pairsNumber;
      for(int th=ThreadNumber;th>=0;--th) if (Ap_threadStart[th] < 0) Ap_threadStart[th]=currentLastStatePair;else currentLastStatePair=Ap_threadStart[th];
     
      int prevLastPos = 0;
      // Finally, populate them.
      for(int thread=0;thread<ThreadNumber;++thread)
      {
  /* I'll try to draw a picture which shows the relation between arrays computed by different threads,
 
  StatePair values  : 0  1  2 | 3  4  5 | 6  7  8
          Ap:  0  8 12 | 0 11 16 | 0  4 12
                              |         |
    threadNo      :     0        1         2      
    currentPosition :    20       18        19
   
    The above picture with three threads shows the following relation between columns
    and the number of elements in them:
    0  8 -0
    1  12-8
    2  20-12
   
    3  11-0
    4  16-11
    5  18-16
   
    ....
   
    When we copy the outcome into Ai and Ax, we have to introduce sequential numbers,
    so column 3 will start where column 2 finished in Ai populated by thread 0,
    i.e. at position 20 (last element filled in by thread 0),
    column 4 will start at 11+20 and so on until data filled in by thread 2,
    hence column 6 will start at position 20+18.
   
    With the above illustration in mind, the code below updates Ap and fills in Ax and Ai.
  */
 
        int lastPair = Ap_threadStart[thread+1];// the position where the next thread has started (or would've started if it was not the last thread).
        for(int i=Ap_threadStart[thread];i<lastPair;++i)
          Ap[i]+=prevLastPos;
       
        // If a thread had no work to do, currentPosition[thread] would stay at zero so we shall not corrupt anything,
        // but Ai_array[thread] may be null, so we'd best check for "no work".
        if (currentPosition[thread]>0)
        {
          System.arraycopy(Ai_array[thread].elements(), 0, Ai, prevLastPos, currentPosition[thread]);
          System.arraycopy(Ax_array[thread].elements(), 0, Ax, prevLastPos, currentPosition[thread]);
          prevLastPos+=currentPosition[thread];
        }
      }
      Ap[pairsNumber]=prevLastPos;
      result = new LSolver(Ap,Ai,Ax,b,new double[pairsNumber]);
    }
    else
    {// we are here to compute the right-hand side only, hence build a dummy solver.
      result = new LSolver(pairsNumber)
      {
        {// constructor: copy b to the result column
          System.arraycopy(b, 0, j_x, 0, pairsNumber);
        }
       
View Full Code Here

   */
  public double [] computeStateCompatibility(int ThreadNumber,final Class<? extends DetermineDiagonalAndRightHandSideInterface> ddrh)
  {
    final int [] incompatiblePairs = new int[getPairNumber()];for(int i=0;i<incompatiblePairs.length;++i) incompatiblePairs[i]=PAIR_OK;
    final int pairsNumber = findIncompatiblePairs(incompatiblePairs,ThreadNumber);
    LSolver solver = buildMatrix_internal(incompatiblePairs, pairsNumber, ThreadNumber,ddrh);
    solver.solve(ThreadNumber);
    solver.freeAllButResult();// deallocate memory before creating a large array.
    double statePairScores[] = new double[incompatiblePairs.length];
    // now fill in the scores in the array.
    for(int i=0;i<incompatiblePairs.length;++i)
      if (incompatiblePairs[i] >=0) statePairScores[i]=solver.j_x[incompatiblePairs[i]];
      else statePairScores[i]=incompatiblePairs[i];// PAIR_INCOMPATIBLE
View Full Code Here

   * Since it messes up the configuration of the graph, it has to be run at the end of every test method rather than multiple times.
   */
  protected void checkBuildMatrix(LearnerGraph gr, DoubleMatrix2D expectedAx, DoubleMatrix1D expectedB)
  {
    GDLearnerGraph ndGraph = new GDLearnerGraph(gr,LearnerGraphND.ignoreRejectStates, false);
    LSolver solver = ndGraph.buildMatrix(ThreadNumber);
    DoubleMatrix2D Ax=solver.toDoubleMatrix2D();
    Assert.assertEquals(getExpectedMatrix2DSlowly(gr),Ax);
    if (expectedAx != null) Assert.assertEquals(expectedAx, Ax);
    DoubleMatrix1D b=solver.toDoubleMatrix1D();
    if (expectedB != null) Assert.assertEquals(expectedB, b);Assert.assertEquals(getExpectedMatrix1DSlowly(gr),b);
    solver.solveExternally(1);// check if we have a solution, just in case it fails.

    // Now check consistency.
    gr.config.setAttenuationK_testOnly(1);DoubleMatrix2D Ax1 = ndGraph.buildMatrix(ThreadNumber).toDoubleMatrix2D();
    gr.config.setAttenuationK(0);DoubleMatrix2D Ax0 = ndGraph.buildMatrix(ThreadNumber).toDoubleMatrix2D();
    DoubleMatrix1D one = DoubleFactory1D.dense.make(Ax1.rows(), 1), a=DoubleFactory1D.dense.make(Ax.rows(), 0);
View Full Code Here

  public final void testDumpEquations1()
  {
    GDLearnerGraph ndGraph = new GDLearnerGraph(buildLearnerGraph("A-a->B-a->B-b->A""testBuildMatrix1",config),LearnerGraphND.ignoreRejectStates, false);
    final int [] incompatiblePairs = new int[ndGraph.getPairNumber()];for(int i=0;i<incompatiblePairs.length;++i) incompatiblePairs[i]=PAIR_OK;
    final int pairsNumber = ndGraph.findIncompatiblePairs(incompatiblePairs,ThreadNumber);
    LSolver solver = ndGraph.buildMatrix_internal(incompatiblePairs, pairsNumber, ThreadNumber,null);

    String outcome = ndGraph.dumpEquations(solver, incompatiblePairs, null).toString();
    Assert.assertEquals("2.0([A,A]:[A,A]) + -"+k+"([A,A]:[B,B]) = 1.0\n"+
        "4.0([B,A]:[B,A]) + -"+k+"([B,A]:[B,B]) = 1.0\n"+
        "-"+k+"([B,B]:[A,A]) + "+(4-k)+"([B,B]:[B,B]) = 2.0\n",outcome);
View Full Code Here

  {
    LearnerGraph graph = buildLearnerGraph("A-a->B-a->B-b->A""testBuildMatrix1",config);
    GDLearnerGraph ndGraph = new GDLearnerGraph(graph,LearnerGraphND.ignoreRejectStates, false);
    final int [] incompatiblePairs = new int[ndGraph.getPairNumber()];for(int i=0;i<incompatiblePairs.length;++i) incompatiblePairs[i]=PAIR_OK;
    final int pairsNumber = ndGraph.findIncompatiblePairs(incompatiblePairs,ThreadNumber);
    LSolver solver = ndGraph.buildMatrix_internal(incompatiblePairs, pairsNumber, ThreadNumber,null);
    Map<CmpVertex,CmpVertex> newToOrig = new TreeMap<CmpVertex,CmpVertex>();
    String P67="P67",P99="B";
    newToOrig.put(graph.findVertex("A"),AbstractLearnerGraph.generateNewCmpVertex(VertexID.parseID(P67), graph.config));
    String outcome = ndGraph.dumpEquations(solver, incompatiblePairs, newToOrig).toString();
    Assert.assertEquals("2.0(["+P67+","+P67+"]:["+P67+","+P67+"]) + -"+k+"(["+P67+","+P67+"]:["+P99+","+P99+"]) = 1.0\n"+
View Full Code Here

  {
    LearnerGraph graph = buildLearnerGraph("A-a->B-a->B-b->A""testBuildMatrix1",config);
    GDLearnerGraph ndGraph = new GDLearnerGraph(graph,LearnerGraphND.ignoreRejectStates, false);
    final int [] incompatiblePairs = new int[ndGraph.getPairNumber()];for(int i=0;i<incompatiblePairs.length;++i) incompatiblePairs[i]=PAIR_OK;
    final int pairsNumber = ndGraph.findIncompatiblePairs(incompatiblePairs,ThreadNumber);
    LSolver solver = ndGraph.buildMatrix_internal(incompatiblePairs, pairsNumber, ThreadNumber,null);
    Map<CmpVertex,CmpVertex> newToOrig = new TreeMap<CmpVertex,CmpVertex>();
    String P67="P67",P99="P99";
    newToOrig.put(graph.findVertex("A"),AbstractLearnerGraph.generateNewCmpVertex(VertexID.parseID(P67), graph.config));
    newToOrig.put(graph.findVertex("B"),AbstractLearnerGraph.generateNewCmpVertex(VertexID.parseID(P99), graph.config));
    String outcome = ndGraph.dumpEquations(solver, incompatiblePairs, newToOrig).toString();
View Full Code Here

        "\nB-b-#G\n","TestComputeStateCompatibility_checking_filtering2",config);
    StatesToConsider filter = TestLearnerGraphND.createInstanceOfFilter(filterClass, gr);
    double score_CC=1./2,score_BB=(2+score_CC*k)/4, score_AA=(1+k*score_BB)/2;
    {
      GDLearnerGraph ndGraph = new GDLearnerGraph(gr,LearnerGraphND.ignoreNone, false);
      LSolver solver = ndGraph.buildMatrix(ThreadNumber);
      DoubleMatrix2D Ax=solver.toDoubleMatrix2D();
      Assert.assertEquals(6,Ax.columns());
    }
    Set<PairScore> pairsSet = addAllPermutations(gr.pairscores.chooseStatePairs(PAIR_INCOMPATIBLE*2,10,ThreadNumber,null,filter, new NonRandomRandom()));
    Set<PairScore> exp = addAllPermutations(Arrays.asList(new PairScore[]{
        new PairScore(gr.findVertex("A"),gr.findVertex("A"),(int)(10*score_AA),1),
 
View Full Code Here

  }
 
  @Test
  public final void testExternalSolver1()
  {
    LSolver s = new LSolver(testMatrix,DoubleFactory1D.dense.make(new double[]{8., 45., -3., 3., 19.}));
    DoubleMatrix1D x = DoubleFactory1D.dense.make(testMatrix.rows());
    for(int i=0;i<s.j_b.length;++i) x.setQuick(i, s.j_b[i]);
   
    // Test 1
    s.solveExternally(1);
    for(int i=0;i<testMatrix.rows();++i)
      Assert.assertEquals(i+1, s.j_x[i],Configuration.fpAccuracy);
    verifyAxb(s);
   
    // Test 2
    LUDecompositionQuick solver = new LUDecompositionQuick();
    solver.decompose(testMatrix);solver.setLU(testMatrix);
    solver.solve(x);
    for(int i=0;i<testMatrix.rows();++i)
      Assert.assertEquals(i+1, x.getQuick(i),Configuration.fpAccuracy);
    verifyAxb(s);

    // Test 3
    for(int i=0;i<testMatrix.rows();++i) s.j_x[i]=0;
    s.solveUsingColt();
    for(int i=0;i<testMatrix.rows();++i)
      Assert.assertEquals(i+1, s.j_x[i],Configuration.fpAccuracy);
    verifyAxb(s);
  }
View Full Code Here

      }
    }, IllegalArgumentException.class,"zero-sized problem");   
    checkForCorrectException(new whatToRun() {
      @SuppressWarnings("unused")
      public @Override void run() throws NumberFormatException {
        new LSolver(Ap, Ai, Ax, b, x);
      }
    }, IllegalArgumentException.class,"zero-sized problem");   
  }
View Full Code Here

TOP

Related Classes of statechum.analysis.learning.rpnicore.LSolver

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.