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 

      throw new IllegalArgumentException("computation algorithm "+coregraph.config.getGdScoreComputationAlgorithm()+" is not currently supported");
    }
   
    final int [] incompatiblePairs = new int[ndGraph.getStateNumber()*(ndGraph.getStateNumber()+1)/2];for(int i=0;i<incompatiblePairs.length;++i) incompatiblePairs[i]=GDLearnerGraph.PAIR_OK;
    final int pairsNumber = ndGraph.findIncompatiblePairs(incompatiblePairs,ThreadNumber);
    LSolver solver = ndGraph.buildMatrix_internal(incompatiblePairs, pairsNumber, ThreadNumber,ddrh);
    solver.solve(ThreadNumber);
    solver.freeAllButResult();// deallocate memory before creating a large array.
    coregraph.pairsAndScores.clear();
    // now fill in the scores in the array.
    for(int i=0;i<incompatiblePairs.length;++i)
    {
      int index = incompatiblePairs[i];
View Full Code Here


      throw new IllegalArgumentException("computation algorithm "+coregraph.config.getGdScoreComputationAlgorithm()+" is not currently supported");
    }
   
    final int [] incompatiblePairs = new int[ndGraph.getStateNumber()*(ndGraph.getStateNumber()+1)/2];for(int i=0;i<incompatiblePairs.length;++i) incompatiblePairs[i]=GDLearnerGraph.PAIR_OK;
    final int pairsNumber = ndGraph.findIncompatiblePairs(incompatiblePairs,ThreadNumber);
    LSolver solver = ndGraph.buildMatrix_internal(incompatiblePairs, pairsNumber, ThreadNumber,ddrh);
    solver.solve(ThreadNumber);
    solver.freeAllButResult();// deallocate memory before creating a large array.
    coregraph.pairsAndScores.clear();
    // now fill in the scores in the array.
    for(int i=0;i<incompatiblePairs.length;++i)
    {
      int index = incompatiblePairs[i];
View Full Code Here

    Random rnd = new Random(0);
    for(int i=0;i<1000;++i) graph.transform.addRejectStateRandomly(rnd);
    //for(int i=0;i<5000;++i) graph.transform.addRejectStateRandomly(rnd);
    tmFinished = new Date().getTime();
    System.out.println("random reject vertices added: "+((double)tmFinished-tmStarted)/1000+" sec");tmStarted=tmFinished;
    LSolver sl  = graph.linear.buildMatrix(ThreadNumber);
    //Collection<List<String>> wset = WMethod.computeWSetOrig(result);outcome.clear();outcome.addAll(wset);
    //WMethod.computeWSet_reducedmemory(result);
    tmFinished = new Date().getTime();
    System.out.println("matrix built: "+((double)tmFinished-tmStarted)/1000+" sec");tmStarted=tmFinished;
    System.out.println("size: "+(sl.j_Ap.length-1)+" non-zeroes: "+sl.j_Ap[sl.j_Ap.length-1]);
    tmStarted = new Date().getTime();
    sl.solve();
    tmFinished = new Date().getTime();
    System.out.println("solver time taken: "+((double)tmFinished-tmStarted)/1000+" sec");
  }
