Class RelationUtil


  • public final class RelationUtil
    extends java.lang.Object
    Utility functions for handling database relation.
    Since:
    0.5.5
    Author:
    Erich Schubert
    • Constructor Detail

      • RelationUtil

        private RelationUtil()
        Fake constructor: do not instantiate.
    • Method Detail

      • assumeVectorField

        public static <V extends FeatureVector<?>> VectorFieldTypeInformation<V> assumeVectorField​(Relation<V> relation)
        Get the vector field type information from a relation.
        Type Parameters:
        V - Vector type
        Parameters:
        relation - relation
        Returns:
        Vector field type information
      • getNumberVectorFactory

        public static <V extends NumberVectorNumberVector.Factory<V> getNumberVectorFactory​(Relation<V> relation)
        Get the number vector factory of a database relation.
        Type Parameters:
        V - Vector type
        Parameters:
        relation - relation
        Returns:
        Vector field type information
      • dimensionality

        public static int dimensionality​(Relation<? extends SpatialComparable> relation)
        Get the dimensionality of a database relation.
        Parameters:
        relation - relation
        Returns:
        Database dimensionality
      • maxDimensionality

        public static int maxDimensionality​(Relation<? extends SpatialComparable> relation)
        Get the dimensionality of a database relation.
        Parameters:
        relation - relation
        Returns:
        Database dimensionality
      • computeMinMax

        public static double[][] computeMinMax​(Relation<? extends NumberVector> relation)
        Determines the minimum and maximum values in each dimension of all objects stored in the given database.
        Parameters:
        relation - the database storing the objects
        Returns:
        Minimum and Maximum vector for the hyperrectangle
      • relationAsMatrix

        public static double[][] relationAsMatrix​(Relation<? extends NumberVector> relation,
                                                  ArrayDBIDs ids)
        Copy a relation into a double matrix.

        This is not recommended unless you need to modify the data temporarily.

        Parameters:
        relation - Relation
        ids - IDs, with well-defined order (i.e. array)
        Returns:
        Data matrix
      • getColumnLabel

        public static <V extends SpatialComparable> java.lang.String getColumnLabel​(Relation<? extends V> rel,
                                                                                    int col)
        Get the column name or produce a generic label "Column XY".
        Type Parameters:
        V - Vector type
        Parameters:
        rel - Relation
        col - Column
        Returns:
        Label
      • relationUglyVectorCast

        public static <V extends NumberVector,​T extends NumberVectorRelation<V> relationUglyVectorCast​(Relation<T> database)
        An ugly vector type cast unavoidable in some situations due to Generics.
        Type Parameters:
        V - Base vector type
        T - Derived vector type (is actually V, too)
        Parameters:
        database - Database
        Returns:
        Database