jsat.linear
Class ConstantVector
- java.lang.Object
-
- jsat.linear.Vec
-
- jsat.linear.ConstantVector
-
- All Implemented Interfaces:
- java.io.Serializable, java.lang.Cloneable, java.lang.Iterable<IndexValue>
public class ConstantVector extends Vec
This class provides a simple utility to represent an immutable vector where all values in the vector must have the same constant value. The standard mutable methods can not alter this vector. However, the length and constant value can be altered by calling thesetLength(int)andsetConstant(double)values respectively. The Constant Vector representation uses only constant space.
This class can be useful in providing a generalized way to handle multiple unique values or a constant value. For example, a separate regularization constant could be used for every feature in a learning problem. Instead of writing code to handle multiple values separately from a single value, a ConstantVector can be used so that the constant value case can be an efficient call to the multiple value version of the code.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor and Description ConstantVector(double constant, int length)Creates a new vector where all values have a single implicit value
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description ConstantVectorclone()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.intlength()Returns the length of this vectordoublemean()Computes the mean value of all values stored in this vectordoublemedian()Returns the median value in this vectorVecnormalized()Returns a new vector that is the result of normalizing this vector by the L2 normdoublepNorm(double p)Returns the p-norm of this vector.voidset(int index, double val)Sets the value stored at a specified index in the vectorvoidsetConstant(double constant)Sets the constant value that will be used as the value stored in every index of this vector.voidsetLength(int length)Sets the length of this vector.doublestandardDeviation()Computes the standard deviation of the values in this vectordoublesum()Computes the sum of the values in this vectordoublevariance()Computes the variance of the values in this vector, which isVec.standardDeviation()2-
Methods inherited from class jsat.linear.Vec
add, add, applyFunction, applyIndexFunction, arrayCopy, canBeMutated, copyTo, copyToCol, copyToRow, countNaNs, divide, dot, equals, equals, getNonZeroIterator, getNonZeroIterator, hashCode, increment, iterator, kurtosis, max, min, multiply, multiply, multiply, multiply, mutableAdd, mutableAdd, mutableAdd, mutableDivide, mutableMultiply, mutablePairwiseDivide, mutablePairwiseMultiply, mutableSubtract, mutableSubtract, mutableSubtract, nnz, normalize, pairwiseDivide, pairwiseMultiply, pNormDist, random, random, skewness, sortedCopy, subtract, subtract, toString, zeroOut, zeros
-
-
-
-
Constructor Detail
-
ConstantVector
public ConstantVector(double constant, int length)Creates a new vector where all values have a single implicit value- Parameters:
constant- the constant to use as the single value for all indiceslength- the length of this vector
-
-
Method Detail
-
setConstant
public void setConstant(double constant)
Sets the constant value that will be used as the value stored in every index of this vector.- Parameters:
constant- the constant value to represent as a vector
-
setLength
public void setLength(int length)
Sets the length of this vector. The length must be a non zero value- Parameters:
length- the new length for 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
-
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
-
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
-
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
-
pNorm
public double pNorm(double p)
Description copied from class:VecReturns the p-norm of this vector.
-
median
public double median()
Description copied from class:VecReturns the median value in this 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 ConstantVector clone()
-
-
DataMelt 3.0 © DataMelt by jWork.ORG