Class CachedQMatrix

  • All Implemented Interfaces:
    QMatrix

    public final class CachedQMatrix
    extends java.lang.Object
    implements QMatrix
    This is the original cache from the libSVN implementation. The code is very C stylish, and probably not half as effective on Java due to garbage collection.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private int[] chain
      LRU: backward and forward chaining
      private float[][] data
      Data storage
      private QMatrix inner
      Wrapped inner matrix
      private int[] len
      Number of valid entries in each buffer
      private int lru
      LRU head
      private static long MEGABYTES
      Constant for parameterization in megabytes
      private long size
      Remaining memory (in floats)
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private void discard​(int h)
      Discard a cache entry.
      (package private) float[] get_data​(int h, int len)  
      void get_Q​(int column, int len, float[] out)
      Get a column of the matrix.
      double[] get_QD()
      Get the diagonal values, as reference.
      void initialize()
      Initialize the Q Matrix.
      private void link​(int p, int n)
      Link two objects in the LRU chain.
      private void lru_delete​(int h)
      Delete from the LRU list.
      private void lru_insert​(int h)
      Insert into the last position of the LRU list.
      private int next​(int i)
      Get the next element in the LRU chain.
      private int prev​(int i)
      Get the previous element in the LRU chain.
      private void selflink​(int p)
      Link an element to itself only.
      double similarity​(int i, int j)
      (Slow) compute the similarity (not distance) of objects i and j.
      void swap_index​(int i, int j)
      Reorganize the data by swapping two entries.
      • Methods inherited from class java.lang.Object

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

      • MEGABYTES

        private static final long MEGABYTES
        Constant for parameterization in megabytes
        See Also:
        Constant Field Values
      • size

        private long size
        Remaining memory (in floats)
      • inner

        private final QMatrix inner
        Wrapped inner matrix
      • data

        private final float[][] data
        Data storage
      • len

        private final int[] len
        Number of valid entries in each buffer
      • lru

        private int lru
        LRU head
      • chain

        private final int[] chain
        LRU: backward and forward chaining
    • Constructor Detail

      • CachedQMatrix

        public CachedQMatrix​(int l,
                             double cache_size,
                             QMatrix inner)
      • CachedQMatrix

        public CachedQMatrix​(int l,
                             long size_,
                             QMatrix inner)
    • Method Detail

      • initialize

        public void initialize()
        Description copied from interface: QMatrix
        Initialize the Q Matrix.
        Specified by:
        initialize in interface QMatrix
      • next

        private final int next​(int i)
        Get the next element in the LRU chain.
        Parameters:
        i - Entry
        Returns:
        Next
      • prev

        private final int prev​(int i)
        Get the previous element in the LRU chain.
        Parameters:
        i - Entry
        Returns:
        Prev
      • link

        private final void link​(int p,
                                int n)
        Link two objects in the LRU chain.
        Parameters:
        p - Previous object
        n - Next pbject
      • selflink

        private final void selflink​(int p)
        Link an element to itself only.
        Parameters:
        p - Element to link
      • lru_insert

        private final void lru_insert​(int h)
        Insert into the last position of the LRU list.
        Parameters:
        h - Object to be inserted
      • lru_delete

        private final void lru_delete​(int h)
        Delete from the LRU list.
        Parameters:
        h - Object index to be deleted
      • discard

        private final void discard​(int h)
        Discard a cache entry.
        Parameters:
        h - entry index
      • get_data

        float[] get_data​(int h,
                         int len)
      • swap_index

        public void swap_index​(int i,
                               int j)
        Description copied from interface: QMatrix
        Reorganize the data by swapping two entries.

        This also must modify the QD array!

        Specified by:
        swap_index in interface QMatrix
        Parameters:
        i - First entry
        j - Second entry
      • get_Q

        public void get_Q​(int column,
                          int len,
                          float[] out)
        Description copied from interface: QMatrix
        Get a column of the matrix.
        Specified by:
        get_Q in interface QMatrix
        Parameters:
        column - Column number
        len - Number of entries to get
        out - Output array for similarity values
      • get_QD

        public double[] get_QD()
        Description copied from interface: QMatrix
        Get the diagonal values, as reference.
        Specified by:
        get_QD in interface QMatrix
        Returns:
        Diagonal values
      • similarity

        public double similarity​(int i,
                                 int j)
        Description copied from interface: QMatrix
        (Slow) compute the similarity (not distance) of objects i and j.

        If you need many, use QMatrix.get_Q(int, int, float[]) instead.

        Specified by:
        similarity in interface QMatrix
        Parameters:
        i - First object
        j - Second object
        Returns:
        Similarity