Package eu.bandm.tools.ops
Class FreeVector<I>
java.lang.Object
eu.bandm.tools.ops.AbstractFreeVector<I>
eu.bandm.tools.ops.FreeVector<I>
- Type Parameters:
I
- the index type
A real-valued vector over an index set with finitely many nonzero
coordinates.
-
Nested Class Summary
Nested Classes -
Field Summary
Fields inherited from class eu.bandm.tools.ops.AbstractFreeVector
coords
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionadd
(FreeVector<I> other) Returns a vector that is the sum of this and another vector.double
breadth()
static <I> FreeVector
<I> build
(Set<I> support, ToDoubleFunction<? super I> value) Returns a vector with computed coordinates.double
depth()
double
Returns the coordinate for the given index.multiply
(FreeMatrix<I> other) double
multiply
(FreeVector<I> other) Returns the scalar product of this and another vector.int
norm0()
double
norm1()
Returns the length of this vector measured along unit vectors.double
norm2()
Returns the length of this vector measured in a straight line.double
normMax()
scale
(double factor) Returns a scaled copy of this vector.support()
Returns the set of indices for which this vector has explicit coordinates.<J> FreeVector
<J> Returns a vector that reassigns the coordinates of this vector to different indices.trim
(double epsilon) Return a copy of this vector with coordinate values close to zero removed.static <I> FreeVector
<I> unit
(I index) Returns a unit vector for the given index.static <I> FreeVector
<I> unit
(I index, double value) Returns a scaled unit vector for the given index.static <I> FreeVector
<I> zero()
Returns a zero vector.Methods inherited from class eu.bandm.tools.ops.AbstractFreeVector
addCoords, buildCoords, nearlyEqual, scaleCoords, transformCoords, trimCoords
-
Constructor Details
-
FreeVector
Creates a new instance.- Parameters:
coords
- a map containing at least all nonzero coordinates
-
-
Method Details
-
get
Returns the coordinate for the given index.- Parameters:
index
- an index- Returns:
- the coordinate for index, or zero if not specified
-
zero
Returns a zero vector.- Returns:
- a vector whose coordinates are all zero
-
unit
Returns a unit vector for the given index.- Parameters:
index
- an index- Returns:
- a vector whose coordinate is one for the given index, or otherwise zero
- Throws:
NullPointerException
- ifindex
is null
-
unit
Returns a scaled unit vector for the given index.- Parameters:
index
- an indexvalue
- the scale value- Returns:
- a vector whose coordinate is the given value for the given index, or otherwise zero
- Throws:
NullPointerException
- ifindex
is null
-
build
Returns a vector with computed coordinates.- Parameters:
support
- the set of index elements with nonzero coordinatesvalue
- a function to compute the coordinate for each index- Returns:
- a vector built by evaluating
value
once for each element ofsupport
- Throws:
NullPointerException
- ifsupport
orvalue
is null
-
scale
Returns a scaled copy of this vector.- Specified by:
scale
in classAbstractFreeVector<I>
- Parameters:
factor
- the scaling factor- Returns:
- a vector that has the coordinates of this vector multiplied by
factor
-
trim
Return a copy of this vector with coordinate values close to zero removed.- Specified by:
trim
in classAbstractFreeVector<I>
- Parameters:
epsilon
- the largest absolute value to treat as removable- Returns:
- a vector that retains all coordinates of this vector with absolute
value greater than
epsilon
-
add
Returns a vector that is the sum of this and another vector.- Parameters:
other
- the other vector- Returns:
- a vector whose coordinates for each index are the sum of the respective coordinates of this and the other vector
-
multiply
Returns the scalar product of this and another vector.- Parameters:
other
- the other vector- Returns:
- the sum of the pairwise products of the respective coordinates of this and the other vector
-
transform
Returns a vector that reassigns the coordinates of this vector to different indices.The new indices are computed from the old ones by means of a function. If multiple old indices are mapped to the same new index, the respective coordinates are added.
- Parameters:
fun
- the index transforming function- Returns:
- a vector with coordinates from this vector reassigned to new
indices as specified by
fun
-
norm0
public int norm0() -
norm1
public double norm1()Returns the length of this vector measured along unit vectors. -
norm2
public double norm2()Returns the length of this vector measured in a straight line. -
normMax
public double normMax() -
breadth
public double breadth() -
depth
public double depth() -
support
Returns the set of indices for which this vector has explicit coordinates. All other coordinates are implicitly zero. -
multiply
-