public interface Vector extends Cloneable
NOTE: All implementing classes must have a constructor that takes an int for cardinality and a no-arg constructor that can be used for marshalling the Writable instance
NOTE: Implementations may choose to reuse the Vector.Element in the Iterable methods
Modifier and Type | Interface and Description |
---|---|
static interface |
Vector.Element
A holder for information about a specific item in the Vector.
|
Modifier and Type | Method and Description |
---|---|
double |
aggregate(DoubleDoubleFunction aggregator,
DoubleFunction map)
Examples speak louder than words: aggregate(plus, pow(2)) is another way to say
getLengthSquared(), aggregate(max, abs) is norm(Double.POSITIVE_INFINITY).
|
double |
aggregate(Vector other,
DoubleDoubleFunction aggregator,
DoubleDoubleFunction combiner)
Generalized inner product - take two vectors, iterate over them both, using the combiner to combine together
(and possibly map in some way) each pair of values, which are then aggregated with the previous accumulated
value in the combiner.
|
Iterable<Vector.Element> |
all() |
String |
asFormatString() |
Vector |
assign(double value)
Assign the value to all elements of the receiver
|
Vector |
assign(double[] values)
Assign the values to the receiver
|
Vector |
assign(DoubleDoubleFunction f,
double y)
Apply the function to each element of the receiver, using the y value as the second argument of the
DoubleDoubleFunction
|
Vector |
assign(DoubleFunction function)
Apply the function to each element of the receiver
|
Vector |
assign(Vector other)
Assign the other vector values to the receiver
|
Vector |
assign(Vector other,
DoubleDoubleFunction function)
Apply the function to each element of the receiver and the corresponding element of the other argument
|
Vector |
clone()
Return a copy of the recipient
|
Matrix |
cross(Vector other)
Return the cross product of the receiver and the other vector
|
Vector |
divide(double x)
Return a new vector containing the values of the recipient divided by the argument
|
double |
dot(Vector x)
Return the dot product of the recipient and the argument
|
double |
get(int index)
Return the value at the given index
|
double |
getDistanceSquared(Vector v)
Get the square of the distance between this vector and the other vector.
|
Vector.Element |
getElement(int index)
Return an object of Vector.Element representing an element of this Vector.
|
double |
getIteratorAdvanceCost()
Gets an estimate of the cost (in number of operations) it takes to advance an iterator through the nonzero
elements of this vector.
|
double |
getLengthSquared()
Return the sum of squares of all elements in the vector.
|
double |
getLookupCost()
Gets an estimate of the cost (in number of operations) it takes to lookup a random element in this vector.
|
int |
getNumNondefaultElements()
Return the number of values in the recipient which are not the default value.
|
int |
getNumNonZeroElements()
Return the number of non zero elements in the vector.
|
double |
getQuick(int index)
Return the value at the given index, without checking bounds
|
void |
incrementQuick(int index,
double increment)
Increment the value at the given index by the given value.
|
boolean |
isAddConstantTime()
Return true iff adding a new (nonzero) element takes constant time for this vector.
|
boolean |
isDense()
true if this implementation should be considered dense -- that it explicitly
represents every value
|
boolean |
isSequentialAccess()
true if this implementation should be considered to be iterable in index order in an efficient way.
|
Vector |
like()
Return an empty vector of the same underlying class as the receiver
|
Vector |
like(int cardinality)
Return a new empty vector of the same underlying class as the receiver with given cardinality
|
Vector |
logNormalize()
Return a new vector containing the log(1 + entry)/ L_2 norm values of the recipient
|
Vector |
logNormalize(double power)
Return a new Vector with a normalized value calculated as log_power(1 + entry)/ L_power norm.
|
double |
maxValue() |
int |
maxValueIndex() |
void |
mergeUpdates(OrderedIntDoubleMapping updates)
Merge a set of (index, value) pairs into the vector.
|
Vector |
minus(Vector x)
Return a new vector containing the element by element difference of the recipient and the argument
|
double |
minValue() |
int |
minValueIndex() |
Iterable<Vector.Element> |
nonZeroes() |
double |
norm(double power)
Return the k-norm of the vector.
|
Vector |
normalize()
Return a new vector containing the normalized (L_2 norm) values of the recipient
|
Vector |
normalize(double power)
Return a new Vector containing the normalized (L_power norm) values of the recipient.
|
Vector |
plus(double x)
Return a new vector containing the sum of each value of the recipient and the argument
|
Vector |
plus(Vector x)
Return a new vector containing the element by element sum of the recipient and the argument
|
void |
set(int index,
double value)
Set the value at the given index
|
void |
setQuick(int index,
double value)
Set the value at the given index, without checking bounds
|
int |
size()
Return the cardinality of the recipient (the maximum number of values)
|
Vector |
times(double x)
Return a new vector containing the product of each value of the recipient and the argument
|
Vector |
times(Vector x)
Return a new vector containing the element-wise product of the recipient and the argument
|
Vector |
viewPart(int offset,
int length)
Return a new vector containing the subset of the recipient
|
double |
zSum()
Return the sum of all the elements of the receiver
|
String asFormatString()
Vector assign(double value)
value
- a double valueVector assign(double[] values)
values
- a double[] of valuesCardinalityException
- if the cardinalities differVector assign(Vector other)
other
- a VectorCardinalityException
- if the cardinalities differVector assign(DoubleFunction function)
function
- a DoubleFunction to applyVector assign(Vector other, DoubleDoubleFunction function)
other
- a Vector containing the second arguments to the functionfunction
- a DoubleDoubleFunction to applyCardinalityException
- if the cardinalities differVector assign(DoubleDoubleFunction f, double y)
f
- a DoubleDoubleFunction to be appliedy
- a double value to be argument to the functionint size()
boolean isDense()
boolean isSequentialAccess()
all()
and nonZeroes()
()} return elements
in ascending order by index.Vector clone()
Iterable<Vector.Element> all()
Iterable<Vector.Element> nonZeroes()
Vector.Element getElement(int index)
index
- Index of the Vector.Element requiredvoid mergeUpdates(OrderedIntDoubleMapping updates)
updates
- an ordered mapping of indices to values to be merged in.Vector divide(double x)
x
- a double valuedouble dot(Vector x)
x
- a VectorCardinalityException
- if the cardinalities differdouble get(int index)
index
- an int indexIndexException
- if the index is out of boundsdouble getQuick(int index)
index
- an int indexVector like()
Vector like(int cardinality)
cardinality
- - size of vectorVector
Vector minus(Vector x)
x
- a VectorCardinalityException
- if the cardinalities differVector normalize()
Vector normalize(double power)
See http://en.wikipedia.org/wiki/Lp_space
Technically, when 0 < power < 1
, we don't have a norm, just a metric,
but we'll overload this here.
Also supports power == 0
(number of non-zero elements) and power = Double.POSITIVE_INFINITY
(max element). Again, see the Wikipedia page for more info
power
- The power to use. Must be >= 0. May also be Double.POSITIVE_INFINITY
. See the Wikipedia link
for more on this.Vector logNormalize()
Vector logNormalize(double power)
power
- The power to use. Must be > 1. Cannot be Double.POSITIVE_INFINITY
.double norm(double power)
Technically, when 0 > power < 1
, we don't have a norm, just a metric, but we'll overload this here. Also supports power == 0 (number of
non-zero elements) and power = Double.POSITIVE_INFINITY
(max element). Again, see the Wikipedia page for
more info.
power
- The power to use.normalize(double)
double minValue()
int minValueIndex()
double maxValue()
int maxValueIndex()
Vector plus(double x)
x
- a doubleVector plus(Vector x)
x
- a VectorCardinalityException
- if the cardinalities differvoid set(int index, double value)
index
- an int index into the receivervalue
- a double value to setIndexException
- if the index is out of boundsvoid setQuick(int index, double value)
index
- an int index into the receivervalue
- a double value to setvoid incrementQuick(int index, double increment)
index
- an int index into the receiverincrement
- sets the value at the given index to value + increment;int getNumNondefaultElements()
int getNumNonZeroElements()
Vector times(double x)
x
- a double argumentVector times(Vector x)
x
- a Vector argumentCardinalityException
- if the cardinalities differVector viewPart(int offset, int length)
offset
- an int offset into the receiverlength
- the cardinality of the desired resultCardinalityException
- if the length is greater than the cardinality of the receiverIndexException
- if the offset is negative or the offset+length is outside of the receiverdouble zSum()
Matrix cross(Vector other)
other
- another Vectordouble aggregate(DoubleDoubleFunction aggregator, DoubleFunction map)
aggregator
- used to combine the current value of the aggregation with the result of map.apply(nextValue)map
- a function to apply to each element of the vector in turn before passing to the aggregatordouble aggregate(Vector other, DoubleDoubleFunction aggregator, DoubleDoubleFunction combiner)
Generalized inner product - take two vectors, iterate over them both, using the combiner to combine together (and possibly map in some way) each pair of values, which are then aggregated with the previous accumulated value in the combiner.
Example: dot(other) could be expressed as aggregate(other, Plus, Times), and kernelized inner products (which are symmetric on the indices) work similarly.
other
- a vector to aggregate in combination withaggregator
- function we're aggregating with; facombiner
- function we're combining with; fcif r0 = fc(this[0], other[0]), ri = fa(r_{i-1}, fc(this[i], other[i]))
for all i > 0
double getLengthSquared()
double getDistanceSquared(Vector v)
double getLookupCost()
double getIteratorAdvanceCost()
boolean isAddConstantTime()
Copyright © 2008–2017 The Apache Software Foundation. All rights reserved.