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

Class ConstantVector

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


    public class ConstantVector
    extends Vec
    This class provides a simple utility to represent an immutable vector where all values in the vector must have the same constant value. The standard mutable methods can not alter this vector. However, the length and constant value can be altered by calling the setLength(int) and setConstant(double) values respectively. The Constant Vector representation uses only constant space.

    This class can be useful in providing a generalized way to handle multiple unique values or a constant value. For example, a separate regularization constant could be used for every feature in a learning problem. Instead of writing code to handle multiple values separately from a single value, a ConstantVector can be used so that the constant value case can be an efficient call to the multiple value version of the code.
    See Also:
    Serialized Form
    • Constructor Detail

      • ConstantVector

        public ConstantVector(double constant,
                              int length)
        Creates a new vector where all values have a single implicit value
        Parameters:
        constant - the constant to use as the single value for all indices
        length - the length of this vector
    • Method Detail

      • setConstant

        public void setConstant(double constant)
        Sets the constant value that will be used as the value stored in every index of this vector.
        Parameters:
        constant - the constant value to represent as a vector
      • setLength

        public void setLength(int length)
        Sets the length of this vector. The length must be a non zero value
        Parameters:
        length - the new length for this 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
      • 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
      • 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
      • 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
      • 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
      • 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
      • 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
      • median

        public double median()
        Description copied from class: Vec
        Returns the median value in this vector
        Overrides:
        median in class Vec
        Returns:
        the median
      • 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
      • 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.