Class DenseAffinityMatrix

  • All Implemented Interfaces:
    AffinityMatrix

    public class DenseAffinityMatrix
    extends java.lang.Object
    implements AffinityMatrix
    Dense affinity matrix storage. TODO: it is likely faster to store this in a 1-d array when possible.
    Since:
    0.7.5
    Author:
    Erich Schubert
    • Field Summary

      Fields 
      Modifier and Type Field Description
      (package private) ArrayDBIDs ids
      Indexed objects.
      (package private) double[][] pij
      Dense storage.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      double get​(int i, int j)
      Get an entry by absolute position.
      int iter​(int x)
      Iterator over non-zero features only.
      int iterAdvance​(int x, int iter)
      Advance the iterator to the next position.
      DBIDArrayIter iterDBIDs()
      Array iterator over the stored objects.
      int iterDim​(int x, int iter)
      Get the dimension an iterator points to.
      boolean iterValid​(int x, int iter)
      Test the iterator position for validity.
      double iterValue​(int x, int iter)
      Get the value an iterator points to.
      void scale​(double d)
      Scale the whole matrix with a constant factor d.
      int size()
      Number of rows.
      • Methods inherited from class java.lang.Object

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

      • pij

        double[][] pij
        Dense storage.
    • Constructor Detail

      • DenseAffinityMatrix

        public DenseAffinityMatrix​(double[][] affinities,
                                   ArrayDBIDs ids)
        Constructor.
        Parameters:
        affinities - Raw affinity matrix
        ids - Indexed objects
    • Method Detail

      • get

        public double get​(int i,
                          int j)
        Description copied from interface: AffinityMatrix
        Get an entry by absolute position. Note: this may be expensive on sparse matrixes.
        Specified by:
        get in interface AffinityMatrix
        Parameters:
        i - Row
        j - Column
        Returns:
        Entry
      • scale

        public void scale​(double d)
        Description copied from interface: AffinityMatrix
        Scale the whole matrix with a constant factor d. This is used to add/remove early exaggeration of tSNE.
        Specified by:
        scale in interface AffinityMatrix
        Parameters:
        d - Scaling factor.
      • iter

        public int iter​(int x)
        Description copied from interface: AffinityMatrix
        Iterator over non-zero features only. Note: depending on the underlying implementation, this may or may not be the dimension. Use AffinityMatrix.iterDim(int, int) to get the actual dimension. In fact, usually this will be the ith non-zero value, assuming an array representation. Think of this number as an iterator. But for efficiency, it has a primitive type, so it does not require garbage collection. With Java 10 value types, we will likely be able to make this both type-safe and highly efficient again. Intended usage:
         
         for (int iter = v.iter(x); v.iterValid(x, iter); iter = v.iterAdvance(x, iter)) {
           final int dim = v.iterDim(x, iter);
           final int val = v.iterValue(x, iter);
         }
         
         
        Important: you need to use the return value of iterAdvance for the next iteration, or you will have an endless loop.
        Specified by:
        iter in interface AffinityMatrix
        Parameters:
        x - Point to get the neighbors for
        Returns:
        Identifier for the first non-zero dimension, not necessarily the dimension!
      • iterAdvance

        public int iterAdvance​(int x,
                               int iter)
        Description copied from interface: AffinityMatrix
        Advance the iterator to the next position.
        Specified by:
        iterAdvance in interface AffinityMatrix
        iter - Previous iterator position
        Returns:
        Next iterator position
      • iterDim

        public int iterDim​(int x,
                           int iter)
        Description copied from interface: AffinityMatrix
        Get the dimension an iterator points to.
        Specified by:
        iterDim in interface AffinityMatrix
        iter - Iterator position
        Returns:
        Dimension the iterator refers to
      • iterValue

        public double iterValue​(int x,
                                int iter)
        Description copied from interface: AffinityMatrix
        Get the value an iterator points to.
        Specified by:
        iterValue in interface AffinityMatrix
        iter - Iterator position
        Returns:
        Dimension the iterator refers to
      • iterValid

        public boolean iterValid​(int x,
                                 int iter)
        Description copied from interface: AffinityMatrix
        Test the iterator position for validity.
        Specified by:
        iterValid in interface AffinityMatrix
        iter - Iterator position
        Returns:
        true when it refers to a valid position.