Class OpenMapRealVector

    • Field Detail

      • DEFAULT_ZERO_TOLERANCE

        public static final double DEFAULT_ZERO_TOLERANCE
        Default Tolerance for having a value considered zero.
        See Also:
        Constant Field Values
    • Constructor Detail

      • OpenMapRealVector

        public OpenMapRealVector​(int dimension)
        Construct a (dimension)-length vector of zeros.
        Parameters:
        dimension - size of the vector
      • OpenMapRealVector

        public OpenMapRealVector​(int dimension,
                                 double epsilon)
        Construct a (dimension)-length vector of zeros, specifying zero tolerance.
        Parameters:
        dimension - Size of the vector
        epsilon - The tolerance for having a value considered zero
      • OpenMapRealVector

        public OpenMapRealVector​(int dimension,
                                 int expectedSize)
        Build a vector with known the sparseness (for advanced use only).
        Parameters:
        dimension - The size of the vector
        expectedSize - The expected number of non-zero entries
      • OpenMapRealVector

        public OpenMapRealVector​(int dimension,
                                 int expectedSize,
                                 double epsilon)
        Build a vector with known the sparseness and zero tolerance setting (for advanced use only).
        Parameters:
        dimension - The size of the vector
        expectedSize - The expected number of non-zero entries
        epsilon - The tolerance for having a value considered zero
      • OpenMapRealVector

        public OpenMapRealVector​(double[] values)
        Create from a double array. Only non-zero entries will be stored
        Parameters:
        values - The set of values to create from
      • OpenMapRealVector

        public OpenMapRealVector​(double[] values,
                                 double epsilon)
        Create from a double array, specifying zero tolerance. Only non-zero entries will be stored
        Parameters:
        values - The set of values to create from
        epsilon - The tolerance for having a value considered zero
      • OpenMapRealVector

        public OpenMapRealVector​(java.lang.Double[] values)
        Create from a Double array. Only non-zero entries will be stored
        Parameters:
        values - The set of values to create from
      • OpenMapRealVector

        public OpenMapRealVector​(java.lang.Double[] values,
                                 double epsilon)
        Create from a Double array. Only non-zero entries will be stored
        Parameters:
        values - The set of values to create from
        epsilon - The tolerance for having a value considered zero
      • OpenMapRealVector

        public OpenMapRealVector​(OpenMapRealVector v)
        Copy constructor.
        Parameters:
        v - The instance to copy from
      • OpenMapRealVector

        public OpenMapRealVector​(RealVector v)
        Generic copy constructor.
        Parameters:
        v - The instance to copy from
    • Method Detail

      • add

        public OpenMapRealVector add​(OpenMapRealVector v)
                              throws java.lang.IllegalArgumentException
        Optimized method to add two OpenMapRealVectors. Copies the larger vector, iterates over the smaller.
        Parameters:
        v - Vector to add with
        Returns:
        The sum of this with v
        Throws:
        java.lang.IllegalArgumentException - If the dimensions don't match
      • append

        public OpenMapRealVector append​(OpenMapRealVector v)
        Optimized method to append a OpenMapRealVector.
        Parameters:
        v - vector to append
        Returns:
        The result of appending v to self
      • append

        public OpenMapRealVector append​(RealVector v)
        Construct a vector by appending a vector to this vector.
        Specified by:
        append in interface RealVector
        Parameters:
        v - vector to append to this one.
        Returns:
        a new vector
      • append

        public OpenMapRealVector append​(double d)
        Construct a vector by appending a double to this vector.
        Specified by:
        append in interface RealVector
        Parameters:
        d - double to append.
        Returns:
        a new vector
      • append

        public OpenMapRealVector append​(double[] a)
        Construct a vector by appending a double array to this vector.
        Specified by:
        append in interface RealVector
        Parameters:
        a - double array to append.
        Returns:
        a new vector
      • dotProduct

        public double dotProduct​(OpenMapRealVector v)
                          throws java.lang.IllegalArgumentException
        Optimized method to compute the dot product with an OpenMapRealVector. Iterates over the smaller of the two.
        Parameters:
        v - The vector to compute the dot product with
        Returns:
        The dot product of this and v
        Throws:
        java.lang.IllegalArgumentException - If the dimensions don't match
      • dotProduct

        public double dotProduct​(RealVector v)
                          throws java.lang.IllegalArgumentException
        Compute the dot product.
        Specified by:
        dotProduct in interface RealVector
        Overrides:
        dotProduct in class AbstractRealVector
        Parameters:
        v - vector with which dot product should be computed
        Returns:
        the scalar dot product between instance and v
        Throws:
        DimensionMismatchException - if v is not the same size as this vector.
        java.lang.IllegalArgumentException
      • ebeDivide

        public OpenMapRealVector ebeDivide​(RealVector v)
                                    throws java.lang.IllegalArgumentException
        Element-by-element division.
        Specified by:
        ebeDivide in interface RealVector
        Parameters:
        v - vector by which instance elements must be divided
        Returns:
        a vector containing this[i] / v[i] for all i
        Throws:
        DimensionMismatchException - if v is not the same size as this vector.
        java.lang.IllegalArgumentException
      • ebeDivide

        public OpenMapRealVector ebeDivide​(double[] v)
                                    throws java.lang.IllegalArgumentException
        Element-by-element division.
        Specified by:
        ebeDivide in interface RealVector
        Overrides:
        ebeDivide in class AbstractRealVector
        Parameters:
        v - vector by which instance elements must be divided
        Returns:
        a vector containing this[i] / v[i] for all i
        Throws:
        DimensionMismatchException - if v is not the same size as this vector.
        java.lang.IllegalArgumentException
      • ebeMultiply

        public OpenMapRealVector ebeMultiply​(RealVector v)
                                      throws java.lang.IllegalArgumentException
        Element-by-element multiplication.
        Specified by:
        ebeMultiply in interface RealVector
        Parameters:
        v - vector by which instance elements must be multiplied
        Returns:
        a vector containing this[i] * v[i] for all i
        Throws:
        DimensionMismatchException - if v is not the same size as this vector.
        java.lang.IllegalArgumentException
      • ebeMultiply

        public OpenMapRealVector ebeMultiply​(double[] v)
                                      throws java.lang.IllegalArgumentException
        Element-by-element multiplication.
        Specified by:
        ebeMultiply in interface RealVector
        Overrides:
        ebeMultiply in class AbstractRealVector
        Parameters:
        v - vector by which instance elements must be multiplied
        Returns:
        a vector containing this[i] * v[i] for all i
        Throws:
        DimensionMismatchException - if v is not the same size as this vector.
        java.lang.IllegalArgumentException
      • getDimension

        public int getDimension()
        Returns the size of the vector.
        Specified by:
        getDimension in interface RealVector
        Returns:
        size
      • getDistance

        public double getDistance​(OpenMapRealVector v)
                           throws java.lang.IllegalArgumentException
        Optimized method to compute distance.
        Parameters:
        v - The vector to compute distance to
        Returns:
        The distance from this and v
        Throws:
        java.lang.IllegalArgumentException - If the dimensions don't match
      • getL1Distance

        public double getL1Distance​(OpenMapRealVector v)
        Distance between two vectors.

        This method computes the distance consistent with L1 norm, i.e. the sum of the absolute values of elements differences.

        Parameters:
        v - vector to which distance is requested
        Returns:
        distance between two vectors.
      • isInfinite

        public boolean isInfinite()
        Check whether any coordinate of this vector is infinite and none are NaN.
        Specified by:
        isInfinite in interface RealVector
        Returns:
        true if any coordinate of this vector is infinite and none are NaN, false otherwise.
      • isNaN

        public boolean isNaN()
        Check whether any coordinate of this vector is NaN.
        Specified by:
        isNaN in interface RealVector
        Returns:
        true if any coordinate of this vector is NaN, false otherwise.
      • outerProduct

        public RealMatrix outerProduct​(double[] v)
                                throws java.lang.IllegalArgumentException
        Compute the outer product.
        Specified by:
        outerProduct in interface RealVector
        Overrides:
        outerProduct in class AbstractRealVector
        Parameters:
        v - vector with which outer product should be computed
        Returns:
        the square matrix outer product between instance and v
        Throws:
        DimensionMismatchException - if v is not the same size as this vector.
        java.lang.IllegalArgumentException
      • projection

        public RealVector projection​(RealVector v)
                              throws java.lang.IllegalArgumentException
        Find the orthogonal projection of this vector onto another vector.
        Specified by:
        projection in interface RealVector
        Parameters:
        v - vector onto which instance must be projected
        Returns:
        projection of the instance onto v
        Throws:
        DimensionMismatchException - if v is not the same size as this vector.
        java.lang.IllegalArgumentException
      • projection

        public OpenMapRealVector projection​(double[] v)
                                     throws java.lang.IllegalArgumentException
        Find the orthogonal projection of this vector onto another vector.
        Specified by:
        projection in interface RealVector
        Overrides:
        projection in class AbstractRealVector
        Parameters:
        v - vector onto which instance must be projected
        Returns:
        projection of the instance onto v
        Throws:
        DimensionMismatchException - if v is not the same size as this vector.
        java.lang.IllegalArgumentException
      • set

        public void set​(double value)
        Set all elements to a single value.
        Specified by:
        set in interface RealVector
        Overrides:
        set in class AbstractRealVector
        Parameters:
        value - single value to set for all elements
      • subtract

        public OpenMapRealVector subtract​(OpenMapRealVector v)
                                   throws java.lang.IllegalArgumentException
        Optimized method to subtract OpenMapRealVectors.
        Parameters:
        v - The vector to subtract from this
        Returns:
        The difference of this and v
        Throws:
        java.lang.IllegalArgumentException - If the dimensions don't match
      • unitize

        public void unitize()
        Converts this vector into a unit vector.

        The instance itself is changed by this method.

        Specified by:
        unitize in interface RealVector
        Overrides:
        unitize in class AbstractRealVector
      • toArray

        public double[] toArray()
        Convert the vector to a double array.

        The array is independent from vector data, it's elements are copied.

        Specified by:
        toArray in interface RealVector
        Overrides:
        toArray in class AbstractRealVector
        Returns:
        array containing a copy of vector elements
      • hashCode

        public int hashCode()

        Implementation Note: This works on exact values, and as a result it is possible for a.subtract(b) to be the zero vector, while a.hashCode() != b.hashCode().

        Overrides:
        hashCode in class java.lang.Object
      • equals

        public boolean equals​(java.lang.Object obj)

        Implementation Note: This performs an exact comparison, and as a result it is possible for a.subtract(b} to be the zero vector, while a.equals(b) == false.

        Overrides:
        equals in class java.lang.Object
      • getSparcity

        @Deprecated
        public double getSparcity()
        Deprecated.
        as of 2.2 replaced by the correctly spelled getSparsity()
        Returns:
        the percentage of none zero elements as a decimal percent.
      • getSparsity

        public double getSparsity()
        Returns:
        the percentage of none zero elements as a decimal percent.
        Since:
        2.2
      • sparseIterator

        public java.util.Iterator<RealVector.Entry> sparseIterator()
        Specialized implementations may choose to not iterate over all dimensions, either because those values are unset, or are equal to defaultValue(), or are small enough to be ignored for the purposes of iteration. No guarantees are made about order of iteration. In dense implementations, this method will often delegate to RealVector.iterator().
        Specified by:
        sparseIterator in interface RealVector
        Overrides:
        sparseIterator in class AbstractRealVector
        Returns:
        a sparse iterator