jsat.linear
Class ScaledVector
- java.lang.Object
-
- jsat.linear.Vec
-
- jsat.linear.ScaledVector
-
- All Implemented Interfaces:
- java.io.Serializable, java.lang.Cloneable, java.lang.Iterable<IndexValue>
public class ScaledVector extends Vec
A wrapper for a vector that represents the vector multiplied by a scalar constant. This allows for using and altering the value multiplied by a constant factor quickly, especially when the multiplicative factor must be changed often. Mutable operations will alter the underling vector, and all operations will automatically be scaled on a per element basis as needed.
If a point is reached where the multiplicative constant will be infrequently modified relative to the use of the vector, it may be more efficient to use the original vector scaled appropriately. This can be done by first callingembedScale()and then callinggetBase().
When the multiplicative constant is set to zero, the underlying base vector iszeroed outand the constant reset to 1.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor and Description ScaledVector(double scale, Vec base)Creates a new scaled vectorScaledVector(Vec vec)Creates a new scaled vector with a default scale of 1.
-
Method Summary
All 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 indicesVecclone()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.voidembedScale()Embeds the current scale factor into the base vector, so that the current scale factor can be set to 1.doubleget(int index)Gets the value stored at a specific index in the vectorVecgetBase()Returns the base vector that is being scaledjava.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.doublegetScale()Returns the current scale in usebooleanisSparse()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 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.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 vectorvoidsetScale(double scale)Explicitly sets the current scale to the given value
NOTE: If the scale is set to zero, the underlying base vector will be zeroed out, and the scale set to 1.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 vectordoublesum()Computes the sum of the values in this 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, canBeMutated, copyTo, copyToCol, copyToRow, countNaNs, divide, equals, equals, getNonZeroIterator, hashCode, increment, iterator, multiply, multiply, multiply, mutableAdd, mutableSubtract, mutableSubtract, mutableSubtract, normalize, normalized, pairwiseDivide, pairwiseMultiply, pNormDist, random, random, subtract, subtract, toString, variance, zeros
-
-
-
-
Constructor Detail
-
ScaledVector
public ScaledVector(double scale, Vec base)Creates a new scaled vector- Parameters:
scale- the initial scaling constantbase- the vector to implicitly scale
-
ScaledVector
public ScaledVector(Vec vec)
Creates a new scaled vector with a default scale of 1.- Parameters:
vec- the vector to implicitly scale
-
-
Method Detail
-
getScale
public double getScale()
Returns the current scale in use- Returns:
- the current scale in use
-
setScale
public void setScale(double scale)
Explicitly sets the current scale to the given value
NOTE: If the scale is set to zero, the underlying base vector will be zeroed out, and the scale set to 1.- Parameters:
scale- the new multiplicative constant to set for the scale
-
getBase
public Vec getBase()
Returns the base vector that is being scaled- Returns:
- the base vector that is being scaled
-
embedScale
public void embedScale()
Embeds the current scale factor into the base vector, so that the current scale factor can be set to 1.
-
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
-
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
-
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
-
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.
-
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.
-
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
-
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(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