Interface SGDVector
- All Superinterfaces:
Iterable<VectorTuple>
,Serializable
,Tensor
- All Known Implementing Classes:
DenseVector
,ShrinkingVector
,SparseVector
Interface for 1 dimensional
Tensor
s.
Vectors have immutable sizes and immutable indices (so SparseVector
can't grow).
-
Method Summary
Modifier and TypeMethodDescriptionvoid
add
(int index, double value) Addsvalue
to the element atindex
.Addsother
to this vector, producing a newSGDVector
.copy()
Returns a deep copy of this vector.default double
cosineDistance
(SGDVector other) Calculates the cosine distance of two vectors.default double
cosineSimilarity
(SGDVector other) Calculates the cosine similarity of two vectors.double
Calculates the dot product between this vector andother
.double
euclideanDistance
(SGDVector other) The l2 or euclidean distance between this vector and the other vector.double
get
(int index) Gets an element from this vector.int
Returns the index of the maximum value.double
l1Distance
(SGDVector other) The l1 or Manhattan distance between this vector and the other vector.default double
l2Distance
(SGDVector other) Synonym for euclideanDistance.double
maxValue()
Returns the maximum value.double
minValue()
Returns the minimum value.void
normalize
(VectorNormalizer normalizer) Normalizes the vector using the supplied vector normalizer.int
Returns the number of non-zero elements (on construction, an element could be set to zero and it would still remain active).double
oneNorm()
Calculates the Manhattan norm for this vector.Generates the matrix representing the outer product between the two vectors.scale
(double coefficient) Generates a new vector with each element scaled bycoefficient
.void
set
(int index, double value) Sets theindex
to thevalue
.int
size()
Returns the dimensionality of this vector.Subtractsother
from this vector, producing a newSGDVector
.double
sum()
Calculates the sum of this vector.double
twoNorm()
Calculates the euclidean norm for this vector.default double
variance()
Calculates the variance of this vector.double
variance
(double mean) Calculates the variance of this vector based on the supplied mean.Methods inherited from interface java.lang.Iterable
forEach, iterator, spliterator
Methods inherited from interface org.tribuo.math.la.Tensor
foreachInPlace, getShape, hadamardProductInPlace, hadamardProductInPlace, intersectAndAddInPlace, intersectAndAddInPlace, reshape, scalarAddInPlace, scaleInPlace
-
Method Details
-
copy
-
size
-
numActiveElements
int numActiveElements()Returns the number of non-zero elements (on construction, an element could be set to zero and it would still remain active).- Returns:
- The number of non-zero elements.
-
scale
-
add
Addsvalue
to the element atindex
.- Parameters:
index
- The index to update.value
- The value to add.
-
add
Addsother
to this vector, producing a newSGDVector
. Adding Dense to Dense/Sparse produces aDenseVector
, adding Sparse to Sparse produces aSparseVector
.- Parameters:
other
- The vector to add.- Returns:
- A new
SGDVector
where each element value = this.get(i) + other.get(i).
-
subtract
Subtractsother
from this vector, producing a newSGDVector
. Subtracting Dense from Dense/Sparse produces aDenseVector
, subtracting Sparse from Sparse produces aSparseVector
.- Parameters:
other
- The vector to subtract.- Returns:
- A new
SGDVector
where each element value = this.get(i) - other.get(i).
-
dot
-
outer
-
sum
-
twoNorm
-
oneNorm
-
get
Gets an element from this vector.- Parameters:
index
- The index of the element.- Returns:
- The value at that index.
-
set
Sets theindex
to thevalue
.- Parameters:
index
- The index to set.value
- The value to set it to.
-
indexOfMax
int indexOfMax()Returns the index of the maximum value. Requires probing the array.- Returns:
- The index of the maximum value.
-
maxValue
double maxValue()Returns the maximum value. Requires probing the array.- Returns:
- The maximum value.
-
minValue
double minValue()Returns the minimum value. Requires probing the array.- Returns:
- The minimum value.
-
normalize
Normalizes the vector using the supplied vector normalizer.- Parameters:
normalizer
- The kind of normalization to apply.
-
l2Distance
Synonym for euclideanDistance.- Parameters:
other
- The other vector.- Returns:
- The l2 norm of the difference between the two vectors.
-
euclideanDistance
The l2 or euclidean distance between this vector and the other vector.- Parameters:
other
- The other vector.- Returns:
- The euclidean distance between them.
-
l1Distance
The l1 or Manhattan distance between this vector and the other vector.- Parameters:
other
- The other vector.- Returns:
- The l1 distance.
-
cosineDistance
Calculates the cosine distance of two vectors. 1 - cos(x,y)- Parameters:
other
- The other vector.- Returns:
- 1 - cosine similarity (this,other)
-
cosineSimilarity
Calculates the cosine similarity of two vectors. cos(x,y) = dot(x,y) / (norm(x) * norm(y))- Parameters:
other
- The other vector.- Returns:
- cosine similarity (this,other)
-
variance
Calculates the variance of this vector.- Returns:
- The variance of the vector.
-
variance
Calculates the variance of this vector based on the supplied mean.- Parameters:
mean
- The mean of the vector.- Returns:
- The variance of the vector.
-