Class FileBasedSparseDoubleDistance

  • All Implemented Interfaces:
    DBIDDistance, DBIDRangeDistance, Distance<DBID>

    public class FileBasedSparseDoubleDistance
    extends AbstractDBIDRangeDistance
    Distance function that is based on double distances given by a distance matrix of an external ASCII file.

    Note: parsing an ASCII file is rather expensive.

    See AsciiDistanceParser for the default input format.

    TODO: use a double[] instead of the hash map?

    Since:
    0.1
    Author:
    Elke Achtert, Erich Schubert
    • Field Detail

      • LOG

        private static final Logging LOG
        Class logger.
      • cache

        private it.unimi.dsi.fastutil.longs.Long2DoubleOpenHashMap cache
        The distance cache
      • matrixfile

        private java.net.URI matrixfile
        Input file of distance matrix
      • min

        private int min
        Minimum and maximum IDs seen.
      • max

        private int max
        Minimum and maximum IDs seen.
      • defaultDistance

        protected double defaultDistance
        Distance to return when not defined otherwise.
    • Constructor Detail

      • FileBasedSparseDoubleDistance

        public FileBasedSparseDoubleDistance​(DistanceParser parser,
                                             java.net.URI matrixfile,
                                             double defaultDistance)
        Constructor.
        Parameters:
        parser - Parser
        matrixfile - input file
        defaultDistance - Default distance (when undefined)
    • Method Detail

      • distance

        public double distance​(int i1,
                               int i2)
        Description copied from interface: DBIDRangeDistance
        Compute the distance for two integer offsets.
        Parameters:
        i1 - First offset
        i2 - Second offset
        Returns:
        Distance
      • loadCache

        protected void loadCache​(int size,
                                 java.io.InputStream in)
        Fill cache from an input stream.
        Parameters:
        size - Expected size
        in - Input stream
      • makeKey

        protected static final long makeKey​(int i1,
                                            int i2)
        Combine two integer ids into a long value.
        Parameters:
        i1 - First id
        i2 - Second id
        Returns:
        Combined value
      • checkRange

        public void checkRange​(DBIDRange range)
        Description copied from interface: DBIDRangeDistance
        Validate the range of DBIDs to use. This will log a warning if an obvious mismatch was found.
        Parameters:
        range - DBID range
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object