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

Class VecWithNorm

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


    public class VecWithNorm
    extends Vec
    A wrapper for a vector that allows for transparent tracking of the 2-norm of the base vector. This class is meant primarily for use when most updates are done by sparse vectors accumulated to a single dense vector. If there are only O(s) non zero values, updating the norm can be done in O(s) time. If most updates will be done by dense vectors, this wrapper may not give any performance improvements.
    The norm is obtained by calling pNorm(double). The original vector can be obtained by calling getBase(). The exact values returned for the norm may differ slightly due to numerical issues.
    See Also:
    Serialized Form
    • Constructor Detail

      • VecWithNorm

        public VecWithNorm(Vec base,
                           double norm)
        Creates a wrapper around the base vector that will update the norm of the vector
        Parameters:
        base - the vector to use as the base value
        norm - the initial value of the norm
      • VecWithNorm

        public VecWithNorm(Vec base)
        Creates a wrapper around the base vector that will update the norm of the vector
        Parameters:
        base - the vector to use as the base value
    • Method Detail

      • getBase

        public Vec getBase()
        Return the base vector that is having its norm tracked
        Returns:
        the base vector that is having its norm tracked
      • 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
      • 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
      • 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.
      • 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
      • 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()
        Description copied from class: Vec
        Returns an iterator that will go over the non zero values in the given vector. The iterator does not support the Iterator.remove() method.
        Overrides:
        getNonZeroIterator in class Vec
        Returns:
        an iterator for the non zero index value pairs.
      • 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.