Documentation of 'mikera.vectorz.impl.SparseIndexedVector' Java class
SparseIndexedVector
mikera.vectorz.impl

Class SparseIndexedVector

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, java.lang.Comparable<INDArray>, java.lang.Iterable<java.lang.Double>, INDArray, ISparse, ISparseVector, IVector


    public class SparseIndexedVector
    extends ASparseIndexedVector
    Indexed sparse vector. Efficient for mutable, mostly sparse vectors. Maintains a indexed array of elements which may be non-zero. These values *can* also be zero. WARNING: individual updates of non-indexed elements are O(n) in the number of non-sparse elements. You should not normally perform element-wise mutation on a SparseIndexedVector if performance is a concern Index must be distinct and sorted.
    See Also:
    Serialized Form
    • Method Detail

      • wrap

        public static SparseIndexedVector wrap(int length,
                                               Index index,
                                               double[] data)
        Creates a SparseIndexedVector with the specified index and data values. Performs no checking - Index must be distinct and sorted.
      • wrap

        public static SparseIndexedVector wrap(int length,
                                               int[] indices,
                                               double[] data)
        Creates a SparseIndexedVector with the specified index and data values. Performs no checking - Index must be distinct and sorted.
      • create

        public static SparseIndexedVector create(int length,
                                                 Index index,
                                                 double[] data)
        Creates a SparseIndexedVector using the given sorted Index to identify the indexes of non-zero values, and a double[] array to specify all the non-zero element values
      • createWithIndices

        public static AVector createWithIndices(AVector v,
                                                int[] ixs)
        Creates a sparse indexed vector using the specified indexed values from the source vector All non-indexed vales will be zero.
        Parameters:
        v -
        ixs -
        Returns:
      • create

        public static SparseIndexedVector create(int length,
                                                 Index index,
                                                 AVector data)
        Creates a SparseIndexedVector using the given sorted Index to identify the indexes of non-zero values, and a dense vector to specify all the non-zero element values
      • create

        public static SparseIndexedVector create(java.lang.Object o)
        Creates a SparseIndexedVector from the source object
        Parameters:
        o -
        Returns:
      • create

        public static SparseIndexedVector create(double[] values)
        Creates a SparseIndexedVector from an array of double values
        Parameters:
        o -
        Returns:
      • create

        public static SparseIndexedVector create(java.lang.Object[] values)
        Creates a SparseIndexedVector from the source object array
        Parameters:
        o -
        Returns:
      • create

        public static SparseIndexedVector create(AVector source)
        Creates a SparseIndexedVector from the given vector, ignoring the zeros in the source.
      • create

        public static SparseIndexedVector create(java.lang.Iterable<?> iterable)
        Creates a SparseIndexedVector from the specified Iterable object
        Parameters:
        iterable - An Iterable containing java.lang.Number instances
        Returns:
      • create

        public static SparseIndexedVector create(java.util.Iterator<?> iterator)
        Creates a SparseIndexedVector from the specified Iterator object
        Parameters:
        iterator - An Iterator over java.lang.Number instances
        Returns:
      • createFromRow

        public static AVector createFromRow(AMatrix m,
                                            int row)
        Creates a SparseIndexedVector from a row of an existing matrix
      • nonSparseElementCount

        public int nonSparseElementCount()
        Description copied from class: ASparseVector
        Returns the number of non-sparse elements in the sparse vector. This will be greater or equal to the number of non-zero elements
        Specified by:
        nonSparseElementCount in class ASparseVector
        Returns:
      • innerProduct

        public AVector innerProduct(SparseRowMatrix m)
        Overloaded implementation for SparseIndexedVector x SparseRowMatrix This is basically a weighted sum of rows!
        Parameters:
        m -
        Returns:
      • addMultiple

        public void addMultiple(AVector v,
                                double factor)
        Description copied from class: AVector
        Adds a scaled multiple of another vector to this vector
        Overrides:
        addMultiple in class ASparseVector
      • addMultipleSparse

        public void addMultipleSparse(AVector v,
                                      double factor)
        Description copied from class: AVector
        Adds a multiple of a source vector to the non-sparse elements of this vector only
        Overrides:
        addMultipleSparse in class AVector
      • addMultipleSparse

        public void addMultipleSparse(ADenseArrayVector v,
                                      double factor)
        Adds a multiple of the source array to the non-sparse elements of this array
      • addSparse

        public void addSparse(double c)
        Description copied from interface: INDArray
        Adds to the non-sparse elements of this array
        Specified by:
        addSparse in interface INDArray
        Overrides:
        addSparse in class AVector
      • setSparse

        public void setSparse(AVector v)
        Description copied from class: AVector
        Sets the non-sparse elements of this vector to the corresponding elements of another vector
        Overrides:
        setSparse in class AVector
      • setSparse

        public void setSparse(double v)
        Description copied from interface: INDArray
        Sets the non-sparse elements of this array to the specified value May throw an exception if non-sparse elements are not mutable
        Specified by:
        setSparse in interface INDArray
        Overrides:
        setSparse in class AVector
      • add

        public void add(double[] src,
                        int srcOffset)
        Description copied from class: AVector
        Adds to this vector from a given double array.
        Overrides:
        add in class AVector
      • addMultiple

        public void addMultiple(ASparseVector v,
                                double factor)
      • addMultiple

        public void addMultiple(SparseIndexedVector v,
                                double factor)
        Description copied from class: AVector
        Adds a scaled multiple of a sparse indexed vector to this vector
        Overrides:
        addMultiple in class AVector
      • sub

        public void sub(AVector v)
        Description copied from class: AVector
        Subtracts a vector from this vector
        Overrides:
        sub in class AVector
      • multiply

        public void multiply(double d)
        Description copied from class: AVector
        Multiplies the vector by a constant factor
        Specified by:
        multiply in interface INDArray
        Overrides:
        multiply in class ASparseIndexedVector
        Parameters:
        d - Factor by which to multiply each component of the vector
      • pow

        public void pow(double exponent)
        Description copied from interface: INDArray
        Raises all elements of the array to a specified power in place
        Specified by:
        pow in interface INDArray
        Overrides:
        pow in class AVector
      • square

        public void square()
        Description copied from interface: INDArray
        Squares all elements of the array in place
        Specified by:
        square in interface INDArray
        Overrides:
        square in class AVector
      • multiply

        public void multiply(AVector v)
        Description copied from class: AVector
        Multiplies this vector by another vector, elementwise.
        Overrides:
        multiply in class AVector
      • multiplyCopy

        public SparseIndexedVector multiplyCopy(double factor)
        Description copied from interface: INDArray
        Returns a copy of the array with all elements multiplied by a single constant value
        Specified by:
        multiplyCopy in interface INDArray
        Overrides:
        multiplyCopy in class AVector
        Parameters:
        factor - A scalar factor
        Returns:
        A new array, with all element values scaled by the given factor
      • multiply

        public void multiply(double[] array,
                             int offset)
        Description copied from class: AVector
        Multiplies the elements in this vector by corresponding elements in the target array
        Overrides:
        multiply in class AVector
        offset - The offset into the target array
      • maxAbsElement

        public double maxAbsElement()
        Description copied from class: AVector
        Returns the maximum absolute element value of a vector
        Overrides:
        maxAbsElement in class AVector
        Returns:
      • maxElementIndex

        public int maxElementIndex()
        Description copied from class: AVector
        Returns the index of the maximum element of a vector
        Overrides:
        maxElementIndex in class AVector
        Returns:
      • maxAbsElementIndex

        public int maxAbsElementIndex()
        Description copied from class: AVector
        Returns the index of the maximum absolute element of a vector
        Overrides:
        maxAbsElementIndex in class AVector
        Returns:
      • minElementIndex

        public int minElementIndex()
        Description copied from class: AVector
        Returns the index of the minimum element of a vector
        Overrides:
        minElementIndex in class AVector
      • negate

        public void negate()
        Description copied from class: AVector
        Negates all emlements of this vector in place.
        Specified by:
        negate in interface INDArray
        Overrides:
        negate in class AVector
      • applyOp

        public void applyOp(Op op)
        Description copied from interface: INDArray
        Applies a unary operator to all elements of the array (in-place)
        Specified by:
        applyOp in interface INDArray
        Overrides:
        applyOp in class AVector
      • applyOp

        public void applyOp(Op2 op,
                            double d)
        Description copied from interface: INDArray
        Applies a binary operator to this array and a double value. Works as if the double value was broadcast to the shape of this array.
        Specified by:
        applyOp in interface INDArray
        Overrides:
        applyOp in class AVector
      • reduce

        public double reduce(Op2 op,
                             double init)
        Description copied from interface: INDArray
        Reduces over all elements of the array in row-major order. Applies the operator to the initial/previous result at each step. Returns the final result.
        Specified by:
        reduce in interface INDArray
        Overrides:
        reduce in class ASparseVector
      • reduce

        public double reduce(Op2 op)
        Description copied from interface: INDArray
        Reduces over all elements of the array in row-major order. Applies the operator to the previous result at each step. Returns the final result.
        Specified by:
        reduce in interface INDArray
        Overrides:
        reduce in class ASparseVector
      • abs

        public void abs()
        Description copied from interface: INDArray
        Replaces all elements of this array with their absolute values, according to Math.abs(double)
        Specified by:
        abs in interface INDArray
        Overrides:
        abs in class AVector
      • get

        public double get(int i)
        Description copied from interface: INDArray
        Returns the double value at the specified position in a 1D vector
        Specified by:
        get in interface INDArray
        Specified by:
        get in interface IVector
        Specified by:
        get in class AVector
      • unsafeGet

        public double unsafeGet(int i)
        Description copied from class: AVector
        Like get, but performs no bounds checking. Results are undefined if the index is out of range
        Overrides:
        unsafeGet in class AVector
      • isFullyMutable

        public boolean isFullyMutable()
        Description copied from class: AVector
        Returns true if this vector is fully mutable, i.e. can contain any unconstrained double values
        Specified by:
        isFullyMutable in interface INDArray
        Overrides:
        isFullyMutable in class AVector
      • isMutable

        public boolean isMutable()
        Description copied from class: AVector
        Returns true if this vector is mutable.
        Specified by:
        isMutable in interface INDArray
        Overrides:
        isMutable in class AVector
      • setElements

        public void setElements(double[] array,
                                int offset)
        Description copied from interface: INDArray
        Sets all elements in an array using the given double values
        Specified by:
        setElements in interface INDArray
        Overrides:
        setElements in class AVector
        Parameters:
        array - Element values in a double[] array. There must be at least as many element values as elements in this array.
        offset - Position in the values array from which to start taking values.
      • setElements

        public void setElements(int pos,
                                double[] array,
                                int offset,
                                int length)
        Description copied from interface: INDArray
        Sets elements in an array using the given double values. The source array must contain at least the specified length in terms of number of elements
        Specified by:
        setElements in interface INDArray
        Overrides:
        setElements in class AVector
        Parameters:
        pos - Offset into this array, expressed in terms of number of elements in row major order
        array - Element values in a double[] array. There must be at least as many element values as elements in this array.
        offset - Position in the values array from which to start taking values.
        length - Number of elements to set.
      • set

        public void set(AVector v)
        Description copied from class: AVector
        Sets the vector to equal the value of another vector
        Overrides:
        set in class AVector
      • set

        public void set(ADenseArrayVector v)
        Description copied from class: AVector
        Sets the vector equal to the value of an ADenseArrayVector
        Overrides:
        set in class AVector
      • set

        public void set(int i,
                        double value)
        Description copied from interface: INDArray
        Sets a value at a given position in a mutable 1D array
        Specified by:
        set in interface INDArray
        Specified by:
        set in interface IVector
        Specified by:
        set in class AVector
      • unsafeSet

        public void unsafeSet(int i,
                              double value)
        Description copied from class: AVector
        Like set, but performs no bounds checking. Results are undefined if the index is out of range
        Overrides:
        unsafeSet in class AVector
      • addAt

        public void addAt(int i,
                          double value)
        Description copied from class: AVector
        Adds a value to a specific element of the vector This function does not perform bounds checking, i.e. is an unsafe operation
        Overrides:
        addAt in class AVector
      • roundToZero

        public ASparseVector roundToZero(double precision)
        Description copied from class: ASparseVector
        Returns a vector after replacing all elements with absolute values less-than-or-equal to precision with zeros. May return either this vector or a new vector. If this vector is return, it may have been mutated.
        Overrides:
        roundToZero in class ASparseVector
        Returns:
      • nonSparseIndex

        public Index nonSparseIndex()
        Description copied from class: AVector
        Returns an Index indicating which elements of this vector are defined as non-sparse. A sparse index must be zero. A non-sparse element may be zero, but is typically expected be non-zero.
        Specified by:
        nonSparseIndex in interface ISparseVector
        Specified by:
        nonSparseIndex in class ASparseVector
        Returns:
      • visitNonZero

        public double visitNonZero(IndexedElementVisitor elementVisitor)
        Description copied from class: AVector
        Visits all non-zero elements of this vector. Visitor may return a non-zero value to terminate early, which will return the given value. Returns 0.0 otherwise.
        Overrides:
        visitNonZero in class ASparseVector
      • toVector

        public Vector toVector()
        Description copied from class: AVector
        Coerces this vector to the standard dense Vector format. May return the same vector is this is already a dense Vector, otherwise returns a Vector containing a new clone of the vector elements.
        Specified by:
        toVector in interface INDArray
        Overrides:
        toVector in class AVector
      • clone

        public SparseIndexedVector clone()
        Description copied from class: AVector
        Clones the vector, creating a new mutable copy of all data. The clone is: - not guaranteed to be of the same type. - guaranteed to be fully mutable - guaranteed not to contain a reference (i.e. is a full deep copy)
        Specified by:
        clone in interface INDArray
        Specified by:
        clone in interface IVector
        Overrides:
        clone in class ASparseVector
      • includeIndices

        public void includeIndices(Index ixs)
        Include additional indices in the non-sparse index set of this vector. Useful to improve performance if subsequent operations will access these indices.
        Parameters:
        ixs -
      • includeIndices

        public void includeIndices(AVector v)
        Include additional indices in the non-sparse index set of this vector. Useful to improve performance if subsequent operations will access these indices.
        Parameters:
        ixs -
      • validate

        public void validate()
        Description copied from interface: INDArray
        Validates the internal data structure of the INDArray. Throws an exception on failure. Failure indicates a serious bug and/or data corruption.
        Specified by:
        validate in interface INDArray
        Overrides:
        validate in class AVector

DMelt 3.0 © DataMelt by jWork.ORG

You see the box below because you did not login.