Class ArrayRealVector

    • Constructor Detail

      • ArrayRealVector

        public ArrayRealVector​(int size)
        Construct a vector of zeroes.
        Parameters:
        size - Size of the vector.
      • ArrayRealVector

        public ArrayRealVector​(int size,
                               double preset)
        Construct a vector with preset values.
        Parameters:
        size - Size of the vector
        preset - All entries will be set with this value.
      • ArrayRealVector

        public ArrayRealVector​(double[] d)
        Construct a vector from an array, copying the input array.
        Parameters:
        d - Array.
      • ArrayRealVector

        public ArrayRealVector​(double[] d,
                               boolean copyArray)
                        throws NullArgumentException
        Create a new ArrayRealVector using the input array as the underlying data array. If an array is built specially in order to be embedded in a ArrayRealVector and not used directly, the copyArray may be set to false. This will prevent the copying and improve performance as no new array will be built and no data will be copied.
        Parameters:
        d - Data for the new vector.
        copyArray - if true, the input array will be copied, otherwise it will be referenced.
        Throws:
        NullArgumentException - if d is null.
        See Also:
        ArrayRealVector(double[])
      • ArrayRealVector

        public ArrayRealVector​(Double[] d)
        Construct a vector from an array.
        Parameters:
        d - Array of Doubles.
      • ArrayRealVector

        public ArrayRealVector​(ArrayRealVector v,
                               boolean deep)
        Construct a vector from another vector.
        Parameters:
        v - Vector to copy.
        deep - If true perform a deep copy, otherwise perform a shallow copy.
      • ArrayRealVector

        public ArrayRealVector​(ArrayRealVector v1,
                               ArrayRealVector v2)
        Construct a vector by appending one vector to another vector.
        Parameters:
        v1 - First vector (will be put in front of the new vector).
        v2 - Second vector (will be put at back of the new vector).
      • ArrayRealVector

        public ArrayRealVector​(ArrayRealVector v1,
                               RealVector v2)
        Construct a vector by appending one vector to another vector.
        Parameters:
        v1 - First vector (will be put in front of the new vector).
        v2 - Second vector (will be put at back of the new vector).
      • ArrayRealVector

        public ArrayRealVector​(RealVector v1,
                               ArrayRealVector v2)
        Construct a vector by appending one vector to another vector.
        Parameters:
        v1 - First vector (will be put in front of the new vector).
        v2 - Second vector (will be put at back of the new vector).
      • ArrayRealVector

        public ArrayRealVector​(ArrayRealVector v1,
                               double[] v2)
        Construct a vector by appending one vector to another vector.
        Parameters:
        v1 - First vector (will be put in front of the new vector).
        v2 - Second vector (will be put at back of the new vector).
      • ArrayRealVector

        public ArrayRealVector​(double[] v1,
                               ArrayRealVector v2)
        Construct a vector by appending one vector to another vector.
        Parameters:
        v1 - First vector (will be put in front of the new vector).
        v2 - Second vector (will be put at back of the new vector).
      • ArrayRealVector

        public ArrayRealVector​(double[] v1,
                               double[] v2)
        Construct a vector by appending one vector to another vector.
        Parameters:
        v1 - first vector (will be put in front of the new vector)
        v2 - second vector (will be put at back of the new vector)
    • Method Detail

      • map

        public ArrayRealVector map​(UnivariateFunction function)
        Acts as if implemented as:
          return copy().mapToSelf(function);
         
        Returns a new vector. Does not change instance data.
        Overrides:
        map in class RealVector
        Parameters:
        function - Function to apply to each entry.
        Returns:
        a new vector.
      • mapToSelf

        public ArrayRealVector mapToSelf​(UnivariateFunction function)
        Acts as if it is implemented as:
          Entry e = null;
          for(Iterator it = iterator(); it.hasNext(); e = it.next()) {
              e.setValue(function.value(e.getValue()));
          }
         
        Entries of this vector are modified in-place by this method.
        Overrides:
        mapToSelf in class RealVector
        Parameters:
        function - Function to apply to each entry.
        Returns:
        a reference to this vector.
      • mapAddToSelf

        public RealVector mapAddToSelf​(double d)
        Add a value to each entry. The instance is changed in-place.
        Overrides:
        mapAddToSelf in class RealVector
        Parameters:
        d - Value to be added to each entry.
        Returns:
        this.
      • mapSubtractToSelf

        public RealVector mapSubtractToSelf​(double d)
        Subtract a value from each entry. The instance is changed in-place.
        Overrides:
        mapSubtractToSelf in class RealVector
        Parameters:
        d - Value to be subtracted.
        Returns:
        this.
      • mapMultiplyToSelf

        public RealVector mapMultiplyToSelf​(double d)
        Multiply each entry. The instance is changed in-place.
        Overrides:
        mapMultiplyToSelf in class RealVector
        Parameters:
        d - Multiplication factor.
        Returns:
        this.
      • mapDivideToSelf

        public RealVector mapDivideToSelf​(double d)
        Divide each entry by the argument. The instance is changed in-place.
        Overrides:
        mapDivideToSelf in class RealVector
        Parameters:
        d - Value to divide by.
        Returns:
        this.
      • getDataRef

        public double[] getDataRef()
        Get a reference to the underlying data array. This method does not make a fresh copy of the underlying data.
        Returns:
        the array of entries.
      • getL1Distance

        public double getL1Distance​(RealVector v)
                             throws MathIllegalArgumentException
        Distance between two vectors.

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

        Overrides:
        getL1Distance in class RealVector
        Parameters:
        v - Vector to which distance is requested.
        Returns:
        the distance between two vectors.
        Throws:
        MathIllegalArgumentException - if v is not the same size as this vector.
      • outerProduct

        public RealMatrix outerProduct​(RealVector v)
        Compute the outer product.
        Overrides:
        outerProduct in class RealVector
        Parameters:
        v - Vector with which outer product should be computed.
        Returns:
        the matrix outer product between this instance and v.
      • getDimension

        public int getDimension()
        Returns the size of the vector.
        Specified by:
        getDimension in class RealVector
        Returns:
        the size of this vector.
      • append

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

        public ArrayRealVector append​(ArrayRealVector v)
        Construct a vector by appending a vector to this vector.
        Parameters:
        v - Vector to append to this one.
        Returns:
        a new vector.
      • append

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

        public void setSubVector​(int index,
                                 double[] v)
                          throws MathIllegalArgumentException
        Set a set of consecutive elements.
        Parameters:
        index - Index of first element to be set.
        v - Vector containing the values to set.
        Throws:
        MathIllegalArgumentException - if the index is inconsistent with the vector size.
      • set

        public void set​(double value)
        Set all elements to a single value.
        Overrides:
        set in class RealVector
        Parameters:
        value - Single value to set for all elements.
      • toArray

        public double[] toArray()
        Convert the vector to an array of doubles. The array is independent from this vector data: the elements are copied.
        Overrides:
        toArray in class RealVector
        Returns:
        an array containing a copy of the vector elements.
      • isNaN

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

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

        public boolean equals​(Object other)

        Test for the equality of two real vectors. If all coordinates of two real vectors are exactly the same, and none are NaN, the two real vectors are considered to be equal. NaN coordinates are considered to affect globally the vector and be equals to each other - i.e, if either (or all) coordinates of the real vector are equal to NaN, the real vector is equal to a vector with all NaN coordinates.

        This method must be overriden by concrete subclasses of RealVector (the current implementation throws an exception).

        Overrides:
        equals in class RealVector
        Parameters:
        other - Object to test for equality.
        Returns:
        true if two vector objects are equal, false if other is null, not an instance of RealVector, or not equal to this RealVector instance.
      • hashCode

        public int hashCode()
        . This method must be overriden by concrete subclasses of RealVector (current implementation throws an exception). All NaN values have the same hash code.
        Overrides:
        hashCode in class RealVector
      • combine

        public ArrayRealVector combine​(double a,
                                       double b,
                                       RealVector y)
                                throws MathIllegalArgumentException
        Returns a new vector representing a * this + b * y, the linear combination of this and y. Returns a new vector. Does not change instance data.
        Overrides:
        combine in class RealVector
        Parameters:
        a - Coefficient of this.
        b - Coefficient of y.
        y - Vector with which this is linearly combined.
        Returns:
        a vector containing a * this[i] + b * y[i] for all i.
        Throws:
        MathIllegalArgumentException - if y is not the same size as this vector.
      • walkInOptimizedOrder

        public double walkInOptimizedOrder​(RealVectorPreservingVisitor visitor)
        Visits (but does not alter) all entries of this vector in optimized order. The order in which the entries are visited is selected so as to lead to the most efficient implementation; it might depend on the concrete implementation of this abstract class. In this implementation, the optimized order is the default order.
        Overrides:
        walkInOptimizedOrder in class RealVector
        Parameters:
        visitor - the visitor to be used to process the entries of this vector
        Returns:
        the value returned by RealVectorPreservingVisitor.end() at the end of the walk
      • walkInOptimizedOrder

        public double walkInOptimizedOrder​(RealVectorPreservingVisitor visitor,
                                           int start,
                                           int end)
                                    throws MathIllegalArgumentException
        Visits (but does not alter) some entries of this vector in optimized order. The order in which the entries are visited is selected so as to lead to the most efficient implementation; it might depend on the concrete implementation of this abstract class. In this implementation, the optimized order is the default order.
        Overrides:
        walkInOptimizedOrder in class RealVector
        Parameters:
        visitor - visitor to be used to process the entries of this vector
        start - the index of the first entry to be visited
        end - the index of the last entry to be visited (inclusive)
        Returns:
        the value returned by RealVectorPreservingVisitor.end() at the end of the walk
        Throws:
        MathIllegalArgumentException - if end < start.
      • walkInOptimizedOrder

        public double walkInOptimizedOrder​(RealVectorChangingVisitor visitor)
        Visits (and possibly alters) all entries of this vector in optimized order. The order in which the entries are visited is selected so as to lead to the most efficient implementation; it might depend on the concrete implementation of this abstract class. In this implementation, the optimized order is the default order.
        Overrides:
        walkInOptimizedOrder in class RealVector
        Parameters:
        visitor - the visitor to be used to process the entries of this vector
        Returns:
        the value returned by RealVectorChangingVisitor.end() at the end of the walk
      • walkInOptimizedOrder

        public double walkInOptimizedOrder​(RealVectorChangingVisitor visitor,
                                           int start,
                                           int end)
                                    throws MathIllegalArgumentException
        Visits (and possibly change) some entries of this vector in optimized order. The order in which the entries are visited is selected so as to lead to the most efficient implementation; it might depend on the concrete implementation of this abstract class. In this implementation, the optimized order is the default order.
        Overrides:
        walkInOptimizedOrder in class RealVector
        Parameters:
        visitor - visitor to be used to process the entries of this vector
        start - the index of the first entry to be visited
        end - the index of the last entry to be visited (inclusive)
        Returns:
        the value returned by RealVectorChangingVisitor.end() at the end of the walk
        Throws:
        MathIllegalArgumentException - if end < start.