jsat.linear
Class VecWithNorm
- java.lang.Object
-
- jsat.linear.Vec
-
- jsat.linear.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 callingpNorm(double). The original vector can be obtained by callinggetBase(). The exact values returned for the norm may differ slightly due to numerical issues.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor and Description VecWithNorm(Vec base)Creates a wrapper around the base vector that will update the norm of the vectorVecWithNorm(Vec base, double norm)Creates a wrapper around the base vector that will update the norm of the vector
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description VecWithNormclone()doubleget(int index)Gets the value stored at a specific index in the vectorVecgetBase()Return the base vector that is having its norm trackedjava.util.Iterator<IndexValue>getNonZeroIterator()Returns an iterator that will go over the non zero values in the given 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.booleanisSparse()Indicates whether or not this vector is optimized for sparce computation, meaning that most values in the vector are zero - and considered implicit.intlength()Returns the length of this vectorvoidmutableAdd(double c)Alters this vector such that this = this + c
This method should be overloaded for a serious implementation.voidmutableAdd(double c, Vec b)Alters this vector such that this = this + c * b
This method should be overloaded for a serious implementation.voidmutableDivide(double c)Mutatesthis /= c
This method should be overloaded for a serious implementation.voidmutableMultiply(double c)Mutatesthis *= c
This method should be overloaded for a serious implementation.voidmutablePairwiseDivide(Vec b)Mutatesthisby dividing each value by the value inbthat has the same index
This method should be overloaded for a serious implementation.voidmutablePairwiseMultiply(Vec b)Mutatesthisby multiplying each value by the value inbthat has the same index.intnnz()Computes the number of non zero values in this vectordoublepNorm(double p)Returns the p-norm of this vector.voidset(int index, double val)Sets the value stored at a specified index in the vectorvoidzeroOut()Zeroes out all values in this vector
This method should be overloaded for a serious implementation.-
Methods inherited from class jsat.linear.Vec
add, add, applyFunction, applyIndexFunction, arrayCopy, canBeMutated, copyTo, copyToCol, copyToRow, countNaNs, divide, dot, equals, equals, hashCode, increment, iterator, kurtosis, max, mean, median, min, multiply, multiply, multiply, multiply, mutableAdd, mutableSubtract, mutableSubtract, mutableSubtract, normalize, normalized, pairwiseDivide, pairwiseMultiply, pNormDist, random, random, skewness, sortedCopy, standardDeviation, subtract, subtract, sum, toString, variance, zeros
-
-
-
-
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 valuenorm- 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:VecReturns the p-norm of this vector.
-
length
public int length()
Description copied from class:VecReturns the length of this vector
-
get
public double get(int index)
Description copied from class:VecGets the value stored at a specific index in the vector
-
set
public void set(int index, double val)Description copied from class:VecSets the value stored at a specified index in the vector
-
isSparse
public boolean isSparse()
Description copied from class:VecIndicates 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.
-
clone
public VecWithNorm clone()
-
mutableAdd
public void mutableAdd(double c)
Description copied from class:VecAlters this vector such that this = this + c
This method should be overloaded for a serious implementation.- Overrides:
mutableAddin classVec- 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:VecAlters this vector such that this = this + c * b
This method should be overloaded for a serious implementation.- Overrides:
mutableAddin classVec- Parameters:
c- a scalar constantb- the vector to add to this
-
mutablePairwiseMultiply
public void mutablePairwiseMultiply(Vec b)
Description copied from class:VecMutatesthisby multiplying each value by the value inbthat has the same index.
This method should be overloaded for a serious implementation.- Overrides:
mutablePairwiseMultiplyin classVec- Parameters:
b- the vector to pairwise multiply by
-
mutableMultiply
public void mutableMultiply(double c)
Description copied from class:VecMutatesthis *= c
This method should be overloaded for a serious implementation.- Overrides:
mutableMultiplyin classVec- Parameters:
c- the constant to multiply by
-
mutablePairwiseDivide
public void mutablePairwiseDivide(Vec b)
Description copied from class:VecMutatesthisby dividing each value by the value inbthat has the same index
This method should be overloaded for a serious implementation.- Overrides:
mutablePairwiseDividein classVec- Parameters:
b- the vector to pairwise divide by
-
mutableDivide
public void mutableDivide(double c)
Description copied from class:VecMutatesthis /= c
This method should be overloaded for a serious implementation.- Overrides:
mutableDividein classVec- Parameters:
c- the constant to divide by
-
zeroOut
public void zeroOut()
Description copied from class:VecZeroes out all values in this vector
This method should be overloaded for a serious implementation.
-
nnz
public int nnz()
Description copied from class:VecComputes the number of non zero values in this vector
-
getNonZeroIterator
public java.util.Iterator<IndexValue> getNonZeroIterator()
Description copied from class:VecReturns an iterator that will go over the non zero values in the given vector. The iterator does not support theIterator.remove()method.- Overrides:
getNonZeroIteratorin classVec- Returns:
- an iterator for the non zero index value pairs.
-
getNonZeroIterator
public java.util.Iterator<IndexValue> getNonZeroIterator(int start)
Description copied from class:VecReturns an iterator that will go over the non zero values starting from the specified index in the given vector. The iterator does not support theIterator.remove()method.
This method should be overloaded for a serious implementation.- Overrides:
getNonZeroIteratorin classVec- 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