public class DenseVector extends Object implements SGDVector
Modifier and Type | Field and Description |
---|---|
protected double[] |
elements |
Modifier | Constructor and Description |
---|---|
protected |
DenseVector(DenseVector other) |
protected |
DenseVector(double[] values)
Does not defensively copy the input, used internally.
|
|
DenseVector(int size) |
|
DenseVector(int size,
double value) |
Modifier and Type | Method and Description |
---|---|
void |
add(int index,
double value)
Adds
value to the element at index . |
DenseVector |
add(SGDVector other)
Adds
other to this vector, producing a new DenseVector . |
DenseVector |
copy()
Returns a deep copy of this vector.
|
static DenseVector |
createDenseVector(double[] values)
Defensively copies the values before construction.
|
double |
dot(SGDVector other)
Calculates the dot product between this vector and
other . |
boolean |
equals(Object other)
Equals is defined mathematically, that is two SGDVectors are equal iff they have the same indices
and the same values at those indices.
|
double |
euclideanDistance(SGDVector other)
The l2 or euclidean distance between this vector and the other vector.
|
void |
expNormalize(double total)
An optimisation for the exponential normalizer when
you already know the normalization constant.
|
void |
fill(double value)
Fills this
DenseVector with value . |
void |
foreachInPlace(DoubleUnaryOperator f)
Applies a
DoubleUnaryOperator elementwise to this Tensor . |
double |
get(int index)
Gets an element from this vector.
|
int[] |
getShape()
Returns an int array specifying the shape of this
Tensor . |
void |
hadamardProductInPlace(Tensor other,
DoubleUnaryOperator f)
Updates this
Tensor with the Hadamard product
(i.e., a term by term multiply) of this and other . |
int |
hashCode() |
int |
indexOfMax()
Returns the index of the maximum value.
|
void |
intersectAndAddInPlace(Tensor other,
DoubleUnaryOperator f)
Updates this
Tensor by adding all the values from the intersection with other . |
VectorIterator |
iterator() |
double |
l1Distance(SGDVector other)
The l1 or Manhattan distance between this vector and the other vector.
|
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 |
numActiveElements()
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.
|
Matrix |
outer(SGDVector other)
Generates the matrix representing the outer product between the two vectors.
|
double |
reduce(double initialValue,
DoubleUnaryOperator op,
DoubleBinaryOperator reduction)
Performs a reduction from left to right of this vector.
|
Tensor |
reshape(int[] newShape)
Reshapes the Tensor to the supplied shape.
|
DenseVector |
scale(double coefficient)
Generates a new vector with each element scaled by
coefficient . |
void |
set(int index,
double value)
Sets the
index to the value . |
void |
setElements(DenseVector other)
Sets all the elements of this vector to be the same as
other . |
int |
size()
Returns the dimensionality of this vector.
|
SparseVector |
sparsify()
Generates a
SparseVector representation from this dense vector, removing all values
with absolute value below VectorTuple.DELTA . |
SparseVector |
sparsify(double tolerance)
Generates a
SparseVector representation from this dense vector, removing all values
with absolute value below the supplied tolerance. |
DenseVector |
subtract(SGDVector other)
Subtracts
other from this vector, producing a new DenseVector . |
double |
sum()
Calculates the sum of this vector.
|
double |
sum(DoubleUnaryOperator f) |
double[] |
toArray()
Generates a copy of the values in this DenseVector.
|
String |
toString() |
double |
twoNorm()
Calculates the euclidean norm for this vector.
|
double |
variance(double mean)
Calculates the variance of this vector based on the supplied mean.
|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
cosineDistance, cosineSimilarity, l2Distance, variance
hadamardProductInPlace, intersectAndAddInPlace, scalarAddInPlace, scaleInPlace, shapeCheck, shapeSum
forEach, spliterator
public DenseVector(int size)
public DenseVector(int size, double value)
protected DenseVector(double[] values)
values
- The values of this dense vector.protected DenseVector(DenseVector other)
public static DenseVector createDenseVector(double[] values)
values
- The values of this dense vector.public double[] toArray()
This implementation uses Arrays.copyOf, and should be overridden if the get function has been modified.
public int[] getShape()
Tensor
Tensor
.public Tensor reshape(int[] newShape)
Tensor
IllegalArgumentException
if the shape isn't compatible.public DenseVector copy()
SGDVector
public int size()
SGDVector
public int numActiveElements()
SGDVector
numActiveElements
in interface SGDVector
public double reduce(double initialValue, DoubleUnaryOperator op, DoubleBinaryOperator reduction)
initialValue
- The initial value.op
- The element wise operation to apply before reducing.reduction
- The reduction operation (should be commutative).public boolean equals(Object other)
public DenseVector add(SGDVector other)
other
to this vector, producing a new DenseVector
.add
in interface SGDVector
other
- The vector to add.DenseVector
where each element value = this.get(i) + other.get(i).public DenseVector subtract(SGDVector other)
other
from this vector, producing a new DenseVector
.subtract
in interface SGDVector
other
- The vector to subtract.DenseVector
where each element value = this.get(i) - other.get(i).public void intersectAndAddInPlace(Tensor other, DoubleUnaryOperator f)
Tensor
Tensor
by adding all the values from the intersection with other
.
The function f
is applied to all values from other
before the
addition.
Each value is updated as value += f(otherValue).
intersectAndAddInPlace
in interface Tensor
other
- The other Tensor
.f
- A function to apply.public void hadamardProductInPlace(Tensor other, DoubleUnaryOperator f)
Tensor
Tensor
with the Hadamard product
(i.e., a term by term multiply) of this and other
.
The function f
is applied to all values from other
before the addition.
Each value is updated as value *= f(otherValue).
hadamardProductInPlace
in interface Tensor
other
- The other Tensor
.f
- A function to apply.public void foreachInPlace(DoubleUnaryOperator f)
Tensor
DoubleUnaryOperator
elementwise to this Tensor
.foreachInPlace
in interface Tensor
f
- The function to apply.public DenseVector scale(double coefficient)
SGDVector
coefficient
.public void add(int index, double value)
SGDVector
value
to the element at index
.public double dot(SGDVector other)
SGDVector
other
.public Matrix outer(SGDVector other)
SGDVector
public double sum()
SGDVector
public double sum(DoubleUnaryOperator f)
public double twoNorm()
SGDVector
public double oneNorm()
SGDVector
public double get(int index)
SGDVector
public void set(int index, double value)
SGDVector
index
to the value
.public void setElements(DenseVector other)
other
.other
- The DenseVector
to copy.public void fill(double value)
DenseVector
with value
.value
- The value to store in this vector.public int indexOfMax()
SGDVector
indexOfMax
in interface SGDVector
public double maxValue()
SGDVector
public double minValue()
SGDVector
public void normalize(VectorNormalizer normalizer)
SGDVector
public void expNormalize(double total)
total
- The normalization constant.public double variance(double mean)
SGDVector
public VectorIterator iterator()
iterator
in interface Iterable<VectorTuple>
public SparseVector sparsify()
SparseVector
representation from this dense vector, removing all values
with absolute value below VectorTuple.DELTA
.SparseVector
.public SparseVector sparsify(double tolerance)
SparseVector
representation from this dense vector, removing all values
with absolute value below the supplied tolerance.tolerance
- The threshold below which to set a value to zero.SparseVector
.public double euclideanDistance(SGDVector other)
euclideanDistance
in interface SGDVector
other
- The other vector.public double l1Distance(SGDVector other)
l1Distance
in interface SGDVector
other
- The other vector.Copyright © 2015–2021 Oracle and/or its affiliates. All rights reserved.