jsat.linear
Class ShiftedVec
- java.lang.Object
-
- jsat.linear.Vec
-
- jsat.linear.ShiftedVec
-
- All Implemented Interfaces:
- java.io.Serializable, java.lang.Cloneable, java.lang.Iterable<IndexValue>
public class ShiftedVec extends Vec
A wrapper for a vector that represents the vector added with a scalar value. This allows for using and altering the value added by a constant factor quickly. Mutable operations will alter the underling vector, and all operations will automatically be adjusted on a per element basis as needed. The most significant performance difference is in representing a sparse input sifted by a constant factor. Note, that when using a sparse base vector - the ShiftedVec will always returntrueforisSparse(), even if shifting makes all values non-zero- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor and Description ShiftedVec(Vec base, double shift)Creates a new vector represented asbase+shift
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description ShiftedVecclone()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.voidembedShift()Embeds the current shift scalar into the base vector, modifying it and then setting the new shit to zero.doubleget(int index)Gets the value stored at a specific index in the vectorVecgetBase()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.doublegetShift()voidincrement(int index, double val)Increments the value stored at a specified 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 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 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.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.doublepNorm(double p)Returns the p-norm of this vector.voidset(int index, double val)Sets the value stored at a specified index in the vectorvoidsetShift(double shift)Directly alters the shift value used for this vector.doublestandardDeviation()Computes the standard deviation of the values in this vectordoublevariance()Computes the variance of the values in this vector, which isVec.standardDeviation()2voidzeroOut()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, equals, equals, getNonZeroIterator, hashCode, iterator, multiply, multiply, multiply, multiply, mutableSubtract, mutableSubtract, mutableSubtract, nnz, normalize, normalized, pairwiseDivide, pairwiseMultiply, pNormDist, random, random, skewness, sortedCopy, subtract, subtract, sum, toString, zeros
-
-
-
-
Constructor Detail
-
ShiftedVec
public ShiftedVec(Vec base, double shift)
Creates a new vector represented asbase+shift- Parameters:
base- the base vector to representshift- the scalar shift to add to the base vector
-
-
Method Detail
-
getBase
public Vec getBase()
- Returns:
- the base vector used by this object
-
setShift
public void setShift(double shift)
Directly alters the shift value used for this vector. The old sift is "forgotten" immediately.- Parameters:
shift- the new value to use for the additive scalar
-
getShift
public double getShift()
- Returns:
- the additive scalar used to shift over the
basevalue
-
embedShift
public void embedShift()
Embeds the current shift scalar into the base vector, modifying it and then setting the new shit to zero. This makes the base vector have the value represented by this ShiftedVec
-
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
-
increment
public void increment(int index, double val)Description copied from class:VecIncrements the value stored at a specified index in the 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
-
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
-
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
-
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
-
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
-
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.
-
zeroOut
public void zeroOut()
Description copied from class:VecZeroes out all values in this vector
This method should be overloaded for a serious implementation.
-
pNorm
public double pNorm(double p)
Description copied from class:VecReturns the p-norm of this vector.
-
mean
public double mean()
Description copied from class:VecComputes the mean value of all values stored in this vector
-
variance
public double variance()
Description copied from class:VecComputes the variance of the values in this vector, which isVec.standardDeviation()2
-
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
-
kurtosis
public double kurtosis()
Description copied from class:VecComputes the kurtosis of this vector, which is the 4th moment.
-
max
public double max()
Description copied from class:VecReturns the maximum value stored in this vector
-
min
public double min()
Description copied from class:VecReturns the minimum value stored in this vector
-
median
public double median()
Description copied from class:VecReturns the median value in this vector
-
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
-
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 ShiftedVec clone()
-
-
DataMelt 3.0 © DataMelt by jWork.ORG