Class MjSparseMatrix


  • public class MjSparseMatrix
    extends java.lang.Object
    Sparse matrix implemented with a hash map. All undefined entries are zero.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  MjSparseMatrix.Index
      Used to reference a single element in the matrix.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private MjSparseMatrix.Index m_kIndexKeyTmp
      Instantiate once instead of each time a value key (Index) is needed.
      private java.util.HashMap m_kMap
      Mapping of Index(row,col).
      private static float ms_fTolerance
      DOCUMENT ME!
    • Constructor Summary

      Constructors 
      Constructor Description
      MjSparseMatrix()
      Matrix of undefined dimensions.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private static float dot​(int iSize, float[] afU, float[] afV)
      conjugate gradient methods.
      float getElement​(int iRow, int iCol)
      Get the element value at the specified row,col.
      java.util.Iterator iterator()
      Return iterator to non-zero elements in the matrix.
      private void multiply​(int iSize, float[] afX, float[] afProd)
      DOCUMENT ME!
      void setElement​(int iRow, int iCol, float fValue)
      Set the element value at the specified row,col.
      int size()
      return number of non-zero entries in the matrix.
      (package private) boolean solveSymmetricCG​(int iSize, float[] afB, float[] afX)
      Conjugate gradient method for sparse, symmetric matrices.
      private static void updateP​(int iSize, float[] afP, float fBeta, float[] afR)
      DOCUMENT ME!
      private static void updateR​(int iSize, float[] afR, float fAlpha, float[] afW)
      DOCUMENT ME!
      private static void updateX​(int iSize, float[] afX, float fAlpha, float[] afP)
      DOCUMENT ME!
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • m_kIndexKeyTmp

        private MjSparseMatrix.Index m_kIndexKeyTmp
        Instantiate once instead of each time a value key (Index) is needed.
      • m_kMap

        private java.util.HashMap m_kMap
        Mapping of Index(row,col).
    • Constructor Detail

      • MjSparseMatrix

        public MjSparseMatrix()
        Matrix of undefined dimensions. Initially all elements are zero.
    • Method Detail

      • getElement

        public float getElement​(int iRow,
                                int iCol)
        Get the element value at the specified row,col.
        Parameters:
        iRow - DOCUMENT ME!
        iCol - DOCUMENT ME!
        Returns:
        DOCUMENT ME!
      • iterator

        public java.util.Iterator iterator()
        Return iterator to non-zero elements in the matrix. Each entry in the iterator is of Map.Entry type where the key is of Index type and the value is of Float type.
        Returns:
        DOCUMENT ME!
      • setElement

        public void setElement​(int iRow,
                               int iCol,
                               float fValue)
        Set the element value at the specified row,col.
        Parameters:
        iRow - DOCUMENT ME!
        iCol - DOCUMENT ME!
        fValue - DOCUMENT ME!
      • size

        public int size()
        return number of non-zero entries in the matrix.
        Returns:
        DOCUMENT ME!
      • solveSymmetricCG

        boolean solveSymmetricCG​(int iSize,
                                 float[] afB,
                                 float[] afX)
        Conjugate gradient method for sparse, symmetric matrices. Input: The nonzero entries of the symmetrix matrix A are stored in a map whose keys are pairs (i,j) and whose values are real numbers. The pair (i,j) is the location of the value in the array. Only one of (i,j) and (j,i) should be stored since A is symmetric. The code assumes this is how you set up A. The column vector B is stored as an array of contiguous valuess. If B itself is sparse, another solver can be implemented which uses a map to store B. Output: B[iSize] is the solution x to Ax = B
        Parameters:
        iSize - DOCUMENT ME!
        afB - DOCUMENT ME!
        afX - DOCUMENT ME!
        Returns:
        DOCUMENT ME!
      • dot

        private static float dot​(int iSize,
                                 float[] afU,
                                 float[] afV)
        conjugate gradient methods.
        Parameters:
        iSize - DOCUMENT ME!
        afU - DOCUMENT ME!
        afV - DOCUMENT ME!
        Returns:
        DOCUMENT ME!
      • updateP

        private static void updateP​(int iSize,
                                    float[] afP,
                                    float fBeta,
                                    float[] afR)
        DOCUMENT ME!
        Parameters:
        iSize - DOCUMENT ME!
        afP - DOCUMENT ME!
        fBeta - DOCUMENT ME!
        afR - DOCUMENT ME!
      • updateR

        private static void updateR​(int iSize,
                                    float[] afR,
                                    float fAlpha,
                                    float[] afW)
        DOCUMENT ME!
        Parameters:
        iSize - DOCUMENT ME!
        afR - DOCUMENT ME!
        fAlpha - DOCUMENT ME!
        afW - DOCUMENT ME!
      • updateX

        private static void updateX​(int iSize,
                                    float[] afX,
                                    float fAlpha,
                                    float[] afP)
        DOCUMENT ME!
        Parameters:
        iSize - DOCUMENT ME!
        afX - DOCUMENT ME!
        fAlpha - DOCUMENT ME!
        afP - DOCUMENT ME!
      • multiply

        private void multiply​(int iSize,
                              float[] afX,
                              float[] afProd)
        DOCUMENT ME!
        Parameters:
        iSize - DOCUMENT ME!
        afX - DOCUMENT ME!
        afProd - DOCUMENT ME!