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

Class ScaledVector

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


    public class ScaledVector
    extends Vec
    A wrapper for a vector that represents the vector multiplied by a scalar constant. This allows for using and altering the value multiplied by a constant factor quickly, especially when the multiplicative factor must be changed often. Mutable operations will alter the underling vector, and all operations will automatically be scaled on a per element basis as needed.

    If a point is reached where the multiplicative constant will be infrequently modified relative to the use of the vector, it may be more efficient to use the original vector scaled appropriately. This can be done by first calling embedScale() and then calling getBase() .

    When the multiplicative constant is set to zero, the underlying base vector is zeroed out and the constant reset to 1.
    See Also:
    Serialized Form
    • Constructor Summary

      Constructors 
      Constructor and Description
      ScaledVector(double scale, Vec base)
      Creates a new scaled vector
      ScaledVector(Vec vec)
      Creates a new scaled vector with a default scale of 1.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method and Description
      double[] arrayCopy()
      Creates a new array that contains all the values of this vector in the appropriate indices
      Vec clone() 
      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.
      void embedScale()
      Embeds the current scale factor into the base vector, so that the current scale factor can be set to 1.
      double get(int index)
      Gets the value stored at a specific index in the vector
      Vec getBase()
      Returns the base vector that is being scaled
      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.
      double getScale()
      Returns the current scale in use
      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
      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 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.
      int nnz()
      Computes the number of non zero values in this vector
      double pNorm(double p)
      Returns the p-norm of this vector.
      void set(int index, double val)
      Sets the value stored at a specified index in the vector
      void setScale(double scale)
      Explicitly sets the current scale to the given value

      NOTE: If the scale is set to zero, the underlying base vector will be zeroed out, and the scale set to 1.
      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
      double sum()
      Computes the sum of the values in this vector
      void zeroOut()
      Zeroes out all values in this vector

      This method should be overloaded for a serious implementation.
      • Methods inherited from class java.lang.Object

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

        forEach, spliterator
    • Constructor Detail

      • ScaledVector

        public ScaledVector(double scale,
                            Vec base)
        Creates a new scaled vector
        Parameters:
        scale - the initial scaling constant
        base - the vector to implicitly scale
      • ScaledVector

        public ScaledVector(Vec vec)
        Creates a new scaled vector with a default scale of 1.
        Parameters:
        vec - the vector to implicitly scale
    • Method Detail

      • getScale

        public double getScale()
        Returns the current scale in use
        Returns:
        the current scale in use
      • setScale

        public void setScale(double scale)
        Explicitly sets the current scale to the given value

        NOTE: If the scale is set to zero, the underlying base vector will be zeroed out, and the scale set to 1.
        Parameters:
        scale - the new multiplicative constant to set for the scale
      • getBase

        public Vec getBase()
        Returns the base vector that is being scaled
        Returns:
        the base vector that is being scaled
      • embedScale

        public void embedScale()
        Embeds the current scale factor into the base vector, so that the current scale factor can be set to 1.
      • 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
      • 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
      • 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
      • 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(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
      • 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
      • 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
      • 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.
      • clone

        public Vec clone()
        Specified by:
        clone in class Vec
      • 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
      • 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
      • zeroOut

        public void zeroOut()
        Description copied from class: Vec
        Zeroes out all values in this vector

        This method should be overloaded for a serious implementation.
        Overrides:
        zeroOut in class Vec
      • 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
      • 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

DataMelt 3.0 © DataMelt by jWork.ORG

You see the box below because you did not login.