ch.akuhn.matrix

## Class Vector

• Direct Known Subclasses:
DenseVector, SparseVector

```public abstract class Vector
extends Object```
An ordered list of floating point numbers.
Author:
• ### Nested Class Summary

Nested Classes
Modifier and Type Class and Description
`class ` `Vector.Entry`
An entry in a sparse vector
• ### Constructor Summary

Constructors
Constructor and Description
`Vector()`
• ### Method Summary

All Methods
Modifier and Type Method and Description
`double` ```add(int index, double value)```
Add the given value to the value at the given index
`void` `applyCentering()`
mean-center the vector
`static Vector` ```copy(double[] values, int start, int length)```
Copy a range from an array into a vector.
`static Vector` `dense(int size)`
Create an empty dense vector
`double` `density()`
`double` `dot(Vector x)`
Returns the dot/scalar product.
`Iterable<Vector.Entry>` `entries()`
Iterates over all entries.
`abstract boolean` ```equals(Vector v, double epsilon)```
Test for equality
`static Vector` `from(double... values)`
Construct a Vector from an array of values
`abstract double` `get(int index)`
Get the value at the given index
`double` `mean()`
`double` `norm()`
Compute the L2 norm
`abstract double` ```put(int index, double value)```
Set the value at an index
`void` ```scaleAndAddTo(double a, Vector y)```
y = y + a*`this`.
`abstract int` `size()`
`static Vector` `sparse(int size)`
Create an empty sparse vector
`void` ```storeOn(double[] array, int start)```
I/O
`double` `sum()`
`abstract Vector` `times(double scalar)`
Multiply by a constant, creating a new vector
`abstract Vector` `timesEquals(double scalar)`
Multiply by a constant in-place
`String` `toString()`
`double[]` `unwrap()`
`int` `used()`
Returns number of non-zero-valued entries.
`static Vector` `wrap(double... values)`
Wrap an array in a vector
• ### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`
• ### Constructor Detail

• #### Vector

`public Vector()`
• ### Method Detail

```public double add(int index,
double value)```
Add the given value to the value at the given index
Parameters:
`index` -
`value` -
Returns:
the new value
• #### density

`public double density()`
Returns:
the density
• #### entries

`public Iterable<Vector.Entry> entries()`
Iterates over all entries. Some vectors omit zero-valued entries.
Returns:
value and index of each entry.
• #### get

`public abstract double get(int index)`
Get the value at the given index
Parameters:
`index` -
Returns:
the value
• #### norm

`public double norm()`
Compute the L2 norm
Returns:
the L2 norm
• #### put

```public abstract double put(int index,
double value)```
Set the value at an index
Parameters:
`index` -
`value` -
Returns:
the new value
• #### size

`public abstract int size()`
Returns:
the length of the vector
• #### sum

`public double sum()`
Returns:
the sum of values
• #### used

`public int used()`
Returns number of non-zero-valued entries.
Returns:
a positive integer.
• #### from

`public static Vector from(double... values)`
Construct a Vector from an array of values
Parameters:
`values` -
Returns:
the vector
• #### copy

```public static Vector copy(double[] values,
int start,
int length)```
Copy a range from an array into a vector.
Parameters:
`values` -
`start` -
`length` -
Returns:
the vector
• #### wrap

`public static Vector wrap(double... values)`
Wrap an array in a vector
Parameters:
`values` -
Returns:
the vector
• #### dense

`public static Vector dense(int size)`
Create an empty dense vector
Parameters:
`size` -
Returns:
the vector
• #### sparse

`public static Vector sparse(int size)`
Create an empty sparse vector
Parameters:
`size` -
Returns:
the vector
• #### dot

`public double dot(Vector x)`
Returns the dot/scalar product.
Parameters:
`x` -
Returns:
the dot product

```public void scaleAndAddTo(double a,
Vector y)```
y = y + a*`this`.
Parameters:
`a` -
`y` -
• #### storeOn

```public void storeOn(double[] array,
int start)```
I/O
Parameters:
`array` -
`start` -
• #### toString

`public String toString()`
Overrides:
`toString` in class `Object`
• #### times

`public abstract Vector times(double scalar)`
Multiply by a constant, creating a new vector
Parameters:
`scalar` -
Returns:
the vector
• #### timesEquals

`public abstract Vector timesEquals(double scalar)`
Multiply by a constant in-place
Parameters:
`scalar` -
Returns:
this
• #### equals

```public abstract boolean equals(Vector v,
double epsilon)```
Test for equality
Parameters:
`v` -
`epsilon` -
Returns:
true if the same; false otherwise
• #### unwrap

`public double[] unwrap()`
Returns:
an array
• #### applyCentering

`public void applyCentering()`
mean-center the vector
• #### mean

`public double mean()`
Returns:
the mean of the values