jsat.linear
Class DenseVector
- java.lang.Object
-
- jsat.linear.Vec
-
- jsat.linear.DenseVector
-
- All Implemented Interfaces:
- java.io.Serializable, java.lang.Cloneable, java.lang.Iterable<IndexValue>
public class DenseVector extends Vec
A vector implementation that is dense, meaning all values are allocated - even if their values will be implicitly zero.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor and Description DenseVector(double[] array)Creates a new Dense Vector that uses the given array as its values.DenseVector(double[] array, int start, int end)Creates a new Dense Vector that uses the given array as its values.DenseVector(int length)Creates a new Dense Vector of zerosDenseVector(java.util.List<java.lang.Double> list)Creates a new vector of the length of the given list, and values copied over in order.DenseVector(Vec toCopy)Creates a new Dense Vector that contains a copy of the values in the given vector
-
Method Summary
All Methods Static 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 indicesDenseVectorclone()DenseVectordeepCopy()doubledot(Vec v)Computes the dot product between two vectors, which is equivalent to
Σ thisi*vi
This method should be overloaded for a serious implementation.booleanequals(java.lang.Object obj)booleanequals(java.lang.Object obj, double range)doubleget(int index)Gets the value stored at a specific index in the vectorbooleanisSparse()Indicates whether or not this vector is optimized for sparce computation, meaning that most values in the vector are zero - and considered implicit.doublekurtosis()Computes the kurtosis of this vector, which is the 4th moment.intlength()Returns the length of this vectordoublemax()Returns the maximum value stored in this vectordoublemedian()Returns the median value in this vectordoublemin()Returns the minimum value stored in this vectorvoidmultiply(double c, Matrix A, Vec b)If this is vector a, this this computes b = b + c aT*AvoidmutableAdd(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.voidmutableSubtract(double c)Alters this vector such that this = this - cvoidnormalize()Mutates this vector to be normalized by the L2 normdoublepNorm(double p)Returns the p-norm of this vector.doublepNormDist(double p, Vec y)Returns the p-norm distance between this and another vector y.voidset(int index, double val)Sets the value stored at a specified index in the vectordoubleskewness()Computes the skewness of this vector, which is the 3rd moment.DenseVectorsortedCopy()Returns a copy of this array with the values moved around so that they are in sorted orderdoublesum()Computes the sum of the values in this vectorstatic DenseVectortoDenseVec(double... array)Returns a new dense vector backed by the given array.doublevariance()Computes the variance of the values in this vector, which isVec.standardDeviation()2-
Methods inherited from class jsat.linear.Vec
add, add, applyFunction, applyIndexFunction, canBeMutated, copyTo, copyToCol, copyToRow, countNaNs, divide, getNonZeroIterator, getNonZeroIterator, hashCode, increment, iterator, mean, multiply, multiply, multiply, mutableAdd, mutableSubtract, mutableSubtract, nnz, normalized, pairwiseDivide, pairwiseMultiply, random, random, standardDeviation, subtract, subtract, toString, zeroOut, zeros
-
-
-
-
Constructor Detail
-
DenseVector
public DenseVector(int length)
Creates a new Dense Vector of zeros- Parameters:
length- the length of the vector
-
DenseVector
public DenseVector(java.util.List<java.lang.Double> list)
Creates a new vector of the length of the given list, and values copied over in order.- Parameters:
list- the list of values to copy into a new vector
-
DenseVector
public DenseVector(double[] array)
Creates a new Dense Vector that uses the given array as its values. Its values will not be copied, and raw access and mutations tot he given array may occur.- Parameters:
array- the backing array to use for a new vector of the same length
-
DenseVector
public DenseVector(double[] array, int start, int end)Creates a new Dense Vector that uses the given array as its values. Its values will not be copied, and raw access and mutations tot he given array may occur.- Parameters:
array- the backing array to use for a new vectorstart- the first index in the array, inclusive, to mark the start of the vector.end- the last index in the array, exclusive, to mark the end of the vector.
-
DenseVector
public DenseVector(Vec toCopy)
Creates a new Dense Vector that contains a copy of the values in the given vector- Parameters:
toCopy- the vector to copy
-
-
Method Detail
-
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
-
min
public double min()
Description copied from class:VecReturns the minimum value stored in this vector
-
max
public double max()
Description copied from class:VecReturns the maximum value stored in this vector
-
sum
public double sum()
Description copied from class:VecComputes the sum of the values in this vector
-
median
public double median()
Description copied from class:VecReturns the median value in this vector
-
skewness
public double skewness()
Description copied from class:VecComputes the skewness of this vector, which is the 3rd moment.
-
kurtosis
public double kurtosis()
Description copied from class:VecComputes the kurtosis of this vector, which is the 4th moment.
-
sortedCopy
public DenseVector sortedCopy()
Description copied from class:VecReturns a copy of this array with the values moved around so that they are in sorted order- Overrides:
sortedCopyin classVec- Returns:
- a new array in sorted order
-
variance
public double variance()
Description copied from class:VecComputes the variance of the values in this vector, which isVec.standardDeviation()2
-
dot
public double dot(Vec v)
Description copied from class:VecComputes the dot product between two vectors, which is equivalent to
Σ thisi*vi
This method should be overloaded for a serious implementation.
-
deepCopy
public DenseVector deepCopy()
-
multiply
public void multiply(double c, Matrix A, Vec b)Description copied from class:VecIf this is vector a, this this computes b = b + c aT*A
-
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
-
mutableSubtract
public void mutableSubtract(double c)
Description copied from class:VecAlters this vector such that this = this - c- Overrides:
mutableSubtractin classVec- Parameters:
c- the scalar constant to subtract from all values in this vector
-
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
-
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
-
pNormDist
public double pNormDist(double p, Vec y)Description copied from class:VecReturns the p-norm distance between this and another vector y.
-
pNorm
public double pNorm(double p)
Description copied from class:VecReturns the p-norm of this vector.
-
clone
public DenseVector clone()
-
normalize
public void normalize()
Description copied from class:VecMutates this vector to be normalized by the L2 norm
-
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
-
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
-
toDenseVec
public static DenseVector toDenseVec(double... array)
Returns a new dense vector backed by the given array. This is a weak reference, the given array should no longer be altered - as it will effect the values of the dense vector.- Parameters:
array- the array to use as the backing of a dense vector- Returns:
- a Dense Vector that is backed using the given array
-
arrayCopy
public double[] arrayCopy()
Description copied from class:VecCreates a new array that contains all the values of this vector in the appropriate indices
-
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.
-
-
DataMelt 3.0 © DataMelt by jWork.ORG