Documentation of 'jsat.linear.VecPaired' Java class
VecPaired
jsat.linear

Class VecPaired<V extends Vec,P>

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, java.lang.Iterable<IndexValue>
    Direct Known Subclasses:
    VecPairedComparable


    public class VecPaired<V extends Vec,P>
    extends Vec
    This data structure allows to wrap a Vector so that it is associated with some object time. Note, that operations that return a vector will not be a Paired Vector, as there is no reason to associate a different vector with this vector's pair.
    See Also:
    Serialized Form
    • Constructor Summary

      Constructors 
      Constructor and Description
      VecPaired(V v, P p) 
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method and Description
      Vec add(double c)
      Returns a new vector that is the result of this + c
      Vec add(Vec b)
      Returns a new vector that is the result of this + b
      double[] arrayCopy()
      Creates a new array that contains all the values of this vector in the appropriate indices
      Vec clone() 
      Vec divide(double c)
      Returns a new vector that is the result of this / c
      double dot(Vec v)
      Computes the dot product between two vectors, which is equivalent to
      Σ thisi*vi

      This method should be overloaded for a serious implementation.
      boolean equals(java.lang.Object obj) 
      boolean equals(java.lang.Object obj, double range) 
      static Vec extractTrueVec(Vec b)
      This method is used assuming multiple VecPaired are used together.
      double get(int index)
      Gets the value stored at a specific index in the vector
      java.util.Iterator<IndexValue> getNonZeroIterator(int start)
      Returns an iterator that will go over the non zero values starting from the specified index in the given vector.
      P getPair() 
      V getVector() 
      int hashCode()
      Provides a hashcode for Vectors.
      boolean isSparse()
      Indicates whether or not this vector is optimized for sparce computation, meaning that most values in the vector are zero - and considered implicit.
      double kurtosis()
      Computes the kurtosis of this vector, which is the 4th moment.
      int length()
      Returns the length of this vector
      double max()
      Returns the maximum value stored in this vector
      double mean()
      Computes the mean value of all values stored in this vector
      double median()
      Returns the median value in this vector
      double min()
      Returns the minimum value stored in this vector
      Vec multiply(double c)
      Returns a new vector that is the result of this * c
      void multiply(double c, Matrix A, Vec b)
      If this is vector a, this this computes b = b + c aT*A
      void mutableAdd(double c)
      Alters this vector such that this = this + c

      This method should be overloaded for a serious implementation.
      void mutableAdd(double c, Vec b)
      Alters this vector such that this = this + c * b

      This method should be overloaded for a serious implementation.
      void mutableAdd(Vec b)
      Alters this vector such that this = this + b
      void mutableDivide(double c)
      Mutates this /= c

      This method should be overloaded for a serious implementation.
      void mutableMultiply(double c)
      Mutates this *= c

      This method should be overloaded for a serious implementation.
      void mutablePairwiseDivide(Vec b)
      Mutates this by dividing each value by the value in b that has the same index

      This method should be overloaded for a serious implementation.
      void mutablePairwiseMultiply(Vec b)
      Mutates this by multiplying each value by the value in b that has the same index.
      void mutableSubtract(Vec b)
      Alters this vector such that this = this - b
      int nnz()
      Computes the number of non zero values in this vector
      void normalize()
      Mutates this vector to be normalized by the L2 norm
      Vec normalized()
      Returns a new vector that is the result of normalizing this vector by the L2 norm
      Vec pairwiseDivide(Vec b)
      Returns a new vector that is the result of dividing each value in this by the value in the same index in b
      Vec pairwiseMultiply(Vec b)
      Returns a new vector that is the result of multiplying each value in this by its corresponding value in b
      double pNorm(double p)
      Returns the p-norm of this vector.
      double pNormDist(double p, Vec y)
      Returns the p-norm distance between this and another vector y.
      void set(int index, double val)
      Sets the value stored at a specified index in the vector
      void setPair(P pair) 
      void setVector(V vector) 
      double skewness()
      Computes the skewness of this vector, which is the 3rd moment.
      Vec sortedCopy()
      Returns a copy of this array with the values moved around so that they are in sorted order
      double standardDeviation()
      Computes the standard deviation of the values in this vector
      Vec subtract(Vec b)
      Returns a new vector that is the result of this - b
      double sum()
      Computes the sum of the values in this vector
      java.lang.String toString() 
      double variance()
      Computes the variance of the values in this vector, which is Vec.standardDeviation()2
      static <V extends Vec,P extends java.lang.Comparable<P>>
      java.util.Comparator<VecPaired<V,P>>
      vecPairedComparator() 
      • Methods inherited from class java.lang.Object

        getClass, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface java.lang.Iterable

        forEach, spliterator
    • Constructor Detail

      • VecPaired

        public VecPaired(V v,
                         P p)
    • Method Detail

      • getPair

        public P getPair()
      • setPair

        public void setPair(P pair)
      • getVector

        public V getVector()
      • setVector

        public void setVector(V vector)
      • length

        public int length()
        Description copied from class: Vec
        Returns the length of this vector
        Specified by:
        length in class Vec
        Returns:
        the length of this vector
      • nnz

        public int nnz()
        Description copied from class: Vec
        Computes the number of non zero values in this vector
        Overrides:
        nnz in class Vec
        Returns:
        the number of non zero values stored
      • get

        public double get(int index)
        Description copied from class: Vec
        Gets the value stored at a specific index in the vector
        Specified by:
        get in class Vec
        Parameters:
        index - the index to access
        Returns:
        the double value in the vector
      • set

        public void set(int index,
                        double val)
        Description copied from class: Vec
        Sets the value stored at a specified index in the vector
        Specified by:
        set in class Vec
        Parameters:
        index - the index to access
        val - the value to store in the index
      • add

        public Vec add(double c)
        Description copied from class: Vec
        Returns a new vector that is the result of this + c
        Overrides:
        add in class Vec
        Parameters:
        c - the constant to add
        Returns:
        the result of adding c to this
      • add

        public Vec add(Vec b)
        Description copied from class: Vec
        Returns a new vector that is the result of this + b
        Overrides:
        add in class Vec
        Parameters:
        b - the vector to add
        Returns:
        the result of b + this
      • subtract

        public Vec subtract(Vec b)
        Description copied from class: Vec
        Returns a new vector that is the result of this - b
        Overrides:
        subtract in class Vec
        Parameters:
        b - the vector to subtract from this
        Returns:
        the result of this - b
      • pairwiseMultiply

        public Vec pairwiseMultiply(Vec b)
        Description copied from class: Vec
        Returns a new vector that is the result of multiplying each value in this by its corresponding value in b
        Overrides:
        pairwiseMultiply in class Vec
        Parameters:
        b - the vector to pairwise multiply by
        Returns:
        the result of the pairwise multiplication of b onto the values of this
      • multiply

        public Vec multiply(double c)
        Description copied from class: Vec
        Returns a new vector that is the result of this * c
        Overrides:
        multiply in class Vec
        Parameters:
        c - the constant to multiply by
        Returns:
        the result of this * c
      • multiply

        public void multiply(double c,
                             Matrix A,
                             Vec b)
        Description copied from class: Vec
        If this is vector a, this this computes b = b + c aT*A
        Overrides:
        multiply in class Vec
        Parameters:
        c - the constant factor to multiply by
        A - the matrix to multiple by
        b - the vector to mutate by adding the result to
      • pairwiseDivide

        public Vec pairwiseDivide(Vec b)
        Description copied from class: Vec
        Returns a new vector that is the result of dividing each value in this by the value in the same index in b
        Overrides:
        pairwiseDivide in class Vec
        Parameters:
        b - the vector to pairwise divide by
        Returns:
        the result of pairwise division of this by b
      • divide

        public Vec divide(double c)
        Description copied from class: Vec
        Returns a new vector that is the result of this / c
        Overrides:
        divide in class Vec
        Parameters:
        c - the constant to divide by
        Returns:
        the result of this / c
      • mutableAdd

        public void mutableAdd(double c)
        Description copied from class: Vec
        Alters this vector such that this = this + c

        This method should be overloaded for a serious implementation.
        Overrides:
        mutableAdd in class Vec
        Parameters:
        c - a scalar constant to add to each value in this vector
      • mutableAdd

        public void mutableAdd(Vec b)
        Description copied from class: Vec
        Alters this vector such that this = this + b
        Overrides:
        mutableAdd in class Vec
        Parameters:
        b - the vector to add to this
      • mutableSubtract

        public void mutableSubtract(Vec b)
        Description copied from class: Vec
        Alters this vector such that this = this - b
        Overrides:
        mutableSubtract in class Vec
        Parameters:
        b - the vector to subtract from this
      • mutablePairwiseMultiply

        public void mutablePairwiseMultiply(Vec b)
        Description copied from class: Vec
        Mutates this by multiplying each value by the value in b that has the same index.

        This method should be overloaded for a serious implementation.
        Overrides:
        mutablePairwiseMultiply in class Vec
        Parameters:
        b - the vector to pairwise multiply by
      • mutableMultiply

        public void mutableMultiply(double c)
        Description copied from class: Vec
        Mutates this *= c

        This method should be overloaded for a serious implementation.
        Overrides:
        mutableMultiply in class Vec
        Parameters:
        c - the constant to multiply by
      • mutablePairwiseDivide

        public void mutablePairwiseDivide(Vec b)
        Description copied from class: Vec
        Mutates this by dividing each value by the value in b that has the same index

        This method should be overloaded for a serious implementation.
        Overrides:
        mutablePairwiseDivide in class Vec
        Parameters:
        b - the vector to pairwise divide by
      • mutableDivide

        public void mutableDivide(double c)
        Description copied from class: Vec
        Mutates this /= c

        This method should be overloaded for a serious implementation.
        Overrides:
        mutableDivide in class Vec
        Parameters:
        c - the constant to divide by
      • sortedCopy

        public Vec sortedCopy()
        Description copied from class: Vec
        Returns a copy of this array with the values moved around so that they are in sorted order
        Overrides:
        sortedCopy in class Vec
        Returns:
        a new array in sorted order
      • min

        public double min()
        Description copied from class: Vec
        Returns the minimum value stored in this vector
        Overrides:
        min in class Vec
        Returns:
        the minimum value in this vector
      • max

        public double max()
        Description copied from class: Vec
        Returns the maximum value stored in this vector
        Overrides:
        max in class Vec
        Returns:
        the maximum value in this vector
      • sum

        public double sum()
        Description copied from class: Vec
        Computes the sum of the values in this vector
        Overrides:
        sum in class Vec
        Returns:
        the sum of this vector's values
      • mean

        public double mean()
        Description copied from class: Vec
        Computes the mean value of all values stored in this vector
        Overrides:
        mean in class Vec
        Returns:
        the mean value
      • standardDeviation

        public double standardDeviation()
        Description copied from class: Vec
        Computes the standard deviation of the values in this vector
        Overrides:
        standardDeviation in class Vec
        Returns:
        the standard deviation
      • variance

        public double variance()
        Description copied from class: Vec
        Computes the variance of the values in this vector, which is Vec.standardDeviation()2
        Overrides:
        variance in class Vec
        Returns:
        the variance
      • median

        public double median()
        Description copied from class: Vec
        Returns the median value in this vector
        Overrides:
        median in class Vec
        Returns:
        the median
      • skewness

        public double skewness()
        Description copied from class: Vec
        Computes the skewness of this vector, which is the 3rd moment.
        Overrides:
        skewness in class Vec
        Returns:
        the skewness
      • kurtosis

        public double kurtosis()
        Description copied from class: Vec
        Computes the kurtosis of this vector, which is the 4th moment.
        Overrides:
        kurtosis in class Vec
        Returns:
        the kurtosis
      • clone

        public Vec clone()
        Specified by:
        clone in class Vec
      • normalized

        public Vec normalized()
        Description copied from class: Vec
        Returns a new vector that is the result of normalizing this vector by the L2 norm
        Overrides:
        normalized in class Vec
        Returns:
        a normalized version of this vector
      • normalize

        public void normalize()
        Description copied from class: Vec
        Mutates this vector to be normalized by the L2 norm
        Overrides:
        normalize in class Vec
      • pNormDist

        public double pNormDist(double p,
                                Vec y)
        Description copied from class: Vec
        Returns the p-norm distance between this and another vector y.
        Overrides:
        pNormDist in class Vec
        Parameters:
        p - the distance type. 2 is the common value
        y - the other vector to compare against
        Returns:
        the p-norm distance
      • pNorm

        public double pNorm(double p)
        Description copied from class: Vec
        Returns the p-norm of this vector.
        Overrides:
        pNorm in class Vec
        Parameters:
        p - the norm type. 2 is a common value
        Returns:
        the p-norm of this vector
      • dot

        public double dot(Vec v)
        Description copied from class: Vec
        Computes the dot product between two vectors, which is equivalent to
        Σ thisi*vi

        This method should be overloaded for a serious implementation.
        Overrides:
        dot in class Vec
        Parameters:
        v - the other vector
        Returns:
        the dot product of this vector and another
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class Vec
      • equals

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

        public boolean equals(java.lang.Object obj,
                              double range)
        Overrides:
        equals in class Vec
      • arrayCopy

        public double[] arrayCopy()
        Description copied from class: Vec
        Creates a new array that contains all the values of this vector in the appropriate indices
        Overrides:
        arrayCopy in class Vec
        Returns:
        a new array that is a copy of this vector
      • mutableAdd

        public void mutableAdd(double c,
                               Vec b)
        Description copied from class: Vec
        Alters this vector such that this = this + c * b

        This method should be overloaded for a serious implementation.
        Overrides:
        mutableAdd in class Vec
        Parameters:
        c - a scalar constant
        b - the vector to add to this
      • getNonZeroIterator

        public java.util.Iterator<IndexValue> getNonZeroIterator(int start)
        Description copied from class: Vec
        Returns an iterator that will go over the non zero values starting from the specified index in the given vector. The iterator does not support the Iterator.remove() method.

        This method should be overloaded for a serious implementation.
        Overrides:
        getNonZeroIterator in class Vec
        Parameters:
        start - the first index (inclusive) to start returning non-zero values from
        Returns:
        an iterator for the non zero index value pairs
      • extractTrueVec

        public static Vec extractTrueVec(Vec b)
        This method is used assuming multiple VecPaired are used together. The implementation of the vector may have logic to handle the case that the other vector is of the same type. This will go through every layer of VecPaired to return the final base vector.
        Parameters:
        b - a Vec, that may or may not be an instance of VecPaired
        Returns:
        the final Vec backing b, which may be b itself.
      • vecPairedComparator

        public static <V extends Vec,P extends java.lang.Comparable<P>> java.util.Comparator<VecPaired<V,P>> vecPairedComparator()
      • hashCode

        public int hashCode()
        Description copied from class: Vec
        Provides a hashcode for Vectors. All vector implementations should return the same result for cases when Vec.equals(java.lang.Object) returns true. Below is the code used for this class

        int result = 1;

        for (int i = 0; i < length(); i++)
        {
        double val = get(i);
        if(val != 0)
        {
        long bits = Double.doubleToLongBits(val);
        result = 31 * result + (int)(bits ^ (bits >>> 32));
        result = 31 * result + i;
        }
        }

        return 31* result + length();

        Overrides:
        hashCode in class Vec
        Returns:
        the hash code for a vector
      • isSparse

        public boolean isSparse()
        Description copied from class: Vec
        Indicates whether or not this vector is optimized for sparce computation, meaning that most values in the vector are zero - and considered implicit. Only non-zero values are stored.
        Specified by:
        isSparse in class Vec
        Returns:
        true if the vector is sparce, false otherwise.

DataMelt 3.0 © DataMelt by jWork.ORG

You see the box below because you did not login.