Class FreeVector<I>

java.lang.Object
eu.bandm.tools.ops.AbstractFreeVector<I>
eu.bandm.tools.ops.FreeVector<I>
Type Parameters:
I - the index type

public class FreeVector<I> extends AbstractFreeVector<I>
A real-valued vector over an index set with finitely many nonzero coordinates.
  • Constructor Details

    • FreeVector

      protected FreeVector(Map<I,Double> coords)
      Creates a new instance.
      Parameters:
      coords - a map containing at least all nonzero coordinates
  • Method Details

    • get

      public double get(I index)
      Returns the coordinate for the given index.
      Parameters:
      index - an index
      Returns:
      the coordinate for index, or zero if not specified
    • zero

      public static <I> FreeVector<I> zero()
      Returns a zero vector.
      Returns:
      a vector whose coordinates are all zero
    • unit

      public static <I> FreeVector<I> unit(I index)
      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 - if index is null
    • unit

      public static <I> FreeVector<I> unit(I index, double value)
      Returns a scaled unit vector for the given index.
      Parameters:
      index - an index
      value - the scale value
      Returns:
      a vector whose coordinate is the given value for the given index, or otherwise zero
      Throws:
      NullPointerException - if index is null
    • build

      public static <I> FreeVector<I> build(Set<I> support, ToDoubleFunction<? super I> value)
      Returns a vector with computed coordinates.
      Parameters:
      support - the set of index elements with nonzero coordinates
      value - a function to compute the coordinate for each index
      Returns:
      a vector built by evaluating value once for each element of support
      Throws:
      NullPointerException - if support or value is null
    • scale

      public FreeVector<I> scale(double factor)
      Returns a scaled copy of this vector.
      Specified by:
      scale in class AbstractFreeVector<I>
      Parameters:
      factor - the scaling factor
      Returns:
      a vector that has the coordinates of this vector multiplied by factor
    • trim

      public FreeVector<I> trim(double epsilon)
      Return a copy of this vector with coordinate values close to zero removed.
      Specified by:
      trim in class AbstractFreeVector<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

      public FreeVector<I> add(FreeVector<I> other)
      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

      public double multiply(FreeVector<I> other)
      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

      public <J> FreeVector<J> transform(Function<? super I,? extends J> fun)
      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

      public Set<I> support()
      Returns the set of indices for which this vector has explicit coordinates. All other coordinates are implicitly zero.
    • multiply

      public FreeVector<I> multiply(FreeMatrix<I> other)