jsat.linear
Class VecPaired<V extends Vec,P>
- java.lang.Object
-
- jsat.linear.Vec
-
- jsat.linear.VecPaired<V,P>
-
- All Implemented Interfaces:
- java.io.Serializable, java.lang.Cloneable, java.lang.Iterable<IndexValue>
- Direct Known Subclasses:
- VecPairedComparable
public class VecPaired<V extends Vec,P> extends Vec
This data structure allows to wrap a Vector so that it is associated with some object time. Note, that operations that return a vector will not be a Paired Vector, as there is no reason to associate a different vector with this vector's pair.- See Also:
- Serialized Form
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method and Description Vecadd(double c)Returns a new vector that is the result ofthis + cVecadd(Vec b)Returns a new vector that is the result ofthis + bdouble[]arrayCopy()Creates a new array that contains all the values of this vector in the appropriate indicesVecclone()Vecdivide(double c)Returns a new vector that is the result ofthis / cdoubledot(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)static VecextractTrueVec(Vec b)This method is used assuming multiple VecPaired are used together.doubleget(int index)Gets the value stored at a specific index in the vectorjava.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.PgetPair()VgetVector()inthashCode()Provides a hashcode for Vectors.booleanisSparse()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 vectordoublemean()Computes the mean value of all values stored in this vectordoublemedian()Returns the median value in this vectordoublemin()Returns the minimum value stored in this vectorVecmultiply(double c)Returns a new vector that is the result ofthis * cvoidmultiply(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.voidmutableAdd(Vec b)Alters this vector such that this = this + bvoidmutableDivide(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(Vec b)Alters this vector such that this = this - bintnnz()Computes the number of non zero values in this vectorvoidnormalize()Mutates this vector to be normalized by the L2 normVecnormalized()Returns a new vector that is the result of normalizing this vector by the L2 normVecpairwiseDivide(Vec b)Returns a new vector that is the result of dividing each value inthisby the value in the same index inbVecpairwiseMultiply(Vec b)Returns a new vector that is the result of multiplying each value inthisby its corresponding value inbdoublepNorm(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 vectorvoidsetPair(P pair)voidsetVector(V vector)doubleskewness()Computes the skewness of this vector, which is the 3rd moment.VecsortedCopy()Returns a copy of this array with the values moved around so that they are in sorted orderdoublestandardDeviation()Computes the standard deviation of the values in this vectorVecsubtract(Vec b)Returns a new vector that is the result ofthis - bdoublesum()Computes the sum of the values in this vectorjava.lang.StringtoString()doublevariance()Computes the variance of the values in this vector, which isVec.standardDeviation()2static <V extends Vec,P extends java.lang.Comparable<P>>
java.util.Comparator<VecPaired<V,P>>vecPairedComparator()-
Methods inherited from class jsat.linear.Vec
applyFunction, applyIndexFunction, canBeMutated, copyTo, copyToCol, copyToRow, countNaNs, getNonZeroIterator, increment, iterator, multiply, multiply, mutableSubtract, mutableSubtract, random, random, subtract, zeroOut, zeros
-
-
-
-
Method Detail
-
getPair
public P getPair()
-
setPair
public void setPair(P pair)
-
getVector
public V getVector()
-
setVector
public void setVector(V vector)
-
length
public int length()
Description copied from class:VecReturns the length of this vector
-
nnz
public int nnz()
Description copied from class:VecComputes the number of non zero values in 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
-
add
public Vec add(double c)
Description copied from class:VecReturns a new vector that is the result ofthis + c
-
add
public Vec add(Vec b)
Description copied from class:VecReturns a new vector that is the result ofthis + b
-
subtract
public Vec subtract(Vec b)
Description copied from class:VecReturns a new vector that is the result ofthis - b
-
pairwiseMultiply
public Vec pairwiseMultiply(Vec b)
Description copied from class:VecReturns a new vector that is the result of multiplying each value inthisby its corresponding value inb- Overrides:
pairwiseMultiplyin classVec- Parameters:
b- the vector to pairwise multiply by- Returns:
- the result of the pairwise multiplication of
bonto the values ofthis
-
multiply
public Vec multiply(double c)
Description copied from class:VecReturns a new vector that is the result ofthis * c
-
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
-
pairwiseDivide
public Vec pairwiseDivide(Vec b)
Description copied from class:VecReturns a new vector that is the result of dividing each value inthisby the value in the same index inb- Overrides:
pairwiseDividein classVec- Parameters:
b- the vector to pairwise divide by- Returns:
- the result of pairwise division of
thisbyb
-
divide
public Vec divide(double c)
Description copied from class:VecReturns a new vector that is the result ofthis / c
-
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(Vec b)
Description copied from class:VecAlters this vector such that this = this + b- Overrides:
mutableAddin classVec- Parameters:
b- the vector to add to this
-
mutableSubtract
public void mutableSubtract(Vec b)
Description copied from class:VecAlters this vector such that this = this - b- Overrides:
mutableSubtractin classVec- Parameters:
b- the vector to subtract from 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
-
sortedCopy
public Vec 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
-
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
-
mean
public double mean()
Description copied from class:VecComputes the mean value of all values stored in this vector
-
standardDeviation
public double standardDeviation()
Description copied from class:VecComputes the standard deviation of the values in this vector- Overrides:
standardDeviationin classVec- Returns:
- the standard deviation
-
variance
public double variance()
Description copied from class:VecComputes the variance of the values in this vector, which isVec.standardDeviation()2
-
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.
-
normalized
public Vec normalized()
Description copied from class:VecReturns a new vector that is the result of normalizing this vector by the L2 norm- Overrides:
normalizedin classVec- Returns:
- a normalized version of this vector
-
normalize
public void normalize()
Description copied from class:VecMutates this vector to be normalized by the L2 norm
-
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.
-
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.
-
arrayCopy
public double[] arrayCopy()
Description copied from class:VecCreates a new array that contains all the values of this vector in the appropriate indices
-
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
-
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
-
extractTrueVec
public static Vec extractTrueVec(Vec b)
This method is used assuming multiple VecPaired are used together. The implementation of the vector may have logic to handle the case that the other vector is of the same type. This will go through every layer of VecPaired to return the final base vector.- Parameters:
b- a Vec, that may or may not be an instance ofVecPaired- Returns:
- the final Vec backing b, which may be b itself.
-
vecPairedComparator
public static <V extends Vec,P extends java.lang.Comparable<P>> java.util.Comparator<VecPaired<V,P>> vecPairedComparator()
-
hashCode
public int hashCode()
Description copied from class:VecProvides a hashcode for Vectors. All vector implementations should return the same result for cases whenVec.equals(java.lang.Object)returns true. Below is the code used for this class
int result = 1;
for (int i = 0; i < length(); i++)
{
double val = get(i);
if(val != 0)
{
long bits = Double.doubleToLongBits(val);
result = 31 * result + (int)(bits ^ (bits >>> 32));
result = 31 * result + i;
}
}
return 31* result + length();
-
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