View Full Code Here

      throw new IllegalArgumentException("computation algorithm "+coregraph.config.getGdScoreComputationAlgorithm()+" is not currently supported");
    }
   
    final int [] incompatiblePairs = new int[ndGraph.getStateNumber()*(ndGraph.getStateNumber()+1)/2];for(int i=0;i<incompatiblePairs.length;++i) incompatiblePairs[i]=GDLearnerGraph.PAIR_OK;
    final int pairsNumber = ndGraph.findIncompatiblePairs(incompatiblePairs,ThreadNumber);
    LSolver solver = ndGraph.buildMatrix_internal(incompatiblePairs, pairsNumber, ThreadNumber,ddrh);
    solver.solve(ThreadNumber);
    solver.freeAllButResult();// deallocate memory before creating a large array.
    coregraph.pairsAndScores.clear();
    // now fill in the scores in the array.
    for(int i=0;i<incompatiblePairs.length;++i)
    {
      int index = incompatiblePairs[i];
View Full Code Here

      throw new IllegalArgumentException("computation algorithm "+coregraph.config.getGdScoreComputationAlgorithm()+" is not currently supported");
    }
   
    final int [] incompatiblePairs = new int[ndGraph.getStateNumber()*(ndGraph.getStateNumber()+1)/2];for(int i=0;i<incompatiblePairs.length;++i) incompatiblePairs[i]=GDLearnerGraph.PAIR_OK;
    final int pairsNumber = ndGraph.findIncompatiblePairs(incompatiblePairs,ThreadNumber);
    LSolver solver = ndGraph.buildMatrix_internal(incompatiblePairs, pairsNumber, ThreadNumber,ddrh);
    solver.solve(ThreadNumber);
    solver.freeAllButResult();// deallocate memory before creating a large array.
    coregraph.pairsAndScores.clear();
    // now fill in the scores in the array.
    for(int i=0;i<incompatiblePairs.length;++i)
    {
      int index = incompatiblePairs[i];
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

      // Now the system of equations will be built and solved. The only exception is where
      // argConfig.getGdScoreComputation() == GDScoreComputationEnum.GD_DIRECT in which case
      // the solver returned will be a dummy with b[] part copied to the x one.
      {
        LSolver solverForward = forward.buildMatrix_internal(pairScores, numberOfPairs, ThreadNumber,ddrh);
        JConsole_Diagnostics.getDiagnostics().setStatus("finished building matrix forward "+DateFormat.getTimeInstance().format(new Date()));
        forward.stateToCorrespondingGraph = null;// deallocate memory
        //System.out.println(forward.dumpEquations(solverForward, pairScores, newBToOrig));
        solverForward.solve(threads);
        solverForward.freeAllButResult();// deallocate memory before creating a large array.
        scoresForward = solverForward.j_x;
      }

      JConsole_Diagnostics.getDiagnostics().setStatus("started building matrix inverse "+DateFormat.getTimeInstance().format(new Date()));
      {
        LSolver solverInverse = inverse.buildMatrix_internal(pairScores, numberOfPairs, ThreadNumber,ddrh);
        //System.out.println(inverse.dumpEquations(solverInverse, pairScores, newBToOrig));
        JConsole_Diagnostics.getDiagnostics().setStatus("finished building matrix inverse "+DateFormat.getTimeInstance().format(new Date()));
        inverse.stateToCorrespondingGraph = null;// deallocate memory
        solverInverse.solve(threads);
        solverInverse.freeAllButResult();// deallocate memory before creating a large array.
        scoresInverse = solverInverse.j_x;
      }
      JConsole_Diagnostics.getDiagnostics().setStatus("finished with the inverse solver"+DateFormat.getTimeInstance().format(new Date()));
    }
View Full Code Here

      throw new IllegalArgumentException("computation algorithm "+coregraph.config.getGdScoreComputationAlgorithm()+" is not currently supported");
    }
   
    final int [] incompatiblePairs = new int[ndGraph.getStateNumber()*(ndGraph.getStateNumber()+1)/2];for(int i=0;i<incompatiblePairs.length;++i) incompatiblePairs[i]=GDLearnerGraph.PAIR_OK;
    final int pairsNumber = ndGraph.findIncompatiblePairs(incompatiblePairs,ThreadNumber);
    LSolver solver = ndGraph.buildMatrix_internal(incompatiblePairs, pairsNumber, ThreadNumber,ddrh);
    solver.solve(ThreadNumber);
    solver.freeAllButResult();// deallocate memory before creating a large array.
    coregraph.pairsAndScores.clear();
    // now fill in the scores in the array.
    for(int i=0;i<incompatiblePairs.length;++i)
    {
      int index = incompatiblePairs[i];
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

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.